00001 #ifndef DEBDB_PARSER_H 00002 #define DEBDB_PARSER_H 00003 00008 /* 00009 * Copyright (C) 2003,2004,2005 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/ParserBase.h> 00027 00028 #include <map> 00029 00030 namespace Debtags 00031 { 00032 00033 /* 00034 class DebDBConsumer 00035 { 00036 public: 00037 virtual void consumeField(const std::string& name, const std::string& val) throw () = 0; 00038 virtual void consumeEndOfRecord() throw () = 0; 00039 }; 00040 */ 00041 00045 class DebDBParser 00046 { 00047 protected: 00048 Tagcoll::ParserInput& in; 00049 bool isBOL; 00050 bool isEOF; 00051 00052 // Eat spaces and empty lines 00053 // Returns the number of '\n' encountered 00054 int eatSpacesAndEmptyLines() throw (Tagcoll::ParserException); 00055 00056 // Get the ^([A-Za-z0-9]+) field name 00057 std::string getFieldName() throw (Tagcoll::ParserException); 00058 00059 // Eat the \s*: characters that divide the field name and the field 00060 // data 00061 void eatFieldSep() throw (Tagcoll::ParserException); 00062 00063 // Get the \s*(.+?)\s*\n of a body line 00064 void appendFieldBody(std::string& body) throw (Tagcoll::ParserException); 00065 00066 public: 00067 typedef std::map<std::string, std::string> Record; 00068 00069 DebDBParser(Tagcoll::ParserInput& input) throw (Tagcoll::ParserException); 00070 00071 const std::string& fileName() const throw () { return in.fileName(); } 00072 int lineNumber() const throw () { return in.lineNumber(); } 00073 00074 // Read a record and positions itself at the start of the next one 00075 // Returns false when there are no more records available 00076 bool nextRecord(Record& rec) throw (Tagcoll::ParserException); 00077 }; 00078 00079 }; 00080 00081 // vim:set ts=4 sw=4: 00082 #endif