libRocket
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
BaseXMLParser.h
Go to the documentation of this file.
1 /*
2  * This source file is part of libRocket, the HTML/CSS Interface Middleware
3  *
4  * For the latest information, see http://www.librocket.com
5  *
6  * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  *
26  */
27 
28 #ifndef ROCKETCOREBASEXMLPARSER_H
29 #define ROCKETCOREBASEXMLPARSER_H
30 
31 #include "Header.h"
32 #include "Types.h"
33 #include "Dictionary.h"
34 #include <set>
35 
36 namespace Rocket {
37 namespace Core {
38 
39 class Stream;
40 
42 
48 {
49  public:
50  BaseXMLParser();
51  virtual ~BaseXMLParser();
52 
56  void RegisterCDATATag(const String& tag);
57 
60  void Parse(Stream* stream);
61 
64  int GetLineNumber();
65 
67  virtual void HandleElementStart(const String& name, const XMLAttributes& attributes);
69  virtual void HandleElementEnd(const String& name);
71  virtual void HandleData(const String& data);
72 
73  protected:
74  // The stream we're reading the XML from.
76 
77  private:
78  void ReadHeader();
79  void ReadBody();
80 
81  bool ReadOpenTag();
82  bool ReadCloseTag();
83  bool ReadAttributes(XMLAttributes& attributes);
84  bool ReadCDATA(const char* terminator = NULL);
85 
86  // Reads from the stream until a complete word is found.
87  // @param[out] word Word thats been found
88  // @param[in] terminators List of characters that terminate the search
89  bool FindWord(String& word, const char* terminators = NULL);
90  // Reads from the stream until the given character set is found. All
91  // intervening characters will be returned in data.
92  bool FindString(const unsigned char* string, String& data);
93  // Returns true if the next sequence of characters in the stream
94  // matches the given string. If consume is set and this returns true,
95  // the characters will be consumed.
96  bool PeekString(const unsigned char* string, bool consume = true);
97 
98  // Fill the buffer as much as possible, without removing any content that is still pending
99  bool FillBuffer();
100 
101  unsigned char* read;
102  unsigned char* buffer;
103  int buffer_size;
104  int buffer_used;
105  int line_number;
106  int open_tag_depth;
107 
108  // The element attributes being read.
109  XMLAttributes attributes;
110  // The loose data being read.
111  String data;
112 
113  std::set< String > cdata_tags;
114 };
115 
116 }
117 }
118 
119 #endif
#define NULL
Definition: Types.h:33
#define ROCKETCORE_API
Definition: Header.h:73
Definition: Clipboard.h:33
Definition: BaseXMLParser.h:47
Definition: Dictionary.h:44
Definition: StringBase.h:42
Definition: Stream.h:47
unsigned short word
Definition: Types.h:51
Stream * xml_source
Definition: BaseXMLParser.h:75
Dictionary XMLAttributes
Definition: BaseXMLParser.h:39