Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXXML.h
1 /********************************************************************************
2 * *
3 * X M L R e a d e r & W r i t e r *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2016,2021 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXXML_H
22 #define FXXML_H
23 
24 
25 namespace FX {
26 
27 
31 class FXAPI FXXML {
32 public:
33  enum Error {
34  ErrOK,
48  ErrEof
49  };
50  enum Direction {
51  Stop = 0,
52  Save = 1,
53  Load = 2
54  };
55  enum {
56  CRLF = 0x0001,
57  REFS = 0x0002,
58  };
59  enum {
60  UTF8 = 1,
61  UTF16LE = 2,
62  UTF16BE = 3,
63  UTF32LE = 4,
64  UTF32BE = 5
65  };
66 protected:
67  class Element; // Element info
68 protected:
69  FXchar *begptr; // Text buffer begin ptr
70  FXchar *endptr; // Text buffer end ptr
71  FXchar *wptr; // Text buffer write ptr
72  FXchar *rptr; // Text buffer read ptr
73  FXchar *sptr; // Text buffer scan ptr
74  FXlong offset; // Position from start
75  Element *current; // Current element instance
76  FXint column; // Column number
77  FXint line; // Line number
78  Direction dir; // Direction
79  FXString vers; // Version
80  FXuint enc; // Encoding
81 private:
82  FXbool need(FXival n);
83  FXbool emit(const FXchar* str,FXint count);
84  FXbool emit(FXchar ch,FXint count);
85  FXuint guess();
86  void spaces();
87  FXbool name();
88  FXbool match(FXchar ch);
89  FXbool match(const FXchar* str,FXint len);
90  Error parsestring(FXString& str);
91  Error parsexml();
92  Error parseversion();
93  Error parseencoding();
94  Error parsestandalone();
95  Error parseelementdecl();
96  Error parseexternalid();
97  Error parseinternalsubset();
98  Error parsedeclarations();
99  Error parseprocessing();
100  Error parsecomment();
101  Error parseattribute(Element& elm);
102  Error parsestarttag(Element& elm);
103  Error parseendtag(Element& elm);
104  Error parsecdata(Element& elm);
105  Error parsecontents(Element& elm);
106  Error parseelement();
107 private:
108  static const FXchar *const errors[];
109 private:
110  FXXML(const FXXML&);
111  FXXML& operator=(const FXXML&);
112 public:
113 
116 
119 
122 
125 
128 
131 
134 
135 public:
136 
140  FXXML();
141 
146  FXXML(FXchar* buffer,FXuval sz=4096,Direction d=Load);
147 
152  FXbool open(FXchar* buffer=NULL,FXuval sz=4096,Direction d=Load);
153 
157  FXuval size() const { return endptr-begptr; }
158 
162  Direction direction() const { return dir; }
163 
167  FXint getLine() const { return line; }
168 
172  FXint getColumn() const { return column; }
173 
177  FXlong getOffset() const { return offset; }
178 
183  Error parse();
184 
186  Error startDocument();
187 
189  Error startElement(const FXString& tag);
190 
192  Error startElement(const FXString& tag,const FXStringDictionary& atts);
193 
195  Error characters(const FXString& text);
196 
198  Error comment(const FXString& text);
199 
201  Error processing(const FXString& target,const FXString& text);
202 
204  Error endElement(const FXString& tag);
205 
207  Error endDocument();
208 
210  static const FXchar* getError(Error err){ return errors[err]; }
211 
215  virtual FXival fill(FXival count);
216 
220  virtual FXival flush(FXival count);
221 
225  FXbool close();
226 
230  static FXbool decode(FXString& dst,const FXString& src,FXuint flags=CRLF|REFS);
231 
235  static FXbool encode(FXString& dst,const FXString& src,FXuint flags=CRLF|REFS);
236 
240  virtual ~FXXML();
241  };
242 
243 }
244 
245 #endif
Expected semicolon.
Definition: FXXML.h:46
The XML serializer loads or saves data to xml text file.
Definition: FXXML.h:31
No errors.
Definition: FXXML.h:35
FXCallback< Error(const FXString &) > commentCB
Called to pass comment string.
Definition: FXXML.h:124
Illegal token.
Definition: FXXML.h:43
FXint getLine() const
Return current line number.
Definition: FXXML.h:167
No data loaded.
Definition: FXXML.h:36
FXCallback< Error(const FXString &) > charactersCB
Called to pass batch of decoded characters.
Definition: FXXML.h:121
FXuval size() const
Return size of parse buffer.
Definition: FXXML.h:157
Unable to load.
Definition: FXXML.h:38
Expected space.
Definition: FXXML.h:39
Expected equals sign &#39;=&#39;.
Definition: FXXML.h:40
FXCallback< Error(const FXString &, const FXString &) > processingCB
Called to pass processing instruction.
Definition: FXXML.h:127
Expected name.
Definition: FXXML.h:41
static const FXchar * getError(Error err)
Returns error code for given error.
Definition: FXXML.h:210
FXCallback< Error(const FXString &, const FXStringDictionary &) > startElementCB
Called when start of element is recognized.
Definition: FXXML.h:118
Expected hex digit.
Definition: FXXML.h:45
Error
Definition: FXXML.h:33
Definition: FX4Splitter.h:28
Unknown reference.
Definition: FXXML.h:47
Expected string.
Definition: FXXML.h:42
Direction direction() const
Return direction in effect.
Definition: FXXML.h:162
FXint getColumn() const
Return current column number.
Definition: FXXML.h:172
FXCallback< Error() > endDocumentCB
Called when end of document is recognized.
Definition: FXXML.h:133
FXCallback< Error(const FXString &) > endElementCB
Called when end of element is recognized.
Definition: FXXML.h:130
FXlong getOffset() const
Return offset from begin of file.
Definition: FXXML.h:177
FXCallback< Error() > startDocumentCB
Called when start of document is recognized.
Definition: FXXML.h:115
Direction
Definition: FXXML.h:50
Unable to save.
Definition: FXXML.h:37
The dictionary class maintains a fast-access hash table of entities indexed by a character string...
Definition: FXStringDictionary.h:31
Expected digit.
Definition: FXXML.h:44
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2020 Jeroen van der Zijp