UCommon
|
00001 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks. 00002 // Copyright (C) 2015 Cherokees of Idaho. 00003 // 00004 // This file is part of GNU uCommon C++. 00005 // 00006 // GNU uCommon C++ is free software: you can redistribute it and/or modify 00007 // it under the terms of the GNU Lesser General Public License as published 00008 // by the Free Software Foundation, either version 3 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // GNU uCommon C++ is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>. 00018 00024 #ifndef _UCOMMON_STRING_H_ 00025 #include <ucommon/string.h> 00026 #endif 00027 00028 #ifndef _UCOMMON_PROTOCOLS_H_ 00029 #include <ucommon/protocols.h> 00030 #endif 00031 00032 #ifndef _UCOMMON_XML_H_ 00033 #define _UCOMMON_XML_H_ 00034 00035 namespace ucommon { 00036 00048 class __EXPORT XMLParser 00049 { 00050 private: 00051 int ecount, dcount; 00052 enum {TAG, CDATA, COMMENT, DTD, AMP, NONE, END} state; 00053 char *buffer; 00054 unsigned bufpos, bufsize; 00055 __LOCAL bool parseTag(void); 00056 __LOCAL void putBuffer(char c); 00057 __LOCAL void clearBuffer(void); 00058 00059 protected: 00064 XMLParser(unsigned size = 8192); 00065 00069 virtual ~XMLParser(); 00070 00076 virtual void comment(caddr_t text, size_t size); 00077 00083 virtual void characters(caddr_t text, size_t size); 00084 00088 virtual void startDocument(void); 00089 00093 virtual void endDocument(void); 00094 00100 virtual void startElement(caddr_t name, caddr_t *attr) = 0; 00101 00106 virtual void endElement(caddr_t name) = 0; 00107 00117 bool partial(const char *address, size_t size); 00118 00128 bool parse(CharacterProtocol& stream); 00129 00139 bool parse(FILE *file); 00140 00145 bool end(void) const { 00146 return state == END; 00147 } 00148 }; 00149 00150 } // namespace ucommon 00151 00152 #endif