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:
00043 Parser( TagHandler* ph, bool deleteRoot = true );
00044
00048 virtual ~Parser();
00049
00056 int feed( std::string& data );
00057
00063 void cleanup( bool deleteRoot = true );
00064
00065 private:
00066 enum ParserInternalState
00067 {
00068 Initial,
00069 InterTag,
00070 TagOpening,
00071 TagOpeningSlash,
00072 TagOpeningLt,
00073 TagInside,
00074 TagNameCollect,
00075 TagNameComplete,
00076 TagNameAlmostComplete,
00077 TagAttribute,
00078 TagAttributeComplete,
00079 TagAttributeEqual,
00080 TagClosing,
00081 TagClosingSlash,
00082 TagValueApos,
00083 TagAttributeValue,
00084 TagPreamble,
00085 TagCDATASection
00086 };
00087
00088 enum ForwardScanState
00089 {
00090 ForwardFound,
00091 ForwardNotFound,
00092 ForwardInsufficientSize
00093 };
00094
00095 enum DecodeState
00096 {
00097 DecodeValid,
00098 DecodeInvalid,
00099 DecodeInsufficient
00100 };
00101
00102 void addTag();
00103 void addAttribute();
00104 void addCData();
00105 bool closeTag();
00106 bool isWhitespace( unsigned char c );
00107 bool isValid( unsigned char c );
00108 void streamEvent( Tag* tag );
00109 ForwardScanState forwardScan( std::string::size_type& pos, const std::string& data,
00110 const std::string& needle );
00111 DecodeState decode( std::string::size_type& pos, const std::string& data );
00112
00113 TagHandler* m_tagHandler;
00114 Tag* m_current;
00115 Tag* m_root;
00116 StringMap* m_xmlnss;
00117
00118 ParserInternalState m_state;
00119 Tag::AttributeList m_attribs;
00120 std::string m_tag;
00121 std::string m_cdata;
00122 std::string m_attrib;
00123 std::string m_value;
00124 std::string m_xmlns;
00125 std::string m_tagPrefix;
00126 std::string m_attribPrefix;
00127 std::string m_backBuffer;
00128 int m_preamble;
00129 bool m_quote;
00130 bool m_haveTagPrefix;
00131 bool m_haveAttribPrefix;
00132 bool m_attribIsXmlns;
00133 bool m_deleteRoot;
00134
00135 };
00136
00137 }
00138
00139 #endif // PARSER_H__