libept
recordparser.h
Go to the documentation of this file.
1#ifndef EPT_APT_RECORDPARSER_H
2#define EPT_APT_RECORDPARSER_H
3
8/*
9 * Copyright (C) 2007 Enrico Zini <enrico@enricozini.org>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26#include <vector>
27#include <string>
28
29namespace ept {
30namespace apt {
31
39{
41 std::string buffer;
42
44 std::vector<size_t> ends;
45
47 std::vector<size_t> sorted;
48
49public:
51 RecordParser(const std::string& str) { scan(str); }
52
54 void scan(const std::string& str);
55
61 size_t index(const std::string& str) const;
62
64 std::string field(size_t idx) const;
65
67 std::string name(size_t idx) const;
68
70 std::string lookup(size_t idx) const;
71
73 std::string lookup(const std::string& name) const { return lookup(index(name)); }
74
76 std::string operator[](size_t idx) const { return lookup(idx); }
77
79 std::string operator[](const std::string& name) const { return lookup(name); }
80
82 const std::string& record() const { return buffer; }
83
85 std::string record() { return buffer; }
86
88 size_t size() const { return ends.size(); }
89};
90
91}
92}
93
94// vim:set ts=4 sw=4:
95#endif
Access the fields of a package record contained inside a std::string.
Definition recordparser.h:39
std::string field(size_t idx) const
Return the field by its index.
Definition recordparser.cc:110
const std::string & record() const
Return the entire record.
Definition recordparser.h:82
RecordParser()
Definition recordparser.h:50
void scan(const std::string &str)
Index a new record.
Definition recordparser.cc:45
size_t index(const std::string &str) const
Get the index of the field with the given name.
Definition recordparser.cc:145
size_t size() const
Return the number of fields in the record.
Definition recordparser.h:88
std::string name(size_t idx) const
Return the name of a field by its index.
Definition recordparser.cc:120
std::string lookup(const std::string &name) const
Return the content of a field by its name.
Definition recordparser.h:73
RecordParser(const std::string &str)
Definition recordparser.h:51
std::string operator[](size_t idx) const
Return the content of a field by its index.
Definition recordparser.h:76
std::string lookup(size_t idx) const
Return the content of a field by its index.
Definition recordparser.cc:129
std::string operator[](const std::string &name) const
Return the content of a field by its name.
Definition recordparser.h:79
std::string record()
Return the entire record.
Definition recordparser.h:85
String functions.
Definition apt.cc:40