libept
debdbparser.h
Go to the documentation of this file.
1 #ifndef EPT_DEBTAGS_DEBDBPARSER_H
2 #define EPT_DEBTAGS_DEBDBPARSER_H
3 
8 /*
9  * Copyright (C) 2003--2007 Enrico Zini <enrico@debian.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program 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
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  */
25 
26 #include <tagcoll/input/base.h>
27 
28 // TODO: is there a way to forward-declare this?
29 #include <map>
30 
31 namespace tagcoll {
32 namespace input {
33 class Input;
34 }
35 }
36 
37 namespace ept {
38 namespace debtags {
39 
40 /*
41 class DebDBConsumer
42 {
43 public:
44  virtual void consumeField(const std::string& name, const std::string& val) throw () = 0;
45  virtual void consumeEndOfRecord() throw () = 0;
46 };
47 */
48 
53 {
54 protected:
55  tagcoll::input::Input& in;
56  bool isBOL;
57  bool isEOF;
58 
59  // Eat spaces and empty lines
60  // Returns the number of '\n' encountered
62 
63  // Get the ^([A-Za-z0-9]+) field name
64  std::string getFieldName();
65 
66  // Eat the \s*: characters that divide the field name and the field
67  // data
68  void eatFieldSep();
69 
70  // Get the \s*(.+?)\s*\n of a body line
71  void appendFieldBody(std::string& body);
72 
73 public:
74  typedef std::map<std::string, std::string> Record;
75 
76  DebDBParser(tagcoll::input::Input& input);
77 
78  const std::string& fileName() const throw () { return in.fileName(); }
79  int lineNumber() const throw () { return in.lineNumber(); }
80 
81  // Read a record and positions itself at the start of the next one
82  // Returns false when there are no more records available
83  bool nextRecord(Record& rec);
84 };
85 
86 }
87 }
88 
89 // vim:set ts=4 sw=4:
90 #endif