Coverage Report

Created: 2025-07-11 06:50

/src/xpdf-4.05/xpdf/Zoox.h
Line
Count
Source (jump to first uncovered line)
1
//========================================================================
2
//
3
// Zoox.h
4
//
5
//========================================================================
6
7
#ifndef ZOOX_H
8
#define ZOOX_H
9
10
#include <aconf.h>
11
12
#include "gtypes.h"
13
14
class GString;
15
class GList;
16
class GHash;
17
18
class ZxAttr;
19
class ZxDocTypeDecl;
20
class ZxElement;
21
class ZxXMLDecl;
22
23
//------------------------------------------------------------------------
24
25
typedef bool (*ZxWriteFunc)(void *stream, const char *data, int length);
26
27
//------------------------------------------------------------------------
28
29
class ZxNode {
30
public:
31
32
  ZxNode();
33
  virtual ~ZxNode();
34
35
0
  virtual bool isDoc() { return false; }
36
624
  virtual bool isXMLDecl()  { return false; }
37
624
  virtual bool isDocTypeDecl() { return false; }
38
0
  virtual bool isComment() { return false; }
39
0
  virtual bool isPI() { return false; }
40
72.6k
  virtual bool isElement() { return false; }
41
126k
  virtual bool isElement(const char *type) { return false; }
42
80
  virtual bool isCharData() { return false; }
43
85.6k
  virtual ZxNode *getFirstChild() { return firstChild; }
44
158k
  virtual ZxNode *getNextChild() { return next; }
45
0
  ZxNode *getParent() { return parent; }
46
  ZxNode *deleteChild(ZxNode *child);
47
  void appendChild(ZxNode *child);
48
  void insertChildAfter(ZxNode *child, ZxNode *prev);
49
  ZxElement *findFirstElement(const char *type);
50
  ZxElement *findFirstChildElement(const char *type);
51
  GList *findAllElements(const char *type);
52
  GList *findAllChildElements(const char *type);
53
  virtual void addChild(ZxNode *child);
54
55
  virtual bool write(ZxWriteFunc writeFunc, void *stream) = 0;
56
57
protected:
58
59
  void findAllElements(const char *type, GList *results);
60
61
  ZxNode *next;
62
  ZxNode *parent;
63
  ZxNode *firstChild,
64
         *lastChild;
65
};
66
67
//------------------------------------------------------------------------
68
69
class ZxDoc: public ZxNode {
70
public:
71
72
  ZxDoc();
73
74
  // Parse from memory.  Returns NULL on error.
75
  static ZxDoc *loadMem(const char *data, Guint dataLen);
76
77
  // Parse from disk.  Returns NULL on error.
78
  static ZxDoc *loadFile(const char *fileName);
79
80
  virtual ~ZxDoc();
81
82
  // Write to disk.  Returns false on error.
83
  bool writeFile(const char *fileName);
84
85
0
  virtual bool isDoc() { return true; }
86
0
  ZxXMLDecl *getXMLDecl() { return xmlDecl; }
87
0
  ZxDocTypeDecl *getDocTypeDecl() { return docTypeDecl; }
88
2.03k
  ZxElement *getRoot() { return root; }
89
  virtual void addChild(ZxNode *node);
90
91
  virtual bool write(ZxWriteFunc writeFunc, void *stream);
92
93
private:
94
95
  bool parse(const char *data, Guint dataLen);
96
  void parseXMLDecl(ZxNode *par);
97
  void parseDocTypeDecl(ZxNode *par);
98
  void parseElement(ZxNode *par);
99
  ZxAttr *parseAttr();
100
  void parseContent(ZxElement *par);
101
  void parseCharData(ZxElement *par);
102
  void appendUTF8(GString *s, unsigned int c);
103
  void parseCDSect(ZxNode *par);
104
  void parseMisc(ZxNode *par);
105
  void parseComment(ZxNode *par);
106
  void parsePI(ZxNode *par);
107
  GString *parseName();
108
  GString *parseQuotedString();
109
  void parseBOM();
110
  void parseSpace();
111
  bool match(const char *s);
112
113
  ZxXMLDecl *xmlDecl;   // may be NULL
114
  ZxDocTypeDecl *docTypeDecl; // may be NULL
115
  ZxElement *root;    // may be NULL
116
117
  const char *parsePtr;
118
  const char *parseEnd;
119
};
120
121
//------------------------------------------------------------------------
122
123
class ZxXMLDecl: public ZxNode {
124
public:
125
126
  ZxXMLDecl(GString *versionA, GString *encodingA, bool standaloneA);
127
  virtual ~ZxXMLDecl();
128
129
231
  virtual bool isXMLDecl() { return true; }
130
0
  GString *getVersion() { return version; }
131
0
  GString *getEncoding() { return encoding; }
132
0
  bool getStandalone() { return standalone; }
133
134
  virtual bool write(ZxWriteFunc writeFunc, void *stream);
135
136
private:
137
138
  GString *version;
139
  GString *encoding;    // may be NULL
140
  bool standalone;
141
};
142
143
//------------------------------------------------------------------------
144
145
class ZxDocTypeDecl: public ZxNode {
146
public:
147
148
  ZxDocTypeDecl(GString *nameA);
149
  virtual ~ZxDocTypeDecl();
150
151
0
  virtual bool isDocTypeDecl() { return true; }
152
0
  GString *getName() { return name; }
153
154
  virtual bool write(ZxWriteFunc writeFunc, void *stream);
155
156
private:
157
158
  GString *name;
159
};
160
161
//------------------------------------------------------------------------
162
163
class ZxComment: public ZxNode {
164
public:
165
166
  ZxComment(GString *textA);
167
  virtual ~ZxComment();
168
169
0
  virtual bool isComment() { return true; }
170
0
  GString *getText() { return text; }
171
172
  virtual bool write(ZxWriteFunc writeFunc, void *stream);
173
174
private:
175
176
  GString *text;
177
};
178
179
//------------------------------------------------------------------------
180
181
class ZxPI: public ZxNode {
182
public:
183
184
  ZxPI(GString *targetA, GString *textA);
185
  virtual ~ZxPI();
186
187
0
  virtual bool isPI() { return true; }
188
0
  GString *getTarget() { return target; }
189
0
  GString *getText() { return text; }
190
191
  virtual bool write(ZxWriteFunc writeFunc, void *stream);
192
193
private:
194
195
  GString *target;
196
  GString *text;
197
};
198
199
//------------------------------------------------------------------------
200
201
class ZxElement: public ZxNode {
202
public:
203
204
  ZxElement(GString *typeA);
205
  virtual ~ZxElement();
206
207
87.7k
  virtual bool isElement() { return true; }
208
  virtual bool isElement(const char *typeA);
209
173k
  GString *getType() { return type; }
210
  ZxAttr *findAttr(const char *attrName);
211
0
  ZxAttr *getFirstAttr() { return firstAttr; }
212
  void addAttr(ZxAttr *attr);
213
214
  virtual bool write(ZxWriteFunc writeFunc, void *stream);
215
216
private:
217
218
  void appendEscapedAttrValue(GString *out, GString *s);
219
220
  GString *type;
221
  GHash *attrs;     // [ZxAttr]
222
  ZxAttr *firstAttr, *lastAttr;
223
};
224
225
//------------------------------------------------------------------------
226
227
class ZxAttr {
228
public:
229
230
  ZxAttr(GString *nameA, GString *valueA);
231
  ~ZxAttr();
232
233
87.8k
  GString *getName() { return name; }
234
52.1k
  GString *getValue() { return value; }
235
0
  ZxAttr *getNextAttr() { return next; }
236
0
  ZxNode *getParent() { return parent; }
237
238
private:
239
240
  GString *name;
241
  GString *value;
242
  ZxElement *parent;
243
  ZxAttr *next;
244
245
  friend class ZxElement;
246
};
247
248
//------------------------------------------------------------------------
249
250
class ZxCharData: public ZxNode {
251
public:
252
253
  ZxCharData(GString *dataA, bool parsedA);
254
  virtual ~ZxCharData();
255
256
491
  virtual bool isCharData() { return true; }
257
491
  GString *getData() { return data; }
258
0
  bool isParsed() { return parsed; }
259
260
  virtual bool write(ZxWriteFunc writeFunc, void *stream);
261
262
private:
263
264
  GString *data;    // in UTF-8 format
265
  bool parsed;
266
};
267
268
#endif