gloox  1.0.1
parser.h
1 /*
2  Copyright (c) 2004-2012 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 
15 #ifndef PARSER_H__
16 #define PARSER_H__
17 
18 #include "gloox.h"
19 #include "taghandler.h"
20 #include "tag.h"
21 
22 #include <string>
23 
24 namespace gloox
25 {
26 
27 
34  class GLOOX_API Parser
35  {
36  public:
43  Parser( TagHandler* ph, bool deleteRoot = true );
44 
48  virtual ~Parser();
49 
56  int feed( std::string& data );
57 
63  void cleanup( bool deleteRoot = true );
64 
65  private:
66  enum ParserInternalState
67  {
68  Initial,
69  InterTag,
70  TagOpening,
71  TagOpeningSlash,
72  TagOpeningLt,
73  TagInside,
74  TagNameCollect,
75  TagNameComplete,
76  TagNameAlmostComplete,
77  TagAttribute,
78  TagAttributeComplete,
79  TagAttributeEqual,
80  TagClosing,
81  TagClosingSlash,
82  TagValueApos,
83  TagAttributeValue,
84  TagPreamble,
85  TagCDATASection
86  };
87 
88  enum ForwardScanState
89  {
90  ForwardFound,
91  ForwardNotFound,
92  ForwardInsufficientSize
93  };
94 
95  enum DecodeState
96  {
97  DecodeValid,
98  DecodeInvalid,
99  DecodeInsufficient
100  };
101 
102  void addTag();
103  void addAttribute();
104  void addCData();
105  bool closeTag();
106  bool isWhitespace( unsigned char c );
107  bool isValid( unsigned char c );
108  void streamEvent( Tag* tag );
109  ForwardScanState forwardScan( std::string::size_type& pos, const std::string& data,
110  const std::string& needle );
111  DecodeState decode( std::string::size_type& pos, const std::string& data );
112 
113  TagHandler* m_tagHandler;
114  Tag* m_current;
115  Tag* m_root;
116  StringMap* m_xmlnss;
117 
118  ParserInternalState m_state;
119  Tag::AttributeList m_attribs;
120  std::string m_tag;
121  std::string m_cdata;
122  std::string m_attrib;
123  std::string m_value;
124  std::string m_xmlns;
125  std::string m_tagPrefix;
126  std::string m_attribPrefix;
127  std::string m_backBuffer;
128  int m_preamble;
129  bool m_quote;
130  bool m_haveTagPrefix;
131  bool m_haveAttribPrefix;
132  bool m_attribIsXmlns;
133  bool m_deleteRoot;
134 
135  };
136 
137 }
138 
139 #endif // PARSER_H__