Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

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

Generated on Sun Oct 12 16:25:16 2008 for gloox by  doxygen 1.4.1