parser.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef PARSER_H__
00016 #define PARSER_H__
00017
00018 #include "gloox.h"
00019 #include "taghandler.h"
00020 #include "tag.h"
00021
00022 #include <string>
00023
00024 namespace gloox
00025 {
00026
00027
00034 class GLOOX_API Parser
00035 {
00036 public:
00041 Parser( TagHandler *ph );
00042
00046 virtual ~Parser();
00047
00053 bool feed( const std::string& data );
00054
00058 void reset() { cleanup(); }
00059
00060 private:
00061 void addTag();
00062 void addAttribute();
00063 void addCData();
00064 bool closeTag();
00065 void cleanup();
00066 bool isWhitespace( unsigned char c );
00067 bool isValid( unsigned char c );
00068 void streamEvent( Tag *tag );
00069
00070 enum ParserInternalState
00071 {
00072 Initial,
00073 TagOpening,
00074 TagOpeningSlash,
00075 TagOpeningLt,
00076 TagInside,
00077 TagNameCollect,
00078 TagNameComplete,
00079 TagAttribute,
00080 TagAttributeComplete,
00081 TagAttributeEqual,
00082 TagClosing,
00083 TagClosingSlash,
00084 TagValueApos,
00085 TagValue,
00086 TagPreamble
00087 };
00088
00089 TagHandler *m_tagHandler;
00090 Tag *m_current;
00091 Tag *m_root;
00092
00093 ParserInternalState m_state;
00094 Tag::AttributeList m_attribs;
00095 std::string m_tag;
00096 std::string m_cdata;
00097 std::string m_attrib;
00098 std::string m_value;
00099 int m_preamble;
00100 bool m_quote;
00101
00102 };
00103
00104 }
00105
00106 #endif // PARSER_H__