parser.h

00001 /*
00002   Copyright (c) 2004-2008 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
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__

Generated on Sun Apr 27 11:08:13 2008 for gloox by  doxygen 1.5.5