gloox  0.9.9.12
parser.h
1 /*
2  Copyright (c) 2004-2008 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:
41  Parser( TagHandler *ph );
42 
46  virtual ~Parser();
47 
53  bool feed( const std::string& data );
54 
58  void reset() { cleanup(); }
59 
60  private:
61  void addTag();
62  void addAttribute();
63  void addCData();
64  bool closeTag();
65  void cleanup();
66  bool isWhitespace( unsigned char c );
67  bool isValid( unsigned char c );
68  void streamEvent( Tag *tag );
69 
70  enum ParserInternalState
71  {
72  Initial,
73  TagOpening,
74  TagOpeningSlash,
75  TagOpeningLt,
76  TagInside,
77  TagNameCollect,
78  TagNameComplete,
79  TagAttribute,
80  TagAttributeComplete,
81  TagAttributeEqual,
82  TagClosing,
83  TagClosingSlash,
84  TagValueApos,
85  TagValue,
86  TagPreamble
87  };
88 
89  TagHandler *m_tagHandler;
90  Tag *m_current;
91  Tag *m_root;
92 
93  ParserInternalState m_state;
94  Tag::AttributeList m_attribs;
95  std::string m_tag;
96  std::string m_cdata;
97  std::string m_attrib;
98  std::string m_value;
99  int m_preamble;
100  bool m_quote;
101 
102  };
103 
104 }
105 
106 #endif // PARSER_H__