00001 #ifndef EPT_DEBTAGS_DEBDBPARSER_H 00002 #define EPT_DEBTAGS_DEBDBPARSER_H 00003 00008 /* 00009 * Copyright (C) 2003--2007 Enrico Zini <enrico@debian.org> 00010 * 00011 * This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License as published by 00013 * the Free Software Foundation; either version 2 of the License, or 00014 * (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 */ 00025 00026 #include <tagcoll/input/base.h> 00027 00028 // TODO: is there a way to forward-declare this? 00029 #include <map> 00030 00031 namespace tagcoll { 00032 namespace input { 00033 class Input; 00034 } 00035 } 00036 00037 namespace ept { 00038 namespace debtags { 00039 00040 /* 00041 class DebDBConsumer 00042 { 00043 public: 00044 virtual void consumeField(const std::string& name, const std::string& val) throw () = 0; 00045 virtual void consumeEndOfRecord() throw () = 0; 00046 }; 00047 */ 00048 00052 class DebDBParser 00053 { 00054 protected: 00055 tagcoll::input::Input& in; 00056 bool isBOL; 00057 bool isEOF; 00058 00059 // Eat spaces and empty lines 00060 // Returns the number of '\n' encountered 00061 int eatSpacesAndEmptyLines(); 00062 00063 // Get the ^([A-Za-z0-9]+) field name 00064 std::string getFieldName(); 00065 00066 // Eat the \s*: characters that divide the field name and the field 00067 // data 00068 void eatFieldSep(); 00069 00070 // Get the \s*(.+?)\s*\n of a body line 00071 void appendFieldBody(std::string& body); 00072 00073 public: 00074 typedef std::map<std::string, std::string> Record; 00075 00076 DebDBParser(tagcoll::input::Input& input); 00077 00078 const std::string& fileName() const throw () { return in.fileName(); } 00079 int lineNumber() const throw () { return in.lineNumber(); } 00080 00081 // Read a record and positions itself at the start of the next one 00082 // Returns false when there are no more records available 00083 bool nextRecord(Record& rec); 00084 }; 00085 00086 } 00087 } 00088 00089 // vim:set ts=4 sw=4: 00090 #endif