~ari-tczew/ubuntu/natty/clementine/lp-747113

« back to all changes in this revision

Viewing changes to 3rdparty/gloox/parser.h

  • Committer: Artur Rona
  • Date: 2011-04-04 20:05:33 UTC
  • Revision ID: ari-tczew@ubuntu.com-20110404200533-6aclzasj5pp8t1hq
* New upstream release. (LP: #747113)
* Drop all patches, have been applied upstream.
* Update debian/copyright.
* Refresh description in debian/control in order to avoid lintian error.
* Bump debhelper to 8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2004-2009 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
 
 
28
  /**
 
29
   * @brief This class implements an XML parser.
 
30
   *
 
31
   * @author Jakob Schroeter <js@camaya.net>
 
32
   * @since 0.9
 
33
   */
 
34
  class GLOOX_API Parser
 
35
  {
 
36
    public:
 
37
      /**
 
38
       * Constructs a new Parser object.
 
39
       * @param ph The object to send incoming Tags to.
 
40
       * @param deleteRoot Indicates whether a parsed Tag should be
 
41
       * deleted after pushing it upstream. Defaults to @p true.
 
42
       */
 
43
      Parser( TagHandler* ph, bool deleteRoot = true );
 
44
 
 
45
      /**
 
46
       * Virtual destructor.
 
47
       */
 
48
      virtual ~Parser();
 
49
 
 
50
      /**
 
51
       * Use this function to feed the parser with more XML.
 
52
       * @param data Raw xml to parse. It may be modified if backbuffering is necessary.
 
53
       * @return Returns @b -1 if parsing was successful. If a parse error occured, the
 
54
       * character position where the error was occured is returned.
 
55
       */
 
56
      int feed( std::string& data );
 
57
 
 
58
      /**
 
59
       * Resets internal state.
 
60
       * @param deleteRoot Whether to delete the m_root member. For
 
61
       * internal use only.
 
62
       */
 
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__