Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/xml/sax/qxml.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtXml module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
24 | ** | - | ||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
35 | ** | - | ||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||
37 | ** | - | ||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||
39 | - | |||||||||||||
40 | #include "qxml.h" | - | ||||||||||||
41 | #include "qxml_p.h" | - | ||||||||||||
42 | #include "qtextcodec.h" | - | ||||||||||||
43 | #include "qbuffer.h" | - | ||||||||||||
44 | #include "qregexp.h" | - | ||||||||||||
45 | #include "qmap.h" | - | ||||||||||||
46 | #include "qhash.h" | - | ||||||||||||
47 | #include "qstack.h" | - | ||||||||||||
48 | #include <qdebug.h> | - | ||||||||||||
49 | - | |||||||||||||
50 | - | |||||||||||||
51 | #ifdef Q_CC_BOR // borland 6 finds bogus warnings when building this file in uic3 | - | ||||||||||||
52 | # pragma warn -8080 | - | ||||||||||||
53 | #endif | - | ||||||||||||
54 | - | |||||||||||||
55 | //#define QT_QXML_DEBUG | - | ||||||||||||
56 | - | |||||||||||||
57 | // Error strings for the XML reader | - | ||||||||||||
58 | #define XMLERR_OK QT_TRANSLATE_NOOP("QXml", "no error occurred") | - | ||||||||||||
59 | #define XMLERR_ERRORBYCONSUMER QT_TRANSLATE_NOOP("QXml", "error triggered by consumer") | - | ||||||||||||
60 | #define XMLERR_UNEXPECTEDEOF QT_TRANSLATE_NOOP("QXml", "unexpected end of file") | - | ||||||||||||
61 | #define XMLERR_MORETHANONEDOCTYPE QT_TRANSLATE_NOOP("QXml", "more than one document type definition") | - | ||||||||||||
62 | #define XMLERR_ERRORPARSINGELEMENT QT_TRANSLATE_NOOP("QXml", "error occurred while parsing element") | - | ||||||||||||
63 | #define XMLERR_TAGMISMATCH QT_TRANSLATE_NOOP("QXml", "tag mismatch") | - | ||||||||||||
64 | #define XMLERR_ERRORPARSINGCONTENT QT_TRANSLATE_NOOP("QXml", "error occurred while parsing content") | - | ||||||||||||
65 | #define XMLERR_UNEXPECTEDCHARACTER QT_TRANSLATE_NOOP("QXml", "unexpected character") | - | ||||||||||||
66 | #define XMLERR_INVALIDNAMEFORPI QT_TRANSLATE_NOOP("QXml", "invalid name for processing instruction") | - | ||||||||||||
67 | #define XMLERR_VERSIONEXPECTED QT_TRANSLATE_NOOP("QXml", "version expected while reading the XML declaration") | - | ||||||||||||
68 | #define XMLERR_WRONGVALUEFORSDECL QT_TRANSLATE_NOOP("QXml", "wrong value for standalone declaration") | - | ||||||||||||
69 | #define XMLERR_EDECLORSDDECLEXPECTED QT_TRANSLATE_NOOP("QXml", "encoding declaration or standalone declaration expected while reading the XML declaration") | - | ||||||||||||
70 | #define XMLERR_SDDECLEXPECTED QT_TRANSLATE_NOOP("QXml", "standalone declaration expected while reading the XML declaration") | - | ||||||||||||
71 | #define XMLERR_ERRORPARSINGDOCTYPE QT_TRANSLATE_NOOP("QXml", "error occurred while parsing document type definition") | - | ||||||||||||
72 | #define XMLERR_LETTEREXPECTED QT_TRANSLATE_NOOP("QXml", "letter is expected") | - | ||||||||||||
73 | #define XMLERR_ERRORPARSINGCOMMENT QT_TRANSLATE_NOOP("QXml", "error occurred while parsing comment") | - | ||||||||||||
74 | #define XMLERR_ERRORPARSINGREFERENCE QT_TRANSLATE_NOOP("QXml", "error occurred while parsing reference") | - | ||||||||||||
75 | #define XMLERR_INTERNALGENERALENTITYINDTD QT_TRANSLATE_NOOP("QXml", "internal general entity reference not allowed in DTD") | - | ||||||||||||
76 | #define XMLERR_EXTERNALGENERALENTITYINAV QT_TRANSLATE_NOOP("QXml", "external parsed general entity reference not allowed in attribute value") | - | ||||||||||||
77 | #define XMLERR_EXTERNALGENERALENTITYINDTD QT_TRANSLATE_NOOP("QXml", "external parsed general entity reference not allowed in DTD") | - | ||||||||||||
78 | #define XMLERR_UNPARSEDENTITYREFERENCE QT_TRANSLATE_NOOP("QXml", "unparsed entity reference in wrong context") | - | ||||||||||||
79 | #define XMLERR_RECURSIVEENTITIES QT_TRANSLATE_NOOP("QXml", "recursive entities") | - | ||||||||||||
80 | #define XMLERR_ERRORINTEXTDECL QT_TRANSLATE_NOOP("QXml", "error in the text declaration of an external entity") | - | ||||||||||||
81 | - | |||||||||||||
82 | QT_BEGIN_NAMESPACE | - | ||||||||||||
83 | - | |||||||||||||
84 | namespace { | - | ||||||||||||
85 | - | |||||||||||||
86 | // work around missing std::stack::clear() | - | ||||||||||||
87 | template <typename Container> | - | ||||||||||||
88 | void clear(Container &c) { c = Container(); } executed 2261 times by 6 tests: end of block Executed by:
| 2261 | ||||||||||||
89 | - | |||||||||||||
90 | } | - | ||||||||||||
91 | - | |||||||||||||
92 | // the constants for the lookup table | - | ||||||||||||
93 | static const signed char cltWS = 0; // white space | - | ||||||||||||
94 | static const signed char cltPer = 1; // % | - | ||||||||||||
95 | static const signed char cltAmp = 2; // & | - | ||||||||||||
96 | static const signed char cltGt = 3; // > | - | ||||||||||||
97 | static const signed char cltLt = 4; // < | - | ||||||||||||
98 | static const signed char cltSlash = 5; // / | - | ||||||||||||
99 | static const signed char cltQm = 6; // ? | - | ||||||||||||
100 | static const signed char cltEm = 7; // ! | - | ||||||||||||
101 | static const signed char cltDash = 8; // - | - | ||||||||||||
102 | static const signed char cltCB = 9; // ] | - | ||||||||||||
103 | static const signed char cltOB = 10; // [ | - | ||||||||||||
104 | static const signed char cltEq = 11; // = | - | ||||||||||||
105 | static const signed char cltDq = 12; // " | - | ||||||||||||
106 | static const signed char cltSq = 13; // ' | - | ||||||||||||
107 | static const signed char cltUnknown = 14; | - | ||||||||||||
108 | - | |||||||||||||
109 | // character lookup table | - | ||||||||||||
110 | static const signed char charLookupTable[256]={ | - | ||||||||||||
111 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x00 - 0x07 | - | ||||||||||||
112 | cltUnknown, // 0x08 | - | ||||||||||||
113 | cltWS, // 0x09 \t | - | ||||||||||||
114 | cltWS, // 0x0A \n | - | ||||||||||||
115 | cltUnknown, // 0x0B | - | ||||||||||||
116 | cltUnknown, // 0x0C | - | ||||||||||||
117 | cltWS, // 0x0D \r | - | ||||||||||||
118 | cltUnknown, // 0x0E | - | ||||||||||||
119 | cltUnknown, // 0x0F | - | ||||||||||||
120 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x17 - 0x16 | - | ||||||||||||
121 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x18 - 0x1F | - | ||||||||||||
122 | cltWS, // 0x20 Space | - | ||||||||||||
123 | cltEm, // 0x21 ! | - | ||||||||||||
124 | cltDq, // 0x22 " | - | ||||||||||||
125 | cltUnknown, // 0x23 | - | ||||||||||||
126 | cltUnknown, // 0x24 | - | ||||||||||||
127 | cltPer, // 0x25 % | - | ||||||||||||
128 | cltAmp, // 0x26 & | - | ||||||||||||
129 | cltSq, // 0x27 ' | - | ||||||||||||
130 | cltUnknown, // 0x28 | - | ||||||||||||
131 | cltUnknown, // 0x29 | - | ||||||||||||
132 | cltUnknown, // 0x2A | - | ||||||||||||
133 | cltUnknown, // 0x2B | - | ||||||||||||
134 | cltUnknown, // 0x2C | - | ||||||||||||
135 | cltDash, // 0x2D - | - | ||||||||||||
136 | cltUnknown, // 0x2E | - | ||||||||||||
137 | cltSlash, // 0x2F / | - | ||||||||||||
138 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x30 - 0x37 | - | ||||||||||||
139 | cltUnknown, // 0x38 | - | ||||||||||||
140 | cltUnknown, // 0x39 | - | ||||||||||||
141 | cltUnknown, // 0x3A | - | ||||||||||||
142 | cltUnknown, // 0x3B | - | ||||||||||||
143 | cltLt, // 0x3C < | - | ||||||||||||
144 | cltEq, // 0x3D = | - | ||||||||||||
145 | cltGt, // 0x3E > | - | ||||||||||||
146 | cltQm, // 0x3F ? | - | ||||||||||||
147 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x40 - 0x47 | - | ||||||||||||
148 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x48 - 0x4F | - | ||||||||||||
149 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x50 - 0x57 | - | ||||||||||||
150 | cltUnknown, // 0x58 | - | ||||||||||||
151 | cltUnknown, // 0x59 | - | ||||||||||||
152 | cltUnknown, // 0x5A | - | ||||||||||||
153 | cltOB, // 0x5B [ | - | ||||||||||||
154 | cltUnknown, // 0x5C | - | ||||||||||||
155 | cltCB, // 0x5D] | - | ||||||||||||
156 | cltUnknown, // 0x5E | - | ||||||||||||
157 | cltUnknown, // 0x5F | - | ||||||||||||
158 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x60 - 0x67 | - | ||||||||||||
159 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x68 - 0x6F | - | ||||||||||||
160 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x70 - 0x77 | - | ||||||||||||
161 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x78 - 0x7F | - | ||||||||||||
162 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x80 - 0x87 | - | ||||||||||||
163 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x88 - 0x8F | - | ||||||||||||
164 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x90 - 0x97 | - | ||||||||||||
165 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0x98 - 0x9F | - | ||||||||||||
166 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0xA0 - 0xA7 | - | ||||||||||||
167 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0xA8 - 0xAF | - | ||||||||||||
168 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0xB0 - 0xB7 | - | ||||||||||||
169 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0xB8 - 0xBF | - | ||||||||||||
170 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0xC0 - 0xC7 | - | ||||||||||||
171 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0xC8 - 0xCF | - | ||||||||||||
172 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0xD0 - 0xD7 | - | ||||||||||||
173 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0xD8 - 0xDF | - | ||||||||||||
174 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0xE0 - 0xE7 | - | ||||||||||||
175 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0xE8 - 0xEF | - | ||||||||||||
176 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, // 0xF0 - 0xF7 | - | ||||||||||||
177 | cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown, cltUnknown // 0xF8 - 0xFF | - | ||||||||||||
178 | }; | - | ||||||||||||
179 | - | |||||||||||||
180 | // | - | ||||||||||||
181 | // local helper functions | - | ||||||||||||
182 | // | - | ||||||||||||
183 | - | |||||||||||||
184 | /* | - | ||||||||||||
185 | This function strips the TextDecl [77] ("<?xml ...?>") from the string \a | - | ||||||||||||
186 | str. The stripped version is stored in \a str. If this function finds an | - | ||||||||||||
187 | invalid TextDecl, it returns \c false, otherwise true. | - | ||||||||||||
188 | - | |||||||||||||
189 | This function is used for external entities since those can include an | - | ||||||||||||
190 | TextDecl that must be stripped before inserting the entity. | - | ||||||||||||
191 | */ | - | ||||||||||||
192 | static bool stripTextDecl(QString& str) | - | ||||||||||||
193 | { | - | ||||||||||||
194 | QString textDeclStart(QLatin1String("<?xml")); | - | ||||||||||||
195 | if (str.startsWith(textDeclStart)) { | - | ||||||||||||
196 | QRegExp textDecl(QString::fromLatin1( | - | ||||||||||||
197 | "^<\\?xml\\s+" | - | ||||||||||||
198 | "(version\\s*=\\s*((['\"])[-a-zA-Z0-9_.:]+\\3))?" | - | ||||||||||||
199 | "\\s*" | - | ||||||||||||
200 | "(encoding\\s*=\\s*((['\"])[A-Za-z][-a-zA-Z0-9_.]*\\6))?" | - | ||||||||||||
201 | "\\s*\\?>" | - | ||||||||||||
202 | )); | - | ||||||||||||
203 | QString strTmp = str.replace(textDecl, QLatin1String("")); | - | ||||||||||||
204 | if (strTmp.length() != str.length()) | - | ||||||||||||
205 | return false; // external entity has wrong TextDecl | - | ||||||||||||
206 | str = strTmp; | - | ||||||||||||
207 | } | - | ||||||||||||
208 | return true; | - | ||||||||||||
209 | } | - | ||||||||||||
210 | - | |||||||||||||
211 | - | |||||||||||||
212 | class QXmlAttributesPrivate | - | ||||||||||||
213 | { | - | ||||||||||||
214 | }; | - | ||||||||||||
215 | - | |||||||||||||
216 | /* \class QXmlInputSourcePrivate | - | ||||||||||||
217 | \internal | - | ||||||||||||
218 | - | |||||||||||||
219 | There's a slight misdesign in this class that can | - | ||||||||||||
220 | be worth to keep in mind: the `str' member is | - | ||||||||||||
221 | a buffer which QXmlInputSource::next() returns from, | - | ||||||||||||
222 | and which is populated from the input device or input | - | ||||||||||||
223 | stream. However, when the input is a QString(the user called | - | ||||||||||||
224 | QXmlInputSource::setData()), `str' has two roles: it's the | - | ||||||||||||
225 | buffer, but also the source. This /seems/ to be no problem | - | ||||||||||||
226 | because in the case of having no device or stream, the QString | - | ||||||||||||
227 | is read in one go. | - | ||||||||||||
228 | */ | - | ||||||||||||
229 | class QXmlInputSourcePrivate | - | ||||||||||||
230 | { | - | ||||||||||||
231 | public: | - | ||||||||||||
232 | QIODevice *inputDevice; | - | ||||||||||||
233 | QTextStream *inputStream; | - | ||||||||||||
234 | - | |||||||||||||
235 | QString str; | - | ||||||||||||
236 | const QChar *unicode; | - | ||||||||||||
237 | int pos; | - | ||||||||||||
238 | int length; | - | ||||||||||||
239 | bool nextReturnedEndOfData; | - | ||||||||||||
240 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||
241 | QTextDecoder *encMapper; | - | ||||||||||||
242 | #endif | - | ||||||||||||
243 | - | |||||||||||||
244 | QByteArray encodingDeclBytes; | - | ||||||||||||
245 | QString encodingDeclChars; | - | ||||||||||||
246 | bool lookingForEncodingDecl; | - | ||||||||||||
247 | }; | - | ||||||||||||
248 | class QXmlParseExceptionPrivate | - | ||||||||||||
249 | { | - | ||||||||||||
250 | public: | - | ||||||||||||
251 | QXmlParseExceptionPrivate() | - | ||||||||||||
252 | : column(-1), line(-1) | - | ||||||||||||
253 | { | - | ||||||||||||
254 | } | - | ||||||||||||
255 | QXmlParseExceptionPrivate(const QXmlParseExceptionPrivate &other) | - | ||||||||||||
256 | : msg(other.msg), column(other.column), line(other.line), | - | ||||||||||||
257 | pub(other.pub), sys(other.sys) | - | ||||||||||||
258 | { | - | ||||||||||||
259 | } | - | ||||||||||||
260 | - | |||||||||||||
261 | QString msg; | - | ||||||||||||
262 | int column; | - | ||||||||||||
263 | int line; | - | ||||||||||||
264 | QString pub; | - | ||||||||||||
265 | QString sys; | - | ||||||||||||
266 | - | |||||||||||||
267 | }; | - | ||||||||||||
268 | - | |||||||||||||
269 | class QXmlLocatorPrivate | - | ||||||||||||
270 | { | - | ||||||||||||
271 | }; | - | ||||||||||||
272 | - | |||||||||||||
273 | class QXmlDefaultHandlerPrivate | - | ||||||||||||
274 | { | - | ||||||||||||
275 | }; | - | ||||||||||||
276 | - | |||||||||||||
277 | /*! | - | ||||||||||||
278 | \class QXmlParseException | - | ||||||||||||
279 | \reentrant | - | ||||||||||||
280 | \brief The QXmlParseException class is used to report errors with | - | ||||||||||||
281 | the QXmlErrorHandler interface. | - | ||||||||||||
282 | - | |||||||||||||
283 | \inmodule QtXml | - | ||||||||||||
284 | \ingroup xml-tools | - | ||||||||||||
285 | - | |||||||||||||
286 | The XML subsystem constructs an instance of this class when it | - | ||||||||||||
287 | detects an error. You can retrieve the place where the error | - | ||||||||||||
288 | occurred using systemId(), publicId(), lineNumber() and | - | ||||||||||||
289 | columnNumber(), along with the error message(). The possible error | - | ||||||||||||
290 | messages are: | - | ||||||||||||
291 | - | |||||||||||||
292 | - | |||||||||||||
293 | \list | - | ||||||||||||
294 | \li "no error occurred" | - | ||||||||||||
295 | \li "error triggered by consumer" | - | ||||||||||||
296 | \li "unexpected end of file" | - | ||||||||||||
297 | \li "more than one document type definition" | - | ||||||||||||
298 | \li "error occurred while parsing element" | - | ||||||||||||
299 | \li "tag mismatch" | - | ||||||||||||
300 | \li "error occurred while parsing content" | - | ||||||||||||
301 | \li "unexpected character" | - | ||||||||||||
302 | \li "invalid name for processing instruction" | - | ||||||||||||
303 | \li "version expected while reading the XML declaration" | - | ||||||||||||
304 | \li "wrong value for standalone declaration" | - | ||||||||||||
305 | \li "encoding declaration or standalone declaration expected while reading the XML declaration" | - | ||||||||||||
306 | \li "standalone declaration expected while reading the XML declaration" | - | ||||||||||||
307 | \li "error occurred while parsing document type definition" | - | ||||||||||||
308 | \li "letter is expected" | - | ||||||||||||
309 | \li "error occurred while parsing comment" | - | ||||||||||||
310 | \li "error occurred while parsing reference" | - | ||||||||||||
311 | \li "internal general entity reference not allowed in DTD" | - | ||||||||||||
312 | \li "external parsed general entity reference not allowed in attribute value" | - | ||||||||||||
313 | \li "external parsed general entity reference not allowed in DTD" | - | ||||||||||||
314 | \li "unparsed entity reference n wrong context" | - | ||||||||||||
315 | \li "recursive entities" | - | ||||||||||||
316 | \li "error in the text declaration of an external entity" | - | ||||||||||||
317 | \endlist | - | ||||||||||||
318 | - | |||||||||||||
319 | Note that, if you want to display these error messages to your | - | ||||||||||||
320 | application's users, they will be displayed in English unless | - | ||||||||||||
321 | they are explicitly translated. | - | ||||||||||||
322 | - | |||||||||||||
323 | \sa QXmlErrorHandler, QXmlReader | - | ||||||||||||
324 | */ | - | ||||||||||||
325 | - | |||||||||||||
326 | /*! | - | ||||||||||||
327 | Constructs a parse exception with the error string \a name for | - | ||||||||||||
328 | column \a c and line \a l for the public identifier \a p and the | - | ||||||||||||
329 | system identifier \a s. | - | ||||||||||||
330 | */ | - | ||||||||||||
331 | - | |||||||||||||
332 | QXmlParseException::QXmlParseException(const QString& name, int c, int l, | - | ||||||||||||
333 | const QString& p, const QString& s) | - | ||||||||||||
334 | : d(new QXmlParseExceptionPrivate) | - | ||||||||||||
335 | { | - | ||||||||||||
336 | d->msg = name; | - | ||||||||||||
337 | d->column = c; | - | ||||||||||||
338 | d->line = l; | - | ||||||||||||
339 | d->pub = p; | - | ||||||||||||
340 | d->sys = s; | - | ||||||||||||
341 | } | - | ||||||||||||
342 | - | |||||||||||||
343 | /*! | - | ||||||||||||
344 | Creates a copy of \a other. | - | ||||||||||||
345 | */ | - | ||||||||||||
346 | QXmlParseException::QXmlParseException(const QXmlParseException& other) : | - | ||||||||||||
347 | d(new QXmlParseExceptionPrivate(*other.d)) | - | ||||||||||||
348 | { | - | ||||||||||||
349 | - | |||||||||||||
350 | } | - | ||||||||||||
351 | - | |||||||||||||
352 | /*! | - | ||||||||||||
353 | Destroys the QXmlParseException. | - | ||||||||||||
354 | */ | - | ||||||||||||
355 | QXmlParseException::~QXmlParseException() | - | ||||||||||||
356 | { | - | ||||||||||||
357 | } | - | ||||||||||||
358 | - | |||||||||||||
359 | /*! | - | ||||||||||||
360 | Returns the error message. | - | ||||||||||||
361 | */ | - | ||||||||||||
362 | QString QXmlParseException::message() const | - | ||||||||||||
363 | { | - | ||||||||||||
364 | return d->msg; | - | ||||||||||||
365 | } | - | ||||||||||||
366 | /*! | - | ||||||||||||
367 | Returns the column number where the error occurred. | - | ||||||||||||
368 | */ | - | ||||||||||||
369 | int QXmlParseException::columnNumber() const | - | ||||||||||||
370 | { | - | ||||||||||||
371 | return d->column; | - | ||||||||||||
372 | } | - | ||||||||||||
373 | /*! | - | ||||||||||||
374 | Returns the line number where the error occurred. | - | ||||||||||||
375 | */ | - | ||||||||||||
376 | int QXmlParseException::lineNumber() const | - | ||||||||||||
377 | { | - | ||||||||||||
378 | return d->line; | - | ||||||||||||
379 | } | - | ||||||||||||
380 | /*! | - | ||||||||||||
381 | Returns the public identifier where the error occurred. | - | ||||||||||||
382 | */ | - | ||||||||||||
383 | QString QXmlParseException::publicId() const | - | ||||||||||||
384 | { | - | ||||||||||||
385 | return d->pub; | - | ||||||||||||
386 | } | - | ||||||||||||
387 | /*! | - | ||||||||||||
388 | Returns the system identifier where the error occurred. | - | ||||||||||||
389 | */ | - | ||||||||||||
390 | QString QXmlParseException::systemId() const | - | ||||||||||||
391 | { | - | ||||||||||||
392 | return d->sys; | - | ||||||||||||
393 | } | - | ||||||||||||
394 | - | |||||||||||||
395 | - | |||||||||||||
396 | /*! | - | ||||||||||||
397 | \class QXmlLocator | - | ||||||||||||
398 | \reentrant | - | ||||||||||||
399 | \brief The QXmlLocator class provides the XML handler classes with | - | ||||||||||||
400 | information about the parsing position within a file. | - | ||||||||||||
401 | - | |||||||||||||
402 | \inmodule QtXml | - | ||||||||||||
403 | \ingroup xml-tools | - | ||||||||||||
404 | - | |||||||||||||
405 | The reader reports a QXmlLocator to the content handler before it | - | ||||||||||||
406 | starts to parse the document. This is done with the | - | ||||||||||||
407 | QXmlContentHandler::setDocumentLocator() function. The handler | - | ||||||||||||
408 | classes can now use this locator to get the position (lineNumber() | - | ||||||||||||
409 | and columnNumber()) that the reader has reached. | - | ||||||||||||
410 | */ | - | ||||||||||||
411 | - | |||||||||||||
412 | /*! | - | ||||||||||||
413 | Constructor. | - | ||||||||||||
414 | */ | - | ||||||||||||
415 | QXmlLocator::QXmlLocator() | - | ||||||||||||
416 | { | - | ||||||||||||
417 | } | - | ||||||||||||
418 | - | |||||||||||||
419 | /*! | - | ||||||||||||
420 | Destructor. | - | ||||||||||||
421 | */ | - | ||||||||||||
422 | QXmlLocator::~QXmlLocator() | - | ||||||||||||
423 | { | - | ||||||||||||
424 | } | - | ||||||||||||
425 | - | |||||||||||||
426 | /*! | - | ||||||||||||
427 | \fn int QXmlLocator::columnNumber() const | - | ||||||||||||
428 | - | |||||||||||||
429 | Returns the column number (starting at 1) or -1 if there is no | - | ||||||||||||
430 | column number available. | - | ||||||||||||
431 | */ | - | ||||||||||||
432 | - | |||||||||||||
433 | /*! | - | ||||||||||||
434 | \fn int QXmlLocator::lineNumber() const | - | ||||||||||||
435 | - | |||||||||||||
436 | Returns the line number (starting at 1) or -1 if there is no line | - | ||||||||||||
437 | number available. | - | ||||||||||||
438 | */ | - | ||||||||||||
439 | - | |||||||||||||
440 | class QXmlSimpleReaderLocator : public QXmlLocator | - | ||||||||||||
441 | { | - | ||||||||||||
442 | public: | - | ||||||||||||
443 | QXmlSimpleReaderLocator(QXmlSimpleReader* parent) | - | ||||||||||||
444 | { | - | ||||||||||||
445 | reader = parent; | - | ||||||||||||
446 | } | - | ||||||||||||
447 | ~QXmlSimpleReaderLocator() | - | ||||||||||||
448 | { | - | ||||||||||||
449 | } | - | ||||||||||||
450 | - | |||||||||||||
451 | int columnNumber() const Q_DECL_OVERRIDE | - | ||||||||||||
452 | { | - | ||||||||||||
453 | return (reader->d_ptr->columnNr == -1 ? -1 : reader->d_ptr->columnNr + 1); | - | ||||||||||||
454 | } | - | ||||||||||||
455 | int lineNumber() const Q_DECL_OVERRIDE | - | ||||||||||||
456 | { | - | ||||||||||||
457 | return (reader->d_ptr->lineNr == -1 ? -1 : reader->d_ptr->lineNr + 1); | - | ||||||||||||
458 | } | - | ||||||||||||
459 | // QString getPublicId() | - | ||||||||||||
460 | // QString getSystemId() | - | ||||||||||||
461 | - | |||||||||||||
462 | private: | - | ||||||||||||
463 | QXmlSimpleReader *reader; | - | ||||||||||||
464 | }; | - | ||||||||||||
465 | - | |||||||||||||
466 | /********************************************* | - | ||||||||||||
467 | * | - | ||||||||||||
468 | * QXmlNamespaceSupport | - | ||||||||||||
469 | * | - | ||||||||||||
470 | *********************************************/ | - | ||||||||||||
471 | - | |||||||||||||
472 | typedef QMap<QString, QString> NamespaceMap; | - | ||||||||||||
473 | - | |||||||||||||
474 | class QXmlNamespaceSupportPrivate | - | ||||||||||||
475 | { | - | ||||||||||||
476 | public: | - | ||||||||||||
477 | QXmlNamespaceSupportPrivate() | - | ||||||||||||
478 | { | - | ||||||||||||
479 | ns.insert(QLatin1String("xml"), QLatin1String("http://www.w3.org/XML/1998/namespace")); // the XML namespace | - | ||||||||||||
480 | } | - | ||||||||||||
481 | - | |||||||||||||
482 | ~QXmlNamespaceSupportPrivate() | - | ||||||||||||
483 | { | - | ||||||||||||
484 | } | - | ||||||||||||
485 | - | |||||||||||||
486 | QStack<NamespaceMap> nsStack; | - | ||||||||||||
487 | NamespaceMap ns; | - | ||||||||||||
488 | }; | - | ||||||||||||
489 | - | |||||||||||||
490 | /*! | - | ||||||||||||
491 | \class QXmlNamespaceSupport | - | ||||||||||||
492 | \since 4.4 | - | ||||||||||||
493 | \reentrant | - | ||||||||||||
494 | \brief The QXmlNamespaceSupport class is a helper class for XML | - | ||||||||||||
495 | readers which want to include namespace support. | - | ||||||||||||
496 | - | |||||||||||||
497 | \inmodule QtXml | - | ||||||||||||
498 | \ingroup xml-tools | - | ||||||||||||
499 | - | |||||||||||||
500 | You can set the prefix for the current namespace with setPrefix(), | - | ||||||||||||
501 | and get the list of current prefixes (or those for a given URI) | - | ||||||||||||
502 | with prefixes(). The namespace URI is available from uri(). Use | - | ||||||||||||
503 | pushContext() to start a new namespace context, and popContext() | - | ||||||||||||
504 | to return to the previous namespace context. Use splitName() or | - | ||||||||||||
505 | processName() to split a name into its prefix and local name. | - | ||||||||||||
506 | - | |||||||||||||
507 | \sa {Namespace Support via Features} | - | ||||||||||||
508 | */ | - | ||||||||||||
509 | - | |||||||||||||
510 | /*! | - | ||||||||||||
511 | Constructs a QXmlNamespaceSupport. | - | ||||||||||||
512 | */ | - | ||||||||||||
513 | QXmlNamespaceSupport::QXmlNamespaceSupport() | - | ||||||||||||
514 | { | - | ||||||||||||
515 | d = new QXmlNamespaceSupportPrivate; | - | ||||||||||||
516 | } | - | ||||||||||||
517 | - | |||||||||||||
518 | /*! | - | ||||||||||||
519 | Destroys a QXmlNamespaceSupport. | - | ||||||||||||
520 | */ | - | ||||||||||||
521 | QXmlNamespaceSupport::~QXmlNamespaceSupport() | - | ||||||||||||
522 | { | - | ||||||||||||
523 | delete d; | - | ||||||||||||
524 | } | - | ||||||||||||
525 | - | |||||||||||||
526 | /*! | - | ||||||||||||
527 | This function declares a prefix \a pre in the current namespace | - | ||||||||||||
528 | context to be the namespace URI \a uri. The prefix remains in | - | ||||||||||||
529 | force until this context is popped, unless it is shadowed in a | - | ||||||||||||
530 | descendant context. | - | ||||||||||||
531 | - | |||||||||||||
532 | Note that there is an asymmetry in this library. prefix() does not | - | ||||||||||||
533 | return the default "" prefix, even if you have declared one; to | - | ||||||||||||
534 | check for a default prefix, you must look it up explicitly using | - | ||||||||||||
535 | uri(). This asymmetry exists to make it easier to look up prefixes | - | ||||||||||||
536 | for attribute names, where the default prefix is not allowed. | - | ||||||||||||
537 | */ | - | ||||||||||||
538 | void QXmlNamespaceSupport::setPrefix(const QString& pre, const QString& uri) | - | ||||||||||||
539 | { | - | ||||||||||||
540 | if(pre.isNull()) { | - | ||||||||||||
541 | d->ns.insert(QLatin1String(""), uri); | - | ||||||||||||
542 | } else { | - | ||||||||||||
543 | d->ns.insert(pre, uri); | - | ||||||||||||
544 | } | - | ||||||||||||
545 | } | - | ||||||||||||
546 | - | |||||||||||||
547 | /*! | - | ||||||||||||
548 | Returns one of the prefixes mapped to the namespace URI \a uri. | - | ||||||||||||
549 | - | |||||||||||||
550 | If more than one prefix is currently mapped to the same URI, this | - | ||||||||||||
551 | function makes an arbitrary selection; if you want all of the | - | ||||||||||||
552 | prefixes, use prefixes() instead. | - | ||||||||||||
553 | - | |||||||||||||
554 | Note: to check for a default prefix, use the uri() function with | - | ||||||||||||
555 | an argument of "". | - | ||||||||||||
556 | */ | - | ||||||||||||
557 | QString QXmlNamespaceSupport::prefix(const QString& uri) const | - | ||||||||||||
558 | { | - | ||||||||||||
559 | NamespaceMap::const_iterator itc, it = d->ns.constBegin(); | - | ||||||||||||
560 | while ((itc=it) != d->ns.constEnd()) { | - | ||||||||||||
561 | ++it; | - | ||||||||||||
562 | if (*itc == uri && !itc.key().isEmpty()) | - | ||||||||||||
563 | return itc.key(); | - | ||||||||||||
564 | } | - | ||||||||||||
565 | return QLatin1String(""); | - | ||||||||||||
566 | } | - | ||||||||||||
567 | - | |||||||||||||
568 | /*! | - | ||||||||||||
569 | Looks up the prefix \a prefix in the current context and returns | - | ||||||||||||
570 | the currently-mapped namespace URI. Use the empty string ("") for | - | ||||||||||||
571 | the default namespace. | - | ||||||||||||
572 | */ | - | ||||||||||||
573 | QString QXmlNamespaceSupport::uri(const QString& prefix) const | - | ||||||||||||
574 | { | - | ||||||||||||
575 | return d->ns[prefix]; | - | ||||||||||||
576 | } | - | ||||||||||||
577 | - | |||||||||||||
578 | /*! | - | ||||||||||||
579 | Splits the name \a qname at the ':' and returns the prefix in \a | - | ||||||||||||
580 | prefix and the local name in \a localname. | - | ||||||||||||
581 | - | |||||||||||||
582 | \sa processName() | - | ||||||||||||
583 | */ | - | ||||||||||||
584 | void QXmlNamespaceSupport::splitName(const QString& qname, QString& prefix, | - | ||||||||||||
585 | QString& localname) const | - | ||||||||||||
586 | { | - | ||||||||||||
587 | int pos = qname.indexOf(QLatin1Char(':')); | - | ||||||||||||
588 | if (pos == -1) | - | ||||||||||||
589 | pos = qname.size(); | - | ||||||||||||
590 | - | |||||||||||||
591 | prefix = qname.left(pos); | - | ||||||||||||
592 | localname = qname.mid(pos+1); | - | ||||||||||||
593 | } | - | ||||||||||||
594 | - | |||||||||||||
595 | /*! | - | ||||||||||||
596 | Processes a raw XML 1.0 name in the current context by removing | - | ||||||||||||
597 | the prefix and looking it up among the prefixes currently | - | ||||||||||||
598 | declared. | - | ||||||||||||
599 | - | |||||||||||||
600 | \a qname is the raw XML 1.0 name to be processed. \a isAttribute | - | ||||||||||||
601 | is true if the name is an attribute name. | - | ||||||||||||
602 | - | |||||||||||||
603 | This function stores the namespace URI in \a nsuri (which will be | - | ||||||||||||
604 | set to an empty string if the raw name has an undeclared prefix), | - | ||||||||||||
605 | and stores the local name (without prefix) in \a localname (which | - | ||||||||||||
606 | will be set to an empty string if no namespace is in use). | - | ||||||||||||
607 | - | |||||||||||||
608 | Note that attribute names are processed differently than element | - | ||||||||||||
609 | names: an unprefixed element name gets the default namespace (if | - | ||||||||||||
610 | any), while an unprefixed attribute name does not. | - | ||||||||||||
611 | */ | - | ||||||||||||
612 | void QXmlNamespaceSupport::processName(const QString& qname, | - | ||||||||||||
613 | bool isAttribute, | - | ||||||||||||
614 | QString& nsuri, QString& localname) const | - | ||||||||||||
615 | { | - | ||||||||||||
616 | int len = qname.size(); | - | ||||||||||||
617 | const QChar *data = qname.constData(); | - | ||||||||||||
618 | for (int pos = 0; pos < len; ++pos) { | - | ||||||||||||
619 | if (data[pos] == QLatin1Char(':')) { | - | ||||||||||||
620 | nsuri = uri(qname.left(pos)); | - | ||||||||||||
621 | localname = qname.mid(pos + 1); | - | ||||||||||||
622 | return; | - | ||||||||||||
623 | } | - | ||||||||||||
624 | } | - | ||||||||||||
625 | - | |||||||||||||
626 | // there was no ':' | - | ||||||||||||
627 | nsuri.clear(); | - | ||||||||||||
628 | // attributes don't take default namespace | - | ||||||||||||
629 | if (!isAttribute && !d->ns.isEmpty()) { | - | ||||||||||||
630 | /* | - | ||||||||||||
631 | We want to access d->ns.value(""), but as an optimization | - | ||||||||||||
632 | we use the fact that "" compares less than any other | - | ||||||||||||
633 | string, so it's either first in the map or not there. | - | ||||||||||||
634 | */ | - | ||||||||||||
635 | NamespaceMap::const_iterator first = d->ns.constBegin(); | - | ||||||||||||
636 | if (first.key().isEmpty()) | - | ||||||||||||
637 | nsuri = first.value(); // get default namespace | - | ||||||||||||
638 | } | - | ||||||||||||
639 | localname = qname; | - | ||||||||||||
640 | } | - | ||||||||||||
641 | - | |||||||||||||
642 | /*! | - | ||||||||||||
643 | Returns a list of all the prefixes currently declared. | - | ||||||||||||
644 | - | |||||||||||||
645 | If there is a default prefix, this function does not return it in | - | ||||||||||||
646 | the list; check for the default prefix using uri() with an | - | ||||||||||||
647 | argument of "". | - | ||||||||||||
648 | */ | - | ||||||||||||
649 | QStringList QXmlNamespaceSupport::prefixes() const | - | ||||||||||||
650 | { | - | ||||||||||||
651 | QStringList list; | - | ||||||||||||
652 | - | |||||||||||||
653 | NamespaceMap::const_iterator itc, it = d->ns.constBegin(); | - | ||||||||||||
654 | while ((itc=it) != d->ns.constEnd()) { | - | ||||||||||||
655 | ++it; | - | ||||||||||||
656 | if (!itc.key().isEmpty()) | - | ||||||||||||
657 | list.append(itc.key()); | - | ||||||||||||
658 | } | - | ||||||||||||
659 | return list; | - | ||||||||||||
660 | } | - | ||||||||||||
661 | - | |||||||||||||
662 | /*! | - | ||||||||||||
663 | \overload | - | ||||||||||||
664 | - | |||||||||||||
665 | Returns a list of all prefixes currently declared for the | - | ||||||||||||
666 | namespace URI \a uri. | - | ||||||||||||
667 | - | |||||||||||||
668 | The "xml:" prefix is included. If you only want one prefix that is | - | ||||||||||||
669 | mapped to the namespace URI, and you don't care which one you get, | - | ||||||||||||
670 | use the prefix() function instead. | - | ||||||||||||
671 | - | |||||||||||||
672 | Note: The empty (default) prefix is never included in this list; | - | ||||||||||||
673 | to check for the presence of a default namespace, call uri() with | - | ||||||||||||
674 | "" as the argument. | - | ||||||||||||
675 | */ | - | ||||||||||||
676 | QStringList QXmlNamespaceSupport::prefixes(const QString& uri) const | - | ||||||||||||
677 | { | - | ||||||||||||
678 | QStringList list; | - | ||||||||||||
679 | - | |||||||||||||
680 | NamespaceMap::const_iterator itc, it = d->ns.constBegin(); | - | ||||||||||||
681 | while ((itc=it) != d->ns.constEnd()) { | - | ||||||||||||
682 | ++it; | - | ||||||||||||
683 | if (*itc == uri && !itc.key().isEmpty()) | - | ||||||||||||
684 | list.append(itc.key()); | - | ||||||||||||
685 | } | - | ||||||||||||
686 | return list; | - | ||||||||||||
687 | } | - | ||||||||||||
688 | - | |||||||||||||
689 | /*! | - | ||||||||||||
690 | Starts a new namespace context. | - | ||||||||||||
691 | - | |||||||||||||
692 | Normally, you should push a new context at the beginning of each | - | ||||||||||||
693 | XML element: the new context automatically inherits the | - | ||||||||||||
694 | declarations of its parent context, and it also keeps track of | - | ||||||||||||
695 | which declarations were made within this context. | - | ||||||||||||
696 | - | |||||||||||||
697 | \sa popContext() | - | ||||||||||||
698 | */ | - | ||||||||||||
699 | void QXmlNamespaceSupport::pushContext() | - | ||||||||||||
700 | { | - | ||||||||||||
701 | d->nsStack.push(d->ns); | - | ||||||||||||
702 | } | - | ||||||||||||
703 | - | |||||||||||||
704 | /*! | - | ||||||||||||
705 | Reverts to the previous namespace context. | - | ||||||||||||
706 | - | |||||||||||||
707 | Normally, you should pop the context at the end of each XML | - | ||||||||||||
708 | element. After popping the context, all namespace prefix mappings | - | ||||||||||||
709 | that were previously in force are restored. | - | ||||||||||||
710 | - | |||||||||||||
711 | \sa pushContext() | - | ||||||||||||
712 | */ | - | ||||||||||||
713 | void QXmlNamespaceSupport::popContext() | - | ||||||||||||
714 | { | - | ||||||||||||
715 | d->ns.clear(); | - | ||||||||||||
716 | if(!d->nsStack.isEmpty()) | - | ||||||||||||
717 | d->ns = d->nsStack.pop(); | - | ||||||||||||
718 | } | - | ||||||||||||
719 | - | |||||||||||||
720 | /*! | - | ||||||||||||
721 | Resets this namespace support object ready for reuse. | - | ||||||||||||
722 | */ | - | ||||||||||||
723 | void QXmlNamespaceSupport::reset() | - | ||||||||||||
724 | { | - | ||||||||||||
725 | QXmlNamespaceSupportPrivate *newD = new QXmlNamespaceSupportPrivate; | - | ||||||||||||
726 | delete d; | - | ||||||||||||
727 | d = newD; | - | ||||||||||||
728 | } | - | ||||||||||||
729 | - | |||||||||||||
730 | - | |||||||||||||
731 | - | |||||||||||||
732 | /********************************************* | - | ||||||||||||
733 | * | - | ||||||||||||
734 | * QXmlAttributes | - | ||||||||||||
735 | * | - | ||||||||||||
736 | *********************************************/ | - | ||||||||||||
737 | - | |||||||||||||
738 | /*! | - | ||||||||||||
739 | \class QXmlAttributes | - | ||||||||||||
740 | \reentrant | - | ||||||||||||
741 | \brief The QXmlAttributes class provides XML attributes. | - | ||||||||||||
742 | - | |||||||||||||
743 | \inmodule QtXml | - | ||||||||||||
744 | \ingroup xml-tools | - | ||||||||||||
745 | - | |||||||||||||
746 | If attributes are reported by QXmlContentHandler::startElement() | - | ||||||||||||
747 | this class is used to pass the attribute values. | - | ||||||||||||
748 | - | |||||||||||||
749 | Use index() to locate the position of an attribute in the list, | - | ||||||||||||
750 | count() to retrieve the number of attributes, and clear() to | - | ||||||||||||
751 | remove the attributes. New attributes can be added with append(). | - | ||||||||||||
752 | Use type() to get an attribute's type and value() to get its | - | ||||||||||||
753 | value. The attribute's name is available from localName() or | - | ||||||||||||
754 | qName(), and its namespace URI from uri(). | - | ||||||||||||
755 | - | |||||||||||||
756 | */ | - | ||||||||||||
757 | - | |||||||||||||
758 | /*! | - | ||||||||||||
759 | \fn QXmlAttributes::QXmlAttributes() | - | ||||||||||||
760 | - | |||||||||||||
761 | Constructs an empty attribute list. | - | ||||||||||||
762 | */ | - | ||||||||||||
763 | QXmlAttributes::QXmlAttributes() | - | ||||||||||||
764 | { | - | ||||||||||||
765 | // ### In Qt 5.0, this function was inlined and d was not initialized | - | ||||||||||||
766 | // The member cannot be used until Qt 6.0 | - | ||||||||||||
767 | Q_UNUSED(d); | - | ||||||||||||
768 | } | - | ||||||||||||
769 | - | |||||||||||||
770 | /*! | - | ||||||||||||
771 | \fn QXmlAttributes::~QXmlAttributes() | - | ||||||||||||
772 | - | |||||||||||||
773 | Destroys the attributes object. | - | ||||||||||||
774 | */ | - | ||||||||||||
775 | QXmlAttributes::~QXmlAttributes() | - | ||||||||||||
776 | { | - | ||||||||||||
777 | } | - | ||||||||||||
778 | - | |||||||||||||
779 | - | |||||||||||||
780 | /*! | - | ||||||||||||
781 | Looks up the index of an attribute by the qualified name \a qName. | - | ||||||||||||
782 | - | |||||||||||||
783 | Returns the index of the attribute or -1 if it wasn't found. | - | ||||||||||||
784 | - | |||||||||||||
785 | \sa {Namespace Support via Features} | - | ||||||||||||
786 | */ | - | ||||||||||||
787 | int QXmlAttributes::index(const QString& qName) const | - | ||||||||||||
788 | { | - | ||||||||||||
789 | for (int i = 0; i < attList.size(); ++i) { | - | ||||||||||||
790 | if (attList.at(i).qname == qName) | - | ||||||||||||
791 | return i; | - | ||||||||||||
792 | } | - | ||||||||||||
793 | return -1; | - | ||||||||||||
794 | } | - | ||||||||||||
795 | - | |||||||||||||
796 | /*! \overload | - | ||||||||||||
797 | */ | - | ||||||||||||
798 | int QXmlAttributes::index(QLatin1String qName) const | - | ||||||||||||
799 | { | - | ||||||||||||
800 | for (int i = 0; i < attList.size(); ++i) { | - | ||||||||||||
801 | if (attList.at(i).qname == qName) | - | ||||||||||||
802 | return i; | - | ||||||||||||
803 | } | - | ||||||||||||
804 | return -1; | - | ||||||||||||
805 | } | - | ||||||||||||
806 | - | |||||||||||||
807 | /*! | - | ||||||||||||
808 | \overload | - | ||||||||||||
809 | - | |||||||||||||
810 | Looks up the index of an attribute by a namespace name. | - | ||||||||||||
811 | - | |||||||||||||
812 | \a uri specifies the namespace URI, or an empty string if the name | - | ||||||||||||
813 | has no namespace URI. \a localPart specifies the attribute's local | - | ||||||||||||
814 | name. | - | ||||||||||||
815 | - | |||||||||||||
816 | Returns the index of the attribute, or -1 if it wasn't found. | - | ||||||||||||
817 | - | |||||||||||||
818 | \sa {Namespace Support via Features} | - | ||||||||||||
819 | */ | - | ||||||||||||
820 | int QXmlAttributes::index(const QString& uri, const QString& localPart) const | - | ||||||||||||
821 | { | - | ||||||||||||
822 | for (int i = 0; i < attList.size(); ++i) { | - | ||||||||||||
823 | const Attribute &att = attList.at(i); | - | ||||||||||||
824 | if (att.uri == uri && att.localname == localPart) | - | ||||||||||||
825 | return i; | - | ||||||||||||
826 | } | - | ||||||||||||
827 | return -1; | - | ||||||||||||
828 | } | - | ||||||||||||
829 | - | |||||||||||||
830 | /*! | - | ||||||||||||
831 | Returns the number of attributes in the list. | - | ||||||||||||
832 | - | |||||||||||||
833 | \sa count() | - | ||||||||||||
834 | */ | - | ||||||||||||
835 | int QXmlAttributes::length() const | - | ||||||||||||
836 | { | - | ||||||||||||
837 | return attList.count(); | - | ||||||||||||
838 | } | - | ||||||||||||
839 | - | |||||||||||||
840 | /*! | - | ||||||||||||
841 | \fn int QXmlAttributes::count() const | - | ||||||||||||
842 | - | |||||||||||||
843 | Returns the number of attributes in the list. This function is | - | ||||||||||||
844 | equivalent to length(). | - | ||||||||||||
845 | */ | - | ||||||||||||
846 | - | |||||||||||||
847 | /*! | - | ||||||||||||
848 | Looks up an attribute's local name for the attribute at position | - | ||||||||||||
849 | \a index. If no namespace processing is done, the local name is | - | ||||||||||||
850 | an empty string. | - | ||||||||||||
851 | - | |||||||||||||
852 | \sa {Namespace Support via Features} | - | ||||||||||||
853 | */ | - | ||||||||||||
854 | QString QXmlAttributes::localName(int index) const | - | ||||||||||||
855 | { | - | ||||||||||||
856 | return attList.at(index).localname; | - | ||||||||||||
857 | } | - | ||||||||||||
858 | - | |||||||||||||
859 | /*! | - | ||||||||||||
860 | Looks up an attribute's XML 1.0 qualified name for the attribute | - | ||||||||||||
861 | at position \a index. | - | ||||||||||||
862 | - | |||||||||||||
863 | \sa {Namespace Support via Features} | - | ||||||||||||
864 | */ | - | ||||||||||||
865 | QString QXmlAttributes::qName(int index) const | - | ||||||||||||
866 | { | - | ||||||||||||
867 | return attList.at(index).qname; | - | ||||||||||||
868 | } | - | ||||||||||||
869 | - | |||||||||||||
870 | /*! | - | ||||||||||||
871 | Looks up an attribute's namespace URI for the attribute at | - | ||||||||||||
872 | position \a index. If no namespace processing is done or if the | - | ||||||||||||
873 | attribute has no namespace, the namespace URI is an empty string. | - | ||||||||||||
874 | - | |||||||||||||
875 | \sa {Namespace Support via Features} | - | ||||||||||||
876 | */ | - | ||||||||||||
877 | QString QXmlAttributes::uri(int index) const | - | ||||||||||||
878 | { | - | ||||||||||||
879 | return attList.at(index).uri; | - | ||||||||||||
880 | } | - | ||||||||||||
881 | - | |||||||||||||
882 | /*! | - | ||||||||||||
883 | Looks up an attribute's type for the attribute at position \a | - | ||||||||||||
884 | index. | - | ||||||||||||
885 | - | |||||||||||||
886 | Currently only "CDATA" is returned. | - | ||||||||||||
887 | */ | - | ||||||||||||
888 | QString QXmlAttributes::type(int) const | - | ||||||||||||
889 | { | - | ||||||||||||
890 | return QLatin1String("CDATA"); | - | ||||||||||||
891 | } | - | ||||||||||||
892 | - | |||||||||||||
893 | /*! | - | ||||||||||||
894 | \overload | - | ||||||||||||
895 | - | |||||||||||||
896 | Looks up an attribute's type for the qualified name \a qName. | - | ||||||||||||
897 | - | |||||||||||||
898 | Currently only "CDATA" is returned. | - | ||||||||||||
899 | */ | - | ||||||||||||
900 | QString QXmlAttributes::type(const QString&) const | - | ||||||||||||
901 | { | - | ||||||||||||
902 | return QLatin1String("CDATA"); | - | ||||||||||||
903 | } | - | ||||||||||||
904 | - | |||||||||||||
905 | /*! | - | ||||||||||||
906 | \overload | - | ||||||||||||
907 | - | |||||||||||||
908 | Looks up an attribute's type by namespace name. | - | ||||||||||||
909 | - | |||||||||||||
910 | \a uri specifies the namespace URI and \a localName specifies the | - | ||||||||||||
911 | local name. If the name has no namespace URI, use an empty string | - | ||||||||||||
912 | for \a uri. | - | ||||||||||||
913 | - | |||||||||||||
914 | Currently only "CDATA" is returned. | - | ||||||||||||
915 | */ | - | ||||||||||||
916 | QString QXmlAttributes::type(const QString&, const QString&) const | - | ||||||||||||
917 | { | - | ||||||||||||
918 | return QLatin1String("CDATA"); | - | ||||||||||||
919 | } | - | ||||||||||||
920 | - | |||||||||||||
921 | /*! | - | ||||||||||||
922 | Returns an attribute's value for the attribute at position \a | - | ||||||||||||
923 | index. The index must be a valid position | - | ||||||||||||
924 | (i.e., 0 <= \a index < count()). | - | ||||||||||||
925 | */ | - | ||||||||||||
926 | QString QXmlAttributes::value(int index) const | - | ||||||||||||
927 | { | - | ||||||||||||
928 | return attList.at(index).value; | - | ||||||||||||
929 | } | - | ||||||||||||
930 | - | |||||||||||||
931 | /*! | - | ||||||||||||
932 | \overload | - | ||||||||||||
933 | - | |||||||||||||
934 | Returns an attribute's value for the qualified name \a qName, or an | - | ||||||||||||
935 | empty string if no attribute exists for the name given. | - | ||||||||||||
936 | - | |||||||||||||
937 | \sa {Namespace Support via Features} | - | ||||||||||||
938 | */ | - | ||||||||||||
939 | QString QXmlAttributes::value(const QString& qName) const | - | ||||||||||||
940 | { | - | ||||||||||||
941 | int i = index(qName); | - | ||||||||||||
942 | if (i == -1) | - | ||||||||||||
943 | return QString(); | - | ||||||||||||
944 | return attList.at(i).value; | - | ||||||||||||
945 | } | - | ||||||||||||
946 | - | |||||||||||||
947 | /*! | - | ||||||||||||
948 | \overload | - | ||||||||||||
949 | - | |||||||||||||
950 | Returns an attribute's value for the qualified name \a qName, or an | - | ||||||||||||
951 | empty string if no attribute exists for the name given. | - | ||||||||||||
952 | - | |||||||||||||
953 | \sa {Namespace Support via Features} | - | ||||||||||||
954 | */ | - | ||||||||||||
955 | QString QXmlAttributes::value(QLatin1String qName) const | - | ||||||||||||
956 | { | - | ||||||||||||
957 | int i = index(qName); | - | ||||||||||||
958 | if (i == -1) | - | ||||||||||||
959 | return QString(); | - | ||||||||||||
960 | return attList.at(i).value; | - | ||||||||||||
961 | } | - | ||||||||||||
962 | - | |||||||||||||
963 | /*! | - | ||||||||||||
964 | \overload | - | ||||||||||||
965 | - | |||||||||||||
966 | Returns an attribute's value by namespace name. | - | ||||||||||||
967 | - | |||||||||||||
968 | \a uri specifies the namespace URI, or an empty string if the name | - | ||||||||||||
969 | has no namespace URI. \a localName specifies the attribute's local | - | ||||||||||||
970 | name. | - | ||||||||||||
971 | */ | - | ||||||||||||
972 | QString QXmlAttributes::value(const QString& uri, const QString& localName) const | - | ||||||||||||
973 | { | - | ||||||||||||
974 | int i = index(uri, localName); | - | ||||||||||||
975 | if (i == -1) | - | ||||||||||||
976 | return QString(); | - | ||||||||||||
977 | return attList.at(i).value; | - | ||||||||||||
978 | } | - | ||||||||||||
979 | - | |||||||||||||
980 | /*! | - | ||||||||||||
981 | Clears the list of attributes. | - | ||||||||||||
982 | - | |||||||||||||
983 | \sa append() | - | ||||||||||||
984 | */ | - | ||||||||||||
985 | void QXmlAttributes::clear() | - | ||||||||||||
986 | { | - | ||||||||||||
987 | attList.clear(); | - | ||||||||||||
988 | } | - | ||||||||||||
989 | - | |||||||||||||
990 | /*! | - | ||||||||||||
991 | Appends a new attribute entry to the list of attributes. The | - | ||||||||||||
992 | qualified name of the attribute is \a qName, the namespace URI is | - | ||||||||||||
993 | \a uri and the local name is \a localPart. The value of the | - | ||||||||||||
994 | attribute is \a value. | - | ||||||||||||
995 | - | |||||||||||||
996 | \sa qName(), uri(), localName(), value() | - | ||||||||||||
997 | */ | - | ||||||||||||
998 | void QXmlAttributes::append(const QString &qName, const QString &uri, const QString &localPart, const QString &value) | - | ||||||||||||
999 | { | - | ||||||||||||
1000 | Attribute att; | - | ||||||||||||
1001 | att.qname = qName; | - | ||||||||||||
1002 | att.uri = uri; | - | ||||||||||||
1003 | att.localname = localPart; | - | ||||||||||||
1004 | att.value = value; | - | ||||||||||||
1005 | - | |||||||||||||
1006 | attList.append(att); | - | ||||||||||||
1007 | } | - | ||||||||||||
1008 | - | |||||||||||||
1009 | - | |||||||||||||
1010 | /********************************************* | - | ||||||||||||
1011 | * | - | ||||||||||||
1012 | * QXmlInputSource | - | ||||||||||||
1013 | * | - | ||||||||||||
1014 | *********************************************/ | - | ||||||||||||
1015 | - | |||||||||||||
1016 | /*! | - | ||||||||||||
1017 | \class QXmlInputSource | - | ||||||||||||
1018 | \reentrant | - | ||||||||||||
1019 | \brief The QXmlInputSource class provides the input data for the | - | ||||||||||||
1020 | QXmlReader subclasses. | - | ||||||||||||
1021 | - | |||||||||||||
1022 | \inmodule QtXml | - | ||||||||||||
1023 | \ingroup xml-tools | - | ||||||||||||
1024 | - | |||||||||||||
1025 | All subclasses of QXmlReader read the input XML document from this | - | ||||||||||||
1026 | class. | - | ||||||||||||
1027 | - | |||||||||||||
1028 | This class recognizes the encoding of the data by reading the | - | ||||||||||||
1029 | encoding declaration in the XML file if it finds one, and reading | - | ||||||||||||
1030 | the data using the corresponding encoding. If it does not find an | - | ||||||||||||
1031 | encoding declaration, then it assumes that the data is either in | - | ||||||||||||
1032 | UTF-8 or UTF-16, depending on whether it can find a byte-order | - | ||||||||||||
1033 | mark. | - | ||||||||||||
1034 | - | |||||||||||||
1035 | There are two ways to populate the input source with data: you can | - | ||||||||||||
1036 | construct it with a QIODevice* so that the input source reads the | - | ||||||||||||
1037 | data from that device. Or you can set the data explicitly with one | - | ||||||||||||
1038 | of the setData() functions. | - | ||||||||||||
1039 | - | |||||||||||||
1040 | Usually you either construct a QXmlInputSource that works on a | - | ||||||||||||
1041 | QIODevice* or you construct an empty QXmlInputSource and set the | - | ||||||||||||
1042 | data with setData(). There are only rare occasions where you would | - | ||||||||||||
1043 | want to mix both methods. | - | ||||||||||||
1044 | - | |||||||||||||
1045 | The QXmlReader subclasses use the next() function to read the | - | ||||||||||||
1046 | input character by character. If you want to start from the | - | ||||||||||||
1047 | beginning again, use reset(). | - | ||||||||||||
1048 | - | |||||||||||||
1049 | The functions data() and fetchData() are useful if you want to do | - | ||||||||||||
1050 | something with the data other than parsing, e.g. displaying the | - | ||||||||||||
1051 | raw XML file. The benefit of using the QXmlInputClass in such | - | ||||||||||||
1052 | cases is that it tries to use the correct encoding. | - | ||||||||||||
1053 | - | |||||||||||||
1054 | \sa QXmlReader, QXmlSimpleReader | - | ||||||||||||
1055 | */ | - | ||||||||||||
1056 | - | |||||||||||||
1057 | // the following two are guaranteed not to be a character | - | ||||||||||||
1058 | const ushort QXmlInputSource::EndOfData = 0xfffe; | - | ||||||||||||
1059 | const ushort QXmlInputSource::EndOfDocument = 0xffff; | - | ||||||||||||
1060 | - | |||||||||||||
1061 | /* | - | ||||||||||||
1062 | Common part of the constructors. | - | ||||||||||||
1063 | */ | - | ||||||||||||
1064 | void QXmlInputSource::init() | - | ||||||||||||
1065 | { | - | ||||||||||||
1066 | d = new QXmlInputSourcePrivate; | - | ||||||||||||
1067 | - | |||||||||||||
1068 | QT_TRY { | - | ||||||||||||
1069 | d->inputDevice = 0; | - | ||||||||||||
1070 | d->inputStream = 0; | - | ||||||||||||
1071 | - | |||||||||||||
1072 | setData(QString()); | - | ||||||||||||
1073 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||
1074 | d->encMapper = 0; | - | ||||||||||||
1075 | #endif | - | ||||||||||||
1076 | d->nextReturnedEndOfData = true; // first call to next() will call fetchData() | - | ||||||||||||
1077 | - | |||||||||||||
1078 | d->encodingDeclBytes.clear(); | - | ||||||||||||
1079 | d->encodingDeclChars.clear(); | - | ||||||||||||
1080 | d->lookingForEncodingDecl = true; | - | ||||||||||||
1081 | } QT_CATCH(...) { dead code: { delete(d); qt_noop(); } | - | ||||||||||||
1082 | delete(d); dead code: { delete(d); qt_noop(); } | - | ||||||||||||
1083 | QT_RETHROW; dead code: { delete(d); qt_noop(); } | - | ||||||||||||
1084 | } dead code: { delete(d); qt_noop(); } | - | ||||||||||||
1085 | } | - | ||||||||||||
1086 | - | |||||||||||||
1087 | /*! | - | ||||||||||||
1088 | Constructs an input source which contains no data. | - | ||||||||||||
1089 | - | |||||||||||||
1090 | \sa setData() | - | ||||||||||||
1091 | */ | - | ||||||||||||
1092 | QXmlInputSource::QXmlInputSource() | - | ||||||||||||
1093 | { | - | ||||||||||||
1094 | init(); | - | ||||||||||||
1095 | } | - | ||||||||||||
1096 | - | |||||||||||||
1097 | /*! | - | ||||||||||||
1098 | Constructs an input source and gets the data from device \a dev. | - | ||||||||||||
1099 | If \a dev is not open, it is opened in read-only mode. If \a dev | - | ||||||||||||
1100 | is 0 or it is not possible to read from the device, the input | - | ||||||||||||
1101 | source will contain no data. | - | ||||||||||||
1102 | - | |||||||||||||
1103 | \sa setData(), fetchData(), QIODevice | - | ||||||||||||
1104 | */ | - | ||||||||||||
1105 | QXmlInputSource::QXmlInputSource(QIODevice *dev) | - | ||||||||||||
1106 | { | - | ||||||||||||
1107 | init(); | - | ||||||||||||
1108 | d->inputDevice = dev; | - | ||||||||||||
1109 | if (dev->isOpen()) | - | ||||||||||||
1110 | d->inputDevice->setTextModeEnabled(false); | - | ||||||||||||
1111 | } | - | ||||||||||||
1112 | - | |||||||||||||
1113 | /*! | - | ||||||||||||
1114 | Destructor. | - | ||||||||||||
1115 | */ | - | ||||||||||||
1116 | QXmlInputSource::~QXmlInputSource() | - | ||||||||||||
1117 | { | - | ||||||||||||
1118 | // ### close the input device. | - | ||||||||||||
1119 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||
1120 | delete d->encMapper; | - | ||||||||||||
1121 | #endif | - | ||||||||||||
1122 | delete d; | - | ||||||||||||
1123 | } | - | ||||||||||||
1124 | - | |||||||||||||
1125 | /*! | - | ||||||||||||
1126 | Returns the next character of the input source. If this function | - | ||||||||||||
1127 | reaches the end of available data, it returns | - | ||||||||||||
1128 | QXmlInputSource::EndOfData. If you call next() after that, it | - | ||||||||||||
1129 | tries to fetch more data by calling fetchData(). If the | - | ||||||||||||
1130 | fetchData() call results in new data, this function returns the | - | ||||||||||||
1131 | first character of that data; otherwise it returns | - | ||||||||||||
1132 | QXmlInputSource::EndOfDocument. | - | ||||||||||||
1133 | - | |||||||||||||
1134 | Readers, such as QXmlSimpleReader, will assume that the end of | - | ||||||||||||
1135 | the XML document has been reached if the this function returns | - | ||||||||||||
1136 | QXmlInputSource::EndOfDocument, and will check that the | - | ||||||||||||
1137 | supplied input is well-formed. Therefore, when reimplementing | - | ||||||||||||
1138 | this function, it is important to ensure that this behavior is | - | ||||||||||||
1139 | duplicated. | - | ||||||||||||
1140 | - | |||||||||||||
1141 | \sa reset(), fetchData(), QXmlSimpleReader::parse(), | - | ||||||||||||
1142 | QXmlSimpleReader::parseContinue() | - | ||||||||||||
1143 | */ | - | ||||||||||||
1144 | QChar QXmlInputSource::next() | - | ||||||||||||
1145 | { | - | ||||||||||||
1146 | if (d->pos >= d->length) { | - | ||||||||||||
1147 | if (d->nextReturnedEndOfData) { | - | ||||||||||||
1148 | d->nextReturnedEndOfData = false; | - | ||||||||||||
1149 | fetchData(); | - | ||||||||||||
1150 | if (d->pos >= d->length) { | - | ||||||||||||
1151 | return EndOfDocument; | - | ||||||||||||
1152 | } | - | ||||||||||||
1153 | return next(); | - | ||||||||||||
1154 | } | - | ||||||||||||
1155 | d->nextReturnedEndOfData = true; | - | ||||||||||||
1156 | return EndOfData; | - | ||||||||||||
1157 | } | - | ||||||||||||
1158 | - | |||||||||||||
1159 | // QXmlInputSource has no way to signal encoding errors. The best we can do | - | ||||||||||||
1160 | // is return EndOfDocument. We do *not* return EndOfData, because the reader | - | ||||||||||||
1161 | // will then just call this function again to get the next char. | - | ||||||||||||
1162 | QChar c = d->unicode[d->pos++]; | - | ||||||||||||
1163 | if (c.unicode() == EndOfData) | - | ||||||||||||
1164 | c = EndOfDocument; | - | ||||||||||||
1165 | return c; | - | ||||||||||||
1166 | } | - | ||||||||||||
1167 | - | |||||||||||||
1168 | /*! | - | ||||||||||||
1169 | This function sets the position used by next() to the beginning of | - | ||||||||||||
1170 | the data returned by data(). This is useful if you want to use the | - | ||||||||||||
1171 | input source for more than one parse. | - | ||||||||||||
1172 | - | |||||||||||||
1173 | \note In the case that the underlying data source is a QIODevice, | - | ||||||||||||
1174 | the current position in the device is not automatically set to the | - | ||||||||||||
1175 | start of input. Call QIODevice::seek(0) on the device to do this. | - | ||||||||||||
1176 | - | |||||||||||||
1177 | \sa next() | - | ||||||||||||
1178 | */ | - | ||||||||||||
1179 | void QXmlInputSource::reset() | - | ||||||||||||
1180 | { | - | ||||||||||||
1181 | d->nextReturnedEndOfData = false; | - | ||||||||||||
1182 | d->pos = 0; | - | ||||||||||||
1183 | } | - | ||||||||||||
1184 | - | |||||||||||||
1185 | /*! | - | ||||||||||||
1186 | Returns the data the input source contains or an empty string if the | - | ||||||||||||
1187 | input source does not contain any data. | - | ||||||||||||
1188 | - | |||||||||||||
1189 | \sa setData(), QXmlInputSource(), fetchData() | - | ||||||||||||
1190 | */ | - | ||||||||||||
1191 | QString QXmlInputSource::data() const | - | ||||||||||||
1192 | { | - | ||||||||||||
1193 | if (d->nextReturnedEndOfData) { | - | ||||||||||||
1194 | QXmlInputSource *that = const_cast<QXmlInputSource*>(this); | - | ||||||||||||
1195 | that->d->nextReturnedEndOfData = false; | - | ||||||||||||
1196 | that->fetchData(); | - | ||||||||||||
1197 | } | - | ||||||||||||
1198 | return d->str; | - | ||||||||||||
1199 | } | - | ||||||||||||
1200 | - | |||||||||||||
1201 | /*! | - | ||||||||||||
1202 | Sets the data of the input source to \a dat. | - | ||||||||||||
1203 | - | |||||||||||||
1204 | If the input source already contains data, this function deletes | - | ||||||||||||
1205 | that data first. | - | ||||||||||||
1206 | - | |||||||||||||
1207 | \sa data() | - | ||||||||||||
1208 | */ | - | ||||||||||||
1209 | void QXmlInputSource::setData(const QString& dat) | - | ||||||||||||
1210 | { | - | ||||||||||||
1211 | d->str = dat; | - | ||||||||||||
1212 | d->unicode = dat.unicode(); | - | ||||||||||||
1213 | d->pos = 0; | - | ||||||||||||
1214 | d->length = d->str.length(); | - | ||||||||||||
1215 | d->nextReturnedEndOfData = false; | - | ||||||||||||
1216 | } | - | ||||||||||||
1217 | - | |||||||||||||
1218 | /*! | - | ||||||||||||
1219 | \overload | - | ||||||||||||
1220 | - | |||||||||||||
1221 | The data \a dat is passed through the correct text-codec, before | - | ||||||||||||
1222 | it is set. | - | ||||||||||||
1223 | */ | - | ||||||||||||
1224 | void QXmlInputSource::setData(const QByteArray& dat) | - | ||||||||||||
1225 | { | - | ||||||||||||
1226 | setData(fromRawData(dat)); | - | ||||||||||||
1227 | } | - | ||||||||||||
1228 | - | |||||||||||||
1229 | /*! | - | ||||||||||||
1230 | This function reads more data from the device that was set during | - | ||||||||||||
1231 | construction. If the input source already contained data, this | - | ||||||||||||
1232 | function deletes that data first. | - | ||||||||||||
1233 | - | |||||||||||||
1234 | This object contains no data after a call to this function if the | - | ||||||||||||
1235 | object was constructed without a device to read data from or if | - | ||||||||||||
1236 | this function was not able to get more data from the device. | - | ||||||||||||
1237 | - | |||||||||||||
1238 | There are two occasions where a fetch is done implicitly by | - | ||||||||||||
1239 | another function call: during construction (so that the object | - | ||||||||||||
1240 | starts out with some initial data where available), and during a | - | ||||||||||||
1241 | call to next() (if the data had run out). | - | ||||||||||||
1242 | - | |||||||||||||
1243 | You don't normally need to use this function if you use next(). | - | ||||||||||||
1244 | - | |||||||||||||
1245 | \sa data(), next(), QXmlInputSource() | - | ||||||||||||
1246 | */ | - | ||||||||||||
1247 | - | |||||||||||||
1248 | void QXmlInputSource::fetchData() | - | ||||||||||||
1249 | { | - | ||||||||||||
1250 | enum | - | ||||||||||||
1251 | { | - | ||||||||||||
1252 | BufferSize = 1024 | - | ||||||||||||
1253 | }; | - | ||||||||||||
1254 | - | |||||||||||||
1255 | QByteArray rawData; | - | ||||||||||||
1256 | - | |||||||||||||
1257 | if (d->inputDevice || d->inputStream) { | - | ||||||||||||
1258 | QIODevice *device = d->inputDevice ? d->inputDevice : d->inputStream->device(); | - | ||||||||||||
1259 | - | |||||||||||||
1260 | if (!device) { | - | ||||||||||||
1261 | if (d->inputStream && d->inputStream->string()) { | - | ||||||||||||
1262 | QString *s = d->inputStream->string(); | - | ||||||||||||
1263 | rawData = QByteArray((const char *) s->constData(), s->size() * sizeof(QChar)); | - | ||||||||||||
1264 | } | - | ||||||||||||
1265 | } else if (device->isOpen() || device->open(QIODevice::ReadOnly)) { | - | ||||||||||||
1266 | rawData.resize(BufferSize); | - | ||||||||||||
1267 | qint64 size = device->read(rawData.data(), BufferSize); | - | ||||||||||||
1268 | - | |||||||||||||
1269 | if (size != -1) { | - | ||||||||||||
1270 | // We don't want to give fromRawData() less than four bytes if we can avoid it. | - | ||||||||||||
1271 | while (size < 4) { | - | ||||||||||||
1272 | if (!device->waitForReadyRead(-1)) | - | ||||||||||||
1273 | break; | - | ||||||||||||
1274 | int ret = device->read(rawData.data() + size, BufferSize - size); | - | ||||||||||||
1275 | if (ret <= 0) | - | ||||||||||||
1276 | break; | - | ||||||||||||
1277 | size += ret; | - | ||||||||||||
1278 | } | - | ||||||||||||
1279 | } | - | ||||||||||||
1280 | - | |||||||||||||
1281 | rawData.resize(qMax(qint64(0), size)); | - | ||||||||||||
1282 | } | - | ||||||||||||
1283 | - | |||||||||||||
1284 | /* We do this inside the "if (d->inputDevice ..." scope | - | ||||||||||||
1285 | * because if we're not using a stream or device, that is, | - | ||||||||||||
1286 | * the user set a QString manually, we don't want to set | - | ||||||||||||
1287 | * d->str. */ | - | ||||||||||||
1288 | setData(fromRawData(rawData)); | - | ||||||||||||
1289 | } | - | ||||||||||||
1290 | } | - | ||||||||||||
1291 | - | |||||||||||||
1292 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||
1293 | static QString extractEncodingDecl(const QString &text, bool *needMoreText) | - | ||||||||||||
1294 | { | - | ||||||||||||
1295 | *needMoreText = false; | - | ||||||||||||
1296 | - | |||||||||||||
1297 | int l = text.length(); | - | ||||||||||||
1298 | QStringconst QLatin1String snip= QString::fromLatin1("<?xml").left, std::min(l);, 5)); | - | ||||||||||||
1299 | if (l > 0 && !text.startsWith(snip))
| 6-3097 | ||||||||||||
1300 | return QString(); executed 1742 times by 2 tests: return QString(); Executed by:
| 1742 | ||||||||||||
1301 | - | |||||||||||||
1302 | int endPos = text.indexOf(QLatin1Char('>')); | - | ||||||||||||
1303 | if (endPos == -1) {
| 119-1242 | ||||||||||||
1304 | *needMoreText = l < 255; // we won't look forever | - | ||||||||||||
1305 | return QString(); executed 1242 times by 1 test: return QString(); Executed by:
| 1242 | ||||||||||||
1306 | } | - | ||||||||||||
1307 | - | |||||||||||||
1308 | int pos = text.indexOf(QLatin1String("encoding")); | - | ||||||||||||
1309 | if (pos == -1 || pos >= endPos)
| 0-67 | ||||||||||||
1310 | return QString(); executed 52 times by 1 test: return QString(); Executed by:
| 52 | ||||||||||||
1311 | - | |||||||||||||
1312 | while (pos < endPos) {
| 0-670 | ||||||||||||
1313 | ushort uc = text.at(pos).unicode(); | - | ||||||||||||
1314 | if (uc == '\'' || uc == '"')
| 0-670 | ||||||||||||
1315 | break; executed 67 times by 2 tests: break; Executed by:
| 67 | ||||||||||||
1316 | ++pos; | - | ||||||||||||
1317 | } executed 603 times by 2 tests: end of block Executed by:
| 603 | ||||||||||||
1318 | - | |||||||||||||
1319 | if (pos == endPos)
| 0-67 | ||||||||||||
1320 | return QString(); never executed: return QString(); | 0 | ||||||||||||
1321 | - | |||||||||||||
1322 | QString encoding; | - | ||||||||||||
1323 | ++pos; | - | ||||||||||||
1324 | while (pos < endPos) {
| 0-404 | ||||||||||||
1325 | ushort uc = text.at(pos).unicode(); | - | ||||||||||||
1326 | if (uc == '\'' || uc == '"')
| 0-404 | ||||||||||||
1327 | break; executed 67 times by 2 tests: break; Executed by:
| 67 | ||||||||||||
1328 | encoding.append(uc); | - | ||||||||||||
1329 | ++pos; | - | ||||||||||||
1330 | } executed 337 times by 2 tests: end of block Executed by:
| 337 | ||||||||||||
1331 | - | |||||||||||||
1332 | return encoding; executed 67 times by 2 tests: return encoding; Executed by:
| 67 | ||||||||||||
1333 | } | - | ||||||||||||
1334 | #endif // QT_NO_TEXTCODEC | - | ||||||||||||
1335 | - | |||||||||||||
1336 | /*! | - | ||||||||||||
1337 | This function reads the XML file from \a data and tries to | - | ||||||||||||
1338 | recognize the encoding. It converts the raw data \a data into a | - | ||||||||||||
1339 | QString and returns it. It tries its best to get the correct | - | ||||||||||||
1340 | encoding for the XML file. | - | ||||||||||||
1341 | - | |||||||||||||
1342 | If \a beginning is true, this function assumes that the data | - | ||||||||||||
1343 | starts at the beginning of a new XML document and looks for an | - | ||||||||||||
1344 | encoding declaration. If \a beginning is false, it converts the | - | ||||||||||||
1345 | raw data using the encoding determined from prior calls. | - | ||||||||||||
1346 | */ | - | ||||||||||||
1347 | QString QXmlInputSource::fromRawData(const QByteArray &data, bool beginning) | - | ||||||||||||
1348 | { | - | ||||||||||||
1349 | #ifdef QT_NO_TEXTCODEC | - | ||||||||||||
1350 | Q_UNUSED(beginning); | - | ||||||||||||
1351 | return QString::fromLatin1(data.constData(), data.size()); | - | ||||||||||||
1352 | #else | - | ||||||||||||
1353 | if (data.size() == 0) | - | ||||||||||||
1354 | return QString(); | - | ||||||||||||
1355 | if (beginning) { | - | ||||||||||||
1356 | delete d->encMapper; | - | ||||||||||||
1357 | d->encMapper = 0; | - | ||||||||||||
1358 | } | - | ||||||||||||
1359 | - | |||||||||||||
1360 | int mib = 106; // UTF-8 | - | ||||||||||||
1361 | - | |||||||||||||
1362 | // This is the initial UTF codec we will read the encoding declaration with | - | ||||||||||||
1363 | if (d->encMapper == 0) { | - | ||||||||||||
1364 | d->encodingDeclBytes.clear(); | - | ||||||||||||
1365 | d->encodingDeclChars.clear(); | - | ||||||||||||
1366 | d->lookingForEncodingDecl = true; | - | ||||||||||||
1367 | - | |||||||||||||
1368 | // look for byte order mark and read the first 5 characters | - | ||||||||||||
1369 | if (data.size() >= 4) { | - | ||||||||||||
1370 | uchar ch1 = data.at(0); | - | ||||||||||||
1371 | uchar ch2 = data.at(1); | - | ||||||||||||
1372 | uchar ch3 = data.at(2); | - | ||||||||||||
1373 | uchar ch4 = data.at(3); | - | ||||||||||||
1374 | - | |||||||||||||
1375 | if ((ch1 == 0 && ch2 == 0 && ch3 == 0xfe && ch4 == 0xff) || | - | ||||||||||||
1376 | (ch1 == 0xff && ch2 == 0xfe && ch3 == 0 && ch4 == 0)) | - | ||||||||||||
1377 | mib = 1017; // UTF-32 with byte order mark | - | ||||||||||||
1378 | else if (ch1 == 0x3c && ch2 == 0x00 && ch3 == 0x00 && ch4 == 0x00) | - | ||||||||||||
1379 | mib = 1019; // UTF-32LE | - | ||||||||||||
1380 | else if (ch1 == 0x00 && ch2 == 0x00 && ch3 == 0x00 && ch4 == 0x3c) | - | ||||||||||||
1381 | mib = 1018; // UTF-32BE | - | ||||||||||||
1382 | } | - | ||||||||||||
1383 | if (mib == 106 && data.size() >= 2) { | - | ||||||||||||
1384 | uchar ch1 = data.at(0); | - | ||||||||||||
1385 | uchar ch2 = data.at(1); | - | ||||||||||||
1386 | - | |||||||||||||
1387 | if ((ch1 == 0xfe && ch2 == 0xff) || (ch1 == 0xff && ch2 == 0xfe)) | - | ||||||||||||
1388 | mib = 1015; // UTF-16 with byte order mark | - | ||||||||||||
1389 | else if (ch1 == 0x3c && ch2 == 0x00) | - | ||||||||||||
1390 | mib = 1014; // UTF-16LE | - | ||||||||||||
1391 | else if (ch1 == 0x00 && ch2 == 0x3c) | - | ||||||||||||
1392 | mib = 1013; // UTF-16BE | - | ||||||||||||
1393 | } | - | ||||||||||||
1394 | - | |||||||||||||
1395 | QTextCodec *codec = QTextCodec::codecForMib(mib); | - | ||||||||||||
1396 | Q_ASSERT(codec); | - | ||||||||||||
1397 | - | |||||||||||||
1398 | d->encMapper = codec->makeDecoder(); | - | ||||||||||||
1399 | } | - | ||||||||||||
1400 | - | |||||||||||||
1401 | QString input = d->encMapper->toUnicode(data.constData(), data.size()); | - | ||||||||||||
1402 | - | |||||||||||||
1403 | if (d->lookingForEncodingDecl) { | - | ||||||||||||
1404 | d->encodingDeclChars += input; | - | ||||||||||||
1405 | - | |||||||||||||
1406 | bool needMoreText; | - | ||||||||||||
1407 | QString encoding = extractEncodingDecl(d->encodingDeclChars, &needMoreText); | - | ||||||||||||
1408 | - | |||||||||||||
1409 | if (!encoding.isEmpty()) { | - | ||||||||||||
1410 | if (QTextCodec *codec = QTextCodec::codecForName(encoding.toLatin1())) { | - | ||||||||||||
1411 | /* If the encoding is the same, we don't have to do toUnicode() all over again. */ | - | ||||||||||||
1412 | if(codec->mibEnum() != mib) { | - | ||||||||||||
1413 | delete d->encMapper; | - | ||||||||||||
1414 | d->encMapper = codec->makeDecoder(); | - | ||||||||||||
1415 | - | |||||||||||||
1416 | /* The variable input can potentially be large, so we deallocate | - | ||||||||||||
1417 | * it before calling toUnicode() in order to avoid having two | - | ||||||||||||
1418 | * large QStrings in memory simultaneously. */ | - | ||||||||||||
1419 | input.clear(); | - | ||||||||||||
1420 | - | |||||||||||||
1421 | // prime the decoder with the data so far | - | ||||||||||||
1422 | d->encMapper->toUnicode(d->encodingDeclBytes.constData(), d->encodingDeclBytes.size()); | - | ||||||||||||
1423 | // now feed it the new data | - | ||||||||||||
1424 | input = d->encMapper->toUnicode(data.constData(), data.size()); | - | ||||||||||||
1425 | } | - | ||||||||||||
1426 | } | - | ||||||||||||
1427 | } | - | ||||||||||||
1428 | - | |||||||||||||
1429 | d->encodingDeclBytes += data; | - | ||||||||||||
1430 | d->lookingForEncodingDecl = needMoreText; | - | ||||||||||||
1431 | } | - | ||||||||||||
1432 | - | |||||||||||||
1433 | return input; | - | ||||||||||||
1434 | #endif | - | ||||||||||||
1435 | } | - | ||||||||||||
1436 | - | |||||||||||||
1437 | - | |||||||||||||
1438 | /********************************************* | - | ||||||||||||
1439 | * | - | ||||||||||||
1440 | * QXmlDefaultHandler | - | ||||||||||||
1441 | * | - | ||||||||||||
1442 | *********************************************/ | - | ||||||||||||
1443 | - | |||||||||||||
1444 | /*! | - | ||||||||||||
1445 | \class QXmlContentHandler | - | ||||||||||||
1446 | \reentrant | - | ||||||||||||
1447 | \brief The QXmlContentHandler class provides an interface to | - | ||||||||||||
1448 | report the logical content of XML data. | - | ||||||||||||
1449 | - | |||||||||||||
1450 | \inmodule QtXml | - | ||||||||||||
1451 | \ingroup xml-tools | - | ||||||||||||
1452 | - | |||||||||||||
1453 | If the application needs to be informed of basic parsing events, | - | ||||||||||||
1454 | it can implement this interface and activate it using | - | ||||||||||||
1455 | QXmlReader::setContentHandler(). The reader can then report basic | - | ||||||||||||
1456 | document-related events like the start and end of elements and | - | ||||||||||||
1457 | character data through this interface. | - | ||||||||||||
1458 | - | |||||||||||||
1459 | The order of events in this interface is very important, and | - | ||||||||||||
1460 | mirrors the order of information in the document itself. For | - | ||||||||||||
1461 | example, all of an element's content (character data, processing | - | ||||||||||||
1462 | instructions, and sub-elements) appears, in order, between the | - | ||||||||||||
1463 | startElement() event and the corresponding endElement() event. | - | ||||||||||||
1464 | - | |||||||||||||
1465 | The class QXmlDefaultHandler provides a default implementation for | - | ||||||||||||
1466 | this interface; subclassing from the QXmlDefaultHandler class is | - | ||||||||||||
1467 | very convenient if you only want to be informed of some parsing | - | ||||||||||||
1468 | events. | - | ||||||||||||
1469 | - | |||||||||||||
1470 | The startDocument() function is called at the start of the | - | ||||||||||||
1471 | document, and endDocument() is called at the end. Before parsing | - | ||||||||||||
1472 | begins setDocumentLocator() is called. For each element | - | ||||||||||||
1473 | startElement() is called, with endElement() being called at the | - | ||||||||||||
1474 | end of each element. The characters() function is called with | - | ||||||||||||
1475 | chunks of character data; ignorableWhitespace() is called with | - | ||||||||||||
1476 | chunks of whitespace and processingInstruction() is called with | - | ||||||||||||
1477 | processing instructions. If an entity is skipped skippedEntity() | - | ||||||||||||
1478 | is called. At the beginning of prefix-URI scopes | - | ||||||||||||
1479 | startPrefixMapping() is called. | - | ||||||||||||
1480 | - | |||||||||||||
1481 | \sa QXmlDTDHandler, QXmlDeclHandler, QXmlEntityResolver, QXmlErrorHandler, | - | ||||||||||||
1482 | QXmlLexicalHandler, {Introduction to SAX2} | - | ||||||||||||
1483 | */ | - | ||||||||||||
1484 | - | |||||||||||||
1485 | /*! | - | ||||||||||||
1486 | \fn QXmlContentHandler::~QXmlContentHandler() | - | ||||||||||||
1487 | - | |||||||||||||
1488 | Destroys the content handler. | - | ||||||||||||
1489 | */ | - | ||||||||||||
1490 | - | |||||||||||||
1491 | /*! | - | ||||||||||||
1492 | \fn void QXmlContentHandler::setDocumentLocator(QXmlLocator* locator) | - | ||||||||||||
1493 | - | |||||||||||||
1494 | The reader calls this function before it starts parsing the | - | ||||||||||||
1495 | document. The argument \a locator is a pointer to a QXmlLocator | - | ||||||||||||
1496 | which allows the application to get the parsing position within | - | ||||||||||||
1497 | the document. | - | ||||||||||||
1498 | - | |||||||||||||
1499 | Do not destroy the \a locator; it is destroyed when the reader is | - | ||||||||||||
1500 | destroyed. (Do not use the \a locator after the reader is | - | ||||||||||||
1501 | destroyed). | - | ||||||||||||
1502 | */ | - | ||||||||||||
1503 | - | |||||||||||||
1504 | /*! | - | ||||||||||||
1505 | \fn bool QXmlContentHandler::startDocument() | - | ||||||||||||
1506 | - | |||||||||||||
1507 | The reader calls this function when it starts parsing the | - | ||||||||||||
1508 | document. The reader calls this function just once, after the call | - | ||||||||||||
1509 | to setDocumentLocator(), and before any other functions in this | - | ||||||||||||
1510 | class or in the QXmlDTDHandler class are called. | - | ||||||||||||
1511 | - | |||||||||||||
1512 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1513 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1514 | get the error message. | - | ||||||||||||
1515 | - | |||||||||||||
1516 | \sa endDocument() | - | ||||||||||||
1517 | */ | - | ||||||||||||
1518 | - | |||||||||||||
1519 | /*! | - | ||||||||||||
1520 | \fn bool QXmlContentHandler::endDocument() | - | ||||||||||||
1521 | - | |||||||||||||
1522 | The reader calls this function after it has finished parsing. It | - | ||||||||||||
1523 | is called just once, and is the last handler function called. It | - | ||||||||||||
1524 | is called after the reader has read all input or has abandoned | - | ||||||||||||
1525 | parsing because of a fatal error. | - | ||||||||||||
1526 | - | |||||||||||||
1527 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1528 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1529 | get the error message. | - | ||||||||||||
1530 | - | |||||||||||||
1531 | \sa startDocument() | - | ||||||||||||
1532 | */ | - | ||||||||||||
1533 | - | |||||||||||||
1534 | /*! | - | ||||||||||||
1535 | \fn bool QXmlContentHandler::startPrefixMapping(const QString& prefix, const QString& uri) | - | ||||||||||||
1536 | - | |||||||||||||
1537 | The reader calls this function to signal the begin of a prefix-URI | - | ||||||||||||
1538 | namespace mapping scope. This information is not necessary for | - | ||||||||||||
1539 | normal namespace processing since the reader automatically | - | ||||||||||||
1540 | replaces prefixes for element and attribute names. | - | ||||||||||||
1541 | - | |||||||||||||
1542 | Note that startPrefixMapping() and endPrefixMapping() calls are | - | ||||||||||||
1543 | not guaranteed to be properly nested relative to each other: all | - | ||||||||||||
1544 | startPrefixMapping() events occur before the corresponding | - | ||||||||||||
1545 | startElement() event, and all endPrefixMapping() events occur | - | ||||||||||||
1546 | after the corresponding endElement() event, but their order is not | - | ||||||||||||
1547 | otherwise guaranteed. | - | ||||||||||||
1548 | - | |||||||||||||
1549 | The argument \a prefix is the namespace prefix being declared and | - | ||||||||||||
1550 | the argument \a uri is the namespace URI the prefix is mapped to. | - | ||||||||||||
1551 | - | |||||||||||||
1552 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1553 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1554 | get the error message. | - | ||||||||||||
1555 | - | |||||||||||||
1556 | \sa endPrefixMapping(), {Namespace Support via Features} | - | ||||||||||||
1557 | */ | - | ||||||||||||
1558 | - | |||||||||||||
1559 | /*! | - | ||||||||||||
1560 | \fn bool QXmlContentHandler::endPrefixMapping(const QString& prefix) | - | ||||||||||||
1561 | - | |||||||||||||
1562 | The reader calls this function to signal the end of a prefix | - | ||||||||||||
1563 | mapping for the prefix \a prefix. | - | ||||||||||||
1564 | - | |||||||||||||
1565 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1566 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1567 | get the error message. | - | ||||||||||||
1568 | - | |||||||||||||
1569 | \sa startPrefixMapping(), {Namespace Support via Features} | - | ||||||||||||
1570 | */ | - | ||||||||||||
1571 | - | |||||||||||||
1572 | /*! | - | ||||||||||||
1573 | \fn bool QXmlContentHandler::startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts) | - | ||||||||||||
1574 | - | |||||||||||||
1575 | The reader calls this function when it has parsed a start element | - | ||||||||||||
1576 | tag. | - | ||||||||||||
1577 | - | |||||||||||||
1578 | There is a corresponding endElement() call when the corresponding | - | ||||||||||||
1579 | end element tag is read. The startElement() and endElement() calls | - | ||||||||||||
1580 | are always nested correctly. Empty element tags (e.g. \c{<x/>}) | - | ||||||||||||
1581 | cause a startElement() call to be immediately followed by an | - | ||||||||||||
1582 | endElement() call. | - | ||||||||||||
1583 | - | |||||||||||||
1584 | The attribute list provided only contains attributes with explicit | - | ||||||||||||
1585 | values. The attribute list contains attributes used for namespace | - | ||||||||||||
1586 | declaration (i.e. attributes starting with xmlns) only if the | - | ||||||||||||
1587 | namespace-prefix property of the reader is true. | - | ||||||||||||
1588 | - | |||||||||||||
1589 | The argument \a namespaceURI is the namespace URI, or | - | ||||||||||||
1590 | an empty string if the element has no namespace URI or if no | - | ||||||||||||
1591 | namespace processing is done. \a localName is the local name | - | ||||||||||||
1592 | (without prefix), or an empty string if no namespace processing is | - | ||||||||||||
1593 | done, \a qName is the qualified name (with prefix) and \a atts are | - | ||||||||||||
1594 | the attributes attached to the element. If there are no | - | ||||||||||||
1595 | attributes, \a atts is an empty attributes object. | - | ||||||||||||
1596 | - | |||||||||||||
1597 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1598 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1599 | get the error message. | - | ||||||||||||
1600 | - | |||||||||||||
1601 | \sa endElement(), {Namespace Support via Features} | - | ||||||||||||
1602 | */ | - | ||||||||||||
1603 | - | |||||||||||||
1604 | /*! | - | ||||||||||||
1605 | \fn bool QXmlContentHandler::endElement(const QString& namespaceURI, const QString& localName, const QString& qName) | - | ||||||||||||
1606 | - | |||||||||||||
1607 | The reader calls this function when it has parsed an end element | - | ||||||||||||
1608 | tag with the qualified name \a qName, the local name \a localName | - | ||||||||||||
1609 | and the namespace URI \a namespaceURI. | - | ||||||||||||
1610 | - | |||||||||||||
1611 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1612 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1613 | get the error message. | - | ||||||||||||
1614 | - | |||||||||||||
1615 | \sa startElement(), {Namespace Support via Features} | - | ||||||||||||
1616 | */ | - | ||||||||||||
1617 | - | |||||||||||||
1618 | /*! | - | ||||||||||||
1619 | \fn bool QXmlContentHandler::characters(const QString& ch) | - | ||||||||||||
1620 | - | |||||||||||||
1621 | The reader calls this function when it has parsed a chunk of | - | ||||||||||||
1622 | character data (either normal character data or character data | - | ||||||||||||
1623 | inside a CDATA section; if you need to distinguish between those | - | ||||||||||||
1624 | two types you must use QXmlLexicalHandler::startCDATA() and | - | ||||||||||||
1625 | QXmlLexicalHandler::endCDATA()). The character data is reported in | - | ||||||||||||
1626 | \a ch. | - | ||||||||||||
1627 | - | |||||||||||||
1628 | Some readers report whitespace in element content using the | - | ||||||||||||
1629 | ignorableWhitespace() function rather than using this one. | - | ||||||||||||
1630 | - | |||||||||||||
1631 | A reader may report the character data of an element in more than | - | ||||||||||||
1632 | one chunk; e.g. a reader might want to report "a\<b" in three | - | ||||||||||||
1633 | characters() events ("a ", "\<" and " b"). | - | ||||||||||||
1634 | - | |||||||||||||
1635 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1636 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1637 | get the error message. | - | ||||||||||||
1638 | */ | - | ||||||||||||
1639 | - | |||||||||||||
1640 | /*! | - | ||||||||||||
1641 | \fn bool QXmlContentHandler::ignorableWhitespace(const QString& ch) | - | ||||||||||||
1642 | - | |||||||||||||
1643 | Some readers may use this function to report each chunk of | - | ||||||||||||
1644 | whitespace in element content. The whitespace is reported in \a ch. | - | ||||||||||||
1645 | - | |||||||||||||
1646 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1647 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1648 | get the error message. | - | ||||||||||||
1649 | */ | - | ||||||||||||
1650 | - | |||||||||||||
1651 | /*! | - | ||||||||||||
1652 | \fn bool QXmlContentHandler::processingInstruction(const QString& target, const QString& data) | - | ||||||||||||
1653 | - | |||||||||||||
1654 | The reader calls this function when it has parsed a processing | - | ||||||||||||
1655 | instruction. | - | ||||||||||||
1656 | - | |||||||||||||
1657 | \a target is the target name of the processing instruction and \a | - | ||||||||||||
1658 | data is the data in the processing instruction. | - | ||||||||||||
1659 | - | |||||||||||||
1660 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1661 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1662 | get the error message. | - | ||||||||||||
1663 | */ | - | ||||||||||||
1664 | - | |||||||||||||
1665 | /*! | - | ||||||||||||
1666 | \fn bool QXmlContentHandler::skippedEntity(const QString& name) | - | ||||||||||||
1667 | - | |||||||||||||
1668 | Some readers may skip entities if they have not seen the | - | ||||||||||||
1669 | declarations (e.g. because they are in an external DTD). If they | - | ||||||||||||
1670 | do so they report that they skipped the entity called \a name by | - | ||||||||||||
1671 | calling this function. | - | ||||||||||||
1672 | - | |||||||||||||
1673 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1674 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1675 | get the error message. | - | ||||||||||||
1676 | */ | - | ||||||||||||
1677 | - | |||||||||||||
1678 | /*! | - | ||||||||||||
1679 | \fn QString QXmlContentHandler::errorString() const | - | ||||||||||||
1680 | - | |||||||||||||
1681 | The reader calls this function to get an error string, e.g. if any | - | ||||||||||||
1682 | of the handler functions returns \c false. | - | ||||||||||||
1683 | */ | - | ||||||||||||
1684 | - | |||||||||||||
1685 | - | |||||||||||||
1686 | /*! | - | ||||||||||||
1687 | \class QXmlErrorHandler | - | ||||||||||||
1688 | \reentrant | - | ||||||||||||
1689 | \brief The QXmlErrorHandler class provides an interface to report | - | ||||||||||||
1690 | errors in XML data. | - | ||||||||||||
1691 | - | |||||||||||||
1692 | \inmodule QtXml | - | ||||||||||||
1693 | \ingroup xml-tools | - | ||||||||||||
1694 | - | |||||||||||||
1695 | If you want your application to report errors to the user or to | - | ||||||||||||
1696 | perform customized error handling, you should subclass this class. | - | ||||||||||||
1697 | - | |||||||||||||
1698 | You can set the error handler with QXmlReader::setErrorHandler(). | - | ||||||||||||
1699 | - | |||||||||||||
1700 | Errors can be reported using warning(), error() and fatalError(), | - | ||||||||||||
1701 | with the error text being reported with errorString(). | - | ||||||||||||
1702 | - | |||||||||||||
1703 | \sa QXmlDTDHandler, QXmlDeclHandler, QXmlContentHandler, QXmlEntityResolver, | - | ||||||||||||
1704 | QXmlLexicalHandler, {Introduction to SAX2} | - | ||||||||||||
1705 | */ | - | ||||||||||||
1706 | - | |||||||||||||
1707 | /*! | - | ||||||||||||
1708 | \fn QXmlErrorHandler::~QXmlErrorHandler() | - | ||||||||||||
1709 | - | |||||||||||||
1710 | Destroys the error handler. | - | ||||||||||||
1711 | */ | - | ||||||||||||
1712 | - | |||||||||||||
1713 | /*! | - | ||||||||||||
1714 | \fn bool QXmlErrorHandler::warning(const QXmlParseException& exception) | - | ||||||||||||
1715 | - | |||||||||||||
1716 | A reader might use this function to report a warning. Warnings are | - | ||||||||||||
1717 | conditions that are not errors or fatal errors as defined by the | - | ||||||||||||
1718 | XML 1.0 specification. Details of the warning are stored in \a | - | ||||||||||||
1719 | exception. | - | ||||||||||||
1720 | - | |||||||||||||
1721 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1722 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1723 | get the error message. | - | ||||||||||||
1724 | */ | - | ||||||||||||
1725 | - | |||||||||||||
1726 | /*! | - | ||||||||||||
1727 | \fn bool QXmlErrorHandler::error(const QXmlParseException& exception) | - | ||||||||||||
1728 | - | |||||||||||||
1729 | A reader might use this function to report a recoverable error. A | - | ||||||||||||
1730 | recoverable error corresponds to the definiton of "error" in | - | ||||||||||||
1731 | section 1.2 of the XML 1.0 specification. Details of the error are | - | ||||||||||||
1732 | stored in \a exception. | - | ||||||||||||
1733 | - | |||||||||||||
1734 | The reader must continue to provide normal parsing events after | - | ||||||||||||
1735 | invoking this function. | - | ||||||||||||
1736 | - | |||||||||||||
1737 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1738 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1739 | get the error message. | - | ||||||||||||
1740 | */ | - | ||||||||||||
1741 | - | |||||||||||||
1742 | /*! | - | ||||||||||||
1743 | \fn bool QXmlErrorHandler::fatalError(const QXmlParseException& exception) | - | ||||||||||||
1744 | - | |||||||||||||
1745 | A reader must use this function to report a non-recoverable error. | - | ||||||||||||
1746 | Details of the error are stored in \a exception. | - | ||||||||||||
1747 | - | |||||||||||||
1748 | If this function returns \c true the reader might try to go on | - | ||||||||||||
1749 | parsing and reporting further errors, but no regular parsing | - | ||||||||||||
1750 | events are reported. | - | ||||||||||||
1751 | */ | - | ||||||||||||
1752 | - | |||||||||||||
1753 | /*! | - | ||||||||||||
1754 | \fn QString QXmlErrorHandler::errorString() const | - | ||||||||||||
1755 | - | |||||||||||||
1756 | The reader calls this function to get an error string if any of | - | ||||||||||||
1757 | the handler functions returns \c false. | - | ||||||||||||
1758 | */ | - | ||||||||||||
1759 | - | |||||||||||||
1760 | - | |||||||||||||
1761 | /*! | - | ||||||||||||
1762 | \class QXmlDTDHandler | - | ||||||||||||
1763 | \reentrant | - | ||||||||||||
1764 | \brief The QXmlDTDHandler class provides an interface to report | - | ||||||||||||
1765 | DTD content of XML data. | - | ||||||||||||
1766 | - | |||||||||||||
1767 | \inmodule QtXml | - | ||||||||||||
1768 | \ingroup xml-tools | - | ||||||||||||
1769 | - | |||||||||||||
1770 | If an application needs information about notations and unparsed | - | ||||||||||||
1771 | entities, it can implement this interface and register an instance | - | ||||||||||||
1772 | with QXmlReader::setDTDHandler(). | - | ||||||||||||
1773 | - | |||||||||||||
1774 | Note that this interface includes only those DTD events that the | - | ||||||||||||
1775 | XML recommendation requires processors to report, i.e. notation | - | ||||||||||||
1776 | and unparsed entity declarations using notationDecl() and | - | ||||||||||||
1777 | unparsedEntityDecl() respectively. | - | ||||||||||||
1778 | - | |||||||||||||
1779 | \sa QXmlDeclHandler, QXmlContentHandler, QXmlEntityResolver, QXmlErrorHandler, | - | ||||||||||||
1780 | QXmlLexicalHandler, {Introduction to SAX2} | - | ||||||||||||
1781 | */ | - | ||||||||||||
1782 | - | |||||||||||||
1783 | /*! | - | ||||||||||||
1784 | \fn QXmlDTDHandler::~QXmlDTDHandler() | - | ||||||||||||
1785 | - | |||||||||||||
1786 | Destroys the DTD handler. | - | ||||||||||||
1787 | */ | - | ||||||||||||
1788 | - | |||||||||||||
1789 | /*! | - | ||||||||||||
1790 | \fn bool QXmlDTDHandler::notationDecl(const QString& name, const QString& publicId, const QString& systemId) | - | ||||||||||||
1791 | - | |||||||||||||
1792 | The reader calls this function when it has parsed a notation | - | ||||||||||||
1793 | declaration. | - | ||||||||||||
1794 | - | |||||||||||||
1795 | The argument \a name is the notation name, \a publicId is the | - | ||||||||||||
1796 | notation's public identifier and \a systemId is the notation's | - | ||||||||||||
1797 | system identifier. | - | ||||||||||||
1798 | - | |||||||||||||
1799 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1800 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1801 | get the error message. | - | ||||||||||||
1802 | */ | - | ||||||||||||
1803 | - | |||||||||||||
1804 | /*! | - | ||||||||||||
1805 | \fn bool QXmlDTDHandler::unparsedEntityDecl(const QString& name, const QString& publicId, const QString& systemId, const QString& notationName) | - | ||||||||||||
1806 | - | |||||||||||||
1807 | The reader calls this function when it finds an unparsed entity | - | ||||||||||||
1808 | declaration. | - | ||||||||||||
1809 | - | |||||||||||||
1810 | The argument \a name is the unparsed entity's name, \a publicId is | - | ||||||||||||
1811 | the entity's public identifier, \a systemId is the entity's system | - | ||||||||||||
1812 | identifier and \a notationName is the name of the associated | - | ||||||||||||
1813 | notation. | - | ||||||||||||
1814 | - | |||||||||||||
1815 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1816 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1817 | get the error message. | - | ||||||||||||
1818 | */ | - | ||||||||||||
1819 | - | |||||||||||||
1820 | /*! | - | ||||||||||||
1821 | \fn QString QXmlDTDHandler::errorString() const | - | ||||||||||||
1822 | - | |||||||||||||
1823 | The reader calls this function to get an error string if any of | - | ||||||||||||
1824 | the handler functions returns \c false. | - | ||||||||||||
1825 | */ | - | ||||||||||||
1826 | - | |||||||||||||
1827 | - | |||||||||||||
1828 | /*! | - | ||||||||||||
1829 | \class QXmlEntityResolver | - | ||||||||||||
1830 | \reentrant | - | ||||||||||||
1831 | \brief The QXmlEntityResolver class provides an interface to | - | ||||||||||||
1832 | resolve external entities contained in XML data. | - | ||||||||||||
1833 | - | |||||||||||||
1834 | \inmodule QtXml | - | ||||||||||||
1835 | \ingroup xml-tools | - | ||||||||||||
1836 | - | |||||||||||||
1837 | If an application needs to implement customized handling for | - | ||||||||||||
1838 | external entities, it must implement this interface, i.e. | - | ||||||||||||
1839 | resolveEntity(), and register it with | - | ||||||||||||
1840 | QXmlReader::setEntityResolver(). | - | ||||||||||||
1841 | - | |||||||||||||
1842 | \sa QXmlDTDHandler, QXmlDeclHandler, QXmlContentHandler, QXmlErrorHandler, | - | ||||||||||||
1843 | QXmlLexicalHandler, {Introduction to SAX2} | - | ||||||||||||
1844 | */ | - | ||||||||||||
1845 | - | |||||||||||||
1846 | /*! | - | ||||||||||||
1847 | \fn QXmlEntityResolver::~QXmlEntityResolver() | - | ||||||||||||
1848 | - | |||||||||||||
1849 | Destroys the entity resolver. | - | ||||||||||||
1850 | */ | - | ||||||||||||
1851 | - | |||||||||||||
1852 | /*! | - | ||||||||||||
1853 | \fn bool QXmlEntityResolver::resolveEntity(const QString& publicId, const QString& systemId, QXmlInputSource*& ret) | - | ||||||||||||
1854 | - | |||||||||||||
1855 | The reader calls this function before it opens any external | - | ||||||||||||
1856 | entity, except the top-level document entity. The application may | - | ||||||||||||
1857 | request the reader to resolve the entity itself (\a ret is 0) or | - | ||||||||||||
1858 | to use an entirely different input source (\a ret points to the | - | ||||||||||||
1859 | input source). | - | ||||||||||||
1860 | - | |||||||||||||
1861 | The reader deletes the input source \a ret when it no longer needs | - | ||||||||||||
1862 | it, so you should allocate it on the heap with \c new. | - | ||||||||||||
1863 | - | |||||||||||||
1864 | The argument \a publicId is the public identifier of the external | - | ||||||||||||
1865 | entity, \a systemId is the system identifier of the external | - | ||||||||||||
1866 | entity and \a ret is the return value of this function. If \a ret | - | ||||||||||||
1867 | is 0 the reader should resolve the entity itself, if it is | - | ||||||||||||
1868 | non-zero it must point to an input source which the reader uses | - | ||||||||||||
1869 | instead. | - | ||||||||||||
1870 | - | |||||||||||||
1871 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1872 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1873 | get the error message. | - | ||||||||||||
1874 | */ | - | ||||||||||||
1875 | - | |||||||||||||
1876 | /*! | - | ||||||||||||
1877 | \fn QString QXmlEntityResolver::errorString() const | - | ||||||||||||
1878 | - | |||||||||||||
1879 | The reader calls this function to get an error string if any of | - | ||||||||||||
1880 | the handler functions returns \c false. | - | ||||||||||||
1881 | */ | - | ||||||||||||
1882 | - | |||||||||||||
1883 | - | |||||||||||||
1884 | /*! | - | ||||||||||||
1885 | \class QXmlLexicalHandler | - | ||||||||||||
1886 | \reentrant | - | ||||||||||||
1887 | \brief The QXmlLexicalHandler class provides an interface to | - | ||||||||||||
1888 | report the lexical content of XML data. | - | ||||||||||||
1889 | - | |||||||||||||
1890 | \inmodule QtXml | - | ||||||||||||
1891 | \ingroup xml-tools | - | ||||||||||||
1892 | - | |||||||||||||
1893 | The events in the lexical handler apply to the entire document, | - | ||||||||||||
1894 | not just to the document element, and all lexical handler events | - | ||||||||||||
1895 | appear between the content handler's startDocument and endDocument | - | ||||||||||||
1896 | events. | - | ||||||||||||
1897 | - | |||||||||||||
1898 | You can set the lexical handler with | - | ||||||||||||
1899 | QXmlReader::setLexicalHandler(). | - | ||||||||||||
1900 | - | |||||||||||||
1901 | This interface's design is based on the SAX2 extension | - | ||||||||||||
1902 | LexicalHandler. | - | ||||||||||||
1903 | - | |||||||||||||
1904 | The interface provides the startDTD(), endDTD(), startEntity(), | - | ||||||||||||
1905 | endEntity(), startCDATA(), endCDATA() and comment() functions. | - | ||||||||||||
1906 | - | |||||||||||||
1907 | \sa QXmlDTDHandler, QXmlDeclHandler, QXmlContentHandler, QXmlEntityResolver, | - | ||||||||||||
1908 | QXmlErrorHandler, {Introduction to SAX2} | - | ||||||||||||
1909 | */ | - | ||||||||||||
1910 | - | |||||||||||||
1911 | /*! | - | ||||||||||||
1912 | \fn QXmlLexicalHandler::~QXmlLexicalHandler() | - | ||||||||||||
1913 | - | |||||||||||||
1914 | Destroys the lexical handler. | - | ||||||||||||
1915 | */ | - | ||||||||||||
1916 | - | |||||||||||||
1917 | /*! | - | ||||||||||||
1918 | \fn bool QXmlLexicalHandler::startDTD(const QString& name, const QString& publicId, const QString& systemId) | - | ||||||||||||
1919 | - | |||||||||||||
1920 | The reader calls this function to report the start of a DTD | - | ||||||||||||
1921 | declaration, if any. It reports the name of the document type in | - | ||||||||||||
1922 | \a name, the public identifier in \a publicId and the system | - | ||||||||||||
1923 | identifier in \a systemId. | - | ||||||||||||
1924 | - | |||||||||||||
1925 | If the public identifier is missing, \a publicId is set to | - | ||||||||||||
1926 | an empty string. If the system identifier is missing, \a systemId is | - | ||||||||||||
1927 | set to an empty string. Note that it is not valid XML to have a | - | ||||||||||||
1928 | public identifier but no system identifier; in such cases a parse | - | ||||||||||||
1929 | error will occur. | - | ||||||||||||
1930 | - | |||||||||||||
1931 | All declarations reported through QXmlDTDHandler or | - | ||||||||||||
1932 | QXmlDeclHandler appear between the startDTD() and endDTD() calls. | - | ||||||||||||
1933 | - | |||||||||||||
1934 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1935 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1936 | get the error message. | - | ||||||||||||
1937 | - | |||||||||||||
1938 | \sa endDTD() | - | ||||||||||||
1939 | */ | - | ||||||||||||
1940 | - | |||||||||||||
1941 | /*! | - | ||||||||||||
1942 | \fn bool QXmlLexicalHandler::endDTD() | - | ||||||||||||
1943 | - | |||||||||||||
1944 | The reader calls this function to report the end of a DTD | - | ||||||||||||
1945 | declaration, if any. | - | ||||||||||||
1946 | - | |||||||||||||
1947 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1948 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1949 | get the error message. | - | ||||||||||||
1950 | - | |||||||||||||
1951 | \sa startDTD() | - | ||||||||||||
1952 | */ | - | ||||||||||||
1953 | - | |||||||||||||
1954 | /*! | - | ||||||||||||
1955 | \fn bool QXmlLexicalHandler::startEntity(const QString& name) | - | ||||||||||||
1956 | - | |||||||||||||
1957 | The reader calls this function to report the start of an entity | - | ||||||||||||
1958 | called \a name. | - | ||||||||||||
1959 | - | |||||||||||||
1960 | Note that if the entity is unknown, the reader reports it through | - | ||||||||||||
1961 | QXmlContentHandler::skippedEntity() and not through this | - | ||||||||||||
1962 | function. | - | ||||||||||||
1963 | - | |||||||||||||
1964 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1965 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1966 | get the error message. | - | ||||||||||||
1967 | - | |||||||||||||
1968 | \sa endEntity(), QXmlSimpleReader::setFeature() | - | ||||||||||||
1969 | */ | - | ||||||||||||
1970 | - | |||||||||||||
1971 | /*! | - | ||||||||||||
1972 | \fn bool QXmlLexicalHandler::endEntity(const QString& name) | - | ||||||||||||
1973 | - | |||||||||||||
1974 | The reader calls this function to report the end of an entity | - | ||||||||||||
1975 | called \a name. | - | ||||||||||||
1976 | - | |||||||||||||
1977 | For every startEntity() call, there is a corresponding endEntity() | - | ||||||||||||
1978 | call. The calls to startEntity() and endEntity() are properly | - | ||||||||||||
1979 | nested. | - | ||||||||||||
1980 | - | |||||||||||||
1981 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1982 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1983 | get the error message. | - | ||||||||||||
1984 | - | |||||||||||||
1985 | \sa startEntity(), QXmlContentHandler::skippedEntity(), QXmlSimpleReader::setFeature() | - | ||||||||||||
1986 | */ | - | ||||||||||||
1987 | - | |||||||||||||
1988 | /*! | - | ||||||||||||
1989 | \fn bool QXmlLexicalHandler::startCDATA() | - | ||||||||||||
1990 | - | |||||||||||||
1991 | The reader calls this function to report the start of a CDATA | - | ||||||||||||
1992 | section. The content of the CDATA section is reported through the | - | ||||||||||||
1993 | QXmlContentHandler::characters() function. This function is | - | ||||||||||||
1994 | intended only to report the boundary. | - | ||||||||||||
1995 | - | |||||||||||||
1996 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
1997 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
1998 | get the error message. | - | ||||||||||||
1999 | - | |||||||||||||
2000 | \sa endCDATA() | - | ||||||||||||
2001 | */ | - | ||||||||||||
2002 | - | |||||||||||||
2003 | /*! | - | ||||||||||||
2004 | \fn bool QXmlLexicalHandler::endCDATA() | - | ||||||||||||
2005 | - | |||||||||||||
2006 | The reader calls this function to report the end of a CDATA | - | ||||||||||||
2007 | section. | - | ||||||||||||
2008 | - | |||||||||||||
2009 | If this function returns \c false the reader stops parsing and reports | - | ||||||||||||
2010 | an error. The reader uses the function errorString() to get the error | - | ||||||||||||
2011 | message. | - | ||||||||||||
2012 | - | |||||||||||||
2013 | \sa startCDATA(), QXmlContentHandler::characters() | - | ||||||||||||
2014 | */ | - | ||||||||||||
2015 | - | |||||||||||||
2016 | /*! | - | ||||||||||||
2017 | \fn bool QXmlLexicalHandler::comment(const QString& ch) | - | ||||||||||||
2018 | - | |||||||||||||
2019 | The reader calls this function to report an XML comment anywhere | - | ||||||||||||
2020 | in the document. It reports the text of the comment in \a ch. | - | ||||||||||||
2021 | - | |||||||||||||
2022 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
2023 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
2024 | get the error message. | - | ||||||||||||
2025 | */ | - | ||||||||||||
2026 | - | |||||||||||||
2027 | /*! | - | ||||||||||||
2028 | \fn QString QXmlLexicalHandler::errorString() const | - | ||||||||||||
2029 | - | |||||||||||||
2030 | The reader calls this function to get an error string if any of | - | ||||||||||||
2031 | the handler functions returns \c false. | - | ||||||||||||
2032 | */ | - | ||||||||||||
2033 | - | |||||||||||||
2034 | - | |||||||||||||
2035 | /*! | - | ||||||||||||
2036 | \class QXmlDeclHandler | - | ||||||||||||
2037 | \reentrant | - | ||||||||||||
2038 | \brief The QXmlDeclHandler class provides an interface to report declaration | - | ||||||||||||
2039 | content of XML data. | - | ||||||||||||
2040 | - | |||||||||||||
2041 | \inmodule QtXml | - | ||||||||||||
2042 | \ingroup xml-tools | - | ||||||||||||
2043 | - | |||||||||||||
2044 | You can set the declaration handler with | - | ||||||||||||
2045 | QXmlReader::setDeclHandler(). | - | ||||||||||||
2046 | - | |||||||||||||
2047 | This interface is based on the SAX2 extension DeclHandler. | - | ||||||||||||
2048 | - | |||||||||||||
2049 | The interface provides attributeDecl(), internalEntityDecl() and | - | ||||||||||||
2050 | externalEntityDecl() functions. | - | ||||||||||||
2051 | - | |||||||||||||
2052 | \sa QXmlDTDHandler, QXmlContentHandler, QXmlEntityResolver, QXmlErrorHandler, | - | ||||||||||||
2053 | QXmlLexicalHandler, {Introduction to SAX2} | - | ||||||||||||
2054 | */ | - | ||||||||||||
2055 | - | |||||||||||||
2056 | /*! | - | ||||||||||||
2057 | \fn QXmlDeclHandler::~QXmlDeclHandler() | - | ||||||||||||
2058 | - | |||||||||||||
2059 | Destroys the declaration handler. | - | ||||||||||||
2060 | */ | - | ||||||||||||
2061 | - | |||||||||||||
2062 | /*! | - | ||||||||||||
2063 | \fn bool QXmlDeclHandler::attributeDecl(const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value) | - | ||||||||||||
2064 | - | |||||||||||||
2065 | The reader calls this function to report an attribute type | - | ||||||||||||
2066 | declaration. Only the effective (first) declaration for an | - | ||||||||||||
2067 | attribute is reported. | - | ||||||||||||
2068 | - | |||||||||||||
2069 | The reader passes the name of the associated element in \a eName | - | ||||||||||||
2070 | and the name of the attribute in \a aName. It passes a string that | - | ||||||||||||
2071 | represents the attribute type in \a type and a string that | - | ||||||||||||
2072 | represents the attribute default in \a valueDefault. This string | - | ||||||||||||
2073 | is one of "#IMPLIED", "#REQUIRED", "#FIXED" or an empty string (if | - | ||||||||||||
2074 | none of the others applies). The reader passes the attribute's | - | ||||||||||||
2075 | default value in \a value. If no default value is specified in the | - | ||||||||||||
2076 | XML file, \a value is an empty string. | - | ||||||||||||
2077 | - | |||||||||||||
2078 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
2079 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
2080 | get the error message. | - | ||||||||||||
2081 | */ | - | ||||||||||||
2082 | - | |||||||||||||
2083 | /*! | - | ||||||||||||
2084 | \fn bool QXmlDeclHandler::internalEntityDecl(const QString& name, const QString& value) | - | ||||||||||||
2085 | - | |||||||||||||
2086 | The reader calls this function to report an internal entity | - | ||||||||||||
2087 | declaration. Only the effective (first) declaration is reported. | - | ||||||||||||
2088 | - | |||||||||||||
2089 | The reader passes the name of the entity in \a name and the value | - | ||||||||||||
2090 | of the entity in \a value. | - | ||||||||||||
2091 | - | |||||||||||||
2092 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
2093 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
2094 | get the error message. | - | ||||||||||||
2095 | */ | - | ||||||||||||
2096 | - | |||||||||||||
2097 | /*! | - | ||||||||||||
2098 | \fn bool QXmlDeclHandler::externalEntityDecl(const QString& name, const QString& publicId, const QString& systemId) | - | ||||||||||||
2099 | - | |||||||||||||
2100 | The reader calls this function to report a parsed external entity | - | ||||||||||||
2101 | declaration. Only the effective (first) declaration for each | - | ||||||||||||
2102 | entity is reported. | - | ||||||||||||
2103 | - | |||||||||||||
2104 | The reader passes the name of the entity in \a name, the public | - | ||||||||||||
2105 | identifier in \a publicId and the system identifier in \a | - | ||||||||||||
2106 | systemId. If there is no public identifier specified, it passes | - | ||||||||||||
2107 | an empty string in \a publicId. | - | ||||||||||||
2108 | - | |||||||||||||
2109 | If this function returns \c false the reader stops parsing and | - | ||||||||||||
2110 | reports an error. The reader uses the function errorString() to | - | ||||||||||||
2111 | get the error message. | - | ||||||||||||
2112 | */ | - | ||||||||||||
2113 | - | |||||||||||||
2114 | /*! | - | ||||||||||||
2115 | \fn QString QXmlDeclHandler::errorString() const | - | ||||||||||||
2116 | - | |||||||||||||
2117 | The reader calls this function to get an error string if any of | - | ||||||||||||
2118 | the handler functions returns \c false. | - | ||||||||||||
2119 | */ | - | ||||||||||||
2120 | - | |||||||||||||
2121 | - | |||||||||||||
2122 | /*! | - | ||||||||||||
2123 | \class QXmlDefaultHandler | - | ||||||||||||
2124 | \reentrant | - | ||||||||||||
2125 | \brief The QXmlDefaultHandler class provides a default implementation of all | - | ||||||||||||
2126 | the XML handler classes. | - | ||||||||||||
2127 | - | |||||||||||||
2128 | \inmodule QtXml | - | ||||||||||||
2129 | \ingroup xml-tools | - | ||||||||||||
2130 | - | |||||||||||||
2131 | This class gathers together the features of | - | ||||||||||||
2132 | the specialized handler classes, making it a convenient | - | ||||||||||||
2133 | starting point when implementing custom handlers for | - | ||||||||||||
2134 | subclasses of QXmlReader, particularly QXmlSimpleReader. | - | ||||||||||||
2135 | The virtual functions from each of the base classes are | - | ||||||||||||
2136 | reimplemented in this class, providing sensible default behavior | - | ||||||||||||
2137 | for many common cases. By subclassing this class, and | - | ||||||||||||
2138 | overriding these functions, you can concentrate | - | ||||||||||||
2139 | on implementing the parts of the handler relevant to your | - | ||||||||||||
2140 | application. | - | ||||||||||||
2141 | - | |||||||||||||
2142 | The XML reader must be told which handler to use for different | - | ||||||||||||
2143 | kinds of events during parsing. This means that, although | - | ||||||||||||
2144 | QXmlDefaultHandler provides default implementations of functions | - | ||||||||||||
2145 | inherited from all its base classes, we can still use specialized | - | ||||||||||||
2146 | handlers for particular kinds of events. | - | ||||||||||||
2147 | - | |||||||||||||
2148 | For example, QXmlDefaultHandler subclasses both | - | ||||||||||||
2149 | QXmlContentHandler and QXmlErrorHandler, so by subclassing | - | ||||||||||||
2150 | it we can use the same handler for both of the following | - | ||||||||||||
2151 | reader functions: | - | ||||||||||||
2152 | - | |||||||||||||
2153 | \snippet rsslisting/listing.cpp 0 | - | ||||||||||||
2154 | - | |||||||||||||
2155 | Since the reader will inform the handler of parsing errors, it is | - | ||||||||||||
2156 | necessary to reimplement QXmlErrorHandler::fatalError() if, for | - | ||||||||||||
2157 | example, we want to stop parsing when such an error occurs: | - | ||||||||||||
2158 | - | |||||||||||||
2159 | \snippet rsslisting/handler.cpp 0 | - | ||||||||||||
2160 | - | |||||||||||||
2161 | The above function returns \c false, which tells the reader to stop | - | ||||||||||||
2162 | parsing. To continue to use the same reader, | - | ||||||||||||
2163 | it is necessary to create a new handler instance, and set up the | - | ||||||||||||
2164 | reader to use it in the manner described above. | - | ||||||||||||
2165 | - | |||||||||||||
2166 | It is useful to examine some of the functions inherited by | - | ||||||||||||
2167 | QXmlDefaultHandler, and consider why they might be | - | ||||||||||||
2168 | reimplemented in a custom handler. | - | ||||||||||||
2169 | Custom handlers will typically reimplement | - | ||||||||||||
2170 | QXmlContentHandler::startDocument() to prepare the handler for | - | ||||||||||||
2171 | new content. Document elements and the text within them can be | - | ||||||||||||
2172 | processed by reimplementing QXmlContentHandler::startElement(), | - | ||||||||||||
2173 | QXmlContentHandler::endElement(), and | - | ||||||||||||
2174 | QXmlContentHandler::characters(). | - | ||||||||||||
2175 | You may want to reimplement QXmlContentHandler::endDocument() | - | ||||||||||||
2176 | to perform some finalization or validation on the content once the | - | ||||||||||||
2177 | document has been read completely. | - | ||||||||||||
2178 | - | |||||||||||||
2179 | \sa QXmlDTDHandler, QXmlDeclHandler, QXmlContentHandler, QXmlEntityResolver, | - | ||||||||||||
2180 | QXmlErrorHandler, QXmlLexicalHandler, {Introduction to SAX2} | - | ||||||||||||
2181 | */ | - | ||||||||||||
2182 | - | |||||||||||||
2183 | /*! | - | ||||||||||||
2184 | \fn QXmlDefaultHandler::QXmlDefaultHandler() | - | ||||||||||||
2185 | - | |||||||||||||
2186 | Constructs a handler for use with subclasses of QXmlReader. | - | ||||||||||||
2187 | */ | - | ||||||||||||
2188 | QXmlDefaultHandler::QXmlDefaultHandler() | - | ||||||||||||
2189 | { | - | ||||||||||||
2190 | // ### In Qt 5.0, this function was inlined and d was not initialized | - | ||||||||||||
2191 | // The member cannot be used until Qt 6.0 | - | ||||||||||||
2192 | Q_UNUSED(d); | - | ||||||||||||
2193 | } | - | ||||||||||||
2194 | - | |||||||||||||
2195 | /*! | - | ||||||||||||
2196 | \fn QXmlDefaultHandler::~QXmlDefaultHandler() | - | ||||||||||||
2197 | - | |||||||||||||
2198 | Destroys the handler. | - | ||||||||||||
2199 | */ | - | ||||||||||||
2200 | QXmlDefaultHandler::~QXmlDefaultHandler() | - | ||||||||||||
2201 | { | - | ||||||||||||
2202 | } | - | ||||||||||||
2203 | - | |||||||||||||
2204 | /*! | - | ||||||||||||
2205 | \reimp | - | ||||||||||||
2206 | - | |||||||||||||
2207 | This reimplementation does nothing. | - | ||||||||||||
2208 | */ | - | ||||||||||||
2209 | void QXmlDefaultHandler::setDocumentLocator(QXmlLocator*) | - | ||||||||||||
2210 | { | - | ||||||||||||
2211 | } | - | ||||||||||||
2212 | - | |||||||||||||
2213 | /*! | - | ||||||||||||
2214 | \reimp | - | ||||||||||||
2215 | - | |||||||||||||
2216 | This reimplementation does nothing. | - | ||||||||||||
2217 | */ | - | ||||||||||||
2218 | bool QXmlDefaultHandler::startDocument() | - | ||||||||||||
2219 | { | - | ||||||||||||
2220 | return true; | - | ||||||||||||
2221 | } | - | ||||||||||||
2222 | - | |||||||||||||
2223 | /*! | - | ||||||||||||
2224 | \reimp | - | ||||||||||||
2225 | - | |||||||||||||
2226 | This reimplementation does nothing. | - | ||||||||||||
2227 | */ | - | ||||||||||||
2228 | bool QXmlDefaultHandler::endDocument() | - | ||||||||||||
2229 | { | - | ||||||||||||
2230 | return true; | - | ||||||||||||
2231 | } | - | ||||||||||||
2232 | - | |||||||||||||
2233 | /*! | - | ||||||||||||
2234 | \reimp | - | ||||||||||||
2235 | - | |||||||||||||
2236 | This reimplementation does nothing. | - | ||||||||||||
2237 | */ | - | ||||||||||||
2238 | bool QXmlDefaultHandler::startPrefixMapping(const QString&, const QString&) | - | ||||||||||||
2239 | { | - | ||||||||||||
2240 | return true; | - | ||||||||||||
2241 | } | - | ||||||||||||
2242 | - | |||||||||||||
2243 | /*! | - | ||||||||||||
2244 | \reimp | - | ||||||||||||
2245 | - | |||||||||||||
2246 | This reimplementation does nothing. | - | ||||||||||||
2247 | */ | - | ||||||||||||
2248 | bool QXmlDefaultHandler::endPrefixMapping(const QString&) | - | ||||||||||||
2249 | { | - | ||||||||||||
2250 | return true; | - | ||||||||||||
2251 | } | - | ||||||||||||
2252 | - | |||||||||||||
2253 | /*! | - | ||||||||||||
2254 | \reimp | - | ||||||||||||
2255 | - | |||||||||||||
2256 | This reimplementation does nothing. | - | ||||||||||||
2257 | */ | - | ||||||||||||
2258 | bool QXmlDefaultHandler::startElement(const QString&, const QString&, | - | ||||||||||||
2259 | const QString&, const QXmlAttributes&) | - | ||||||||||||
2260 | { | - | ||||||||||||
2261 | return true; | - | ||||||||||||
2262 | } | - | ||||||||||||
2263 | - | |||||||||||||
2264 | /*! | - | ||||||||||||
2265 | \reimp | - | ||||||||||||
2266 | - | |||||||||||||
2267 | This reimplementation does nothing. | - | ||||||||||||
2268 | */ | - | ||||||||||||
2269 | bool QXmlDefaultHandler::endElement(const QString&, const QString&, | - | ||||||||||||
2270 | const QString&) | - | ||||||||||||
2271 | { | - | ||||||||||||
2272 | return true; | - | ||||||||||||
2273 | } | - | ||||||||||||
2274 | - | |||||||||||||
2275 | /*! | - | ||||||||||||
2276 | \reimp | - | ||||||||||||
2277 | - | |||||||||||||
2278 | This reimplementation does nothing. | - | ||||||||||||
2279 | */ | - | ||||||||||||
2280 | bool QXmlDefaultHandler::characters(const QString&) | - | ||||||||||||
2281 | { | - | ||||||||||||
2282 | return true; | - | ||||||||||||
2283 | } | - | ||||||||||||
2284 | - | |||||||||||||
2285 | /*! | - | ||||||||||||
2286 | \reimp | - | ||||||||||||
2287 | - | |||||||||||||
2288 | This reimplementation does nothing. | - | ||||||||||||
2289 | */ | - | ||||||||||||
2290 | bool QXmlDefaultHandler::ignorableWhitespace(const QString&) | - | ||||||||||||
2291 | { | - | ||||||||||||
2292 | return true; | - | ||||||||||||
2293 | } | - | ||||||||||||
2294 | - | |||||||||||||
2295 | /*! | - | ||||||||||||
2296 | \reimp | - | ||||||||||||
2297 | - | |||||||||||||
2298 | This reimplementation does nothing. | - | ||||||||||||
2299 | */ | - | ||||||||||||
2300 | bool QXmlDefaultHandler::processingInstruction(const QString&, | - | ||||||||||||
2301 | const QString&) | - | ||||||||||||
2302 | { | - | ||||||||||||
2303 | return true; | - | ||||||||||||
2304 | } | - | ||||||||||||
2305 | - | |||||||||||||
2306 | /*! | - | ||||||||||||
2307 | \reimp | - | ||||||||||||
2308 | - | |||||||||||||
2309 | This reimplementation does nothing. | - | ||||||||||||
2310 | */ | - | ||||||||||||
2311 | bool QXmlDefaultHandler::skippedEntity(const QString&) | - | ||||||||||||
2312 | { | - | ||||||||||||
2313 | return true; | - | ||||||||||||
2314 | } | - | ||||||||||||
2315 | - | |||||||||||||
2316 | /*! | - | ||||||||||||
2317 | \reimp | - | ||||||||||||
2318 | - | |||||||||||||
2319 | This reimplementation does nothing. | - | ||||||||||||
2320 | */ | - | ||||||||||||
2321 | bool QXmlDefaultHandler::warning(const QXmlParseException&) | - | ||||||||||||
2322 | { | - | ||||||||||||
2323 | return true; | - | ||||||||||||
2324 | } | - | ||||||||||||
2325 | - | |||||||||||||
2326 | /*! | - | ||||||||||||
2327 | \reimp | - | ||||||||||||
2328 | - | |||||||||||||
2329 | This reimplementation does nothing. | - | ||||||||||||
2330 | */ | - | ||||||||||||
2331 | bool QXmlDefaultHandler::error(const QXmlParseException&) | - | ||||||||||||
2332 | { | - | ||||||||||||
2333 | return true; | - | ||||||||||||
2334 | } | - | ||||||||||||
2335 | - | |||||||||||||
2336 | /*! | - | ||||||||||||
2337 | \reimp | - | ||||||||||||
2338 | - | |||||||||||||
2339 | This reimplementation does nothing. | - | ||||||||||||
2340 | */ | - | ||||||||||||
2341 | bool QXmlDefaultHandler::fatalError(const QXmlParseException&) | - | ||||||||||||
2342 | { | - | ||||||||||||
2343 | return true; | - | ||||||||||||
2344 | } | - | ||||||||||||
2345 | - | |||||||||||||
2346 | /*! | - | ||||||||||||
2347 | \reimp | - | ||||||||||||
2348 | - | |||||||||||||
2349 | This reimplementation does nothing. | - | ||||||||||||
2350 | */ | - | ||||||||||||
2351 | bool QXmlDefaultHandler::notationDecl(const QString&, const QString&, | - | ||||||||||||
2352 | const QString&) | - | ||||||||||||
2353 | { | - | ||||||||||||
2354 | return true; | - | ||||||||||||
2355 | } | - | ||||||||||||
2356 | - | |||||||||||||
2357 | /*! | - | ||||||||||||
2358 | \reimp | - | ||||||||||||
2359 | - | |||||||||||||
2360 | This reimplementation does nothing. | - | ||||||||||||
2361 | */ | - | ||||||||||||
2362 | bool QXmlDefaultHandler::unparsedEntityDecl(const QString&, const QString&, | - | ||||||||||||
2363 | const QString&, const QString&) | - | ||||||||||||
2364 | { | - | ||||||||||||
2365 | return true; | - | ||||||||||||
2366 | } | - | ||||||||||||
2367 | - | |||||||||||||
2368 | /*! | - | ||||||||||||
2369 | \reimp | - | ||||||||||||
2370 | - | |||||||||||||
2371 | Sets \a ret to 0, so that the reader uses the system identifier | - | ||||||||||||
2372 | provided in the XML document. | - | ||||||||||||
2373 | */ | - | ||||||||||||
2374 | bool QXmlDefaultHandler::resolveEntity(const QString&, const QString&, | - | ||||||||||||
2375 | QXmlInputSource*& ret) | - | ||||||||||||
2376 | { | - | ||||||||||||
2377 | ret = 0; | - | ||||||||||||
2378 | return true; | - | ||||||||||||
2379 | } | - | ||||||||||||
2380 | - | |||||||||||||
2381 | /*! | - | ||||||||||||
2382 | \reimp | - | ||||||||||||
2383 | - | |||||||||||||
2384 | Returns the default error string. | - | ||||||||||||
2385 | */ | - | ||||||||||||
2386 | QString QXmlDefaultHandler::errorString() const | - | ||||||||||||
2387 | { | - | ||||||||||||
2388 | return QString::fromLatin1(XMLERR_ERRORBYCONSUMER); | - | ||||||||||||
2389 | } | - | ||||||||||||
2390 | - | |||||||||||||
2391 | /*! | - | ||||||||||||
2392 | \reimp | - | ||||||||||||
2393 | - | |||||||||||||
2394 | This reimplementation does nothing. | - | ||||||||||||
2395 | */ | - | ||||||||||||
2396 | bool QXmlDefaultHandler::startDTD(const QString&, const QString&, const QString&) | - | ||||||||||||
2397 | { | - | ||||||||||||
2398 | return true; | - | ||||||||||||
2399 | } | - | ||||||||||||
2400 | - | |||||||||||||
2401 | /*! | - | ||||||||||||
2402 | \reimp | - | ||||||||||||
2403 | - | |||||||||||||
2404 | This reimplementation does nothing. | - | ||||||||||||
2405 | */ | - | ||||||||||||
2406 | bool QXmlDefaultHandler::endDTD() | - | ||||||||||||
2407 | { | - | ||||||||||||
2408 | return true; | - | ||||||||||||
2409 | } | - | ||||||||||||
2410 | - | |||||||||||||
2411 | /*! | - | ||||||||||||
2412 | \reimp | - | ||||||||||||
2413 | - | |||||||||||||
2414 | This reimplementation does nothing. | - | ||||||||||||
2415 | */ | - | ||||||||||||
2416 | bool QXmlDefaultHandler::startEntity(const QString&) | - | ||||||||||||
2417 | { | - | ||||||||||||
2418 | return true; | - | ||||||||||||
2419 | } | - | ||||||||||||
2420 | - | |||||||||||||
2421 | /*! | - | ||||||||||||
2422 | \reimp | - | ||||||||||||
2423 | - | |||||||||||||
2424 | This reimplementation does nothing. | - | ||||||||||||
2425 | */ | - | ||||||||||||
2426 | bool QXmlDefaultHandler::endEntity(const QString&) | - | ||||||||||||
2427 | { | - | ||||||||||||
2428 | return true; | - | ||||||||||||
2429 | } | - | ||||||||||||
2430 | - | |||||||||||||
2431 | /*! | - | ||||||||||||
2432 | \reimp | - | ||||||||||||
2433 | - | |||||||||||||
2434 | This reimplementation does nothing. | - | ||||||||||||
2435 | */ | - | ||||||||||||
2436 | bool QXmlDefaultHandler::startCDATA() | - | ||||||||||||
2437 | { | - | ||||||||||||
2438 | return true; | - | ||||||||||||
2439 | } | - | ||||||||||||
2440 | - | |||||||||||||
2441 | /*! | - | ||||||||||||
2442 | \reimp | - | ||||||||||||
2443 | - | |||||||||||||
2444 | This reimplementation does nothing. | - | ||||||||||||
2445 | */ | - | ||||||||||||
2446 | bool QXmlDefaultHandler::endCDATA() | - | ||||||||||||
2447 | { | - | ||||||||||||
2448 | return true; | - | ||||||||||||
2449 | } | - | ||||||||||||
2450 | - | |||||||||||||
2451 | /*! | - | ||||||||||||
2452 | \reimp | - | ||||||||||||
2453 | - | |||||||||||||
2454 | This reimplementation does nothing. | - | ||||||||||||
2455 | */ | - | ||||||||||||
2456 | bool QXmlDefaultHandler::comment(const QString&) | - | ||||||||||||
2457 | { | - | ||||||||||||
2458 | return true; | - | ||||||||||||
2459 | } | - | ||||||||||||
2460 | - | |||||||||||||
2461 | /*! | - | ||||||||||||
2462 | \reimp | - | ||||||||||||
2463 | - | |||||||||||||
2464 | This reimplementation does nothing. | - | ||||||||||||
2465 | */ | - | ||||||||||||
2466 | bool QXmlDefaultHandler::attributeDecl(const QString&, const QString&, const QString&, const QString&, const QString&) | - | ||||||||||||
2467 | { | - | ||||||||||||
2468 | return true; | - | ||||||||||||
2469 | } | - | ||||||||||||
2470 | - | |||||||||||||
2471 | /*! | - | ||||||||||||
2472 | \reimp | - | ||||||||||||
2473 | - | |||||||||||||
2474 | This reimplementation does nothing. | - | ||||||||||||
2475 | */ | - | ||||||||||||
2476 | bool QXmlDefaultHandler::internalEntityDecl(const QString&, const QString&) | - | ||||||||||||
2477 | { | - | ||||||||||||
2478 | return true; | - | ||||||||||||
2479 | } | - | ||||||||||||
2480 | - | |||||||||||||
2481 | /*! | - | ||||||||||||
2482 | \reimp | - | ||||||||||||
2483 | - | |||||||||||||
2484 | This reimplementation does nothing. | - | ||||||||||||
2485 | */ | - | ||||||||||||
2486 | bool QXmlDefaultHandler::externalEntityDecl(const QString&, const QString&, const QString&) | - | ||||||||||||
2487 | { | - | ||||||||||||
2488 | return true; | - | ||||||||||||
2489 | } | - | ||||||||||||
2490 | - | |||||||||||||
2491 | - | |||||||||||||
2492 | /********************************************* | - | ||||||||||||
2493 | * | - | ||||||||||||
2494 | * QXmlSimpleReaderPrivate | - | ||||||||||||
2495 | * | - | ||||||||||||
2496 | *********************************************/ | - | ||||||||||||
2497 | - | |||||||||||||
2498 | inline bool QXmlSimpleReaderPrivate::atEnd() | - | ||||||||||||
2499 | { | - | ||||||||||||
2500 | return (c.unicode()|0x0001) == 0xffff; | - | ||||||||||||
2501 | } | - | ||||||||||||
2502 | - | |||||||||||||
2503 | inline void QXmlSimpleReaderPrivate::stringClear() | - | ||||||||||||
2504 | { | - | ||||||||||||
2505 | stringValueLen = 0; stringArrayPos = 0; | - | ||||||||||||
2506 | } | - | ||||||||||||
2507 | inline void QXmlSimpleReaderPrivate::nameClear() | - | ||||||||||||
2508 | { | - | ||||||||||||
2509 | nameValueLen = 0; nameArrayPos = 0; | - | ||||||||||||
2510 | } | - | ||||||||||||
2511 | - | |||||||||||||
2512 | inline void QXmlSimpleReaderPrivate::refClear() | - | ||||||||||||
2513 | { | - | ||||||||||||
2514 | refValueLen = 0; refArrayPos = 0; | - | ||||||||||||
2515 | } | - | ||||||||||||
2516 | - | |||||||||||||
2517 | QXmlSimpleReaderPrivate::QXmlSimpleReaderPrivate(QXmlSimpleReader *reader) | - | ||||||||||||
2518 | { | - | ||||||||||||
2519 | q_ptr = reader; | - | ||||||||||||
2520 | parseStack = 0; | - | ||||||||||||
2521 | - | |||||||||||||
2522 | locator.reset(new QXmlSimpleReaderLocator(reader)); | - | ||||||||||||
2523 | entityRes = 0; | - | ||||||||||||
2524 | dtdHnd = 0; | - | ||||||||||||
2525 | contentHnd = 0; | - | ||||||||||||
2526 | errorHnd = 0; | - | ||||||||||||
2527 | lexicalHnd = 0; | - | ||||||||||||
2528 | declHnd = 0; | - | ||||||||||||
2529 | - | |||||||||||||
2530 | // default feature settings | - | ||||||||||||
2531 | useNamespaces = true; | - | ||||||||||||
2532 | useNamespacePrefixes = false; | - | ||||||||||||
2533 | reportWhitespaceCharData = true; | - | ||||||||||||
2534 | reportEntities = false; | - | ||||||||||||
2535 | } | - | ||||||||||||
2536 | - | |||||||||||||
2537 | QXmlSimpleReaderPrivate::~QXmlSimpleReaderPrivate() | - | ||||||||||||
2538 | { | - | ||||||||||||
2539 | delete parseStack; | - | ||||||||||||
2540 | } | - | ||||||||||||
2541 | - | |||||||||||||
2542 | void QXmlSimpleReaderPrivate::initIncrementalParsing() | - | ||||||||||||
2543 | { | - | ||||||||||||
2544 | if(parseStack) | - | ||||||||||||
2545 | parseStack->clear(); | - | ||||||||||||
2546 | else | - | ||||||||||||
2547 | parseStack = new QStack<ParseState>; | - | ||||||||||||
2548 | } | - | ||||||||||||
2549 | - | |||||||||||||
2550 | /********************************************* | - | ||||||||||||
2551 | * | - | ||||||||||||
2552 | * QXmlSimpleReader | - | ||||||||||||
2553 | * | - | ||||||||||||
2554 | *********************************************/ | - | ||||||||||||
2555 | - | |||||||||||||
2556 | /*! | - | ||||||||||||
2557 | \class QXmlReader | - | ||||||||||||
2558 | \reentrant | - | ||||||||||||
2559 | \brief The QXmlReader class provides an interface for XML readers (i.e. | - | ||||||||||||
2560 | parsers). | - | ||||||||||||
2561 | - | |||||||||||||
2562 | \inmodule QtXml | - | ||||||||||||
2563 | \ingroup xml-tools | - | ||||||||||||
2564 | - | |||||||||||||
2565 | This abstract class provides an interface for all of Qt's XML | - | ||||||||||||
2566 | readers. Currently there is only one implementation of a reader | - | ||||||||||||
2567 | included in Qt's XML module: QXmlSimpleReader. In future releases | - | ||||||||||||
2568 | there might be more readers with different properties available | - | ||||||||||||
2569 | (e.g. a validating parser). | - | ||||||||||||
2570 | - | |||||||||||||
2571 | The design of the XML classes follows the \l{SAX2 Java interface}, with | - | ||||||||||||
2572 | the names adapted to fit Qt naming conventions. It should be very | - | ||||||||||||
2573 | easy for anybody who has worked with SAX2 to get started with the | - | ||||||||||||
2574 | Qt XML classes. | - | ||||||||||||
2575 | - | |||||||||||||
2576 | All readers use the class QXmlInputSource to read the input | - | ||||||||||||
2577 | document. Since you are normally interested in particular content | - | ||||||||||||
2578 | in the XML document, the reader reports the content through | - | ||||||||||||
2579 | special handler classes (QXmlDTDHandler, QXmlDeclHandler, | - | ||||||||||||
2580 | QXmlContentHandler, QXmlEntityResolver, QXmlErrorHandler and | - | ||||||||||||
2581 | QXmlLexicalHandler), which you must subclass, if you want to | - | ||||||||||||
2582 | process the contents. | - | ||||||||||||
2583 | - | |||||||||||||
2584 | Since the handler classes only describe interfaces you must | - | ||||||||||||
2585 | implement all the functions. We provide the QXmlDefaultHandler | - | ||||||||||||
2586 | class to make this easier: it implements a default behavior (do | - | ||||||||||||
2587 | nothing) for all functions, so you can subclass it and just | - | ||||||||||||
2588 | implement the functions you are interested in. | - | ||||||||||||
2589 | - | |||||||||||||
2590 | Features and properties of the reader can be set with setFeature() | - | ||||||||||||
2591 | and setProperty() respectively. You can set the reader to use your | - | ||||||||||||
2592 | own subclasses with setEntityResolver(), setDTDHandler(), | - | ||||||||||||
2593 | setContentHandler(), setErrorHandler(), setLexicalHandler() and | - | ||||||||||||
2594 | setDeclHandler(). The parse itself is started with a call to | - | ||||||||||||
2595 | parse(). | - | ||||||||||||
2596 | - | |||||||||||||
2597 | \sa QXmlSimpleReader | - | ||||||||||||
2598 | */ | - | ||||||||||||
2599 | - | |||||||||||||
2600 | /*! | - | ||||||||||||
2601 | \fn QXmlReader::~QXmlReader() | - | ||||||||||||
2602 | - | |||||||||||||
2603 | Destroys the reader. | - | ||||||||||||
2604 | */ | - | ||||||||||||
2605 | - | |||||||||||||
2606 | /*! | - | ||||||||||||
2607 | \fn bool QXmlReader::feature(const QString& name, bool *ok) const | - | ||||||||||||
2608 | - | |||||||||||||
2609 | If the reader has the feature called \a name, the feature's value | - | ||||||||||||
2610 | is returned. If no such feature exists the return value is | - | ||||||||||||
2611 | undefined. | - | ||||||||||||
2612 | - | |||||||||||||
2613 | If \a ok is not 0: \c{*}\a{ok} is set to true if the reader has the | - | ||||||||||||
2614 | feature called \a name; otherwise \c{*}\a{ok} is set to false. | - | ||||||||||||
2615 | - | |||||||||||||
2616 | \sa setFeature(), hasFeature() | - | ||||||||||||
2617 | */ | - | ||||||||||||
2618 | - | |||||||||||||
2619 | /*! | - | ||||||||||||
2620 | \fn void QXmlReader::setFeature(const QString& name, bool value) | - | ||||||||||||
2621 | - | |||||||||||||
2622 | Sets the feature called \a name to the given \a value. If the | - | ||||||||||||
2623 | reader doesn't have the feature nothing happens. | - | ||||||||||||
2624 | - | |||||||||||||
2625 | \sa feature(), hasFeature() | - | ||||||||||||
2626 | */ | - | ||||||||||||
2627 | - | |||||||||||||
2628 | /*! | - | ||||||||||||
2629 | \fn bool QXmlReader::hasFeature(const QString& name) const | - | ||||||||||||
2630 | - | |||||||||||||
2631 | Returns \c true if the reader has the feature called \a name; | - | ||||||||||||
2632 | otherwise returns \c false. | - | ||||||||||||
2633 | - | |||||||||||||
2634 | \sa feature(), setFeature() | - | ||||||||||||
2635 | */ | - | ||||||||||||
2636 | - | |||||||||||||
2637 | /*! | - | ||||||||||||
2638 | \fn void* QXmlReader::property(const QString& name, bool *ok) const | - | ||||||||||||
2639 | - | |||||||||||||
2640 | If the reader has the property \a name, this function returns the | - | ||||||||||||
2641 | value of the property; otherwise the return value is undefined. | - | ||||||||||||
2642 | - | |||||||||||||
2643 | If \a ok is not 0: if the reader has the \a name property | - | ||||||||||||
2644 | \c{*}\a{ok} is set to true; otherwise \c{*}\a{ok} is set to false. | - | ||||||||||||
2645 | - | |||||||||||||
2646 | \sa setProperty(), hasProperty() | - | ||||||||||||
2647 | */ | - | ||||||||||||
2648 | - | |||||||||||||
2649 | /*! | - | ||||||||||||
2650 | \fn void QXmlReader::setProperty(const QString& name, void* value) | - | ||||||||||||
2651 | - | |||||||||||||
2652 | Sets the property \a name to \a value. If the reader doesn't have | - | ||||||||||||
2653 | the property nothing happens. | - | ||||||||||||
2654 | - | |||||||||||||
2655 | \sa property(), hasProperty() | - | ||||||||||||
2656 | */ | - | ||||||||||||
2657 | - | |||||||||||||
2658 | /*! | - | ||||||||||||
2659 | \fn bool QXmlReader::hasProperty(const QString& name) const | - | ||||||||||||
2660 | - | |||||||||||||
2661 | Returns \c true if the reader has the property \a name; otherwise | - | ||||||||||||
2662 | returns \c false. | - | ||||||||||||
2663 | - | |||||||||||||
2664 | \sa property(), setProperty() | - | ||||||||||||
2665 | */ | - | ||||||||||||
2666 | - | |||||||||||||
2667 | /*! | - | ||||||||||||
2668 | \fn void QXmlReader::setEntityResolver(QXmlEntityResolver* handler) | - | ||||||||||||
2669 | - | |||||||||||||
2670 | Sets the entity resolver to \a handler. | - | ||||||||||||
2671 | - | |||||||||||||
2672 | \sa entityResolver() | - | ||||||||||||
2673 | */ | - | ||||||||||||
2674 | - | |||||||||||||
2675 | /*! | - | ||||||||||||
2676 | \fn QXmlEntityResolver* QXmlReader::entityResolver() const | - | ||||||||||||
2677 | - | |||||||||||||
2678 | Returns the entity resolver or 0 if none was set. | - | ||||||||||||
2679 | - | |||||||||||||
2680 | \sa setEntityResolver() | - | ||||||||||||
2681 | */ | - | ||||||||||||
2682 | - | |||||||||||||
2683 | /*! | - | ||||||||||||
2684 | \fn void QXmlReader::setDTDHandler(QXmlDTDHandler* handler) | - | ||||||||||||
2685 | - | |||||||||||||
2686 | Sets the DTD handler to \a handler. | - | ||||||||||||
2687 | - | |||||||||||||
2688 | \sa DTDHandler() | - | ||||||||||||
2689 | */ | - | ||||||||||||
2690 | - | |||||||||||||
2691 | /*! | - | ||||||||||||
2692 | \fn QXmlDTDHandler* QXmlReader::DTDHandler() const | - | ||||||||||||
2693 | - | |||||||||||||
2694 | Returns the DTD handler or 0 if none was set. | - | ||||||||||||
2695 | - | |||||||||||||
2696 | \sa setDTDHandler() | - | ||||||||||||
2697 | */ | - | ||||||||||||
2698 | - | |||||||||||||
2699 | /*! | - | ||||||||||||
2700 | \fn void QXmlReader::setContentHandler(QXmlContentHandler* handler) | - | ||||||||||||
2701 | - | |||||||||||||
2702 | Sets the content handler to \a handler. | - | ||||||||||||
2703 | - | |||||||||||||
2704 | \sa contentHandler() | - | ||||||||||||
2705 | */ | - | ||||||||||||
2706 | - | |||||||||||||
2707 | /*! | - | ||||||||||||
2708 | \fn QXmlContentHandler* QXmlReader::contentHandler() const | - | ||||||||||||
2709 | - | |||||||||||||
2710 | Returns the content handler or 0 if none was set. | - | ||||||||||||
2711 | - | |||||||||||||
2712 | \sa setContentHandler() | - | ||||||||||||
2713 | */ | - | ||||||||||||
2714 | - | |||||||||||||
2715 | /*! | - | ||||||||||||
2716 | \fn void QXmlReader::setErrorHandler(QXmlErrorHandler* handler) | - | ||||||||||||
2717 | - | |||||||||||||
2718 | Sets the error handler to \a handler. Clears the error handler if | - | ||||||||||||
2719 | \a handler is 0. | - | ||||||||||||
2720 | - | |||||||||||||
2721 | \sa errorHandler() | - | ||||||||||||
2722 | */ | - | ||||||||||||
2723 | - | |||||||||||||
2724 | /*! | - | ||||||||||||
2725 | \fn QXmlErrorHandler* QXmlReader::errorHandler() const | - | ||||||||||||
2726 | - | |||||||||||||
2727 | Returns the error handler or 0 if none is set. | - | ||||||||||||
2728 | - | |||||||||||||
2729 | \sa setErrorHandler() | - | ||||||||||||
2730 | */ | - | ||||||||||||
2731 | - | |||||||||||||
2732 | /*! | - | ||||||||||||
2733 | \fn void QXmlReader::setLexicalHandler(QXmlLexicalHandler* handler) | - | ||||||||||||
2734 | - | |||||||||||||
2735 | Sets the lexical handler to \a handler. | - | ||||||||||||
2736 | - | |||||||||||||
2737 | \sa lexicalHandler() | - | ||||||||||||
2738 | */ | - | ||||||||||||
2739 | - | |||||||||||||
2740 | /*! | - | ||||||||||||
2741 | \fn QXmlLexicalHandler* QXmlReader::lexicalHandler() const | - | ||||||||||||
2742 | - | |||||||||||||
2743 | Returns the lexical handler or 0 if none was set. | - | ||||||||||||
2744 | - | |||||||||||||
2745 | \sa setLexicalHandler() | - | ||||||||||||
2746 | */ | - | ||||||||||||
2747 | - | |||||||||||||
2748 | /*! | - | ||||||||||||
2749 | \fn void QXmlReader::setDeclHandler(QXmlDeclHandler* handler) | - | ||||||||||||
2750 | - | |||||||||||||
2751 | Sets the declaration handler to \a handler. | - | ||||||||||||
2752 | - | |||||||||||||
2753 | \sa declHandler() | - | ||||||||||||
2754 | */ | - | ||||||||||||
2755 | - | |||||||||||||
2756 | /*! | - | ||||||||||||
2757 | \fn QXmlDeclHandler* QXmlReader::declHandler() const | - | ||||||||||||
2758 | - | |||||||||||||
2759 | Returns the declaration handler or 0 if none was set. | - | ||||||||||||
2760 | - | |||||||||||||
2761 | \sa setDeclHandler() | - | ||||||||||||
2762 | */ | - | ||||||||||||
2763 | - | |||||||||||||
2764 | /*! | - | ||||||||||||
2765 | \fn bool QXmlReader::parse(const QXmlInputSource &input) | - | ||||||||||||
2766 | - | |||||||||||||
2767 | \obsolete | - | ||||||||||||
2768 | - | |||||||||||||
2769 | Parses the given \a input. | - | ||||||||||||
2770 | */ | - | ||||||||||||
2771 | - | |||||||||||||
2772 | /*! | - | ||||||||||||
2773 | \fn bool QXmlReader::parse(const QXmlInputSource *input) | - | ||||||||||||
2774 | - | |||||||||||||
2775 | Reads an XML document from \a input and parses it. Returns \c true if | - | ||||||||||||
2776 | the parsing was successful; otherwise returns \c false. | - | ||||||||||||
2777 | */ | - | ||||||||||||
2778 | - | |||||||||||||
2779 | - | |||||||||||||
2780 | /*! | - | ||||||||||||
2781 | \class QXmlSimpleReader | - | ||||||||||||
2782 | \nonreentrant | - | ||||||||||||
2783 | \brief The QXmlSimpleReader class provides an implementation of a | - | ||||||||||||
2784 | simple XML parser. | - | ||||||||||||
2785 | - | |||||||||||||
2786 | \inmodule QtXml | - | ||||||||||||
2787 | \ingroup xml-tools | - | ||||||||||||
2788 | - | |||||||||||||
2789 | - | |||||||||||||
2790 | This XML reader is suitable for a wide range of applications. It | - | ||||||||||||
2791 | is able to parse well-formed XML and can report the namespaces of | - | ||||||||||||
2792 | elements to a content handler; however, it does not parse any | - | ||||||||||||
2793 | external entities. For historical reasons, Attribute Value | - | ||||||||||||
2794 | Normalization and End-of-Line Handling as described in the XML 1.0 | - | ||||||||||||
2795 | specification is not performed. | - | ||||||||||||
2796 | - | |||||||||||||
2797 | The easiest pattern of use for this class is to create a reader | - | ||||||||||||
2798 | instance, define an input source, specify the handlers to be used | - | ||||||||||||
2799 | by the reader, and parse the data. | - | ||||||||||||
2800 | - | |||||||||||||
2801 | For example, we could use a QFile to supply the input. Here, we | - | ||||||||||||
2802 | create a reader, and define an input source to be used by the | - | ||||||||||||
2803 | reader: | - | ||||||||||||
2804 | - | |||||||||||||
2805 | \snippet simpleparse/main.cpp 0 | - | ||||||||||||
2806 | - | |||||||||||||
2807 | A handler lets us perform actions when the reader encounters | - | ||||||||||||
2808 | certain types of content, or if errors in the input are found. The | - | ||||||||||||
2809 | reader must be told which handler to use for each type of | - | ||||||||||||
2810 | event. For many common applications, we can create a custom | - | ||||||||||||
2811 | handler by subclassing QXmlDefaultHandler, and use this to handle | - | ||||||||||||
2812 | both error and content events: | - | ||||||||||||
2813 | - | |||||||||||||
2814 | \snippet simpleparse/main.cpp 1 | - | ||||||||||||
2815 | - | |||||||||||||
2816 | If you don't set at least the content and error handlers, the | - | ||||||||||||
2817 | parser will fall back on its default behavior---and will do | - | ||||||||||||
2818 | nothing. | - | ||||||||||||
2819 | - | |||||||||||||
2820 | The most convenient way to handle the input is to read it in a | - | ||||||||||||
2821 | single pass using the parse() function with an argument that | - | ||||||||||||
2822 | specifies the input source: | - | ||||||||||||
2823 | - | |||||||||||||
2824 | \snippet simpleparse/main.cpp 2 | - | ||||||||||||
2825 | - | |||||||||||||
2826 | If you can't parse the entire input in one go (for example, it is | - | ||||||||||||
2827 | huge, or is being delivered over a network connection), data can | - | ||||||||||||
2828 | be fed to the parser in pieces. This is achieved by telling | - | ||||||||||||
2829 | parse() to work incrementally, and making subsequent calls to the | - | ||||||||||||
2830 | parseContinue() function, until all the data has been processed. | - | ||||||||||||
2831 | - | |||||||||||||
2832 | A common way to perform incremental parsing is to connect the \c | - | ||||||||||||
2833 | readyRead() signal of a \l{QNetworkReply} {network reply} a slot, | - | ||||||||||||
2834 | and handle the incoming data there. See QNetworkAccessManager. | - | ||||||||||||
2835 | - | |||||||||||||
2836 | Aspects of the parsing behavior can be adapted using setFeature() | - | ||||||||||||
2837 | and setProperty(). | - | ||||||||||||
2838 | - | |||||||||||||
2839 | \snippet code/src_xml_sax_qxml.cpp 0 | - | ||||||||||||
2840 | - | |||||||||||||
2841 | QXmlSimpleReader is not reentrant. If you want to use the class | - | ||||||||||||
2842 | in threaded code, lock the code using QXmlSimpleReader with a | - | ||||||||||||
2843 | locking mechanism, such as a QMutex. | - | ||||||||||||
2844 | */ | - | ||||||||||||
2845 | - | |||||||||||||
2846 | static inline bool is_S(QChar ch) | - | ||||||||||||
2847 | { | - | ||||||||||||
2848 | ushort uc = ch.unicode(); | - | ||||||||||||
2849 | return (uc == ' ' || uc == '\t' || uc == '\n' || uc == '\r'); | - | ||||||||||||
2850 | } | - | ||||||||||||
2851 | - | |||||||||||||
2852 | enum NameChar { NameBeginning, NameNotBeginning, NotName }; | - | ||||||||||||
2853 | - | |||||||||||||
2854 | static const char Begi = (char)NameBeginning; | - | ||||||||||||
2855 | static const char NtBg = (char)NameNotBeginning; | - | ||||||||||||
2856 | static const char NotN = (char)NotName; | - | ||||||||||||
2857 | - | |||||||||||||
2858 | static const char nameCharTable[128] = | - | ||||||||||||
2859 | { | - | ||||||||||||
2860 | // 0x00 | - | ||||||||||||
2861 | NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN, | - | ||||||||||||
2862 | NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN, | - | ||||||||||||
2863 | // 0x10 | - | ||||||||||||
2864 | NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN, | - | ||||||||||||
2865 | NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN, | - | ||||||||||||
2866 | // 0x20 (0x2D is '-', 0x2E is '.') | - | ||||||||||||
2867 | NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN, | - | ||||||||||||
2868 | NotN, NotN, NotN, NotN, NotN, NtBg, NtBg, NotN, | - | ||||||||||||
2869 | // 0x30 (0x30..0x39 are '0'..'9', 0x3A is ':') | - | ||||||||||||
2870 | NtBg, NtBg, NtBg, NtBg, NtBg, NtBg, NtBg, NtBg, | - | ||||||||||||
2871 | NtBg, NtBg, Begi, NotN, NotN, NotN, NotN, NotN, | - | ||||||||||||
2872 | // 0x40 (0x41..0x5A are 'A'..'Z') | - | ||||||||||||
2873 | NotN, Begi, Begi, Begi, Begi, Begi, Begi, Begi, | - | ||||||||||||
2874 | Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi, | - | ||||||||||||
2875 | // 0x50 (0x5F is '_') | - | ||||||||||||
2876 | Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi, | - | ||||||||||||
2877 | Begi, Begi, Begi, NotN, NotN, NotN, NotN, Begi, | - | ||||||||||||
2878 | // 0x60 (0x61..0x7A are 'a'..'z') | - | ||||||||||||
2879 | NotN, Begi, Begi, Begi, Begi, Begi, Begi, Begi, | - | ||||||||||||
2880 | Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi, | - | ||||||||||||
2881 | // 0x70 | - | ||||||||||||
2882 | Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi, | - | ||||||||||||
2883 | Begi, Begi, Begi, NotN, NotN, NotN, NotN, NotN | - | ||||||||||||
2884 | }; | - | ||||||||||||
2885 | - | |||||||||||||
2886 | static inline NameChar fastDetermineNameChar(QChar ch) | - | ||||||||||||
2887 | { | - | ||||||||||||
2888 | ushort uc = ch.unicode(); | - | ||||||||||||
2889 | if (!(uc & ~0x7f)) // uc < 128 | - | ||||||||||||
2890 | return (NameChar)nameCharTable[uc]; | - | ||||||||||||
2891 | - | |||||||||||||
2892 | QChar::Category cat = ch.category(); | - | ||||||||||||
2893 | // ### some these categories might be slightly wrong | - | ||||||||||||
2894 | if ((cat >= QChar::Letter_Uppercase && cat <= QChar::Letter_Other) | - | ||||||||||||
2895 | || cat == QChar::Number_Letter) | - | ||||||||||||
2896 | return NameBeginning; | - | ||||||||||||
2897 | if ((cat >= QChar::Number_DecimalDigit && cat <= QChar::Number_Other) | - | ||||||||||||
2898 | || (cat >= QChar::Mark_NonSpacing && cat <= QChar::Mark_Enclosing)) | - | ||||||||||||
2899 | return NameNotBeginning; | - | ||||||||||||
2900 | return NotName; | - | ||||||||||||
2901 | } | - | ||||||||||||
2902 | - | |||||||||||||
2903 | static NameChar determineNameChar(QChar ch) | - | ||||||||||||
2904 | { | - | ||||||||||||
2905 | return fastDetermineNameChar(ch); | - | ||||||||||||
2906 | } | - | ||||||||||||
2907 | - | |||||||||||||
2908 | /*! | - | ||||||||||||
2909 | Constructs a simple XML reader. | - | ||||||||||||
2910 | - | |||||||||||||
2911 | */ | - | ||||||||||||
2912 | QXmlSimpleReader::QXmlSimpleReader() | - | ||||||||||||
2913 | : d_ptr(new QXmlSimpleReaderPrivate(this)) | - | ||||||||||||
2914 | { | - | ||||||||||||
2915 | } | - | ||||||||||||
2916 | - | |||||||||||||
2917 | /*! | - | ||||||||||||
2918 | Destroys the simple XML reader. | - | ||||||||||||
2919 | */ | - | ||||||||||||
2920 | QXmlSimpleReader::~QXmlSimpleReader() | - | ||||||||||||
2921 | { | - | ||||||||||||
2922 | } | - | ||||||||||||
2923 | - | |||||||||||||
2924 | /*! | - | ||||||||||||
2925 | \reimp | - | ||||||||||||
2926 | */ | - | ||||||||||||
2927 | bool QXmlSimpleReader::feature(const QString& name, bool *ok) const | - | ||||||||||||
2928 | { | - | ||||||||||||
2929 | const QXmlSimpleReaderPrivate *d = d_func(); | - | ||||||||||||
2930 | - | |||||||||||||
2931 | if (ok != 0) | - | ||||||||||||
2932 | *ok = true; | - | ||||||||||||
2933 | if (name == QLatin1String("http://xml.org/sax/features/namespaces")) { | - | ||||||||||||
2934 | return d->useNamespaces; | - | ||||||||||||
2935 | } else if (name == QLatin1String("http://xml.org/sax/features/namespace-prefixes")) { | - | ||||||||||||
2936 | return d->useNamespacePrefixes; | - | ||||||||||||
2937 | } else if (name == QLatin1String("http://trolltech.com/xml/features/report-whitespace-only-CharData") // For compat with Qt 4 | - | ||||||||||||
2938 | || name == QLatin1String("http://qt-project.org/xml/features/report-whitespace-only-CharData")) { | - | ||||||||||||
2939 | return d->reportWhitespaceCharData; | - | ||||||||||||
2940 | } else if (name == QLatin1String("http://trolltech.com/xml/features/report-start-end-entity") // For compat with Qt 4 | - | ||||||||||||
2941 | || name == QLatin1String("http://qt-project.org/xml/features/report-start-end-entity")) { | - | ||||||||||||
2942 | return d->reportEntities; | - | ||||||||||||
2943 | } else { | - | ||||||||||||
2944 | qWarning("Unknown feature %s", name.toLatin1().data()); | - | ||||||||||||
2945 | if (ok != 0) | - | ||||||||||||
2946 | *ok = false; | - | ||||||||||||
2947 | } | - | ||||||||||||
2948 | return false; | - | ||||||||||||
2949 | } | - | ||||||||||||
2950 | - | |||||||||||||
2951 | /*! | - | ||||||||||||
2952 | Turns on the feature \a name if \a enable is true; otherwise turns it off. | - | ||||||||||||
2953 | - | |||||||||||||
2954 | The \a name parameter must be one of the following strings: | - | ||||||||||||
2955 | \table | - | ||||||||||||
2956 | \header \li Feature \li Default \li Notes | - | ||||||||||||
2957 | \row \li \e http://xml.org/sax/features/namespaces | - | ||||||||||||
2958 | \li true | - | ||||||||||||
2959 | \li If enabled, namespaces are reported to the content handler. | - | ||||||||||||
2960 | \row \li \e http://xml.org/sax/features/namespace-prefixes | - | ||||||||||||
2961 | \li false | - | ||||||||||||
2962 | \li If enabled, the original prefixed names | - | ||||||||||||
2963 | and attributes used for namespace declarations are | - | ||||||||||||
2964 | reported. | - | ||||||||||||
2965 | \row \li \e http://qt-project.org/xml/features/report-whitespace-only-CharData | - | ||||||||||||
2966 | \li true | - | ||||||||||||
2967 | \li If enabled, CharData that consist of | - | ||||||||||||
2968 | only whitespace characters are reported | - | ||||||||||||
2969 | using QXmlContentHandler::characters(). If disabled, whitespace is silently | - | ||||||||||||
2970 | discarded. | - | ||||||||||||
2971 | \row \li \e http://qt-project.org/xml/features/report-start-end-entity | - | ||||||||||||
2972 | \li false | - | ||||||||||||
2973 | \li If enabled, the parser reports | - | ||||||||||||
2974 | QXmlContentHandler::startEntity() and | - | ||||||||||||
2975 | QXmlContentHandler::endEntity() events, so character data | - | ||||||||||||
2976 | might be reported in chunks. | - | ||||||||||||
2977 | If disabled, the parser does not report these events, but | - | ||||||||||||
2978 | silently substitutes the entities, and reports the character | - | ||||||||||||
2979 | data in one chunk. | - | ||||||||||||
2980 | \endtable | - | ||||||||||||
2981 | - | |||||||||||||
2982 | \sa feature(), hasFeature(), {SAX2 Features} | - | ||||||||||||
2983 | */ | - | ||||||||||||
2984 | void QXmlSimpleReader::setFeature(const QString& name, bool enable) | - | ||||||||||||
2985 | { | - | ||||||||||||
2986 | Q_D(QXmlSimpleReader); | - | ||||||||||||
2987 | if (name == QLatin1String("http://xml.org/sax/features/namespaces")) { | - | ||||||||||||
2988 | d->useNamespaces = enable; | - | ||||||||||||
2989 | } else if (name == QLatin1String("http://xml.org/sax/features/namespace-prefixes")) { | - | ||||||||||||
2990 | d->useNamespacePrefixes = enable; | - | ||||||||||||
2991 | } else if (name == QLatin1String("http://trolltech.com/xml/features/report-whitespace-only-CharData") // For compat with Qt 4 | - | ||||||||||||
2992 | || name == QLatin1String("http://qt-project.org/xml/features/report-whitespace-only-CharData")) { | - | ||||||||||||
2993 | d->reportWhitespaceCharData = enable; | - | ||||||||||||
2994 | } else if (name == QLatin1String("http://trolltech.com/xml/features/report-start-end-entity") // For compat with Qt 4 | - | ||||||||||||
2995 | || name == QLatin1String("http://qt-project.org/xml/features/report-start-end-entity")) { | - | ||||||||||||
2996 | d->reportEntities = enable; | - | ||||||||||||
2997 | } else { | - | ||||||||||||
2998 | qWarning("Unknown feature %s", name.toLatin1().data()); | - | ||||||||||||
2999 | } | - | ||||||||||||
3000 | } | - | ||||||||||||
3001 | - | |||||||||||||
3002 | /*! \reimp | - | ||||||||||||
3003 | */ | - | ||||||||||||
3004 | bool QXmlSimpleReader::hasFeature(const QString& name) const | - | ||||||||||||
3005 | { | - | ||||||||||||
3006 | if (name == QLatin1String("http://xml.org/sax/features/namespaces") | - | ||||||||||||
3007 | || name == QLatin1String("http://xml.org/sax/features/namespace-prefixes") | - | ||||||||||||
3008 | || name == QLatin1String("http://trolltech.com/xml/features/report-whitespace-only-CharData") // For compat with Qt 4 | - | ||||||||||||
3009 | || name == QLatin1String("http://qt-project.org/xml/features/report-whitespace-only-CharData") | - | ||||||||||||
3010 | || name == QLatin1String("http://trolltech.com/xml/features/report-start-end-entity") // For compat with Qt 4 | - | ||||||||||||
3011 | || name == QLatin1String("http://qt-project.org/xml/features/report-start-end-entity")) { | - | ||||||||||||
3012 | return true; | - | ||||||||||||
3013 | } else { | - | ||||||||||||
3014 | return false; | - | ||||||||||||
3015 | } | - | ||||||||||||
3016 | } | - | ||||||||||||
3017 | - | |||||||||||||
3018 | /*! \reimp | - | ||||||||||||
3019 | */ | - | ||||||||||||
3020 | void* QXmlSimpleReader::property(const QString&, bool *ok) const | - | ||||||||||||
3021 | { | - | ||||||||||||
3022 | if (ok != 0) | - | ||||||||||||
3023 | *ok = false; | - | ||||||||||||
3024 | return 0; | - | ||||||||||||
3025 | } | - | ||||||||||||
3026 | - | |||||||||||||
3027 | /*! \reimp | - | ||||||||||||
3028 | */ | - | ||||||||||||
3029 | void QXmlSimpleReader::setProperty(const QString&, void*) | - | ||||||||||||
3030 | { | - | ||||||||||||
3031 | } | - | ||||||||||||
3032 | - | |||||||||||||
3033 | /*! | - | ||||||||||||
3034 | \reimp | - | ||||||||||||
3035 | */ | - | ||||||||||||
3036 | bool QXmlSimpleReader::hasProperty(const QString&) const | - | ||||||||||||
3037 | { | - | ||||||||||||
3038 | return false; | - | ||||||||||||
3039 | } | - | ||||||||||||
3040 | - | |||||||||||||
3041 | /*! | - | ||||||||||||
3042 | \reimp | - | ||||||||||||
3043 | */ | - | ||||||||||||
3044 | void QXmlSimpleReader::setEntityResolver(QXmlEntityResolver* handler) | - | ||||||||||||
3045 | { | - | ||||||||||||
3046 | Q_D(QXmlSimpleReader); | - | ||||||||||||
3047 | d->entityRes = handler; | - | ||||||||||||
3048 | } | - | ||||||||||||
3049 | - | |||||||||||||
3050 | /*! | - | ||||||||||||
3051 | \reimp | - | ||||||||||||
3052 | */ | - | ||||||||||||
3053 | QXmlEntityResolver* QXmlSimpleReader::entityResolver() const | - | ||||||||||||
3054 | { | - | ||||||||||||
3055 | const QXmlSimpleReaderPrivate *d = d_func(); | - | ||||||||||||
3056 | return d->entityRes; | - | ||||||||||||
3057 | } | - | ||||||||||||
3058 | - | |||||||||||||
3059 | /*! | - | ||||||||||||
3060 | \reimp | - | ||||||||||||
3061 | */ | - | ||||||||||||
3062 | void QXmlSimpleReader::setDTDHandler(QXmlDTDHandler* handler) | - | ||||||||||||
3063 | { | - | ||||||||||||
3064 | Q_D(QXmlSimpleReader); | - | ||||||||||||
3065 | d->dtdHnd = handler; | - | ||||||||||||
3066 | } | - | ||||||||||||
3067 | - | |||||||||||||
3068 | /*! | - | ||||||||||||
3069 | \reimp | - | ||||||||||||
3070 | */ | - | ||||||||||||
3071 | QXmlDTDHandler* QXmlSimpleReader::DTDHandler() const | - | ||||||||||||
3072 | { | - | ||||||||||||
3073 | const QXmlSimpleReaderPrivate *d = d_func(); | - | ||||||||||||
3074 | return d->dtdHnd; | - | ||||||||||||
3075 | } | - | ||||||||||||
3076 | - | |||||||||||||
3077 | /*! | - | ||||||||||||
3078 | \reimp | - | ||||||||||||
3079 | */ | - | ||||||||||||
3080 | void QXmlSimpleReader::setContentHandler(QXmlContentHandler* handler) | - | ||||||||||||
3081 | { | - | ||||||||||||
3082 | Q_D(QXmlSimpleReader); | - | ||||||||||||
3083 | d->contentHnd = handler; | - | ||||||||||||
3084 | } | - | ||||||||||||
3085 | - | |||||||||||||
3086 | /*! | - | ||||||||||||
3087 | \reimp | - | ||||||||||||
3088 | */ | - | ||||||||||||
3089 | QXmlContentHandler* QXmlSimpleReader::contentHandler() const | - | ||||||||||||
3090 | { | - | ||||||||||||
3091 | const QXmlSimpleReaderPrivate *d = d_func(); | - | ||||||||||||
3092 | return d->contentHnd; | - | ||||||||||||
3093 | } | - | ||||||||||||
3094 | - | |||||||||||||
3095 | /*! | - | ||||||||||||
3096 | \reimp | - | ||||||||||||
3097 | */ | - | ||||||||||||
3098 | void QXmlSimpleReader::setErrorHandler(QXmlErrorHandler* handler) | - | ||||||||||||
3099 | { | - | ||||||||||||
3100 | Q_D(QXmlSimpleReader); | - | ||||||||||||
3101 | d->errorHnd = handler; | - | ||||||||||||
3102 | } | - | ||||||||||||
3103 | - | |||||||||||||
3104 | /*! | - | ||||||||||||
3105 | \reimp | - | ||||||||||||
3106 | */ | - | ||||||||||||
3107 | QXmlErrorHandler* QXmlSimpleReader::errorHandler() const | - | ||||||||||||
3108 | { | - | ||||||||||||
3109 | const QXmlSimpleReaderPrivate *d = d_func(); | - | ||||||||||||
3110 | return d->errorHnd; | - | ||||||||||||
3111 | } | - | ||||||||||||
3112 | - | |||||||||||||
3113 | /*! | - | ||||||||||||
3114 | \reimp | - | ||||||||||||
3115 | */ | - | ||||||||||||
3116 | void QXmlSimpleReader::setLexicalHandler(QXmlLexicalHandler* handler) | - | ||||||||||||
3117 | { | - | ||||||||||||
3118 | Q_D(QXmlSimpleReader); | - | ||||||||||||
3119 | d->lexicalHnd = handler; | - | ||||||||||||
3120 | } | - | ||||||||||||
3121 | - | |||||||||||||
3122 | /*! | - | ||||||||||||
3123 | \reimp | - | ||||||||||||
3124 | */ | - | ||||||||||||
3125 | QXmlLexicalHandler* QXmlSimpleReader::lexicalHandler() const | - | ||||||||||||
3126 | { | - | ||||||||||||
3127 | const QXmlSimpleReaderPrivate *d = d_func(); | - | ||||||||||||
3128 | return d->lexicalHnd; | - | ||||||||||||
3129 | } | - | ||||||||||||
3130 | - | |||||||||||||
3131 | /*! | - | ||||||||||||
3132 | \reimp | - | ||||||||||||
3133 | */ | - | ||||||||||||
3134 | void QXmlSimpleReader::setDeclHandler(QXmlDeclHandler* handler) | - | ||||||||||||
3135 | { | - | ||||||||||||
3136 | Q_D(QXmlSimpleReader); | - | ||||||||||||
3137 | d->declHnd = handler; | - | ||||||||||||
3138 | } | - | ||||||||||||
3139 | - | |||||||||||||
3140 | /*! | - | ||||||||||||
3141 | \reimp | - | ||||||||||||
3142 | */ | - | ||||||||||||
3143 | QXmlDeclHandler* QXmlSimpleReader::declHandler() const | - | ||||||||||||
3144 | { | - | ||||||||||||
3145 | const QXmlSimpleReaderPrivate *d = d_func(); | - | ||||||||||||
3146 | return d->declHnd; | - | ||||||||||||
3147 | } | - | ||||||||||||
3148 | - | |||||||||||||
3149 | - | |||||||||||||
3150 | - | |||||||||||||
3151 | /*! | - | ||||||||||||
3152 | \reimp | - | ||||||||||||
3153 | */ | - | ||||||||||||
3154 | bool QXmlSimpleReader::parse(const QXmlInputSource& input) | - | ||||||||||||
3155 | { | - | ||||||||||||
3156 | return parse(&input, false); | - | ||||||||||||
3157 | } | - | ||||||||||||
3158 | - | |||||||||||||
3159 | /*! | - | ||||||||||||
3160 | Reads an XML document from \a input and parses it in one pass (non-incrementally). | - | ||||||||||||
3161 | Returns \c true if the parsing was successful; otherwise returns \c false. | - | ||||||||||||
3162 | */ | - | ||||||||||||
3163 | bool QXmlSimpleReader::parse(const QXmlInputSource* input) | - | ||||||||||||
3164 | { | - | ||||||||||||
3165 | return parse(input, false); | - | ||||||||||||
3166 | } | - | ||||||||||||
3167 | - | |||||||||||||
3168 | /*! | - | ||||||||||||
3169 | Reads an XML document from \a input and parses it. Returns \c true | - | ||||||||||||
3170 | if the parsing is completed successfully; otherwise returns \c false, | - | ||||||||||||
3171 | indicating that an error occurred. | - | ||||||||||||
3172 | - | |||||||||||||
3173 | If \a incremental is false, this function will return false if the XML | - | ||||||||||||
3174 | file is not read completely. The parsing cannot be continued in this | - | ||||||||||||
3175 | case. | - | ||||||||||||
3176 | - | |||||||||||||
3177 | If \a incremental is true, the parser does not return false if | - | ||||||||||||
3178 | it reaches the end of the \a input before reaching the end | - | ||||||||||||
3179 | of the XML file. Instead, it stores the state of the parser so that | - | ||||||||||||
3180 | parsing can be continued later when more data is available. | - | ||||||||||||
3181 | In such a case, you can use the function parseContinue() to | - | ||||||||||||
3182 | continue with parsing. This class stores a pointer to the input | - | ||||||||||||
3183 | source \a input and the parseContinue() function tries to read from | - | ||||||||||||
3184 | that input source. Therefore, you should not delete the input | - | ||||||||||||
3185 | source \a input until you no longer need to call parseContinue(). | - | ||||||||||||
3186 | - | |||||||||||||
3187 | If this function is called with \a incremental set to true | - | ||||||||||||
3188 | while an incremental parse is in progress, a new parsing | - | ||||||||||||
3189 | session will be started, and the previous session will be lost. | - | ||||||||||||
3190 | - | |||||||||||||
3191 | \sa parseContinue(), QTcpSocket | - | ||||||||||||
3192 | */ | - | ||||||||||||
3193 | bool QXmlSimpleReader::parse(const QXmlInputSource *input, bool incremental) | - | ||||||||||||
3194 | { | - | ||||||||||||
3195 | Q_D(QXmlSimpleReader); | - | ||||||||||||
3196 | - | |||||||||||||
3197 | d->literalEntitySizes.clear(); | - | ||||||||||||
3198 | d->referencesToOtherEntities.clear(); | - | ||||||||||||
3199 | d->expandedSizes.clear(); | - | ||||||||||||
3200 | - | |||||||||||||
3201 | if (incremental) {
| 616-1490 | ||||||||||||
3202 | d->initIncrementalParsing(); | - | ||||||||||||
3203 | } else { executed 1490 times by 1 test: end of block Executed by:
| 1490 | ||||||||||||
3204 | delete d->parseStack; | - | ||||||||||||
3205 | d->parseStack = 0; | - | ||||||||||||
3206 | } executed 616 times by 6 tests: end of block Executed by:
| 616 | ||||||||||||
3207 | d->init(input); | - | ||||||||||||
3208 | - | |||||||||||||
3209 | // call the handler | - | ||||||||||||
3210 | if (d->contentHnd) {
| 6-2100 | ||||||||||||
3211 | d->contentHnd->setDocumentLocator(d->locator.data()); | - | ||||||||||||
3212 | if (!d->contentHnd->startDocument()) {
| 0-2100 | ||||||||||||
3213 | d->reportParseError(d->contentHnd->errorString()); | - | ||||||||||||
3214 | clear(d->tags.clear();); | - | ||||||||||||
3215 | return false; never executed: return false; | 0 | ||||||||||||
3216 | } | - | ||||||||||||
3217 | } executed 2100 times by 6 tests: end of block Executed by:
| 2100 | ||||||||||||
3218 | d->skipped_entity_in_content = false; | - | ||||||||||||
3219 | return d->parseBeginOrContinue(0, incremental); executed 2106 times by 6 tests: return d->parseBeginOrContinue(0, incremental); Executed by:
| 2106 | ||||||||||||
3220 | } | - | ||||||||||||
3221 | - | |||||||||||||
3222 | /*! | - | ||||||||||||
3223 | Continues incremental parsing, taking input from the | - | ||||||||||||
3224 | QXmlInputSource that was specified with the most recent | - | ||||||||||||
3225 | call to parse(). To use this function, you \e must have called | - | ||||||||||||
3226 | parse() with the incremental argument set to true. | - | ||||||||||||
3227 | - | |||||||||||||
3228 | Returns \c false if a parsing error occurs; otherwise returns \c true, | - | ||||||||||||
3229 | even if the end of the XML file has not been reached. You can | - | ||||||||||||
3230 | continue parsing at a later stage by calling this function again | - | ||||||||||||
3231 | when there is more data available to parse. | - | ||||||||||||
3232 | - | |||||||||||||
3233 | Calling this function when there is no data available in the input | - | ||||||||||||
3234 | source indicates to the reader that the end of the XML file has | - | ||||||||||||
3235 | been reached. If the input supplied up to this point was | - | ||||||||||||
3236 | not well-formed then a parsing error occurs, and false is returned. | - | ||||||||||||
3237 | If the input supplied was well-formed, true is returned. | - | ||||||||||||
3238 | It is important to end the input in this way because it allows you | - | ||||||||||||
3239 | to reuse the reader to parse other XML files. | - | ||||||||||||
3240 | - | |||||||||||||
3241 | Calling this function after the end of file has been reached, but | - | ||||||||||||
3242 | without available data will cause false to be returned whether the | - | ||||||||||||
3243 | previous input was well-formed or not. | - | ||||||||||||
3244 | - | |||||||||||||
3245 | \sa parse(), QXmlInputSource::data(), QXmlInputSource::next() | - | ||||||||||||
3246 | */ | - | ||||||||||||
3247 | bool QXmlSimpleReader::parseContinue() | - | ||||||||||||
3248 | { | - | ||||||||||||
3249 | Q_D(QXmlSimpleReader); | - | ||||||||||||
3250 | if (d->parseStack == 0 || d->parseStack->isEmpty()) | - | ||||||||||||
3251 | return false; | - | ||||||||||||
3252 | d->initData(); | - | ||||||||||||
3253 | int state = d->parseStack->pop().state; | - | ||||||||||||
3254 | return d->parseBeginOrContinue(state, true); | - | ||||||||||||
3255 | } | - | ||||||||||||
3256 | - | |||||||||||||
3257 | /* | - | ||||||||||||
3258 | Common part of parse() and parseContinue() | - | ||||||||||||
3259 | */ | - | ||||||||||||
3260 | bool QXmlSimpleReaderPrivate::parseBeginOrContinue(int state, bool incremental) | - | ||||||||||||
3261 | { | - | ||||||||||||
3262 | bool atEndOrig = atEnd(); | - | ||||||||||||
3263 | - | |||||||||||||
3264 | if (state==0) {
| 10967-36047 | ||||||||||||
3265 | if (!parseProlog()) {
| 2029-34018 | ||||||||||||
3266 | if (incremental && error.isNull()) {
| 0-33941 | ||||||||||||
3267 | pushParseState(0, 0); | - | ||||||||||||
3268 | return true; executed 33941 times by 1 test: return true; Executed by:
| 33941 | ||||||||||||
3269 | } else { | - | ||||||||||||
3270 | tags.clear();(tags); | - | ||||||||||||
3271 | return false; executed 77 times by 1 test: return false; Executed by:
| 77 | ||||||||||||
3272 | } | - | ||||||||||||
3273 | } | - | ||||||||||||
3274 | state = 1; | - | ||||||||||||
3275 | } executed 2029 times by 6 tests: end of block Executed by:
| 2029 | ||||||||||||
3276 | if (state==1) {
| 2514-10482 | ||||||||||||
3277 | if (!parseElement()) {
| 1961-8521 | ||||||||||||
3278 | if (incremental && error.isNull()) {
| 0-8453 | ||||||||||||
3279 | pushParseState(0, 1); | - | ||||||||||||
3280 | return true; executed 8453 times by 1 test: return true; Executed by:
| 8453 | ||||||||||||
3281 | } else { | - | ||||||||||||
3282 | tags.clear();(tags); | - | ||||||||||||
3283 | return false; executed 68 times by 1 test: return false; Executed by:
| 68 | ||||||||||||
3284 | } | - | ||||||||||||
3285 | } | - | ||||||||||||
3286 | state = 2; | - | ||||||||||||
3287 | } executed 1961 times by 6 tests: end of block Executed by:
| 1961 | ||||||||||||
3288 | // parse Misc* | - | ||||||||||||
3289 | while (!atEnd()) {
| 2340-2392 | ||||||||||||
3290 | if (!parseMisc()) {
| 257-2083 | ||||||||||||
3291 | if (incremental && error.isNull()) {
| 0-2073 | ||||||||||||
3292 | pushParseState(0, 2); | - | ||||||||||||
3293 | return true; executed 2073 times by 1 test: return true; Executed by:
| 2073 | ||||||||||||
3294 | } else { | - | ||||||||||||
3295 | tags.clear();(tags); | - | ||||||||||||
3296 | return false; executed 10 times by 1 test: return false; Executed by:
| 10 | ||||||||||||
3297 | } | - | ||||||||||||
3298 | } | - | ||||||||||||
3299 | } executed 257 times by 2 tests: end of block Executed by:
| 257 | ||||||||||||
3300 | if (!atEndOrig && incremental) {
| 441-1490 | ||||||||||||
3301 | // we parsed something at all, so be prepared to come back later | - | ||||||||||||
3302 | pushParseState(0, 2); | - | ||||||||||||
3303 | return true; executed 441 times by 1 test: return true; Executed by:
| 441 | ||||||||||||
3304 | } | - | ||||||||||||
3305 | // is stack empty? | - | ||||||||||||
3306 | if (!tags.isEmptyempty() && !error.isNull()) {
| 0-1951 | ||||||||||||
3307 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDEOF)); | - | ||||||||||||
3308 | tags.clear();(tags); | - | ||||||||||||
3309 | return false; never executed: return false; | 0 | ||||||||||||
3310 | } | - | ||||||||||||
3311 | // call the handler | - | ||||||||||||
3312 | if (contentHnd) {
| 1-1950 | ||||||||||||
3313 | delete parseStack; | - | ||||||||||||
3314 | parseStack = 0; | - | ||||||||||||
3315 | if (!contentHnd->endDocument()) {
| 0-1950 | ||||||||||||
3316 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3317 | return false; never executed: return false; | 0 | ||||||||||||
3318 | } | - | ||||||||||||
3319 | } executed 1950 times by 6 tests: end of block Executed by:
| 1950 | ||||||||||||
3320 | return true; executed 1951 times by 6 tests: return true; Executed by:
| 1951 | ||||||||||||
3321 | } | - | ||||||||||||
3322 | - | |||||||||||||
3323 | // | - | ||||||||||||
3324 | // The following private parse functions have another semantics for the return | - | ||||||||||||
3325 | // value: They return true iff parsing has finished successfully (i.e. the end | - | ||||||||||||
3326 | // of the XML file must be reached!). If one of these functions return false, | - | ||||||||||||
3327 | // there is only an error when d->error.isNULL() is also false. | - | ||||||||||||
3328 | // | - | ||||||||||||
3329 | - | |||||||||||||
3330 | /* | - | ||||||||||||
3331 | For the incremental parsing, it is very important that the parse...() | - | ||||||||||||
3332 | functions have a certain structure. Since it might be hard to understand how | - | ||||||||||||
3333 | they work, here is a description of the layout of these functions: | - | ||||||||||||
3334 | - | |||||||||||||
3335 | bool QXmlSimpleReader::parse...() | - | ||||||||||||
3336 | { | - | ||||||||||||
3337 | (1) const signed char Init = 0; | - | ||||||||||||
3338 | ... | - | ||||||||||||
3339 | - | |||||||||||||
3340 | (2) const signed char Inp... = 0; | - | ||||||||||||
3341 | ... | - | ||||||||||||
3342 | - | |||||||||||||
3343 | (3) static const signed char table[3][2] = { | - | ||||||||||||
3344 | ... | - | ||||||||||||
3345 | }; | - | ||||||||||||
3346 | signed char state; | - | ||||||||||||
3347 | signed char input; | - | ||||||||||||
3348 | - | |||||||||||||
3349 | (4) if (d->parseStack == 0 || d->parseStack->isEmpty()) { | - | ||||||||||||
3350 | (4a) ... | - | ||||||||||||
3351 | } else { | - | ||||||||||||
3352 | (4b) ... | - | ||||||||||||
3353 | } | - | ||||||||||||
3354 | - | |||||||||||||
3355 | for (; ;) { | - | ||||||||||||
3356 | (5) switch (state) { | - | ||||||||||||
3357 | ... | - | ||||||||||||
3358 | } | - | ||||||||||||
3359 | - | |||||||||||||
3360 | (6) | - | ||||||||||||
3361 | (6a) if (atEnd()) { | - | ||||||||||||
3362 | unexpectedEof(&QXmlSimpleReader::parseNmtoken, state); | - | ||||||||||||
3363 | return false; | - | ||||||||||||
3364 | } | - | ||||||||||||
3365 | (6b) if (determineNameChar(c) != NotName) { | - | ||||||||||||
3366 | ... | - | ||||||||||||
3367 | } | - | ||||||||||||
3368 | (7) state = table[state][input]; | - | ||||||||||||
3369 | - | |||||||||||||
3370 | (8) switch (state) { | - | ||||||||||||
3371 | ... | - | ||||||||||||
3372 | } | - | ||||||||||||
3373 | } | - | ||||||||||||
3374 | } | - | ||||||||||||
3375 | - | |||||||||||||
3376 | Explanation: | - | ||||||||||||
3377 | ad 1: constants for the states (used in the transition table) | - | ||||||||||||
3378 | ad 2: constants for the input (used in the transition table) | - | ||||||||||||
3379 | ad 3: the transition table for the state machine | - | ||||||||||||
3380 | ad 4: test if we are in a parseContinue() step | - | ||||||||||||
3381 | a) if no, do inititalizations | - | ||||||||||||
3382 | b) if yes, restore the state and call parse functions recursively | - | ||||||||||||
3383 | ad 5: Do some actions according to the state; from the logical execution | - | ||||||||||||
3384 | order, this code belongs after 8 (see there for an explanation) | - | ||||||||||||
3385 | ad 6: Check the character that is at the actual "cursor" position: | - | ||||||||||||
3386 | a) If we reached the EOF, report either error or push the state (in the | - | ||||||||||||
3387 | case of incremental parsing). | - | ||||||||||||
3388 | b) Otherwise, set the input character constant for the transition | - | ||||||||||||
3389 | table. | - | ||||||||||||
3390 | ad 7: Get the new state according to the input that was read. | - | ||||||||||||
3391 | ad 8: Do some actions according to the state. The last line in every case | - | ||||||||||||
3392 | statement reads new data (i.e. it move the cursor). This can also be | - | ||||||||||||
3393 | done by calling another parse...() function. If you need processing for | - | ||||||||||||
3394 | this state after that, you have to put it into the switch statement 5. | - | ||||||||||||
3395 | This ensures that you have a well defined re-entry point, when you ran | - | ||||||||||||
3396 | out of data. | - | ||||||||||||
3397 | */ | - | ||||||||||||
3398 | - | |||||||||||||
3399 | /* | - | ||||||||||||
3400 | Parses the prolog [22]. | - | ||||||||||||
3401 | */ | - | ||||||||||||
3402 | - | |||||||||||||
3403 | bool QXmlSimpleReaderPrivate::parseProlog() | - | ||||||||||||
3404 | { | - | ||||||||||||
3405 | const signed char Init = 0; | - | ||||||||||||
3406 | const signed char EatWS = 1; // eat white spaces | - | ||||||||||||
3407 | const signed char Lt = 2; // '<' read | - | ||||||||||||
3408 | const signed char Em = 3; // '!' read | - | ||||||||||||
3409 | const signed char DocType = 4; // read doctype | - | ||||||||||||
3410 | const signed char Comment = 5; // read comment | - | ||||||||||||
3411 | const signed char CommentR = 6; // same as Comment, but already reported | - | ||||||||||||
3412 | const signed char PInstr = 7; // read PI | - | ||||||||||||
3413 | const signed char PInstrR = 8; // same as PInstr, but already reported | - | ||||||||||||
3414 | const signed char Done = 9; | - | ||||||||||||
3415 | - | |||||||||||||
3416 | const signed char InpWs = 0; | - | ||||||||||||
3417 | const signed char InpLt = 1; // < | - | ||||||||||||
3418 | const signed char InpQm = 2; // ? | - | ||||||||||||
3419 | const signed char InpEm = 3; // ! | - | ||||||||||||
3420 | const signed char InpD = 4; // D | - | ||||||||||||
3421 | const signed char InpDash = 5; // - | - | ||||||||||||
3422 | const signed char InpUnknown = 6; | - | ||||||||||||
3423 | - | |||||||||||||
3424 | static const signed char table[9][7] = { | - | ||||||||||||
3425 | /* InpWs InpLt InpQm InpEm InpD InpDash InpUnknown */ | - | ||||||||||||
3426 | { EatWS, Lt, -1, -1, -1, -1, -1 }, // Init | - | ||||||||||||
3427 | { -1, Lt, -1, -1, -1, -1, -1 }, // EatWS | - | ||||||||||||
3428 | { -1, -1, PInstr,Em, Done, -1, Done }, // Lt | - | ||||||||||||
3429 | { -1, -1, -1, -1, DocType, Comment, -1 }, // Em | - | ||||||||||||
3430 | { EatWS, Lt, -1, -1, -1, -1, -1 }, // DocType | - | ||||||||||||
3431 | { EatWS, Lt, -1, -1, -1, -1, -1 }, // Comment | - | ||||||||||||
3432 | { EatWS, Lt, -1, -1, -1, -1, -1 }, // CommentR | - | ||||||||||||
3433 | { EatWS, Lt, -1, -1, -1, -1, -1 }, // PInstr | - | ||||||||||||
3434 | { EatWS, Lt, -1, -1, -1, -1, -1 } // PInstrR | - | ||||||||||||
3435 | }; | - | ||||||||||||
3436 | signed char state; | - | ||||||||||||
3437 | signed char input; | - | ||||||||||||
3438 | - | |||||||||||||
3439 | if (parseStack == 0 || parseStack->isEmpty()) { | - | ||||||||||||
3440 | xmldecl_possible = true; | - | ||||||||||||
3441 | doctype_read = false; | - | ||||||||||||
3442 | state = Init; | - | ||||||||||||
3443 | } else { | - | ||||||||||||
3444 | state = parseStack->pop().state; | - | ||||||||||||
3445 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
3446 | qDebug("QXmlSimpleReader: parseProlog (cont) in state %d", state); | - | ||||||||||||
3447 | #endif | - | ||||||||||||
3448 | if (!parseStack->isEmpty()) { | - | ||||||||||||
3449 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
3450 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
3451 | parseStack->pop(); | - | ||||||||||||
3452 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
3453 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
3454 | #endif | - | ||||||||||||
3455 | } | - | ||||||||||||
3456 | if (!(this->*function)()) { | - | ||||||||||||
3457 | parseFailed(&QXmlSimpleReaderPrivate::parseProlog, state); | - | ||||||||||||
3458 | return false; | - | ||||||||||||
3459 | } | - | ||||||||||||
3460 | } | - | ||||||||||||
3461 | } | - | ||||||||||||
3462 | - | |||||||||||||
3463 | for (;;) { | - | ||||||||||||
3464 | switch (state) { | - | ||||||||||||
3465 | case DocType: | - | ||||||||||||
3466 | if (doctype_read) { | - | ||||||||||||
3467 | reportParseError(QLatin1String(XMLERR_MORETHANONEDOCTYPE)); | - | ||||||||||||
3468 | return false; | - | ||||||||||||
3469 | } else { | - | ||||||||||||
3470 | doctype_read = false; | - | ||||||||||||
3471 | } | - | ||||||||||||
3472 | break; | - | ||||||||||||
3473 | case Comment: | - | ||||||||||||
3474 | if (lexicalHnd) { | - | ||||||||||||
3475 | if (!lexicalHnd->comment(string())) { | - | ||||||||||||
3476 | reportParseError(lexicalHnd->errorString()); | - | ||||||||||||
3477 | return false; | - | ||||||||||||
3478 | } | - | ||||||||||||
3479 | } | - | ||||||||||||
3480 | state = CommentR; | - | ||||||||||||
3481 | break; | - | ||||||||||||
3482 | case PInstr: | - | ||||||||||||
3483 | // call the handler | - | ||||||||||||
3484 | if (contentHnd) { | - | ||||||||||||
3485 | if (xmldecl_possible && !xmlVersion.isEmpty()) { | - | ||||||||||||
3486 | QString value(QLatin1String("version='")); | - | ||||||||||||
3487 | value += xmlVersion; | - | ||||||||||||
3488 | value += QLatin1Char('\''); | - | ||||||||||||
3489 | if (!encoding.isEmpty()) { | - | ||||||||||||
3490 | value += QLatin1String(" encoding='"); | - | ||||||||||||
3491 | value += encoding; | - | ||||||||||||
3492 | value += QLatin1Char('\''); | - | ||||||||||||
3493 | } | - | ||||||||||||
3494 | if (standalone == QXmlSimpleReaderPrivate::Yes) { | - | ||||||||||||
3495 | value += QLatin1String(" standalone='yes'"); | - | ||||||||||||
3496 | } else if (standalone == QXmlSimpleReaderPrivate::No) { | - | ||||||||||||
3497 | value += QLatin1String(" standalone='no'"); | - | ||||||||||||
3498 | } | - | ||||||||||||
3499 | if (!contentHnd->processingInstruction(QLatin1String("xml"), value)) { | - | ||||||||||||
3500 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3501 | return false; | - | ||||||||||||
3502 | } | - | ||||||||||||
3503 | } else { | - | ||||||||||||
3504 | if (!contentHnd->processingInstruction(name(), string())) { | - | ||||||||||||
3505 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3506 | return false; | - | ||||||||||||
3507 | } | - | ||||||||||||
3508 | } | - | ||||||||||||
3509 | } | - | ||||||||||||
3510 | // XML declaration only on first position possible | - | ||||||||||||
3511 | xmldecl_possible = false; | - | ||||||||||||
3512 | state = PInstrR; | - | ||||||||||||
3513 | break; | - | ||||||||||||
3514 | case Done: | - | ||||||||||||
3515 | return true; | - | ||||||||||||
3516 | case -1: | - | ||||||||||||
3517 | reportParseError(QLatin1String(XMLERR_ERRORPARSINGELEMENT)); | - | ||||||||||||
3518 | return false; | - | ||||||||||||
3519 | } | - | ||||||||||||
3520 | - | |||||||||||||
3521 | if (atEnd()) { | - | ||||||||||||
3522 | unexpectedEof(&QXmlSimpleReaderPrivate::parseProlog, state); | - | ||||||||||||
3523 | return false; | - | ||||||||||||
3524 | } | - | ||||||||||||
3525 | if (is_S(c)) { | - | ||||||||||||
3526 | input = InpWs; | - | ||||||||||||
3527 | } else if (c == QLatin1Char('<')) { | - | ||||||||||||
3528 | input = InpLt; | - | ||||||||||||
3529 | } else if (c == QLatin1Char('?')) { | - | ||||||||||||
3530 | input = InpQm; | - | ||||||||||||
3531 | } else if (c == QLatin1Char('!')) { | - | ||||||||||||
3532 | input = InpEm; | - | ||||||||||||
3533 | } else if (c == QLatin1Char('D')) { | - | ||||||||||||
3534 | input = InpD; | - | ||||||||||||
3535 | } else if (c == QLatin1Char('-')) { | - | ||||||||||||
3536 | input = InpDash; | - | ||||||||||||
3537 | } else { | - | ||||||||||||
3538 | input = InpUnknown; | - | ||||||||||||
3539 | } | - | ||||||||||||
3540 | state = table[state][input]; | - | ||||||||||||
3541 | - | |||||||||||||
3542 | switch (state) { | - | ||||||||||||
3543 | case EatWS: | - | ||||||||||||
3544 | // XML declaration only on first position possible | - | ||||||||||||
3545 | xmldecl_possible = false; | - | ||||||||||||
3546 | if (!eat_ws()) { | - | ||||||||||||
3547 | parseFailed(&QXmlSimpleReaderPrivate::parseProlog, state); | - | ||||||||||||
3548 | return false; | - | ||||||||||||
3549 | } | - | ||||||||||||
3550 | break; | - | ||||||||||||
3551 | case Lt: | - | ||||||||||||
3552 | next(); | - | ||||||||||||
3553 | break; | - | ||||||||||||
3554 | case Em: | - | ||||||||||||
3555 | // XML declaration only on first position possible | - | ||||||||||||
3556 | xmldecl_possible = false; | - | ||||||||||||
3557 | next(); | - | ||||||||||||
3558 | break; | - | ||||||||||||
3559 | case DocType: | - | ||||||||||||
3560 | if (!parseDoctype()) { | - | ||||||||||||
3561 | parseFailed(&QXmlSimpleReaderPrivate::parseProlog, state); | - | ||||||||||||
3562 | return false; | - | ||||||||||||
3563 | } | - | ||||||||||||
3564 | break; | - | ||||||||||||
3565 | case Comment: | - | ||||||||||||
3566 | case CommentR: | - | ||||||||||||
3567 | if (!parseComment()) { | - | ||||||||||||
3568 | parseFailed(&QXmlSimpleReaderPrivate::parseProlog, state); | - | ||||||||||||
3569 | return false; | - | ||||||||||||
3570 | } | - | ||||||||||||
3571 | break; | - | ||||||||||||
3572 | case PInstr: | - | ||||||||||||
3573 | case PInstrR: | - | ||||||||||||
3574 | parsePI_xmldecl = xmldecl_possible; | - | ||||||||||||
3575 | if (!parsePI()) { | - | ||||||||||||
3576 | parseFailed(&QXmlSimpleReaderPrivate::parseProlog, state); | - | ||||||||||||
3577 | return false; | - | ||||||||||||
3578 | } | - | ||||||||||||
3579 | break; | - | ||||||||||||
3580 | } | - | ||||||||||||
3581 | } | - | ||||||||||||
3582 | return false; | - | ||||||||||||
3583 | } | - | ||||||||||||
3584 | - | |||||||||||||
3585 | /* | - | ||||||||||||
3586 | Parse an element [39]. | - | ||||||||||||
3587 | - | |||||||||||||
3588 | Precondition: the opening '<' is already read. | - | ||||||||||||
3589 | */ | - | ||||||||||||
3590 | bool QXmlSimpleReaderPrivate::parseElement() | - | ||||||||||||
3591 | { | - | ||||||||||||
3592 | const int Init = 0; | - | ||||||||||||
3593 | const int ReadName = 1; | - | ||||||||||||
3594 | const int Ws1 = 2; | - | ||||||||||||
3595 | const int STagEnd = 3; | - | ||||||||||||
3596 | const int STagEnd2 = 4; | - | ||||||||||||
3597 | const int ETagBegin = 5; | - | ||||||||||||
3598 | const int ETagBegin2 = 6; | - | ||||||||||||
3599 | const int Ws2 = 7; | - | ||||||||||||
3600 | const int EmptyTag = 8; | - | ||||||||||||
3601 | const int Attrib = 9; | - | ||||||||||||
3602 | const int AttribPro = 10; // like Attrib, but processAttribute was already called | - | ||||||||||||
3603 | const int Ws3 = 11; | - | ||||||||||||
3604 | const int Done = 12; | - | ||||||||||||
3605 | - | |||||||||||||
3606 | const int InpWs = 0; // whitespace | - | ||||||||||||
3607 | const int InpNameBe = 1; // NameBeginning | - | ||||||||||||
3608 | const int InpGt = 2; // > | - | ||||||||||||
3609 | const int InpSlash = 3; // / | - | ||||||||||||
3610 | const int InpUnknown = 4; | - | ||||||||||||
3611 | - | |||||||||||||
3612 | static const int table[12][5] = { | - | ||||||||||||
3613 | /* InpWs InpNameBe InpGt InpSlash InpUnknown */ | - | ||||||||||||
3614 | { -1, ReadName, -1, -1, -1 }, // Init | - | ||||||||||||
3615 | { Ws1, Attrib, STagEnd, EmptyTag, -1 }, // ReadName | - | ||||||||||||
3616 | { -1, Attrib, STagEnd, EmptyTag, -1 }, // Ws1 | - | ||||||||||||
3617 | { STagEnd2, STagEnd2, STagEnd2, STagEnd2, STagEnd2 }, // STagEnd | - | ||||||||||||
3618 | { -1, -1, -1, ETagBegin, -1 }, // STagEnd2 | - | ||||||||||||
3619 | { -1, ETagBegin2, -1, -1, -1 }, // ETagBegin | - | ||||||||||||
3620 | { Ws2, -1, Done, -1, -1 }, // ETagBegin2 | - | ||||||||||||
3621 | { -1, -1, Done, -1, -1 }, // Ws2 | - | ||||||||||||
3622 | { -1, -1, Done, -1, -1 }, // EmptyTag | - | ||||||||||||
3623 | { Ws3, Attrib, STagEnd, EmptyTag, -1 }, // Attrib | - | ||||||||||||
3624 | { Ws3, Attrib, STagEnd, EmptyTag, -1 }, // AttribPro | - | ||||||||||||
3625 | { -1, Attrib, STagEnd, EmptyTag, -1 } // Ws3 | - | ||||||||||||
3626 | }; | - | ||||||||||||
3627 | int state; | - | ||||||||||||
3628 | int input; | - | ||||||||||||
3629 | - | |||||||||||||
3630 | if (parseStack == 0 || parseStack->isEmpty()) {
| 1814-11462 | ||||||||||||
3631 | state = Init; | - | ||||||||||||
3632 | } else { executed 5806 times by 6 tests: end of block Executed by:
| 5806 | ||||||||||||
3633 | state = parseStack->pop().state; | - | ||||||||||||
3634 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
3635 | qDebug("QXmlSimpleReader: parseElement (cont) in state %d", state); | - | ||||||||||||
3636 | #endif | - | ||||||||||||
3637 | if (!parseStack->isEmpty()) {
| 1223-8425 | ||||||||||||
3638 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
3639 | if (function == &QXmlSimpleReaderPrivate::eat_ws) {
| 136-8289 | ||||||||||||
3640 | parseStack->pop(); | - | ||||||||||||
3641 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
3642 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
3643 | #endif | - | ||||||||||||
3644 | } executed 136 times by 1 test: end of block Executed by:
| 136 | ||||||||||||
3645 | if (!(this->*function)()) {
| 3566-4859 | ||||||||||||
3646 | parseFailed(&QXmlSimpleReaderPrivate::parseElement, state); | - | ||||||||||||
3647 | return false; executed 4859 times by 1 test: return false; Executed by:
| 4859 | ||||||||||||
3648 | } | - | ||||||||||||
3649 | } executed 3566 times by 1 test: end of block Executed by:
| 3566 | ||||||||||||
3650 | } executed 4789 times by 1 test: end of block Executed by:
| 4789 | ||||||||||||
3651 | - | |||||||||||||
3652 | for (;;) { | - | ||||||||||||
3653 | switch (state) { | - | ||||||||||||
3654 | case ReadName: executed 5802 times by 6 tests: case ReadName: Executed by:
| 5802 | ||||||||||||
3655 | // store it on the stack | - | ||||||||||||
3656 | tags.push(name()); | - | ||||||||||||
3657 | // empty the attributes | - | ||||||||||||
3658 | attList.clear(); | - | ||||||||||||
3659 | if (useNamespaces)
| 1021-4781 | ||||||||||||
3660 | namespaceSupport.pushContext(); executed 4781 times by 3 tests: namespaceSupport.pushContext(); Executed by:
| 4781 | ||||||||||||
3661 | break; executed 5802 times by 6 tests: break; Executed by:
| 5802 | ||||||||||||
3662 | case ETagBegin2: executed 5180 times by 6 tests: case ETagBegin2: Executed by:
| 5180 | ||||||||||||
3663 | if (!processElementETagBegin2())
| 4-5176 | ||||||||||||
3664 | return false; executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||
3665 | break; executed 5176 times by 6 tests: break; Executed by:
| 5176 | ||||||||||||
3666 | case Attrib: executed 12894 times by 6 tests: case Attrib: Executed by:
| 12894 | ||||||||||||
3667 | if (!processElementAttribute())
| 0-12894 | ||||||||||||
3668 | return false; never executed: return false; | 0 | ||||||||||||
3669 | state = AttribPro; | - | ||||||||||||
3670 | break; executed 12894 times by 6 tests: break; Executed by:
| 12894 | ||||||||||||
3671 | case Done: executed 5723 times by 6 tests: case Done: Executed by:
| 5723 | ||||||||||||
3672 | return true; executed 5723 times by 6 tests: return true; Executed by:
| 5723 | ||||||||||||
3673 | case -1: executed 14 times by 1 test: case -1: Executed by:
| 14 | ||||||||||||
3674 | reportParseError(QLatin1String(XMLERR_ERRORPARSINGELEMENT)); | - | ||||||||||||
3675 | return false; executed 14 times by 1 test: return false; Executed by:
| 14 | ||||||||||||
3676 | } | - | ||||||||||||
3677 | - | |||||||||||||
3678 | if (atEnd()) {
| 1225-58942 | ||||||||||||
3679 | unexpectedEof(&QXmlSimpleReaderPrivate::parseElement, state); | - | ||||||||||||
3680 | return false; executed 1225 times by 1 test: return false; Executed by:
| 1225 | ||||||||||||
3681 | } | - | ||||||||||||
3682 | if (fastDetermineNameChar(c) == NameBeginning) {
| 24149-34793 | ||||||||||||
3683 | input = InpNameBe; | - | ||||||||||||
3684 | } else if (c == QLatin1Char('>')) { executed 24149 times by 6 tests: end of block Executed by:
| 10954-24149 | ||||||||||||
3685 | input = InpGt; | - | ||||||||||||
3686 | } else if (is_S(c)) { executed 10954 times by 6 tests: end of block Executed by:
| 7870-15969 | ||||||||||||
3687 | input = InpWs; | - | ||||||||||||
3688 | } else if (c == QLatin1Char('/')) { executed 15969 times by 6 tests: end of block Executed by:
| 2139-15969 | ||||||||||||
3689 | input = InpSlash; | - | ||||||||||||
3690 | } else { executed 5731 times by 6 tests: end of block Executed by:
| 5731 | ||||||||||||
3691 | input = InpUnknown; | - | ||||||||||||
3692 | } executed 2139 times by 5 tests: end of block Executed by:
| 2139 | ||||||||||||
3693 | state = table[state][input]; | - | ||||||||||||
3694 | - | |||||||||||||
3695 | switch (state) { | - | ||||||||||||
3696 | case ReadName: executed 5802 times by 6 tests: case ReadName: Executed by:
| 5802 | ||||||||||||
3697 | parseName_useRef = false; | - | ||||||||||||
3698 | if (!parseName()) {
| 1145-4657 | ||||||||||||
3699 | parseFailed(&QXmlSimpleReaderPrivate::parseElement, state); | - | ||||||||||||
3700 | return false; executed 1145 times by 1 test: return false; Executed by:
| 1145 | ||||||||||||
3701 | } | - | ||||||||||||
3702 | break; executed 4657 times by 6 tests: break; Executed by:
| 4657 | ||||||||||||
3703 | case Ws1: executed 3442 times by 6 tests: case Ws1: Executed by:
| 3442 | ||||||||||||
3704 | case Ws2: executed 20 times by 1 test: case Ws2: Executed by:
| 20 | ||||||||||||
3705 | case Ws3: executed 9662 times by 6 tests: case Ws3: Executed by:
| 9662 | ||||||||||||
3706 | if (!eat_ws()) {
| 134-12990 | ||||||||||||
3707 | parseFailed(&QXmlSimpleReaderPrivate::parseElement, state); | - | ||||||||||||
3708 | return false; executed 134 times by 1 test: return false; Executed by:
| 134 | ||||||||||||
3709 | } | - | ||||||||||||
3710 | break; executed 12990 times by 6 tests: break; Executed by:
| 12990 | ||||||||||||
3711 | case STagEnd: executed 5230 times by 6 tests: case STagEnd: Executed by:
| 5230 | ||||||||||||
3712 | // call the handler | - | ||||||||||||
3713 | if (contentHnd) {
| 4-5226 | ||||||||||||
3714 | const QString &tagsTop = tags.top();if (useNamespaces) {
| 697-4529 | ||||||||||||
3715 | QString uri, lname; | - | ||||||||||||
3716 | namespaceSupport.processName(tagsTop,tags.top(), false, uri, lname); | - | ||||||||||||
3717 | if (!contentHnd->startElement(uri, lname, tagsTop, tags.top(), attList)) {
| 0-4529 | ||||||||||||
3718 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3719 | return false; never executed: return false; | 0 | ||||||||||||
3720 | } | - | ||||||||||||
3721 | } else { executed 4529 times by 2 tests: end of block Executed by:
| 4529 | ||||||||||||
3722 | if (!contentHnd->startElement(QString(), QString(), tagsTop,tags.top(), attList)) {
| 0-697 | ||||||||||||
3723 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3724 | return false; never executed: return false; | 0 | ||||||||||||
3725 | } | - | ||||||||||||
3726 | } executed 697 times by 4 tests: end of block Executed by:
| 697 | ||||||||||||
3727 | } | - | ||||||||||||
3728 | next(); | - | ||||||||||||
3729 | break; executed 5230 times by 6 tests: break; Executed by:
| 5230 | ||||||||||||
3730 | case STagEnd2: executed 5228 times by 6 tests: case STagEnd2: Executed by:
| 5228 | ||||||||||||
3731 | if (!parseContent()) {
| 921-4307 | ||||||||||||
3732 | parseFailed(&QXmlSimpleReaderPrivate::parseElement, state); | - | ||||||||||||
3733 | return false; executed 921 times by 1 test: return false; Executed by:
| 921 | ||||||||||||
3734 | } | - | ||||||||||||
3735 | break; executed 4307 times by 6 tests: break; Executed by:
| 4307 | ||||||||||||
3736 | case ETagBegin: executed 5181 times by 6 tests: case ETagBegin: Executed by:
| 5181 | ||||||||||||
3737 | next(); | - | ||||||||||||
3738 | break; executed 5181 times by 6 tests: break; Executed by:
| 5181 | ||||||||||||
3739 | case ETagBegin2: executed 5180 times by 6 tests: case ETagBegin2: Executed by:
| 5180 | ||||||||||||
3740 | // get the name of the tag | - | ||||||||||||
3741 | parseName_useRef = false; | - | ||||||||||||
3742 | if (!parseName()) {
| 1072-4108 | ||||||||||||
3743 | parseFailed(&QXmlSimpleReaderPrivate::parseElement, state); | - | ||||||||||||
3744 | return false; executed 1072 times by 1 test: return false; Executed by:
| 1072 | ||||||||||||
3745 | } | - | ||||||||||||
3746 | break; executed 4108 times by 6 tests: break; Executed by:
| 4108 | ||||||||||||
3747 | case EmptyTag: executed 550 times by 5 tests: case EmptyTag: Executed by:
| 550 | ||||||||||||
3748 | if (tags.isEmptyempty()) {
| 0-550 | ||||||||||||
3749 | reportParseError(QLatin1String(XMLERR_TAGMISMATCH)); | - | ||||||||||||
3750 | return false; never executed: return false; | 0 | ||||||||||||
3751 | } | - | ||||||||||||
3752 | if (!processElementEmptyTag())
| 0-550 | ||||||||||||
3753 | return false; never executed: return false; | 0 | ||||||||||||
3754 | next(); | - | ||||||||||||
3755 | break; executed 550 times by 5 tests: break; Executed by:
| 550 | ||||||||||||
3756 | case Attrib: executed 12910 times by 6 tests: case Attrib: Executed by:
| 12910 | ||||||||||||
3757 | case AttribPro: never executed: case AttribPro: | 0 | ||||||||||||
3758 | // get name and value of attribute | - | ||||||||||||
3759 | if (!parseAttribute()) {
| 357-12553 | ||||||||||||
3760 | parseFailed(&QXmlSimpleReaderPrivate::parseElement, state); | - | ||||||||||||
3761 | return false; executed 357 times by 1 test: return false; Executed by:
| 357 | ||||||||||||
3762 | } | - | ||||||||||||
3763 | break; executed 12553 times by 6 tests: break; Executed by:
| 12553 | ||||||||||||
3764 | case Done: executed 5723 times by 6 tests: case Done: Executed by:
| 5723 | ||||||||||||
3765 | next(); | - | ||||||||||||
3766 | break; executed 5723 times by 6 tests: break; Executed by:
| 5723 | ||||||||||||
3767 | } | - | ||||||||||||
3768 | } executed 55313 times by 6 tests: end of block Executed by:
| 55313 | ||||||||||||
3769 | return false; never executed: return false; | 0 | ||||||||||||
3770 | } | - | ||||||||||||
3771 | - | |||||||||||||
3772 | /* | - | ||||||||||||
3773 | Helper to break down the size of the code in the case statement. | - | ||||||||||||
3774 | Return false on error, otherwise true. | - | ||||||||||||
3775 | */ | - | ||||||||||||
3776 | bool QXmlSimpleReaderPrivate::processElementEmptyTag() | - | ||||||||||||
3777 | { | - | ||||||||||||
3778 | QString uri, lname; | - | ||||||||||||
3779 | // pop the stack and call the handler | - | ||||||||||||
3780 | if (contentHnd) {
| 9-541 | ||||||||||||
3781 | if (useNamespaces) {
| 217-324 | ||||||||||||
3782 | // report startElement first... | - | ||||||||||||
3783 | namespaceSupport.processName(tags.top(), false, uri, lname); | - | ||||||||||||
3784 | if (!contentHnd->startElement(uri, lname, tags.top(), attList)) {
| 0-217 | ||||||||||||
3785 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3786 | return false; never executed: return false; | 0 | ||||||||||||
3787 | } | - | ||||||||||||
3788 | // ... followed by endElement... | - | ||||||||||||
3789 | if (!const bool endElementReturnedFalse = !contentHnd->endElement(uri, lname, tags.top()); | - | ||||||||||||
3790 | tags.pop()))(); | - | ||||||||||||
3791 | if (endElementReturnedFalse)
| 0-217 | ||||||||||||
3792 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3793 | return false; never executed: return false; | 0 | ||||||||||||
3794 | } | - | ||||||||||||
3795 | // ... followed by endPrefixMapping | - | ||||||||||||
3796 | QStringList prefixesBefore, prefixesAfter; | - | ||||||||||||
3797 | if (contentHnd) {
| 0-217 | ||||||||||||
3798 | prefixesBefore = namespaceSupport.prefixes(); | - | ||||||||||||
3799 | } executed 217 times by 2 tests: end of block Executed by:
| 217 | ||||||||||||
3800 | namespaceSupport.popContext(); | - | ||||||||||||
3801 | // call the handler for prefix mapping | - | ||||||||||||
3802 | prefixesAfter = namespaceSupport.prefixes(); | - | ||||||||||||
3803 | for (QStringList::Iterator it = prefixesBefore.begin(); it != prefixesBefore.end(); ++it) {
| 217-221 | ||||||||||||
3804 | if (!prefixesAfter.contains(*it)) {
| 4-217 | ||||||||||||
3805 | if (!contentHnd->endPrefixMapping(*it)) {
| 0-4 | ||||||||||||
3806 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3807 | return false; never executed: return false; | 0 | ||||||||||||
3808 | } | - | ||||||||||||
3809 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
3810 | } executed 221 times by 2 tests: end of block Executed by:
| 221 | ||||||||||||
3811 | } else { executed 217 times by 2 tests: end of block Executed by:
| 217 | ||||||||||||
3812 | // report startElement first... | - | ||||||||||||
3813 | if (!contentHnd->startElement(QString(), QString(), tags.top(), attList)) {
| 0-324 | ||||||||||||
3814 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3815 | return false; never executed: return false; | 0 | ||||||||||||
3816 | } | - | ||||||||||||
3817 | // ... followed by endElement | - | ||||||||||||
3818 | if (!const bool endElementReturnedFalse = !contentHnd->endElement(QString(), QString(), tags.top()); | - | ||||||||||||
3819 | tags.pop()))(); | - | ||||||||||||
3820 | if (endElementReturnedFalse)
| 0-324 | ||||||||||||
3821 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3822 | return false; never executed: return false; | 0 | ||||||||||||
3823 | } | - | ||||||||||||
3824 | } executed 324 times by 4 tests: end of block Executed by:
| 324 | ||||||||||||
3825 | } else { | - | ||||||||||||
3826 | tags.pop_backpop(); | - | ||||||||||||
3827 | namespaceSupport.popContext(); | - | ||||||||||||
3828 | } executed 9 times by 2 tests: end of block Executed by:
| 9 | ||||||||||||
3829 | return true; executed 550 times by 5 tests: return true; Executed by:
| 550 | ||||||||||||
3830 | } | - | ||||||||||||
3831 | /* | - | ||||||||||||
3832 | Helper to break down the size of the code in the case statement. | - | ||||||||||||
3833 | Return false on error, otherwise true. | - | ||||||||||||
3834 | */ | - | ||||||||||||
3835 | bool QXmlSimpleReaderPrivate::processElementETagBegin2() | - | ||||||||||||
3836 | { | - | ||||||||||||
3837 | const QString &name = QXmlSimpleReaderPrivate::name(); | - | ||||||||||||
3838 | - | |||||||||||||
3839 | // pop the stack and compare it with the name | - | ||||||||||||
3840 | if (const bool nameIsTagsTop = tags.poptop() !=== name; | - | ||||||||||||
3841 | tags.pop(); | - | ||||||||||||
3842 | if (!nameIsTagsTop
| 4-5176 | ||||||||||||
3843 | reportParseError(QLatin1String(XMLERR_TAGMISMATCH)); | - | ||||||||||||
3844 | return false; executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||
3845 | } | - | ||||||||||||
3846 | // call the handler | - | ||||||||||||
3847 | if (contentHnd) {
| 0-5176 | ||||||||||||
3848 | QString uri, lname; | - | ||||||||||||
3849 | - | |||||||||||||
3850 | if (useNamespaces)
| 697-4479 | ||||||||||||
3851 | namespaceSupport.processName(name, false, uri, lname); executed 4479 times by 2 tests: namespaceSupport.processName(name, false, uri, lname); Executed by:
| 4479 | ||||||||||||
3852 | if (!contentHnd->endElement(uri, lname, name)) {
| 0-5176 | ||||||||||||
3853 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3854 | return false; never executed: return false; | 0 | ||||||||||||
3855 | } | - | ||||||||||||
3856 | } executed 5176 times by 6 tests: end of block Executed by:
| 5176 | ||||||||||||
3857 | if (useNamespaces) {
| 697-4479 | ||||||||||||
3858 | NamespaceMap prefixesBefore, prefixesAfter; | - | ||||||||||||
3859 | if (contentHnd)
| 0-4479 | ||||||||||||
3860 | prefixesBefore = namespaceSupport.d->ns; executed 4479 times by 2 tests: prefixesBefore = namespaceSupport.d->ns; Executed by:
| 4479 | ||||||||||||
3861 | - | |||||||||||||
3862 | namespaceSupport.popContext(); | - | ||||||||||||
3863 | // call the handler for prefix mapping | - | ||||||||||||
3864 | if (contentHnd) {
| 0-4479 | ||||||||||||
3865 | prefixesAfter = namespaceSupport.d->ns; | - | ||||||||||||
3866 | if (prefixesBefore.size() != prefixesAfter.size()) {
| 10-4469 | ||||||||||||
3867 | for (NamespaceMap::const_iterator it = prefixesBefore.constBegin(); it != prefixesBefore.constEnd(); ++it) {
| 10-20 | ||||||||||||
3868 | if (!it.key().isEmpty() && !prefixesAfter.contains(it.key())) {
| 0-10 | ||||||||||||
3869 | if (!contentHnd->endPrefixMapping(it.key())) {
| 0 | ||||||||||||
3870 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3871 | return false; never executed: return false; | 0 | ||||||||||||
3872 | } | - | ||||||||||||
3873 | } never executed: end of block | 0 | ||||||||||||
3874 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||
3875 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
3876 | } executed 4479 times by 2 tests: end of block Executed by:
| 4479 | ||||||||||||
3877 | } executed 4479 times by 2 tests: end of block Executed by:
| 4479 | ||||||||||||
3878 | return true; executed 5176 times by 6 tests: return true; Executed by:
| 5176 | ||||||||||||
3879 | } | - | ||||||||||||
3880 | /* | - | ||||||||||||
3881 | Helper to break down the size of the code in the case statement. | - | ||||||||||||
3882 | Return false on error, otherwise true. | - | ||||||||||||
3883 | */ | - | ||||||||||||
3884 | bool QXmlSimpleReaderPrivate::processElementAttribute() | - | ||||||||||||
3885 | { | - | ||||||||||||
3886 | QString uri, lname, prefix; | - | ||||||||||||
3887 | const QString &name = QXmlSimpleReaderPrivate::name(); | - | ||||||||||||
3888 | const QString &string = QXmlSimpleReaderPrivate::string(); | - | ||||||||||||
3889 | - | |||||||||||||
3890 | // add the attribute to the list | - | ||||||||||||
3891 | if (useNamespaces) { | - | ||||||||||||
3892 | // is it a namespace declaration? | - | ||||||||||||
3893 | namespaceSupport.splitName(name, prefix, lname); | - | ||||||||||||
3894 | if (prefix == QLatin1String("xmlns")) { | - | ||||||||||||
3895 | // namespace declaration | - | ||||||||||||
3896 | namespaceSupport.setPrefix(lname, string); | - | ||||||||||||
3897 | if (useNamespacePrefixes) { | - | ||||||||||||
3898 | // according to http://www.w3.org/2000/xmlns/, the "prefix" | - | ||||||||||||
3899 | // xmlns maps to the namespace name | - | ||||||||||||
3900 | // http://www.w3.org/2000/xmlns/ | - | ||||||||||||
3901 | attList.append(name, QLatin1String("http://www.w3.org/2000/xmlns/"), lname, string); | - | ||||||||||||
3902 | } | - | ||||||||||||
3903 | // call the handler for prefix mapping | - | ||||||||||||
3904 | if (contentHnd) { | - | ||||||||||||
3905 | if (!contentHnd->startPrefixMapping(lname, string)) { | - | ||||||||||||
3906 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
3907 | return false; | - | ||||||||||||
3908 | } | - | ||||||||||||
3909 | } | - | ||||||||||||
3910 | } else { | - | ||||||||||||
3911 | // no namespace delcaration | - | ||||||||||||
3912 | namespaceSupport.processName(name, true, uri, lname); | - | ||||||||||||
3913 | attList.append(name, uri, lname, string); | - | ||||||||||||
3914 | } | - | ||||||||||||
3915 | } else { | - | ||||||||||||
3916 | // no namespace support | - | ||||||||||||
3917 | attList.append(name, uri, lname, string); | - | ||||||||||||
3918 | } | - | ||||||||||||
3919 | return true; | - | ||||||||||||
3920 | } | - | ||||||||||||
3921 | - | |||||||||||||
3922 | /* | - | ||||||||||||
3923 | Parse a content [43]. | - | ||||||||||||
3924 | - | |||||||||||||
3925 | A content is only used between tags. If a end tag is found the < is already | - | ||||||||||||
3926 | read and the head stand on the '/' of the end tag '</name>'. | - | ||||||||||||
3927 | */ | - | ||||||||||||
3928 | bool QXmlSimpleReaderPrivate::parseContent() | - | ||||||||||||
3929 | { | - | ||||||||||||
3930 | const signed char Init = 0; | - | ||||||||||||
3931 | const signed char ChD = 1; // CharData | - | ||||||||||||
3932 | const signed char ChD1 = 2; // CharData help state | - | ||||||||||||
3933 | const signed char ChD2 = 3; // CharData help state | - | ||||||||||||
3934 | const signed char Ref = 4; // Reference | - | ||||||||||||
3935 | const signed char Lt = 5; // '<' read | - | ||||||||||||
3936 | const signed char PInstr = 6; // PI | - | ||||||||||||
3937 | const signed char PInstrR = 7; // same as PInstr, but already reported | - | ||||||||||||
3938 | const signed char Elem = 8; // Element | - | ||||||||||||
3939 | const signed char Em = 9; // '!' read | - | ||||||||||||
3940 | const signed char Com = 10; // Comment | - | ||||||||||||
3941 | const signed char ComR = 11; // same as Com, but already reported | - | ||||||||||||
3942 | const signed char CDS = 12; // CDSect | - | ||||||||||||
3943 | const signed char CDS1 = 13; // read a CDSect | - | ||||||||||||
3944 | const signed char CDS2 = 14; // read a CDSect (help state) | - | ||||||||||||
3945 | const signed char CDS3 = 15; // read a CDSect (help state) | - | ||||||||||||
3946 | const signed char Done = 16; // finished reading content | - | ||||||||||||
3947 | - | |||||||||||||
3948 | const signed char InpLt = 0; // < | - | ||||||||||||
3949 | const signed char InpGt = 1; // > | - | ||||||||||||
3950 | const signed char InpSlash = 2; // / | - | ||||||||||||
3951 | const signed char InpQMark = 3; // ? | - | ||||||||||||
3952 | const signed char InpEMark = 4; // ! | - | ||||||||||||
3953 | const signed char InpAmp = 5; // & | - | ||||||||||||
3954 | const signed char InpDash = 6; // - | - | ||||||||||||
3955 | const signed char InpOpenB = 7; // [ | - | ||||||||||||
3956 | const signed char InpCloseB = 8; //] | - | ||||||||||||
3957 | const signed char InpUnknown = 9; | - | ||||||||||||
3958 | - | |||||||||||||
3959 | static const signed char mapCLT2FSMChar[] = { | - | ||||||||||||
3960 | InpUnknown, // white space | - | ||||||||||||
3961 | InpUnknown, // % | - | ||||||||||||
3962 | InpAmp, // & | - | ||||||||||||
3963 | InpGt, // > | - | ||||||||||||
3964 | InpLt, // < | - | ||||||||||||
3965 | InpSlash, // / | - | ||||||||||||
3966 | InpQMark, // ? | - | ||||||||||||
3967 | InpEMark, // ! | - | ||||||||||||
3968 | InpDash, // - | - | ||||||||||||
3969 | InpCloseB, //] | - | ||||||||||||
3970 | InpOpenB, // [ | - | ||||||||||||
3971 | InpUnknown, // = | - | ||||||||||||
3972 | InpUnknown, // " | - | ||||||||||||
3973 | InpUnknown, // ' | - | ||||||||||||
3974 | InpUnknown // unknown | - | ||||||||||||
3975 | }; | - | ||||||||||||
3976 | - | |||||||||||||
3977 | static const signed char table[16][10] = { | - | ||||||||||||
3978 | /* InpLt InpGt InpSlash InpQMark InpEMark InpAmp InpDash InpOpenB InpCloseB InpUnknown */ | - | ||||||||||||
3979 | { Lt, ChD, ChD, ChD, ChD, Ref, ChD, ChD, ChD1, ChD }, // Init | - | ||||||||||||
3980 | { Lt, ChD, ChD, ChD, ChD, Ref, ChD, ChD, ChD1, ChD }, // ChD | - | ||||||||||||
3981 | { Lt, ChD, ChD, ChD, ChD, Ref, ChD, ChD, ChD2, ChD }, // ChD1 | - | ||||||||||||
3982 | { Lt, -1, ChD, ChD, ChD, Ref, ChD, ChD, ChD2, ChD }, // ChD2 | - | ||||||||||||
3983 | { Lt, ChD, ChD, ChD, ChD, Ref, ChD, ChD, ChD, ChD }, // Ref (same as Init) | - | ||||||||||||
3984 | { -1, -1, Done, PInstr, Em, -1, -1, -1, -1, Elem }, // Lt | - | ||||||||||||
3985 | { Lt, ChD, ChD, ChD, ChD, Ref, ChD, ChD, ChD, ChD }, // PInstr (same as Init) | - | ||||||||||||
3986 | { Lt, ChD, ChD, ChD, ChD, Ref, ChD, ChD, ChD, ChD }, // PInstrR | - | ||||||||||||
3987 | { Lt, ChD, ChD, ChD, ChD, Ref, ChD, ChD, ChD, ChD }, // Elem (same as Init) | - | ||||||||||||
3988 | { -1, -1, -1, -1, -1, -1, Com, CDS, -1, -1 }, // Em | - | ||||||||||||
3989 | { Lt, ChD, ChD, ChD, ChD, Ref, ChD, ChD, ChD, ChD }, // Com (same as Init) | - | ||||||||||||
3990 | { Lt, ChD, ChD, ChD, ChD, Ref, ChD, ChD, ChD, ChD }, // ComR | - | ||||||||||||
3991 | { CDS1, CDS1, CDS1, CDS1, CDS1, CDS1, CDS1, CDS1, CDS2, CDS1 }, // CDS | - | ||||||||||||
3992 | { CDS1, CDS1, CDS1, CDS1, CDS1, CDS1, CDS1, CDS1, CDS2, CDS1 }, // CDS1 | - | ||||||||||||
3993 | { CDS1, CDS1, CDS1, CDS1, CDS1, CDS1, CDS1, CDS1, CDS3, CDS1 }, // CDS2 | - | ||||||||||||
3994 | { CDS1, Init, CDS1, CDS1, CDS1, CDS1, CDS1, CDS1, CDS3, CDS1 } // CDS3 | - | ||||||||||||
3995 | }; | - | ||||||||||||
3996 | signed char state; | - | ||||||||||||
3997 | signed char input; | - | ||||||||||||
3998 | - | |||||||||||||
3999 | if (parseStack == 0 || parseStack->isEmpty()) { | - | ||||||||||||
4000 | contentCharDataRead = false; | - | ||||||||||||
4001 | state = Init; | - | ||||||||||||
4002 | } else { | - | ||||||||||||
4003 | state = parseStack->pop().state; | - | ||||||||||||
4004 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
4005 | qDebug("QXmlSimpleReader: parseContent (cont) in state %d", state); | - | ||||||||||||
4006 | #endif | - | ||||||||||||
4007 | if (!parseStack->isEmpty()) { | - | ||||||||||||
4008 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
4009 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
4010 | parseStack->pop(); | - | ||||||||||||
4011 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
4012 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
4013 | #endif | - | ||||||||||||
4014 | } | - | ||||||||||||
4015 | if (!(this->*function)()) { | - | ||||||||||||
4016 | parseFailed(&QXmlSimpleReaderPrivate::parseContent, state); | - | ||||||||||||
4017 | return false; | - | ||||||||||||
4018 | } | - | ||||||||||||
4019 | } | - | ||||||||||||
4020 | } | - | ||||||||||||
4021 | - | |||||||||||||
4022 | for (;;) { | - | ||||||||||||
4023 | switch (state) { | - | ||||||||||||
4024 | case Ref: | - | ||||||||||||
4025 | if (!contentCharDataRead) | - | ||||||||||||
4026 | contentCharDataRead = parseReference_charDataRead; | - | ||||||||||||
4027 | break; | - | ||||||||||||
4028 | case PInstr: | - | ||||||||||||
4029 | if (contentHnd) { | - | ||||||||||||
4030 | if (!contentHnd->processingInstruction(name(),string())) { | - | ||||||||||||
4031 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
4032 | return false; | - | ||||||||||||
4033 | } | - | ||||||||||||
4034 | } | - | ||||||||||||
4035 | state = PInstrR; | - | ||||||||||||
4036 | break; | - | ||||||||||||
4037 | case Com: | - | ||||||||||||
4038 | if (lexicalHnd) { | - | ||||||||||||
4039 | if (!lexicalHnd->comment(string())) { | - | ||||||||||||
4040 | reportParseError(lexicalHnd->errorString()); | - | ||||||||||||
4041 | return false; | - | ||||||||||||
4042 | } | - | ||||||||||||
4043 | } | - | ||||||||||||
4044 | state = ComR; | - | ||||||||||||
4045 | break; | - | ||||||||||||
4046 | case CDS: | - | ||||||||||||
4047 | stringClear(); | - | ||||||||||||
4048 | break; | - | ||||||||||||
4049 | case CDS2: | - | ||||||||||||
4050 | if (!atEnd() && c != QLatin1Char(']')) | - | ||||||||||||
4051 | stringAddC(QLatin1Char(']')); | - | ||||||||||||
4052 | break; | - | ||||||||||||
4053 | case CDS3: | - | ||||||||||||
4054 | // test if this skipping was legal | - | ||||||||||||
4055 | if (!atEnd()) { | - | ||||||||||||
4056 | if (c == QLatin1Char('>')) { | - | ||||||||||||
4057 | // the end of the CDSect | - | ||||||||||||
4058 | if (lexicalHnd) { | - | ||||||||||||
4059 | if (!lexicalHnd->startCDATA()) { | - | ||||||||||||
4060 | reportParseError(lexicalHnd->errorString()); | - | ||||||||||||
4061 | return false; | - | ||||||||||||
4062 | } | - | ||||||||||||
4063 | } | - | ||||||||||||
4064 | if (contentHnd) { | - | ||||||||||||
4065 | if (!contentHnd->characters(string())) { | - | ||||||||||||
4066 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
4067 | return false; | - | ||||||||||||
4068 | } | - | ||||||||||||
4069 | } | - | ||||||||||||
4070 | if (lexicalHnd) { | - | ||||||||||||
4071 | if (!lexicalHnd->endCDATA()) { | - | ||||||||||||
4072 | reportParseError(lexicalHnd->errorString()); | - | ||||||||||||
4073 | return false; | - | ||||||||||||
4074 | } | - | ||||||||||||
4075 | } | - | ||||||||||||
4076 | } else if (c == QLatin1Char(']')) { | - | ||||||||||||
4077 | // three or more ']' | - | ||||||||||||
4078 | stringAddC(QLatin1Char(']')); | - | ||||||||||||
4079 | } else { | - | ||||||||||||
4080 | // after ']]' comes another character | - | ||||||||||||
4081 | stringAddC(QLatin1Char(']')); | - | ||||||||||||
4082 | stringAddC(QLatin1Char(']')); | - | ||||||||||||
4083 | } | - | ||||||||||||
4084 | } | - | ||||||||||||
4085 | break; | - | ||||||||||||
4086 | case Done: | - | ||||||||||||
4087 | // call the handler for CharData | - | ||||||||||||
4088 | if (contentHnd) { | - | ||||||||||||
4089 | if (contentCharDataRead) { | - | ||||||||||||
4090 | if (reportWhitespaceCharData || !string().simplified().isEmpty()) { | - | ||||||||||||
4091 | if (!contentHnd->characters(string())) { | - | ||||||||||||
4092 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
4093 | return false; | - | ||||||||||||
4094 | } | - | ||||||||||||
4095 | } | - | ||||||||||||
4096 | } | - | ||||||||||||
4097 | } | - | ||||||||||||
4098 | // Done | - | ||||||||||||
4099 | return true; | - | ||||||||||||
4100 | case -1: | - | ||||||||||||
4101 | // Error | - | ||||||||||||
4102 | reportParseError(QLatin1String(XMLERR_ERRORPARSINGCONTENT)); | - | ||||||||||||
4103 | return false; | - | ||||||||||||
4104 | } | - | ||||||||||||
4105 | - | |||||||||||||
4106 | // get input (use lookup-table instead of nested ifs for performance | - | ||||||||||||
4107 | // reasons) | - | ||||||||||||
4108 | if (atEnd()) { | - | ||||||||||||
4109 | unexpectedEof(&QXmlSimpleReaderPrivate::parseContent, state); | - | ||||||||||||
4110 | return false; | - | ||||||||||||
4111 | } | - | ||||||||||||
4112 | if (c.row()) { | - | ||||||||||||
4113 | input = InpUnknown; | - | ||||||||||||
4114 | } else { | - | ||||||||||||
4115 | input = mapCLT2FSMChar[charLookupTable[c.cell()]]; | - | ||||||||||||
4116 | } | - | ||||||||||||
4117 | state = table[state][input]; | - | ||||||||||||
4118 | - | |||||||||||||
4119 | switch (state) { | - | ||||||||||||
4120 | case Init: | - | ||||||||||||
4121 | // skip the ending '>' of a CDATASection | - | ||||||||||||
4122 | next(); | - | ||||||||||||
4123 | break; | - | ||||||||||||
4124 | case ChD: | - | ||||||||||||
4125 | // on first call: clear string | - | ||||||||||||
4126 | if (!contentCharDataRead) { | - | ||||||||||||
4127 | contentCharDataRead = true; | - | ||||||||||||
4128 | stringClear(); | - | ||||||||||||
4129 | } | - | ||||||||||||
4130 | stringAddC(); | - | ||||||||||||
4131 | if (reportEntities) { | - | ||||||||||||
4132 | if (!reportEndEntities()) | - | ||||||||||||
4133 | return false; | - | ||||||||||||
4134 | } | - | ||||||||||||
4135 | next(); | - | ||||||||||||
4136 | break; | - | ||||||||||||
4137 | case ChD1: | - | ||||||||||||
4138 | // on first call: clear string | - | ||||||||||||
4139 | if (!contentCharDataRead) { | - | ||||||||||||
4140 | contentCharDataRead = true; | - | ||||||||||||
4141 | stringClear(); | - | ||||||||||||
4142 | } | - | ||||||||||||
4143 | stringAddC(); | - | ||||||||||||
4144 | if (reportEntities) { | - | ||||||||||||
4145 | if (!reportEndEntities()) | - | ||||||||||||
4146 | return false; | - | ||||||||||||
4147 | } | - | ||||||||||||
4148 | next(); | - | ||||||||||||
4149 | break; | - | ||||||||||||
4150 | case ChD2: | - | ||||||||||||
4151 | stringAddC(); | - | ||||||||||||
4152 | if (reportEntities) { | - | ||||||||||||
4153 | if (!reportEndEntities()) | - | ||||||||||||
4154 | return false; | - | ||||||||||||
4155 | } | - | ||||||||||||
4156 | next(); | - | ||||||||||||
4157 | break; | - | ||||||||||||
4158 | case Ref: | - | ||||||||||||
4159 | if (!contentCharDataRead) { | - | ||||||||||||
4160 | // reference may be CharData; so clear string to be safe | - | ||||||||||||
4161 | stringClear(); | - | ||||||||||||
4162 | parseReference_context = InContent; | - | ||||||||||||
4163 | if (!parseReference()) { | - | ||||||||||||
4164 | parseFailed(&QXmlSimpleReaderPrivate::parseContent, state); | - | ||||||||||||
4165 | return false; | - | ||||||||||||
4166 | } | - | ||||||||||||
4167 | } else { | - | ||||||||||||
4168 | if (reportEntities) { | - | ||||||||||||
4169 | // report character data in chunks | - | ||||||||||||
4170 | if (contentHnd) { | - | ||||||||||||
4171 | if (reportWhitespaceCharData || !string().simplified().isEmpty()) { | - | ||||||||||||
4172 | if (!contentHnd->characters(string())) { | - | ||||||||||||
4173 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
4174 | return false; | - | ||||||||||||
4175 | } | - | ||||||||||||
4176 | } | - | ||||||||||||
4177 | } | - | ||||||||||||
4178 | stringClear(); | - | ||||||||||||
4179 | } | - | ||||||||||||
4180 | parseReference_context = InContent; | - | ||||||||||||
4181 | if (!parseReference()) { | - | ||||||||||||
4182 | parseFailed(&QXmlSimpleReaderPrivate::parseContent, state); | - | ||||||||||||
4183 | return false; | - | ||||||||||||
4184 | } | - | ||||||||||||
4185 | } | - | ||||||||||||
4186 | break; | - | ||||||||||||
4187 | case Lt: | - | ||||||||||||
4188 | // call the handler for CharData | - | ||||||||||||
4189 | if (contentHnd) { | - | ||||||||||||
4190 | if (contentCharDataRead) { | - | ||||||||||||
4191 | if (reportWhitespaceCharData || !string().simplified().isEmpty()) { | - | ||||||||||||
4192 | if (!contentHnd->characters(string())) { | - | ||||||||||||
4193 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
4194 | return false; | - | ||||||||||||
4195 | } | - | ||||||||||||
4196 | } | - | ||||||||||||
4197 | } | - | ||||||||||||
4198 | } | - | ||||||||||||
4199 | contentCharDataRead = false; | - | ||||||||||||
4200 | next(); | - | ||||||||||||
4201 | break; | - | ||||||||||||
4202 | case PInstr: | - | ||||||||||||
4203 | case PInstrR: | - | ||||||||||||
4204 | parsePI_xmldecl = false; | - | ||||||||||||
4205 | if (!parsePI()) { | - | ||||||||||||
4206 | parseFailed(&QXmlSimpleReaderPrivate::parseContent, state); | - | ||||||||||||
4207 | return false; | - | ||||||||||||
4208 | } | - | ||||||||||||
4209 | break; | - | ||||||||||||
4210 | case Elem: | - | ||||||||||||
4211 | if (!parseElement()) { | - | ||||||||||||
4212 | parseFailed(&QXmlSimpleReaderPrivate::parseContent, state); | - | ||||||||||||
4213 | return false; | - | ||||||||||||
4214 | } | - | ||||||||||||
4215 | break; | - | ||||||||||||
4216 | case Em: | - | ||||||||||||
4217 | next(); | - | ||||||||||||
4218 | break; | - | ||||||||||||
4219 | case Com: | - | ||||||||||||
4220 | case ComR: | - | ||||||||||||
4221 | if (!parseComment()) { | - | ||||||||||||
4222 | parseFailed(&QXmlSimpleReaderPrivate::parseContent, state); | - | ||||||||||||
4223 | return false; | - | ||||||||||||
4224 | } | - | ||||||||||||
4225 | break; | - | ||||||||||||
4226 | case CDS: | - | ||||||||||||
4227 | parseString_s = QLatin1String("[CDATA["); | - | ||||||||||||
4228 | if (!parseString()) { | - | ||||||||||||
4229 | parseFailed(&QXmlSimpleReaderPrivate::parseContent, state); | - | ||||||||||||
4230 | return false; | - | ||||||||||||
4231 | } | - | ||||||||||||
4232 | break; | - | ||||||||||||
4233 | case CDS1: | - | ||||||||||||
4234 | stringAddC(); | - | ||||||||||||
4235 | next(); | - | ||||||||||||
4236 | break; | - | ||||||||||||
4237 | case CDS2: | - | ||||||||||||
4238 | // skip ']' | - | ||||||||||||
4239 | next(); | - | ||||||||||||
4240 | break; | - | ||||||||||||
4241 | case CDS3: | - | ||||||||||||
4242 | // skip ']'... | - | ||||||||||||
4243 | next(); | - | ||||||||||||
4244 | break; | - | ||||||||||||
4245 | } | - | ||||||||||||
4246 | } | - | ||||||||||||
4247 | return false; | - | ||||||||||||
4248 | } | - | ||||||||||||
4249 | - | |||||||||||||
4250 | bool QXmlSimpleReaderPrivate::reportEndEntities() | - | ||||||||||||
4251 | { | - | ||||||||||||
4252 | int count = (int)xmlRefStack.count(); | - | ||||||||||||
4253 | while (count != 0 && xmlRefStack.top().isEmpty()) { | - | ||||||||||||
4254 | if (contentHnd) { | - | ||||||||||||
4255 | if (reportWhitespaceCharData || !string().simplified().isEmpty()) { | - | ||||||||||||
4256 | if (!contentHnd->characters(string())) { | - | ||||||||||||
4257 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
4258 | return false; | - | ||||||||||||
4259 | } | - | ||||||||||||
4260 | } | - | ||||||||||||
4261 | } | - | ||||||||||||
4262 | stringClear(); | - | ||||||||||||
4263 | if (lexicalHnd) { | - | ||||||||||||
4264 | if (!lexicalHnd->endEntity(xmlRefStack.top().name)) { | - | ||||||||||||
4265 | reportParseError(lexicalHnd->errorString()); | - | ||||||||||||
4266 | return false; | - | ||||||||||||
4267 | } | - | ||||||||||||
4268 | } | - | ||||||||||||
4269 | xmlRefStack.pop_back(); | - | ||||||||||||
4270 | count--; | - | ||||||||||||
4271 | } | - | ||||||||||||
4272 | return true; | - | ||||||||||||
4273 | } | - | ||||||||||||
4274 | - | |||||||||||||
4275 | /* | - | ||||||||||||
4276 | Parse Misc [27]. | - | ||||||||||||
4277 | */ | - | ||||||||||||
4278 | bool QXmlSimpleReaderPrivate::parseMisc() | - | ||||||||||||
4279 | { | - | ||||||||||||
4280 | const signed char Init = 0; | - | ||||||||||||
4281 | const signed char Lt = 1; // '<' was read | - | ||||||||||||
4282 | const signed char Comment = 2; // read comment | - | ||||||||||||
4283 | const signed char eatWS = 3; // eat whitespaces | - | ||||||||||||
4284 | const signed char PInstr = 4; // read PI | - | ||||||||||||
4285 | const signed char Comment2 = 5; // read comment | - | ||||||||||||
4286 | - | |||||||||||||
4287 | const signed char InpWs = 0; // S | - | ||||||||||||
4288 | const signed char InpLt = 1; // < | - | ||||||||||||
4289 | const signed char InpQm = 2; // ? | - | ||||||||||||
4290 | const signed char InpEm = 3; // ! | - | ||||||||||||
4291 | const signed char InpUnknown = 4; | - | ||||||||||||
4292 | - | |||||||||||||
4293 | static const signed char table[3][5] = { | - | ||||||||||||
4294 | /* InpWs InpLt InpQm InpEm InpUnknown */ | - | ||||||||||||
4295 | { eatWS, Lt, -1, -1, -1 }, // Init | - | ||||||||||||
4296 | { -1, -1, PInstr,Comment, -1 }, // Lt | - | ||||||||||||
4297 | { -1, -1, -1, -1, Comment2 } // Comment | - | ||||||||||||
4298 | }; | - | ||||||||||||
4299 | signed char state; | - | ||||||||||||
4300 | signed char input; | - | ||||||||||||
4301 | - | |||||||||||||
4302 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
4303 | state = Init; | - | ||||||||||||
4304 | } else { | - | ||||||||||||
4305 | state = parseStack->pop().state; | - | ||||||||||||
4306 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
4307 | qDebug("QXmlSimpleReader: parseMisc (cont) in state %d", state); | - | ||||||||||||
4308 | #endif | - | ||||||||||||
4309 | if (!parseStack->isEmpty()) { | - | ||||||||||||
4310 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
4311 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
4312 | parseStack->pop(); | - | ||||||||||||
4313 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
4314 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
4315 | #endif | - | ||||||||||||
4316 | } | - | ||||||||||||
4317 | if (!(this->*function)()) { | - | ||||||||||||
4318 | parseFailed(&QXmlSimpleReaderPrivate::parseMisc, state); | - | ||||||||||||
4319 | return false; | - | ||||||||||||
4320 | } | - | ||||||||||||
4321 | } | - | ||||||||||||
4322 | } | - | ||||||||||||
4323 | - | |||||||||||||
4324 | for (;;) { | - | ||||||||||||
4325 | switch (state) { | - | ||||||||||||
4326 | case eatWS: | - | ||||||||||||
4327 | return true; | - | ||||||||||||
4328 | case PInstr: | - | ||||||||||||
4329 | if (contentHnd) { | - | ||||||||||||
4330 | if (!contentHnd->processingInstruction(name(),string())) { | - | ||||||||||||
4331 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
4332 | return false; | - | ||||||||||||
4333 | } | - | ||||||||||||
4334 | } | - | ||||||||||||
4335 | return true; | - | ||||||||||||
4336 | case Comment2: | - | ||||||||||||
4337 | if (lexicalHnd) { | - | ||||||||||||
4338 | if (!lexicalHnd->comment(string())) { | - | ||||||||||||
4339 | reportParseError(lexicalHnd->errorString()); | - | ||||||||||||
4340 | return false; | - | ||||||||||||
4341 | } | - | ||||||||||||
4342 | } | - | ||||||||||||
4343 | return true; | - | ||||||||||||
4344 | case -1: | - | ||||||||||||
4345 | // Error | - | ||||||||||||
4346 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDCHARACTER)); | - | ||||||||||||
4347 | return false; | - | ||||||||||||
4348 | } | - | ||||||||||||
4349 | - | |||||||||||||
4350 | if (atEnd()) { | - | ||||||||||||
4351 | unexpectedEof(&QXmlSimpleReaderPrivate::parseMisc, state); | - | ||||||||||||
4352 | return false; | - | ||||||||||||
4353 | } | - | ||||||||||||
4354 | if (is_S(c)) { | - | ||||||||||||
4355 | input = InpWs; | - | ||||||||||||
4356 | } else if (c == QLatin1Char('<')) { | - | ||||||||||||
4357 | input = InpLt; | - | ||||||||||||
4358 | } else if (c == QLatin1Char('?')) { | - | ||||||||||||
4359 | input = InpQm; | - | ||||||||||||
4360 | } else if (c == QLatin1Char('!')) { | - | ||||||||||||
4361 | input = InpEm; | - | ||||||||||||
4362 | } else { | - | ||||||||||||
4363 | input = InpUnknown; | - | ||||||||||||
4364 | } | - | ||||||||||||
4365 | state = table[state][input]; | - | ||||||||||||
4366 | - | |||||||||||||
4367 | switch (state) { | - | ||||||||||||
4368 | case eatWS: | - | ||||||||||||
4369 | if (!eat_ws()) { | - | ||||||||||||
4370 | parseFailed(&QXmlSimpleReaderPrivate::parseMisc, state); | - | ||||||||||||
4371 | return false; | - | ||||||||||||
4372 | } | - | ||||||||||||
4373 | break; | - | ||||||||||||
4374 | case Lt: | - | ||||||||||||
4375 | next(); | - | ||||||||||||
4376 | break; | - | ||||||||||||
4377 | case PInstr: | - | ||||||||||||
4378 | parsePI_xmldecl = false; | - | ||||||||||||
4379 | if (!parsePI()) { | - | ||||||||||||
4380 | parseFailed(&QXmlSimpleReaderPrivate::parseMisc, state); | - | ||||||||||||
4381 | return false; | - | ||||||||||||
4382 | } | - | ||||||||||||
4383 | break; | - | ||||||||||||
4384 | case Comment: | - | ||||||||||||
4385 | next(); | - | ||||||||||||
4386 | break; | - | ||||||||||||
4387 | case Comment2: | - | ||||||||||||
4388 | if (!parseComment()) { | - | ||||||||||||
4389 | parseFailed(&QXmlSimpleReaderPrivate::parseMisc, state); | - | ||||||||||||
4390 | return false; | - | ||||||||||||
4391 | } | - | ||||||||||||
4392 | break; | - | ||||||||||||
4393 | } | - | ||||||||||||
4394 | } | - | ||||||||||||
4395 | return false; | - | ||||||||||||
4396 | } | - | ||||||||||||
4397 | - | |||||||||||||
4398 | /* | - | ||||||||||||
4399 | Parse a processing instruction [16]. | - | ||||||||||||
4400 | - | |||||||||||||
4401 | If xmldec is true, it tries to parse a PI or a XML declaration [23]. | - | ||||||||||||
4402 | - | |||||||||||||
4403 | Precondition: the beginning '<' of the PI is already read and the head stand | - | ||||||||||||
4404 | on the '?' of '<?'. | - | ||||||||||||
4405 | - | |||||||||||||
4406 | If this funktion was successful, the head-position is on the first | - | ||||||||||||
4407 | character after the PI. | - | ||||||||||||
4408 | */ | - | ||||||||||||
4409 | bool QXmlSimpleReaderPrivate::parsePI() | - | ||||||||||||
4410 | { | - | ||||||||||||
4411 | const signed char Init = 0; | - | ||||||||||||
4412 | const signed char QmI = 1; // ? was read | - | ||||||||||||
4413 | const signed char Name = 2; // read Name | - | ||||||||||||
4414 | const signed char XMLDecl = 3; // read XMLDecl | - | ||||||||||||
4415 | const signed char Ws1 = 4; // eat ws after "xml" of XMLDecl | - | ||||||||||||
4416 | const signed char PInstr = 5; // read PI | - | ||||||||||||
4417 | const signed char Ws2 = 6; // eat ws after Name of PI | - | ||||||||||||
4418 | const signed char Version = 7; // read versionInfo | - | ||||||||||||
4419 | const signed char Ws3 = 8; // eat ws after versionInfo | - | ||||||||||||
4420 | const signed char EorSD = 9; // read EDecl or SDDecl | - | ||||||||||||
4421 | const signed char Ws4 = 10; // eat ws after EDecl or SDDecl | - | ||||||||||||
4422 | const signed char SD = 11; // read SDDecl | - | ||||||||||||
4423 | const signed char Ws5 = 12; // eat ws after SDDecl | - | ||||||||||||
4424 | const signed char ADone = 13; // almost done | - | ||||||||||||
4425 | const signed char Char = 14; // Char was read | - | ||||||||||||
4426 | const signed char Qm = 15; // Qm was read | - | ||||||||||||
4427 | const signed char Done = 16; // finished reading content | - | ||||||||||||
4428 | - | |||||||||||||
4429 | const signed char InpWs = 0; // whitespace | - | ||||||||||||
4430 | const signed char InpNameBe = 1; // NameBeginning | - | ||||||||||||
4431 | const signed char InpGt = 2; // > | - | ||||||||||||
4432 | const signed char InpQm = 3; // ? | - | ||||||||||||
4433 | const signed char InpUnknown = 4; | - | ||||||||||||
4434 | - | |||||||||||||
4435 | static const signed char table[16][5] = { | - | ||||||||||||
4436 | /* InpWs, InpNameBe InpGt InpQm InpUnknown */ | - | ||||||||||||
4437 | { -1, -1, -1, QmI, -1 }, // Init | - | ||||||||||||
4438 | { -1, Name, -1, -1, -1 }, // QmI | - | ||||||||||||
4439 | { -1, -1, -1, -1, -1 }, // Name (this state is left not through input) | - | ||||||||||||
4440 | { Ws1, -1, -1, -1, -1 }, // XMLDecl | - | ||||||||||||
4441 | { -1, Version, -1, -1, -1 }, // Ws1 | - | ||||||||||||
4442 | { Ws2, -1, -1, Qm, -1 }, // PInstr | - | ||||||||||||
4443 | { Char, Char, Char, Qm, Char }, // Ws2 | - | ||||||||||||
4444 | { Ws3, -1, -1, ADone, -1 }, // Version | - | ||||||||||||
4445 | { -1, EorSD, -1, ADone, -1 }, // Ws3 | - | ||||||||||||
4446 | { Ws4, -1, -1, ADone, -1 }, // EorSD | - | ||||||||||||
4447 | { -1, SD, -1, ADone, -1 }, // Ws4 | - | ||||||||||||
4448 | { Ws5, -1, -1, ADone, -1 }, // SD | - | ||||||||||||
4449 | { -1, -1, -1, ADone, -1 }, // Ws5 | - | ||||||||||||
4450 | { -1, -1, Done, -1, -1 }, // ADone | - | ||||||||||||
4451 | { Char, Char, Char, Qm, Char }, // Char | - | ||||||||||||
4452 | { Char, Char, Done, Qm, Char }, // Qm | - | ||||||||||||
4453 | }; | - | ||||||||||||
4454 | signed char state; | - | ||||||||||||
4455 | signed char input; | - | ||||||||||||
4456 | - | |||||||||||||
4457 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
4458 | state = Init; | - | ||||||||||||
4459 | } else { | - | ||||||||||||
4460 | state = parseStack->pop().state; | - | ||||||||||||
4461 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
4462 | qDebug("QXmlSimpleReader: parsePI (cont) in state %d", state); | - | ||||||||||||
4463 | #endif | - | ||||||||||||
4464 | if (!parseStack->isEmpty()) { | - | ||||||||||||
4465 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
4466 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
4467 | parseStack->pop(); | - | ||||||||||||
4468 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
4469 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
4470 | #endif | - | ||||||||||||
4471 | } | - | ||||||||||||
4472 | if (!(this->*function)()) { | - | ||||||||||||
4473 | parseFailed(&QXmlSimpleReaderPrivate::parsePI, state); | - | ||||||||||||
4474 | return false; | - | ||||||||||||
4475 | } | - | ||||||||||||
4476 | } | - | ||||||||||||
4477 | } | - | ||||||||||||
4478 | - | |||||||||||||
4479 | for (;;) { | - | ||||||||||||
4480 | switch (state) { | - | ||||||||||||
4481 | case Name: | - | ||||||||||||
4482 | // test what name was read and determine the next state | - | ||||||||||||
4483 | // (not very beautiful, I admit) | - | ||||||||||||
4484 | if (name().toLower() == QLatin1String("xml")) { | - | ||||||||||||
4485 | if (parsePI_xmldecl && name() == QLatin1String("xml")) { | - | ||||||||||||
4486 | state = XMLDecl; | - | ||||||||||||
4487 | } else { | - | ||||||||||||
4488 | reportParseError(QLatin1String(XMLERR_INVALIDNAMEFORPI)); | - | ||||||||||||
4489 | return false; | - | ||||||||||||
4490 | } | - | ||||||||||||
4491 | } else { | - | ||||||||||||
4492 | state = PInstr; | - | ||||||||||||
4493 | stringClear(); | - | ||||||||||||
4494 | } | - | ||||||||||||
4495 | break; | - | ||||||||||||
4496 | case Version: | - | ||||||||||||
4497 | // get version (syntax like an attribute) | - | ||||||||||||
4498 | if (name() != QLatin1String("version")) { | - | ||||||||||||
4499 | reportParseError(QLatin1String(XMLERR_VERSIONEXPECTED)); | - | ||||||||||||
4500 | return false; | - | ||||||||||||
4501 | } | - | ||||||||||||
4502 | xmlVersion = string(); | - | ||||||||||||
4503 | break; | - | ||||||||||||
4504 | case EorSD: | - | ||||||||||||
4505 | // get the EDecl or SDDecl (syntax like an attribute) | - | ||||||||||||
4506 | if (name() == QLatin1String("standalone")) { | - | ||||||||||||
4507 | if (string()== QLatin1String("yes")) { | - | ||||||||||||
4508 | standalone = QXmlSimpleReaderPrivate::Yes; | - | ||||||||||||
4509 | } else if (string() == QLatin1String("no")) { | - | ||||||||||||
4510 | standalone = QXmlSimpleReaderPrivate::No; | - | ||||||||||||
4511 | } else { | - | ||||||||||||
4512 | reportParseError(QLatin1String(XMLERR_WRONGVALUEFORSDECL)); | - | ||||||||||||
4513 | return false; | - | ||||||||||||
4514 | } | - | ||||||||||||
4515 | } else if (name() == QLatin1String("encoding")) { | - | ||||||||||||
4516 | encoding = string(); | - | ||||||||||||
4517 | } else { | - | ||||||||||||
4518 | reportParseError(QLatin1String(XMLERR_EDECLORSDDECLEXPECTED)); | - | ||||||||||||
4519 | return false; | - | ||||||||||||
4520 | } | - | ||||||||||||
4521 | break; | - | ||||||||||||
4522 | case SD: | - | ||||||||||||
4523 | if (name() != QLatin1String("standalone")) { | - | ||||||||||||
4524 | reportParseError(QLatin1String(XMLERR_SDDECLEXPECTED)); | - | ||||||||||||
4525 | return false; | - | ||||||||||||
4526 | } | - | ||||||||||||
4527 | if (string() == QLatin1String("yes")) { | - | ||||||||||||
4528 | standalone = QXmlSimpleReaderPrivate::Yes; | - | ||||||||||||
4529 | } else if (string() == QLatin1String("no")) { | - | ||||||||||||
4530 | standalone = QXmlSimpleReaderPrivate::No; | - | ||||||||||||
4531 | } else { | - | ||||||||||||
4532 | reportParseError(QLatin1String(XMLERR_WRONGVALUEFORSDECL)); | - | ||||||||||||
4533 | return false; | - | ||||||||||||
4534 | } | - | ||||||||||||
4535 | break; | - | ||||||||||||
4536 | case Qm: | - | ||||||||||||
4537 | // test if the skipping was legal | - | ||||||||||||
4538 | if (!atEnd() && c != QLatin1Char('>')) | - | ||||||||||||
4539 | stringAddC(QLatin1Char('?')); | - | ||||||||||||
4540 | break; | - | ||||||||||||
4541 | case Done: | - | ||||||||||||
4542 | return true; | - | ||||||||||||
4543 | case -1: | - | ||||||||||||
4544 | // Error | - | ||||||||||||
4545 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDCHARACTER)); | - | ||||||||||||
4546 | return false; | - | ||||||||||||
4547 | } | - | ||||||||||||
4548 | - | |||||||||||||
4549 | if (atEnd()) { | - | ||||||||||||
4550 | unexpectedEof(&QXmlSimpleReaderPrivate::parsePI, state); | - | ||||||||||||
4551 | return false; | - | ||||||||||||
4552 | } | - | ||||||||||||
4553 | if (is_S(c)) { | - | ||||||||||||
4554 | input = InpWs; | - | ||||||||||||
4555 | } else if (determineNameChar(c) == NameBeginning) { | - | ||||||||||||
4556 | input = InpNameBe; | - | ||||||||||||
4557 | } else if (c == QLatin1Char('>')) { | - | ||||||||||||
4558 | input = InpGt; | - | ||||||||||||
4559 | } else if (c == QLatin1Char('?')) { | - | ||||||||||||
4560 | input = InpQm; | - | ||||||||||||
4561 | } else { | - | ||||||||||||
4562 | input = InpUnknown; | - | ||||||||||||
4563 | } | - | ||||||||||||
4564 | state = table[state][input]; | - | ||||||||||||
4565 | - | |||||||||||||
4566 | switch (state) { | - | ||||||||||||
4567 | case QmI: | - | ||||||||||||
4568 | next(); | - | ||||||||||||
4569 | break; | - | ||||||||||||
4570 | case Name: | - | ||||||||||||
4571 | parseName_useRef = false; | - | ||||||||||||
4572 | if (!parseName()) { | - | ||||||||||||
4573 | parseFailed(&QXmlSimpleReaderPrivate::parsePI, state); | - | ||||||||||||
4574 | return false; | - | ||||||||||||
4575 | } | - | ||||||||||||
4576 | break; | - | ||||||||||||
4577 | case Ws1: | - | ||||||||||||
4578 | case Ws2: | - | ||||||||||||
4579 | case Ws3: | - | ||||||||||||
4580 | case Ws4: | - | ||||||||||||
4581 | case Ws5: | - | ||||||||||||
4582 | if (!eat_ws()) { | - | ||||||||||||
4583 | parseFailed(&QXmlSimpleReaderPrivate::parsePI, state); | - | ||||||||||||
4584 | return false; | - | ||||||||||||
4585 | } | - | ||||||||||||
4586 | break; | - | ||||||||||||
4587 | case Version: | - | ||||||||||||
4588 | if (!parseAttribute()) { | - | ||||||||||||
4589 | parseFailed(&QXmlSimpleReaderPrivate::parsePI, state); | - | ||||||||||||
4590 | return false; | - | ||||||||||||
4591 | } | - | ||||||||||||
4592 | break; | - | ||||||||||||
4593 | case EorSD: | - | ||||||||||||
4594 | if (!parseAttribute()) { | - | ||||||||||||
4595 | parseFailed(&QXmlSimpleReaderPrivate::parsePI, state); | - | ||||||||||||
4596 | return false; | - | ||||||||||||
4597 | } | - | ||||||||||||
4598 | break; | - | ||||||||||||
4599 | case SD: | - | ||||||||||||
4600 | // get the SDDecl (syntax like an attribute) | - | ||||||||||||
4601 | if (standalone != QXmlSimpleReaderPrivate::Unknown) { | - | ||||||||||||
4602 | // already parsed the standalone declaration | - | ||||||||||||
4603 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDCHARACTER)); | - | ||||||||||||
4604 | return false; | - | ||||||||||||
4605 | } | - | ||||||||||||
4606 | if (!parseAttribute()) { | - | ||||||||||||
4607 | parseFailed(&QXmlSimpleReaderPrivate::parsePI, state); | - | ||||||||||||
4608 | return false; | - | ||||||||||||
4609 | } | - | ||||||||||||
4610 | break; | - | ||||||||||||
4611 | case ADone: | - | ||||||||||||
4612 | next(); | - | ||||||||||||
4613 | break; | - | ||||||||||||
4614 | case Char: | - | ||||||||||||
4615 | stringAddC(); | - | ||||||||||||
4616 | next(); | - | ||||||||||||
4617 | break; | - | ||||||||||||
4618 | case Qm: | - | ||||||||||||
4619 | // skip the '?' | - | ||||||||||||
4620 | next(); | - | ||||||||||||
4621 | break; | - | ||||||||||||
4622 | case Done: | - | ||||||||||||
4623 | next(); | - | ||||||||||||
4624 | break; | - | ||||||||||||
4625 | } | - | ||||||||||||
4626 | } | - | ||||||||||||
4627 | return false; | - | ||||||||||||
4628 | } | - | ||||||||||||
4629 | - | |||||||||||||
4630 | /* | - | ||||||||||||
4631 | Parse a document type definition (doctypedecl [28]). | - | ||||||||||||
4632 | - | |||||||||||||
4633 | Precondition: the beginning '<!' of the doctype is already read the head | - | ||||||||||||
4634 | stands on the 'D' of '<!DOCTYPE'. | - | ||||||||||||
4635 | - | |||||||||||||
4636 | If this function was successful, the head-position is on the first | - | ||||||||||||
4637 | character after the document type definition. | - | ||||||||||||
4638 | */ | - | ||||||||||||
4639 | bool QXmlSimpleReaderPrivate::parseDoctype() | - | ||||||||||||
4640 | { | - | ||||||||||||
4641 | const signed char Init = 0; | - | ||||||||||||
4642 | const signed char Doctype = 1; // read the doctype | - | ||||||||||||
4643 | const signed char Ws1 = 2; // eat_ws | - | ||||||||||||
4644 | const signed char Doctype2 = 3; // read the doctype, part 2 | - | ||||||||||||
4645 | const signed char Ws2 = 4; // eat_ws | - | ||||||||||||
4646 | const signed char Sys = 5; // read SYSTEM or PUBLIC | - | ||||||||||||
4647 | const signed char Ws3 = 6; // eat_ws | - | ||||||||||||
4648 | const signed char MP = 7; // markupdecl or PEReference | - | ||||||||||||
4649 | const signed char MPR = 8; // same as MP, but already reported | - | ||||||||||||
4650 | const signed char PER = 9; // PERReference | - | ||||||||||||
4651 | const signed char Mup = 10; // markupdecl | - | ||||||||||||
4652 | const signed char Ws4 = 11; // eat_ws | - | ||||||||||||
4653 | const signed char MPE = 12; // end of markupdecl or PEReference | - | ||||||||||||
4654 | const signed char Done = 13; | - | ||||||||||||
4655 | - | |||||||||||||
4656 | const signed char InpWs = 0; | - | ||||||||||||
4657 | const signed char InpD = 1; // 'D' | - | ||||||||||||
4658 | const signed char InpS = 2; // 'S' or 'P' | - | ||||||||||||
4659 | const signed char InpOB = 3; // [ | - | ||||||||||||
4660 | const signed char InpCB = 4; //] | - | ||||||||||||
4661 | const signed char InpPer = 5; // % | - | ||||||||||||
4662 | const signed char InpGt = 6; // > | - | ||||||||||||
4663 | const signed char InpUnknown = 7; | - | ||||||||||||
4664 | - | |||||||||||||
4665 | static const signed char table[13][8] = { | - | ||||||||||||
4666 | /* InpWs, InpD InpS InpOB InpCB InpPer InpGt InpUnknown */ | - | ||||||||||||
4667 | { -1, Doctype, -1, -1, -1, -1, -1, -1 }, // Init | - | ||||||||||||
4668 | { Ws1, -1, -1, -1, -1, -1, -1, -1 }, // Doctype | - | ||||||||||||
4669 | { -1, Doctype2, Doctype2, -1, -1, -1, -1, Doctype2 }, // Ws1 | - | ||||||||||||
4670 | { Ws2, -1, Sys, MP, -1, -1, Done, -1 }, // Doctype2 | - | ||||||||||||
4671 | { -1, -1, Sys, MP, -1, -1, Done, -1 }, // Ws2 | - | ||||||||||||
4672 | { Ws3, -1, -1, MP, -1, -1, Done, -1 }, // Sys | - | ||||||||||||
4673 | { -1, -1, -1, MP, -1, -1, Done, -1 }, // Ws3 | - | ||||||||||||
4674 | { -1, -1, -1, -1, MPE, PER, -1, Mup }, // MP | - | ||||||||||||
4675 | { -1, -1, -1, -1, MPE, PER, -1, Mup }, // MPR | - | ||||||||||||
4676 | { Ws4, -1, -1, -1, MPE, PER, -1, Mup }, // PER | - | ||||||||||||
4677 | { Ws4, -1, -1, -1, MPE, PER, -1, Mup }, // Mup | - | ||||||||||||
4678 | { -1, -1, -1, -1, MPE, PER, -1, Mup }, // Ws4 | - | ||||||||||||
4679 | { -1, -1, -1, -1, -1, -1, Done, -1 } // MPE | - | ||||||||||||
4680 | }; | - | ||||||||||||
4681 | signed char state; | - | ||||||||||||
4682 | signed char input; | - | ||||||||||||
4683 | - | |||||||||||||
4684 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
4685 | startDTDwasReported = false; | - | ||||||||||||
4686 | systemId.clear(); | - | ||||||||||||
4687 | publicId.clear(); | - | ||||||||||||
4688 | state = Init; | - | ||||||||||||
4689 | } else { | - | ||||||||||||
4690 | state = parseStack->pop().state; | - | ||||||||||||
4691 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
4692 | qDebug("QXmlSimpleReader: parseDoctype (cont) in state %d", state); | - | ||||||||||||
4693 | #endif | - | ||||||||||||
4694 | if (!parseStack->isEmpty()) { | - | ||||||||||||
4695 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
4696 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
4697 | parseStack->pop(); | - | ||||||||||||
4698 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
4699 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
4700 | #endif | - | ||||||||||||
4701 | } | - | ||||||||||||
4702 | if (!(this->*function)()) { | - | ||||||||||||
4703 | parseFailed(&QXmlSimpleReaderPrivate::parseDoctype, state); | - | ||||||||||||
4704 | return false; | - | ||||||||||||
4705 | } | - | ||||||||||||
4706 | } | - | ||||||||||||
4707 | } | - | ||||||||||||
4708 | - | |||||||||||||
4709 | for (;;) { | - | ||||||||||||
4710 | switch (state) { | - | ||||||||||||
4711 | case Doctype2: | - | ||||||||||||
4712 | doctype = name(); | - | ||||||||||||
4713 | break; | - | ||||||||||||
4714 | case MP: | - | ||||||||||||
4715 | if (!startDTDwasReported && lexicalHnd ) { | - | ||||||||||||
4716 | startDTDwasReported = true; | - | ||||||||||||
4717 | if (!lexicalHnd->startDTD(doctype, publicId, systemId)) { | - | ||||||||||||
4718 | reportParseError(lexicalHnd->errorString()); | - | ||||||||||||
4719 | return false; | - | ||||||||||||
4720 | } | - | ||||||||||||
4721 | } | - | ||||||||||||
4722 | state = MPR; | - | ||||||||||||
4723 | break; | - | ||||||||||||
4724 | case Done: | - | ||||||||||||
4725 | return true; | - | ||||||||||||
4726 | case -1: | - | ||||||||||||
4727 | // Error | - | ||||||||||||
4728 | reportParseError(QLatin1String(XMLERR_ERRORPARSINGDOCTYPE)); | - | ||||||||||||
4729 | return false; | - | ||||||||||||
4730 | } | - | ||||||||||||
4731 | - | |||||||||||||
4732 | if (atEnd()) { | - | ||||||||||||
4733 | unexpectedEof(&QXmlSimpleReaderPrivate::parseDoctype, state); | - | ||||||||||||
4734 | return false; | - | ||||||||||||
4735 | } | - | ||||||||||||
4736 | if (is_S(c)) { | - | ||||||||||||
4737 | input = InpWs; | - | ||||||||||||
4738 | } else if (c == QLatin1Char('D')) { | - | ||||||||||||
4739 | input = InpD; | - | ||||||||||||
4740 | } else if (c == QLatin1Char('S')) { | - | ||||||||||||
4741 | input = InpS; | - | ||||||||||||
4742 | } else if (c == QLatin1Char('P')) { | - | ||||||||||||
4743 | input = InpS; | - | ||||||||||||
4744 | } else if (c == QLatin1Char('[')) { | - | ||||||||||||
4745 | input = InpOB; | - | ||||||||||||
4746 | } else if (c == QLatin1Char(']')) { | - | ||||||||||||
4747 | input = InpCB; | - | ||||||||||||
4748 | } else if (c == QLatin1Char('%')) { | - | ||||||||||||
4749 | input = InpPer; | - | ||||||||||||
4750 | } else if (c == QLatin1Char('>')) { | - | ||||||||||||
4751 | input = InpGt; | - | ||||||||||||
4752 | } else { | - | ||||||||||||
4753 | input = InpUnknown; | - | ||||||||||||
4754 | } | - | ||||||||||||
4755 | state = table[state][input]; | - | ||||||||||||
4756 | - | |||||||||||||
4757 | switch (state) { | - | ||||||||||||
4758 | case Doctype: | - | ||||||||||||
4759 | parseString_s = QLatin1String("DOCTYPE"); | - | ||||||||||||
4760 | if (!parseString()) { | - | ||||||||||||
4761 | parseFailed(&QXmlSimpleReaderPrivate::parseDoctype, state); | - | ||||||||||||
4762 | return false; | - | ||||||||||||
4763 | } | - | ||||||||||||
4764 | break; | - | ||||||||||||
4765 | case Ws1: | - | ||||||||||||
4766 | case Ws2: | - | ||||||||||||
4767 | case Ws3: | - | ||||||||||||
4768 | case Ws4: | - | ||||||||||||
4769 | if (!eat_ws()) { | - | ||||||||||||
4770 | parseFailed(&QXmlSimpleReaderPrivate::parseDoctype, state); | - | ||||||||||||
4771 | return false; | - | ||||||||||||
4772 | } | - | ||||||||||||
4773 | break; | - | ||||||||||||
4774 | case Doctype2: | - | ||||||||||||
4775 | parseName_useRef = false; | - | ||||||||||||
4776 | if (!parseName()) { | - | ||||||||||||
4777 | parseFailed(&QXmlSimpleReaderPrivate::parseDoctype, state); | - | ||||||||||||
4778 | return false; | - | ||||||||||||
4779 | } | - | ||||||||||||
4780 | break; | - | ||||||||||||
4781 | case Sys: | - | ||||||||||||
4782 | parseExternalID_allowPublicID = false; | - | ||||||||||||
4783 | if (!parseExternalID()) { | - | ||||||||||||
4784 | parseFailed(&QXmlSimpleReaderPrivate::parseDoctype, state); | - | ||||||||||||
4785 | return false; | - | ||||||||||||
4786 | } | - | ||||||||||||
4787 | thisPublicId = publicId; | - | ||||||||||||
4788 | thisSystemId = systemId; | - | ||||||||||||
4789 | break; | - | ||||||||||||
4790 | case MP: | - | ||||||||||||
4791 | case MPR: | - | ||||||||||||
4792 | if (!next_eat_ws()) { | - | ||||||||||||
4793 | parseFailed(&QXmlSimpleReaderPrivate::parseDoctype, state); | - | ||||||||||||
4794 | return false; | - | ||||||||||||
4795 | } | - | ||||||||||||
4796 | break; | - | ||||||||||||
4797 | case PER: | - | ||||||||||||
4798 | parsePEReference_context = InDTD; | - | ||||||||||||
4799 | if (!parsePEReference()) { | - | ||||||||||||
4800 | parseFailed(&QXmlSimpleReaderPrivate::parseDoctype, state); | - | ||||||||||||
4801 | return false; | - | ||||||||||||
4802 | } | - | ||||||||||||
4803 | break; | - | ||||||||||||
4804 | case Mup: | - | ||||||||||||
4805 | if (dtdRecursionLimit > 0 && parameterEntities.size() > dtdRecursionLimit) { | - | ||||||||||||
4806 | reportParseError(QString::fromLatin1( | - | ||||||||||||
4807 | "DTD parsing exceeded recursion limit of %1.").arg(dtdRecursionLimit)); | - | ||||||||||||
4808 | return false; | - | ||||||||||||
4809 | } | - | ||||||||||||
4810 | if (!parseMarkupdecl()) { | - | ||||||||||||
4811 | parseFailed(&QXmlSimpleReaderPrivate::parseDoctype, state); | - | ||||||||||||
4812 | return false; | - | ||||||||||||
4813 | } | - | ||||||||||||
4814 | break; | - | ||||||||||||
4815 | case MPE: | - | ||||||||||||
4816 | if (!next_eat_ws()) { | - | ||||||||||||
4817 | parseFailed(&QXmlSimpleReaderPrivate::parseDoctype, state); | - | ||||||||||||
4818 | return false; | - | ||||||||||||
4819 | } | - | ||||||||||||
4820 | break; | - | ||||||||||||
4821 | case Done: | - | ||||||||||||
4822 | if (lexicalHnd) { | - | ||||||||||||
4823 | if (!startDTDwasReported) { | - | ||||||||||||
4824 | startDTDwasReported = true; | - | ||||||||||||
4825 | if (!lexicalHnd->startDTD(doctype, publicId, systemId)) { | - | ||||||||||||
4826 | reportParseError(lexicalHnd->errorString()); | - | ||||||||||||
4827 | return false; | - | ||||||||||||
4828 | } | - | ||||||||||||
4829 | } | - | ||||||||||||
4830 | if (!lexicalHnd->endDTD()) { | - | ||||||||||||
4831 | reportParseError(lexicalHnd->errorString()); | - | ||||||||||||
4832 | return false; | - | ||||||||||||
4833 | } | - | ||||||||||||
4834 | } | - | ||||||||||||
4835 | next(); | - | ||||||||||||
4836 | break; | - | ||||||||||||
4837 | } | - | ||||||||||||
4838 | } | - | ||||||||||||
4839 | return false; | - | ||||||||||||
4840 | } | - | ||||||||||||
4841 | - | |||||||||||||
4842 | /* | - | ||||||||||||
4843 | Parse a ExternalID [75]. | - | ||||||||||||
4844 | - | |||||||||||||
4845 | If allowPublicID is true parse ExternalID [75] or PublicID [83]. | - | ||||||||||||
4846 | */ | - | ||||||||||||
4847 | bool QXmlSimpleReaderPrivate::parseExternalID() | - | ||||||||||||
4848 | { | - | ||||||||||||
4849 | const signed char Init = 0; | - | ||||||||||||
4850 | const signed char Sys = 1; // parse 'SYSTEM' | - | ||||||||||||
4851 | const signed char SysWS = 2; // parse the whitespace after 'SYSTEM' | - | ||||||||||||
4852 | const signed char SysSQ = 3; // parse SystemLiteral with ' | - | ||||||||||||
4853 | const signed char SysSQ2 = 4; // parse SystemLiteral with ' | - | ||||||||||||
4854 | const signed char SysDQ = 5; // parse SystemLiteral with " | - | ||||||||||||
4855 | const signed char SysDQ2 = 6; // parse SystemLiteral with " | - | ||||||||||||
4856 | const signed char Pub = 7; // parse 'PUBLIC' | - | ||||||||||||
4857 | const signed char PubWS = 8; // parse the whitespace after 'PUBLIC' | - | ||||||||||||
4858 | const signed char PubSQ = 9; // parse PubidLiteral with ' | - | ||||||||||||
4859 | const signed char PubSQ2 = 10; // parse PubidLiteral with ' | - | ||||||||||||
4860 | const signed char PubDQ = 11; // parse PubidLiteral with " | - | ||||||||||||
4861 | const signed char PubDQ2 = 12; // parse PubidLiteral with " | - | ||||||||||||
4862 | const signed char PubE = 13; // finished parsing the PubidLiteral | - | ||||||||||||
4863 | const signed char PubWS2 = 14; // parse the whitespace after the PubidLiteral | - | ||||||||||||
4864 | const signed char PDone = 15; // done if allowPublicID is true | - | ||||||||||||
4865 | const signed char Done = 16; | - | ||||||||||||
4866 | - | |||||||||||||
4867 | const signed char InpSQ = 0; // ' | - | ||||||||||||
4868 | const signed char InpDQ = 1; // " | - | ||||||||||||
4869 | const signed char InpS = 2; // S | - | ||||||||||||
4870 | const signed char InpP = 3; // P | - | ||||||||||||
4871 | const signed char InpWs = 4; // white space | - | ||||||||||||
4872 | const signed char InpUnknown = 5; | - | ||||||||||||
4873 | - | |||||||||||||
4874 | static const signed char table[15][6] = { | - | ||||||||||||
4875 | /* InpSQ InpDQ InpS InpP InpWs InpUnknown */ | - | ||||||||||||
4876 | { -1, -1, Sys, Pub, -1, -1 }, // Init | - | ||||||||||||
4877 | { -1, -1, -1, -1, SysWS, -1 }, // Sys | - | ||||||||||||
4878 | { SysSQ, SysDQ, -1, -1, -1, -1 }, // SysWS | - | ||||||||||||
4879 | { Done, SysSQ2, SysSQ2, SysSQ2, SysSQ2, SysSQ2 }, // SysSQ | - | ||||||||||||
4880 | { Done, SysSQ2, SysSQ2, SysSQ2, SysSQ2, SysSQ2 }, // SysSQ2 | - | ||||||||||||
4881 | { SysDQ2, Done, SysDQ2, SysDQ2, SysDQ2, SysDQ2 }, // SysDQ | - | ||||||||||||
4882 | { SysDQ2, Done, SysDQ2, SysDQ2, SysDQ2, SysDQ2 }, // SysDQ2 | - | ||||||||||||
4883 | { -1, -1, -1, -1, PubWS, -1 }, // Pub | - | ||||||||||||
4884 | { PubSQ, PubDQ, -1, -1, -1, -1 }, // PubWS | - | ||||||||||||
4885 | { PubE, -1, PubSQ2, PubSQ2, PubSQ2, PubSQ2 }, // PubSQ | - | ||||||||||||
4886 | { PubE, -1, PubSQ2, PubSQ2, PubSQ2, PubSQ2 }, // PubSQ2 | - | ||||||||||||
4887 | { -1, PubE, PubDQ2, PubDQ2, PubDQ2, PubDQ2 }, // PubDQ | - | ||||||||||||
4888 | { -1, PubE, PubDQ2, PubDQ2, PubDQ2, PubDQ2 }, // PubDQ2 | - | ||||||||||||
4889 | { PDone, PDone, PDone, PDone, PubWS2, PDone }, // PubE | - | ||||||||||||
4890 | { SysSQ, SysDQ, PDone, PDone, PDone, PDone } // PubWS2 | - | ||||||||||||
4891 | }; | - | ||||||||||||
4892 | signed char state; | - | ||||||||||||
4893 | signed char input; | - | ||||||||||||
4894 | - | |||||||||||||
4895 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
4896 | systemId.clear(); | - | ||||||||||||
4897 | publicId.clear(); | - | ||||||||||||
4898 | state = Init; | - | ||||||||||||
4899 | } else { | - | ||||||||||||
4900 | state = parseStack->pop().state; | - | ||||||||||||
4901 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
4902 | qDebug("QXmlSimpleReader: parseExternalID (cont) in state %d", state); | - | ||||||||||||
4903 | #endif | - | ||||||||||||
4904 | if (!parseStack->isEmpty()) { | - | ||||||||||||
4905 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
4906 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
4907 | parseStack->pop(); | - | ||||||||||||
4908 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
4909 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
4910 | #endif | - | ||||||||||||
4911 | } | - | ||||||||||||
4912 | if (!(this->*function)()) { | - | ||||||||||||
4913 | parseFailed(&QXmlSimpleReaderPrivate::parseExternalID, state); | - | ||||||||||||
4914 | return false; | - | ||||||||||||
4915 | } | - | ||||||||||||
4916 | } | - | ||||||||||||
4917 | } | - | ||||||||||||
4918 | - | |||||||||||||
4919 | for (;;) { | - | ||||||||||||
4920 | switch (state) { | - | ||||||||||||
4921 | case PDone: | - | ||||||||||||
4922 | if (parseExternalID_allowPublicID) { | - | ||||||||||||
4923 | publicId = string(); | - | ||||||||||||
4924 | return true; | - | ||||||||||||
4925 | } else { | - | ||||||||||||
4926 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDCHARACTER)); | - | ||||||||||||
4927 | return false; | - | ||||||||||||
4928 | } | - | ||||||||||||
4929 | case Done: | - | ||||||||||||
4930 | return true; | - | ||||||||||||
4931 | case -1: | - | ||||||||||||
4932 | // Error | - | ||||||||||||
4933 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDCHARACTER)); | - | ||||||||||||
4934 | return false; | - | ||||||||||||
4935 | } | - | ||||||||||||
4936 | - | |||||||||||||
4937 | if (atEnd()) { | - | ||||||||||||
4938 | unexpectedEof(&QXmlSimpleReaderPrivate::parseExternalID, state); | - | ||||||||||||
4939 | return false; | - | ||||||||||||
4940 | } | - | ||||||||||||
4941 | if (is_S(c)) { | - | ||||||||||||
4942 | input = InpWs; | - | ||||||||||||
4943 | } else if (c == QLatin1Char('\'')) { | - | ||||||||||||
4944 | input = InpSQ; | - | ||||||||||||
4945 | } else if (c == QLatin1Char('"')) { | - | ||||||||||||
4946 | input = InpDQ; | - | ||||||||||||
4947 | } else if (c == QLatin1Char('S')) { | - | ||||||||||||
4948 | input = InpS; | - | ||||||||||||
4949 | } else if (c == QLatin1Char('P')) { | - | ||||||||||||
4950 | input = InpP; | - | ||||||||||||
4951 | } else { | - | ||||||||||||
4952 | input = InpUnknown; | - | ||||||||||||
4953 | } | - | ||||||||||||
4954 | state = table[state][input]; | - | ||||||||||||
4955 | - | |||||||||||||
4956 | switch (state) { | - | ||||||||||||
4957 | case Sys: | - | ||||||||||||
4958 | parseString_s = QLatin1String("SYSTEM"); | - | ||||||||||||
4959 | if (!parseString()) { | - | ||||||||||||
4960 | parseFailed(&QXmlSimpleReaderPrivate::parseExternalID, state); | - | ||||||||||||
4961 | return false; | - | ||||||||||||
4962 | } | - | ||||||||||||
4963 | break; | - | ||||||||||||
4964 | case SysWS: | - | ||||||||||||
4965 | if (!eat_ws()) { | - | ||||||||||||
4966 | parseFailed(&QXmlSimpleReaderPrivate::parseExternalID, state); | - | ||||||||||||
4967 | return false; | - | ||||||||||||
4968 | } | - | ||||||||||||
4969 | break; | - | ||||||||||||
4970 | case SysSQ: | - | ||||||||||||
4971 | case SysDQ: | - | ||||||||||||
4972 | stringClear(); | - | ||||||||||||
4973 | next(); | - | ||||||||||||
4974 | break; | - | ||||||||||||
4975 | case SysSQ2: | - | ||||||||||||
4976 | case SysDQ2: | - | ||||||||||||
4977 | stringAddC(); | - | ||||||||||||
4978 | next(); | - | ||||||||||||
4979 | break; | - | ||||||||||||
4980 | case Pub: | - | ||||||||||||
4981 | parseString_s = QLatin1String("PUBLIC"); | - | ||||||||||||
4982 | if (!parseString()) { | - | ||||||||||||
4983 | parseFailed(&QXmlSimpleReaderPrivate::parseExternalID, state); | - | ||||||||||||
4984 | return false; | - | ||||||||||||
4985 | } | - | ||||||||||||
4986 | break; | - | ||||||||||||
4987 | case PubWS: | - | ||||||||||||
4988 | if (!eat_ws()) { | - | ||||||||||||
4989 | parseFailed(&QXmlSimpleReaderPrivate::parseExternalID, state); | - | ||||||||||||
4990 | return false; | - | ||||||||||||
4991 | } | - | ||||||||||||
4992 | break; | - | ||||||||||||
4993 | case PubSQ: | - | ||||||||||||
4994 | case PubDQ: | - | ||||||||||||
4995 | stringClear(); | - | ||||||||||||
4996 | next(); | - | ||||||||||||
4997 | break; | - | ||||||||||||
4998 | case PubSQ2: | - | ||||||||||||
4999 | case PubDQ2: | - | ||||||||||||
5000 | stringAddC(); | - | ||||||||||||
5001 | next(); | - | ||||||||||||
5002 | break; | - | ||||||||||||
5003 | case PubE: | - | ||||||||||||
5004 | next(); | - | ||||||||||||
5005 | break; | - | ||||||||||||
5006 | case PubWS2: | - | ||||||||||||
5007 | publicId = string(); | - | ||||||||||||
5008 | if (!eat_ws()) { | - | ||||||||||||
5009 | parseFailed(&QXmlSimpleReaderPrivate::parseExternalID, state); | - | ||||||||||||
5010 | return false; | - | ||||||||||||
5011 | } | - | ||||||||||||
5012 | break; | - | ||||||||||||
5013 | case Done: | - | ||||||||||||
5014 | systemId = string(); | - | ||||||||||||
5015 | next(); | - | ||||||||||||
5016 | break; | - | ||||||||||||
5017 | } | - | ||||||||||||
5018 | } | - | ||||||||||||
5019 | return false; | - | ||||||||||||
5020 | } | - | ||||||||||||
5021 | - | |||||||||||||
5022 | /* | - | ||||||||||||
5023 | Parse a markupdecl [29]. | - | ||||||||||||
5024 | */ | - | ||||||||||||
5025 | bool QXmlSimpleReaderPrivate::parseMarkupdecl() | - | ||||||||||||
5026 | { | - | ||||||||||||
5027 | const signed char Init = 0; | - | ||||||||||||
5028 | const signed char Lt = 1; // < was read | - | ||||||||||||
5029 | const signed char Em = 2; // ! was read | - | ||||||||||||
5030 | const signed char CE = 3; // E was read | - | ||||||||||||
5031 | const signed char Qm = 4; // ? was read | - | ||||||||||||
5032 | const signed char Dash = 5; // - was read | - | ||||||||||||
5033 | const signed char CA = 6; // A was read | - | ||||||||||||
5034 | const signed char CEL = 7; // EL was read | - | ||||||||||||
5035 | const signed char CEN = 8; // EN was read | - | ||||||||||||
5036 | const signed char CN = 9; // N was read | - | ||||||||||||
5037 | const signed char Done = 10; | - | ||||||||||||
5038 | - | |||||||||||||
5039 | const signed char InpLt = 0; // < | - | ||||||||||||
5040 | const signed char InpQm = 1; // ? | - | ||||||||||||
5041 | const signed char InpEm = 2; // ! | - | ||||||||||||
5042 | const signed char InpDash = 3; // - | - | ||||||||||||
5043 | const signed char InpA = 4; // A | - | ||||||||||||
5044 | const signed char InpE = 5; // E | - | ||||||||||||
5045 | const signed char InpL = 6; // L | - | ||||||||||||
5046 | const signed char InpN = 7; // N | - | ||||||||||||
5047 | const signed char InpUnknown = 8; | - | ||||||||||||
5048 | - | |||||||||||||
5049 | static const signed char table[4][9] = { | - | ||||||||||||
5050 | /* InpLt InpQm InpEm InpDash InpA InpE InpL InpN InpUnknown */ | - | ||||||||||||
5051 | { Lt, -1, -1, -1, -1, -1, -1, -1, -1 }, // Init | - | ||||||||||||
5052 | { -1, Qm, Em, -1, -1, -1, -1, -1, -1 }, // Lt | - | ||||||||||||
5053 | { -1, -1, -1, Dash, CA, CE, -1, CN, -1 }, // Em | - | ||||||||||||
5054 | { -1, -1, -1, -1, -1, -1, CEL, CEN, -1 } // CE | - | ||||||||||||
5055 | }; | - | ||||||||||||
5056 | signed char state; | - | ||||||||||||
5057 | signed char input; | - | ||||||||||||
5058 | - | |||||||||||||
5059 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
5060 | state = Init; | - | ||||||||||||
5061 | } else { | - | ||||||||||||
5062 | state = parseStack->pop().state; | - | ||||||||||||
5063 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
5064 | qDebug("QXmlSimpleReader: parseMarkupdecl (cont) in state %d", state); | - | ||||||||||||
5065 | #endif | - | ||||||||||||
5066 | if (!parseStack->isEmpty()) { | - | ||||||||||||
5067 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
5068 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
5069 | parseStack->pop(); | - | ||||||||||||
5070 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
5071 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
5072 | #endif | - | ||||||||||||
5073 | } | - | ||||||||||||
5074 | if (!(this->*function)()) { | - | ||||||||||||
5075 | parseFailed(&QXmlSimpleReaderPrivate::parseMarkupdecl, state); | - | ||||||||||||
5076 | return false; | - | ||||||||||||
5077 | } | - | ||||||||||||
5078 | } | - | ||||||||||||
5079 | } | - | ||||||||||||
5080 | - | |||||||||||||
5081 | for (;;) { | - | ||||||||||||
5082 | switch (state) { | - | ||||||||||||
5083 | case Qm: | - | ||||||||||||
5084 | if (contentHnd) { | - | ||||||||||||
5085 | if (!contentHnd->processingInstruction(name(),string())) { | - | ||||||||||||
5086 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
5087 | return false; | - | ||||||||||||
5088 | } | - | ||||||||||||
5089 | } | - | ||||||||||||
5090 | return true; | - | ||||||||||||
5091 | case Dash: | - | ||||||||||||
5092 | if (lexicalHnd) { | - | ||||||||||||
5093 | if (!lexicalHnd->comment(string())) { | - | ||||||||||||
5094 | reportParseError(lexicalHnd->errorString()); | - | ||||||||||||
5095 | return false; | - | ||||||||||||
5096 | } | - | ||||||||||||
5097 | } | - | ||||||||||||
5098 | return true; | - | ||||||||||||
5099 | case CA: | - | ||||||||||||
5100 | return true; | - | ||||||||||||
5101 | case CEL: | - | ||||||||||||
5102 | return true; | - | ||||||||||||
5103 | case CEN: | - | ||||||||||||
5104 | return true; | - | ||||||||||||
5105 | case CN: | - | ||||||||||||
5106 | return true; | - | ||||||||||||
5107 | case Done: | - | ||||||||||||
5108 | return true; | - | ||||||||||||
5109 | case -1: | - | ||||||||||||
5110 | // Error | - | ||||||||||||
5111 | reportParseError(QLatin1String(XMLERR_LETTEREXPECTED)); | - | ||||||||||||
5112 | return false; | - | ||||||||||||
5113 | } | - | ||||||||||||
5114 | - | |||||||||||||
5115 | if (atEnd()) { | - | ||||||||||||
5116 | unexpectedEof(&QXmlSimpleReaderPrivate::parseMarkupdecl, state); | - | ||||||||||||
5117 | return false; | - | ||||||||||||
5118 | } | - | ||||||||||||
5119 | if (c == QLatin1Char('<')) { | - | ||||||||||||
5120 | input = InpLt; | - | ||||||||||||
5121 | } else if (c == QLatin1Char('?')) { | - | ||||||||||||
5122 | input = InpQm; | - | ||||||||||||
5123 | } else if (c == QLatin1Char('!')) { | - | ||||||||||||
5124 | input = InpEm; | - | ||||||||||||
5125 | } else if (c == QLatin1Char('-')) { | - | ||||||||||||
5126 | input = InpDash; | - | ||||||||||||
5127 | } else if (c == QLatin1Char('A')) { | - | ||||||||||||
5128 | input = InpA; | - | ||||||||||||
5129 | } else if (c == QLatin1Char('E')) { | - | ||||||||||||
5130 | input = InpE; | - | ||||||||||||
5131 | } else if (c == QLatin1Char('L')) { | - | ||||||||||||
5132 | input = InpL; | - | ||||||||||||
5133 | } else if (c == QLatin1Char('N')) { | - | ||||||||||||
5134 | input = InpN; | - | ||||||||||||
5135 | } else { | - | ||||||||||||
5136 | input = InpUnknown; | - | ||||||||||||
5137 | } | - | ||||||||||||
5138 | state = table[state][input]; | - | ||||||||||||
5139 | - | |||||||||||||
5140 | switch (state) { | - | ||||||||||||
5141 | case Lt: | - | ||||||||||||
5142 | next(); | - | ||||||||||||
5143 | break; | - | ||||||||||||
5144 | case Em: | - | ||||||||||||
5145 | next(); | - | ||||||||||||
5146 | break; | - | ||||||||||||
5147 | case CE: | - | ||||||||||||
5148 | next(); | - | ||||||||||||
5149 | break; | - | ||||||||||||
5150 | case Qm: | - | ||||||||||||
5151 | parsePI_xmldecl = false; | - | ||||||||||||
5152 | if (!parsePI()) { | - | ||||||||||||
5153 | parseFailed(&QXmlSimpleReaderPrivate::parseMarkupdecl, state); | - | ||||||||||||
5154 | return false; | - | ||||||||||||
5155 | } | - | ||||||||||||
5156 | break; | - | ||||||||||||
5157 | case Dash: | - | ||||||||||||
5158 | if (!parseComment()) { | - | ||||||||||||
5159 | parseFailed(&QXmlSimpleReaderPrivate::parseMarkupdecl, state); | - | ||||||||||||
5160 | return false; | - | ||||||||||||
5161 | } | - | ||||||||||||
5162 | break; | - | ||||||||||||
5163 | case CA: | - | ||||||||||||
5164 | if (!parseAttlistDecl()) { | - | ||||||||||||
5165 | parseFailed(&QXmlSimpleReaderPrivate::parseMarkupdecl, state); | - | ||||||||||||
5166 | return false; | - | ||||||||||||
5167 | } | - | ||||||||||||
5168 | break; | - | ||||||||||||
5169 | case CEL: | - | ||||||||||||
5170 | if (!parseElementDecl()) { | - | ||||||||||||
5171 | parseFailed(&QXmlSimpleReaderPrivate::parseMarkupdecl, state); | - | ||||||||||||
5172 | return false; | - | ||||||||||||
5173 | } | - | ||||||||||||
5174 | break; | - | ||||||||||||
5175 | case CEN: | - | ||||||||||||
5176 | if (!parseEntityDecl()) { | - | ||||||||||||
5177 | parseFailed(&QXmlSimpleReaderPrivate::parseMarkupdecl, state); | - | ||||||||||||
5178 | return false; | - | ||||||||||||
5179 | } | - | ||||||||||||
5180 | break; | - | ||||||||||||
5181 | case CN: | - | ||||||||||||
5182 | if (!parseNotationDecl()) { | - | ||||||||||||
5183 | parseFailed(&QXmlSimpleReaderPrivate::parseMarkupdecl, state); | - | ||||||||||||
5184 | return false; | - | ||||||||||||
5185 | } | - | ||||||||||||
5186 | break; | - | ||||||||||||
5187 | } | - | ||||||||||||
5188 | } | - | ||||||||||||
5189 | return false; | - | ||||||||||||
5190 | } | - | ||||||||||||
5191 | - | |||||||||||||
5192 | /* | - | ||||||||||||
5193 | Parse a PEReference [69] | - | ||||||||||||
5194 | */ | - | ||||||||||||
5195 | bool QXmlSimpleReaderPrivate::parsePEReference() | - | ||||||||||||
5196 | { | - | ||||||||||||
5197 | const signed char Init = 0; | - | ||||||||||||
5198 | const signed char Next = 1; | - | ||||||||||||
5199 | const signed char Name = 2; | - | ||||||||||||
5200 | const signed char NameR = 3; // same as Name, but already reported | - | ||||||||||||
5201 | const signed char Done = 4; | - | ||||||||||||
5202 | - | |||||||||||||
5203 | const signed char InpSemi = 0; // ; | - | ||||||||||||
5204 | const signed char InpPer = 1; // % | - | ||||||||||||
5205 | const signed char InpUnknown = 2; | - | ||||||||||||
5206 | - | |||||||||||||
5207 | static const signed char table[4][3] = { | - | ||||||||||||
5208 | /* InpSemi InpPer InpUnknown */ | - | ||||||||||||
5209 | { -1, Next, -1 }, // Init | - | ||||||||||||
5210 | { -1, -1, Name }, // Next | - | ||||||||||||
5211 | { Done, -1, -1 }, // Name | - | ||||||||||||
5212 | { Done, -1, -1 } // NameR | - | ||||||||||||
5213 | }; | - | ||||||||||||
5214 | signed char state; | - | ||||||||||||
5215 | signed char input; | - | ||||||||||||
5216 | - | |||||||||||||
5217 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
5218 | state = Init; | - | ||||||||||||
5219 | } else { | - | ||||||||||||
5220 | state = parseStack->pop().state; | - | ||||||||||||
5221 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
5222 | qDebug("QXmlSimpleReader: parsePEReference (cont) in state %d", state); | - | ||||||||||||
5223 | #endif | - | ||||||||||||
5224 | if (!parseStack->isEmpty()) { | - | ||||||||||||
5225 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
5226 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
5227 | parseStack->pop(); | - | ||||||||||||
5228 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
5229 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
5230 | #endif | - | ||||||||||||
5231 | } | - | ||||||||||||
5232 | if (!(this->*function)()) { | - | ||||||||||||
5233 | parseFailed(&QXmlSimpleReaderPrivate::parsePEReference, state); | - | ||||||||||||
5234 | return false; | - | ||||||||||||
5235 | } | - | ||||||||||||
5236 | } | - | ||||||||||||
5237 | } | - | ||||||||||||
5238 | - | |||||||||||||
5239 | for (;;) { | - | ||||||||||||
5240 | switch (state) { | - | ||||||||||||
5241 | case Name: | - | ||||||||||||
5242 | { | - | ||||||||||||
5243 | bool skipIt = true; | - | ||||||||||||
5244 | QString xmlRefString; | - | ||||||||||||
5245 | - | |||||||||||||
5246 | QMap<QString,QString>::Iterator it; | - | ||||||||||||
5247 | it = parameterEntities.find(ref()); | - | ||||||||||||
5248 | if (it != parameterEntities.end()) { | - | ||||||||||||
5249 | skipIt = false; | - | ||||||||||||
5250 | xmlRefString = *it; | - | ||||||||||||
5251 | } else if (entityRes) { | - | ||||||||||||
5252 | QMap<QString,QXmlSimpleReaderPrivate::ExternParameterEntity>::Iterator it2; | - | ||||||||||||
5253 | it2 = externParameterEntities.find(ref()); | - | ||||||||||||
5254 | QXmlInputSource *ret = 0; | - | ||||||||||||
5255 | if (it2 != externParameterEntities.end()) { | - | ||||||||||||
5256 | if (!entityRes->resolveEntity((*it2).publicId, (*it2).systemId, ret)) { | - | ||||||||||||
5257 | delete ret; | - | ||||||||||||
5258 | reportParseError(entityRes->errorString()); | - | ||||||||||||
5259 | return false; | - | ||||||||||||
5260 | } | - | ||||||||||||
5261 | if (ret) { | - | ||||||||||||
5262 | QString buffer = ret->data(); | - | ||||||||||||
5263 | while (!buffer.isEmpty()) { | - | ||||||||||||
5264 | xmlRefString += buffer; | - | ||||||||||||
5265 | ret->fetchData(); | - | ||||||||||||
5266 | buffer = ret->data(); | - | ||||||||||||
5267 | } | - | ||||||||||||
5268 | delete ret; | - | ||||||||||||
5269 | if (!stripTextDecl(xmlRefString)) { | - | ||||||||||||
5270 | reportParseError(QLatin1String(XMLERR_ERRORINTEXTDECL)); | - | ||||||||||||
5271 | return false; | - | ||||||||||||
5272 | } | - | ||||||||||||
5273 | skipIt = false; | - | ||||||||||||
5274 | } | - | ||||||||||||
5275 | } | - | ||||||||||||
5276 | } | - | ||||||||||||
5277 | - | |||||||||||||
5278 | if (skipIt) { | - | ||||||||||||
5279 | if (contentHnd) { | - | ||||||||||||
5280 | if (!contentHnd->skippedEntity(QLatin1Char('%') + ref())) { | - | ||||||||||||
5281 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
5282 | return false; | - | ||||||||||||
5283 | } | - | ||||||||||||
5284 | } | - | ||||||||||||
5285 | } else { | - | ||||||||||||
5286 | if (parsePEReference_context == InEntityValue) { | - | ||||||||||||
5287 | // Included in literal | - | ||||||||||||
5288 | if (!insertXmlRef(xmlRefString, ref(), true)) | - | ||||||||||||
5289 | return false; | - | ||||||||||||
5290 | } else if (parsePEReference_context == InDTD) { | - | ||||||||||||
5291 | // Included as PE | - | ||||||||||||
5292 | if (!insertXmlRef(QLatin1Char(' ') + xmlRefString + QLatin1Char(' '), ref(), false)) | - | ||||||||||||
5293 | return false; | - | ||||||||||||
5294 | } | - | ||||||||||||
5295 | } | - | ||||||||||||
5296 | } | - | ||||||||||||
5297 | state = NameR; | - | ||||||||||||
5298 | break; | - | ||||||||||||
5299 | case Done: | - | ||||||||||||
5300 | return true; | - | ||||||||||||
5301 | case -1: | - | ||||||||||||
5302 | // Error | - | ||||||||||||
5303 | reportParseError(QLatin1String(XMLERR_LETTEREXPECTED)); | - | ||||||||||||
5304 | return false; | - | ||||||||||||
5305 | } | - | ||||||||||||
5306 | - | |||||||||||||
5307 | if (atEnd()) { | - | ||||||||||||
5308 | unexpectedEof(&QXmlSimpleReaderPrivate::parsePEReference, state); | - | ||||||||||||
5309 | return false; | - | ||||||||||||
5310 | } | - | ||||||||||||
5311 | if (c == QLatin1Char(';')) { | - | ||||||||||||
5312 | input = InpSemi; | - | ||||||||||||
5313 | } else if (c == QLatin1Char('%')) { | - | ||||||||||||
5314 | input = InpPer; | - | ||||||||||||
5315 | } else { | - | ||||||||||||
5316 | input = InpUnknown; | - | ||||||||||||
5317 | } | - | ||||||||||||
5318 | state = table[state][input]; | - | ||||||||||||
5319 | - | |||||||||||||
5320 | switch (state) { | - | ||||||||||||
5321 | case Next: | - | ||||||||||||
5322 | next(); | - | ||||||||||||
5323 | break; | - | ||||||||||||
5324 | case Name: | - | ||||||||||||
5325 | case NameR: | - | ||||||||||||
5326 | parseName_useRef = true; | - | ||||||||||||
5327 | if (!parseName()) { | - | ||||||||||||
5328 | parseFailed(&QXmlSimpleReaderPrivate::parsePEReference, state); | - | ||||||||||||
5329 | return false; | - | ||||||||||||
5330 | } | - | ||||||||||||
5331 | break; | - | ||||||||||||
5332 | case Done: | - | ||||||||||||
5333 | next(); | - | ||||||||||||
5334 | break; | - | ||||||||||||
5335 | } | - | ||||||||||||
5336 | } | - | ||||||||||||
5337 | return false; | - | ||||||||||||
5338 | } | - | ||||||||||||
5339 | - | |||||||||||||
5340 | /* | - | ||||||||||||
5341 | Parse a AttlistDecl [52]. | - | ||||||||||||
5342 | - | |||||||||||||
5343 | Precondition: the beginning '<!' is already read and the head | - | ||||||||||||
5344 | stands on the 'A' of '<!ATTLIST' | - | ||||||||||||
5345 | */ | - | ||||||||||||
5346 | bool QXmlSimpleReaderPrivate::parseAttlistDecl() | - | ||||||||||||
5347 | { | - | ||||||||||||
5348 | const signed char Init = 0; | - | ||||||||||||
5349 | const signed char Attlist = 1; // parse the string "ATTLIST" | - | ||||||||||||
5350 | const signed char Ws = 2; // whitespace read | - | ||||||||||||
5351 | const signed char Name = 3; // parse name | - | ||||||||||||
5352 | const signed char Ws1 = 4; // whitespace read | - | ||||||||||||
5353 | const signed char Attdef = 5; // parse the AttDef | - | ||||||||||||
5354 | const signed char Ws2 = 6; // whitespace read | - | ||||||||||||
5355 | const signed char Atttype = 7; // parse the AttType | - | ||||||||||||
5356 | const signed char Ws3 = 8; // whitespace read | - | ||||||||||||
5357 | const signed char DDecH = 9; // DefaultDecl with # | - | ||||||||||||
5358 | const signed char DefReq = 10; // parse the string "REQUIRED" | - | ||||||||||||
5359 | const signed char DefImp = 11; // parse the string "IMPLIED" | - | ||||||||||||
5360 | const signed char DefFix = 12; // parse the string "FIXED" | - | ||||||||||||
5361 | const signed char Attval = 13; // parse the AttValue | - | ||||||||||||
5362 | const signed char Ws4 = 14; // whitespace read | - | ||||||||||||
5363 | const signed char Done = 15; | - | ||||||||||||
5364 | - | |||||||||||||
5365 | const signed char InpWs = 0; // white space | - | ||||||||||||
5366 | const signed char InpGt = 1; // > | - | ||||||||||||
5367 | const signed char InpHash = 2; // # | - | ||||||||||||
5368 | const signed char InpA = 3; // A | - | ||||||||||||
5369 | const signed char InpI = 4; // I | - | ||||||||||||
5370 | const signed char InpF = 5; // F | - | ||||||||||||
5371 | const signed char InpR = 6; // R | - | ||||||||||||
5372 | const signed char InpUnknown = 7; | - | ||||||||||||
5373 | - | |||||||||||||
5374 | static const signed char table[15][8] = { | - | ||||||||||||
5375 | /* InpWs InpGt InpHash InpA InpI InpF InpR InpUnknown */ | - | ||||||||||||
5376 | { -1, -1, -1, Attlist, -1, -1, -1, -1 }, // Init | - | ||||||||||||
5377 | { Ws, -1, -1, -1, -1, -1, -1, -1 }, // Attlist | - | ||||||||||||
5378 | { -1, -1, -1, Name, Name, Name, Name, Name }, // Ws | - | ||||||||||||
5379 | { Ws1, Done, Attdef, Attdef, Attdef, Attdef, Attdef, Attdef }, // Name | - | ||||||||||||
5380 | { -1, Done, Attdef, Attdef, Attdef, Attdef, Attdef, Attdef }, // Ws1 | - | ||||||||||||
5381 | { Ws2, -1, -1, -1, -1, -1, -1, -1 }, // Attdef | - | ||||||||||||
5382 | { -1, Atttype, Atttype, Atttype, Atttype, Atttype, Atttype, Atttype }, // Ws2 | - | ||||||||||||
5383 | { Ws3, -1, -1, -1, -1, -1, -1, -1 }, // Attype | - | ||||||||||||
5384 | { -1, Attval, DDecH, Attval, Attval, Attval, Attval, Attval }, // Ws3 | - | ||||||||||||
5385 | { -1, -1, -1, -1, DefImp, DefFix, DefReq, -1 }, // DDecH | - | ||||||||||||
5386 | { Ws4, Ws4, -1, -1, -1, -1, -1, -1 }, // DefReq | - | ||||||||||||
5387 | { Ws4, Ws4, -1, -1, -1, -1, -1, -1 }, // DefImp | - | ||||||||||||
5388 | { Ws3, -1, -1, -1, -1, -1, -1, -1 }, // DefFix | - | ||||||||||||
5389 | { Ws4, Ws4, -1, -1, -1, -1, -1, -1 }, // Attval | - | ||||||||||||
5390 | { -1, Done, Attdef, Attdef, Attdef, Attdef, Attdef, Attdef } // Ws4 | - | ||||||||||||
5391 | }; | - | ||||||||||||
5392 | signed char state; | - | ||||||||||||
5393 | signed char input; | - | ||||||||||||
5394 | - | |||||||||||||
5395 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
5396 | state = Init; | - | ||||||||||||
5397 | } else { | - | ||||||||||||
5398 | state = parseStack->pop().state; | - | ||||||||||||
5399 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
5400 | qDebug("QXmlSimpleReader: parseAttlistDecl (cont) in state %d", state); | - | ||||||||||||
5401 | #endif | - | ||||||||||||
5402 | if (!parseStack->isEmpty()) { | - | ||||||||||||
5403 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
5404 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
5405 | parseStack->pop(); | - | ||||||||||||
5406 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
5407 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
5408 | #endif | - | ||||||||||||
5409 | } | - | ||||||||||||
5410 | if (!(this->*function)()) { | - | ||||||||||||
5411 | parseFailed(&QXmlSimpleReaderPrivate::parseAttlistDecl, state); | - | ||||||||||||
5412 | return false; | - | ||||||||||||
5413 | } | - | ||||||||||||
5414 | } | - | ||||||||||||
5415 | } | - | ||||||||||||
5416 | - | |||||||||||||
5417 | for (;;) { | - | ||||||||||||
5418 | switch (state) { | - | ||||||||||||
5419 | case Name: | - | ||||||||||||
5420 | attDeclEName = name(); | - | ||||||||||||
5421 | break; | - | ||||||||||||
5422 | case Attdef: | - | ||||||||||||
5423 | attDeclAName = name(); | - | ||||||||||||
5424 | break; | - | ||||||||||||
5425 | case Done: | - | ||||||||||||
5426 | return true; | - | ||||||||||||
5427 | case -1: | - | ||||||||||||
5428 | // Error | - | ||||||||||||
5429 | reportParseError(QLatin1String(XMLERR_LETTEREXPECTED)); | - | ||||||||||||
5430 | return false; | - | ||||||||||||
5431 | } | - | ||||||||||||
5432 | - | |||||||||||||
5433 | if (atEnd()) { | - | ||||||||||||
5434 | unexpectedEof(&QXmlSimpleReaderPrivate::parseAttlistDecl, state); | - | ||||||||||||
5435 | return false; | - | ||||||||||||
5436 | } | - | ||||||||||||
5437 | if (is_S(c)) { | - | ||||||||||||
5438 | input = InpWs; | - | ||||||||||||
5439 | } else if (c == QLatin1Char('>')) { | - | ||||||||||||
5440 | input = InpGt; | - | ||||||||||||
5441 | } else if (c == QLatin1Char('#')) { | - | ||||||||||||
5442 | input = InpHash; | - | ||||||||||||
5443 | } else if (c == QLatin1Char('A')) { | - | ||||||||||||
5444 | input = InpA; | - | ||||||||||||
5445 | } else if (c == QLatin1Char('I')) { | - | ||||||||||||
5446 | input = InpI; | - | ||||||||||||
5447 | } else if (c == QLatin1Char('F')) { | - | ||||||||||||
5448 | input = InpF; | - | ||||||||||||
5449 | } else if (c == QLatin1Char('R')) { | - | ||||||||||||
5450 | input = InpR; | - | ||||||||||||
5451 | } else { | - | ||||||||||||
5452 | input = InpUnknown; | - | ||||||||||||
5453 | } | - | ||||||||||||
5454 | state = table[state][input]; | - | ||||||||||||
5455 | - | |||||||||||||
5456 | switch (state) { | - | ||||||||||||
5457 | case Attlist: | - | ||||||||||||
5458 | parseString_s = QLatin1String("ATTLIST"); | - | ||||||||||||
5459 | if (!parseString()) { | - | ||||||||||||
5460 | parseFailed(&QXmlSimpleReaderPrivate::parseAttlistDecl, state); | - | ||||||||||||
5461 | return false; | - | ||||||||||||
5462 | } | - | ||||||||||||
5463 | break; | - | ||||||||||||
5464 | case Ws: | - | ||||||||||||
5465 | case Ws1: | - | ||||||||||||
5466 | case Ws2: | - | ||||||||||||
5467 | case Ws3: | - | ||||||||||||
5468 | if (!eat_ws()) { | - | ||||||||||||
5469 | parseFailed(&QXmlSimpleReaderPrivate::parseAttlistDecl, state); | - | ||||||||||||
5470 | return false; | - | ||||||||||||
5471 | } | - | ||||||||||||
5472 | break; | - | ||||||||||||
5473 | case Name: | - | ||||||||||||
5474 | parseName_useRef = false; | - | ||||||||||||
5475 | if (!parseName()) { | - | ||||||||||||
5476 | parseFailed(&QXmlSimpleReaderPrivate::parseAttlistDecl, state); | - | ||||||||||||
5477 | return false; | - | ||||||||||||
5478 | } | - | ||||||||||||
5479 | break; | - | ||||||||||||
5480 | case Attdef: | - | ||||||||||||
5481 | parseName_useRef = false; | - | ||||||||||||
5482 | if (!parseName()) { | - | ||||||||||||
5483 | parseFailed(&QXmlSimpleReaderPrivate::parseAttlistDecl, state); | - | ||||||||||||
5484 | return false; | - | ||||||||||||
5485 | } | - | ||||||||||||
5486 | break; | - | ||||||||||||
5487 | case Atttype: | - | ||||||||||||
5488 | if (!parseAttType()) { | - | ||||||||||||
5489 | parseFailed(&QXmlSimpleReaderPrivate::parseAttlistDecl, state); | - | ||||||||||||
5490 | return false; | - | ||||||||||||
5491 | } | - | ||||||||||||
5492 | break; | - | ||||||||||||
5493 | case DDecH: | - | ||||||||||||
5494 | next(); | - | ||||||||||||
5495 | break; | - | ||||||||||||
5496 | case DefReq: | - | ||||||||||||
5497 | parseString_s = QLatin1String("REQUIRED"); | - | ||||||||||||
5498 | if (!parseString()) { | - | ||||||||||||
5499 | parseFailed(&QXmlSimpleReaderPrivate::parseAttlistDecl, state); | - | ||||||||||||
5500 | return false; | - | ||||||||||||
5501 | } | - | ||||||||||||
5502 | break; | - | ||||||||||||
5503 | case DefImp: | - | ||||||||||||
5504 | parseString_s = QLatin1String("IMPLIED"); | - | ||||||||||||
5505 | if (!parseString()) { | - | ||||||||||||
5506 | parseFailed(&QXmlSimpleReaderPrivate::parseAttlistDecl, state); | - | ||||||||||||
5507 | return false; | - | ||||||||||||
5508 | } | - | ||||||||||||
5509 | break; | - | ||||||||||||
5510 | case DefFix: | - | ||||||||||||
5511 | parseString_s = QLatin1String("FIXED"); | - | ||||||||||||
5512 | if (!parseString()) { | - | ||||||||||||
5513 | parseFailed(&QXmlSimpleReaderPrivate::parseAttlistDecl, state); | - | ||||||||||||
5514 | return false; | - | ||||||||||||
5515 | } | - | ||||||||||||
5516 | break; | - | ||||||||||||
5517 | case Attval: | - | ||||||||||||
5518 | if (!parseAttValue()) { | - | ||||||||||||
5519 | parseFailed(&QXmlSimpleReaderPrivate::parseAttlistDecl, state); | - | ||||||||||||
5520 | return false; | - | ||||||||||||
5521 | } | - | ||||||||||||
5522 | break; | - | ||||||||||||
5523 | case Ws4: | - | ||||||||||||
5524 | if (declHnd) { | - | ||||||||||||
5525 | // ### not all values are computed yet... | - | ||||||||||||
5526 | if (!declHnd->attributeDecl(attDeclEName, attDeclAName, QLatin1String(""), QLatin1String(""), QLatin1String(""))) { | - | ||||||||||||
5527 | reportParseError(declHnd->errorString()); | - | ||||||||||||
5528 | return false; | - | ||||||||||||
5529 | } | - | ||||||||||||
5530 | } | - | ||||||||||||
5531 | if (!eat_ws()) { | - | ||||||||||||
5532 | parseFailed(&QXmlSimpleReaderPrivate::parseAttlistDecl, state); | - | ||||||||||||
5533 | return false; | - | ||||||||||||
5534 | } | - | ||||||||||||
5535 | break; | - | ||||||||||||
5536 | case Done: | - | ||||||||||||
5537 | next(); | - | ||||||||||||
5538 | break; | - | ||||||||||||
5539 | } | - | ||||||||||||
5540 | } | - | ||||||||||||
5541 | return false; | - | ||||||||||||
5542 | } | - | ||||||||||||
5543 | - | |||||||||||||
5544 | /* | - | ||||||||||||
5545 | Parse a AttType [54] | - | ||||||||||||
5546 | */ | - | ||||||||||||
5547 | bool QXmlSimpleReaderPrivate::parseAttType() | - | ||||||||||||
5548 | { | - | ||||||||||||
5549 | const signed char Init = 0; | - | ||||||||||||
5550 | const signed char ST = 1; // StringType | - | ||||||||||||
5551 | const signed char TTI = 2; // TokenizedType starting with 'I' | - | ||||||||||||
5552 | const signed char TTI2 = 3; // TokenizedType helpstate | - | ||||||||||||
5553 | const signed char TTI3 = 4; // TokenizedType helpstate | - | ||||||||||||
5554 | const signed char TTE = 5; // TokenizedType starting with 'E' | - | ||||||||||||
5555 | const signed char TTEY = 6; // TokenizedType starting with 'ENTITY' | - | ||||||||||||
5556 | const signed char TTEI = 7; // TokenizedType starting with 'ENTITI' | - | ||||||||||||
5557 | const signed char N = 8; // N read (TokenizedType or Notation) | - | ||||||||||||
5558 | const signed char TTNM = 9; // TokenizedType starting with 'NM' | - | ||||||||||||
5559 | const signed char TTNM2 = 10; // TokenizedType helpstate | - | ||||||||||||
5560 | const signed char NO = 11; // Notation | - | ||||||||||||
5561 | const signed char NO2 = 12; // Notation helpstate | - | ||||||||||||
5562 | const signed char NO3 = 13; // Notation helpstate | - | ||||||||||||
5563 | const signed char NOName = 14; // Notation, read name | - | ||||||||||||
5564 | const signed char NO4 = 15; // Notation helpstate | - | ||||||||||||
5565 | const signed char EN = 16; // Enumeration | - | ||||||||||||
5566 | const signed char ENNmt = 17; // Enumeration, read Nmtoken | - | ||||||||||||
5567 | const signed char EN2 = 18; // Enumeration helpstate | - | ||||||||||||
5568 | const signed char ADone = 19; // almost done (make next and accept) | - | ||||||||||||
5569 | const signed char Done = 20; | - | ||||||||||||
5570 | - | |||||||||||||
5571 | const signed char InpWs = 0; // whitespace | - | ||||||||||||
5572 | const signed char InpOp = 1; // ( | - | ||||||||||||
5573 | const signed char InpCp = 2; //) | - | ||||||||||||
5574 | const signed char InpPipe = 3; // | | - | ||||||||||||
5575 | const signed char InpC = 4; // C | - | ||||||||||||
5576 | const signed char InpE = 5; // E | - | ||||||||||||
5577 | const signed char InpI = 6; // I | - | ||||||||||||
5578 | const signed char InpM = 7; // M | - | ||||||||||||
5579 | const signed char InpN = 8; // N | - | ||||||||||||
5580 | const signed char InpO = 9; // O | - | ||||||||||||
5581 | const signed char InpR = 10; // R | - | ||||||||||||
5582 | const signed char InpS = 11; // S | - | ||||||||||||
5583 | const signed char InpY = 12; // Y | - | ||||||||||||
5584 | const signed char InpUnknown = 13; | - | ||||||||||||
5585 | - | |||||||||||||
5586 | static const signed char table[19][14] = { | - | ||||||||||||
5587 | /* InpWs InpOp InpCp InpPipe InpC InpE InpI InpM InpN InpO InpR InpS InpY InpUnknown */ | - | ||||||||||||
5588 | { -1, EN, -1, -1, ST, TTE, TTI, -1, N, -1, -1, -1, -1, -1 }, // Init | - | ||||||||||||
5589 | { Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done }, // ST | - | ||||||||||||
5590 | { Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, TTI2, Done, Done, Done }, // TTI | - | ||||||||||||
5591 | { Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, TTI3, Done, Done }, // TTI2 | - | ||||||||||||
5592 | { Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done }, // TTI3 | - | ||||||||||||
5593 | { -1, -1, -1, -1, -1, -1, TTEI, -1, -1, -1, -1, -1, TTEY, -1 }, // TTE | - | ||||||||||||
5594 | { Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done }, // TTEY | - | ||||||||||||
5595 | { Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done }, // TTEI | - | ||||||||||||
5596 | { -1, -1, -1, -1, -1, -1, -1, TTNM, -1, NO, -1, -1, -1, -1 }, // N | - | ||||||||||||
5597 | { Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, TTNM2, Done, Done }, // TTNM | - | ||||||||||||
5598 | { Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done, Done }, // TTNM2 | - | ||||||||||||
5599 | { NO2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // NO | - | ||||||||||||
5600 | { -1, NO3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // NO2 | - | ||||||||||||
5601 | { NOName, NOName, NOName, NOName, NOName, NOName, NOName, NOName, NOName, NOName, NOName, NOName, NOName, NOName }, // NO3 | - | ||||||||||||
5602 | { NO4, -1, ADone, NO3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // NOName | - | ||||||||||||
5603 | { -1, -1, ADone, NO3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // NO4 | - | ||||||||||||
5604 | { -1, -1, ENNmt, -1, ENNmt, ENNmt, ENNmt, ENNmt, ENNmt, ENNmt, ENNmt, ENNmt, ENNmt, ENNmt }, // EN | - | ||||||||||||
5605 | { EN2, -1, ADone, EN, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // ENNmt | - | ||||||||||||
5606 | { -1, -1, ADone, EN, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } // EN2 | - | ||||||||||||
5607 | }; | - | ||||||||||||
5608 | signed char state; | - | ||||||||||||
5609 | signed char input; | - | ||||||||||||
5610 | - | |||||||||||||
5611 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
5612 | state = Init; | - | ||||||||||||
5613 | } else { | - | ||||||||||||
5614 | state = parseStack->pop().state; | - | ||||||||||||
5615 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
5616 | qDebug("QXmlSimpleReader: parseAttType (cont) in state %d", state); | - | ||||||||||||
5617 | #endif | - | ||||||||||||
5618 | if (!parseStack->isEmpty()) { | - | ||||||||||||
5619 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
5620 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
5621 | parseStack->pop(); | - | ||||||||||||
5622 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
5623 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
5624 | #endif | - | ||||||||||||
5625 | } | - | ||||||||||||
5626 | if (!(this->*function)()) { | - | ||||||||||||
5627 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5628 | return false; | - | ||||||||||||
5629 | } | - | ||||||||||||
5630 | } | - | ||||||||||||
5631 | } | - | ||||||||||||
5632 | - | |||||||||||||
5633 | for (;;) { | - | ||||||||||||
5634 | switch (state) { | - | ||||||||||||
5635 | case ADone: | - | ||||||||||||
5636 | return true; | - | ||||||||||||
5637 | case Done: | - | ||||||||||||
5638 | return true; | - | ||||||||||||
5639 | case -1: | - | ||||||||||||
5640 | // Error | - | ||||||||||||
5641 | reportParseError(QLatin1String(XMLERR_LETTEREXPECTED)); | - | ||||||||||||
5642 | return false; | - | ||||||||||||
5643 | } | - | ||||||||||||
5644 | - | |||||||||||||
5645 | if (atEnd()) { | - | ||||||||||||
5646 | unexpectedEof(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5647 | return false; | - | ||||||||||||
5648 | } | - | ||||||||||||
5649 | if (is_S(c)) { | - | ||||||||||||
5650 | input = InpWs; | - | ||||||||||||
5651 | } else if (c == QLatin1Char('(')) { | - | ||||||||||||
5652 | input = InpOp; | - | ||||||||||||
5653 | } else if (c == QLatin1Char(')')) { | - | ||||||||||||
5654 | input = InpCp; | - | ||||||||||||
5655 | } else if (c == QLatin1Char('|')) { | - | ||||||||||||
5656 | input = InpPipe; | - | ||||||||||||
5657 | } else if (c == QLatin1Char('C')) { | - | ||||||||||||
5658 | input = InpC; | - | ||||||||||||
5659 | } else if (c == QLatin1Char('E')) { | - | ||||||||||||
5660 | input = InpE; | - | ||||||||||||
5661 | } else if (c == QLatin1Char('I')) { | - | ||||||||||||
5662 | input = InpI; | - | ||||||||||||
5663 | } else if (c == QLatin1Char('M')) { | - | ||||||||||||
5664 | input = InpM; | - | ||||||||||||
5665 | } else if (c == QLatin1Char('N')) { | - | ||||||||||||
5666 | input = InpN; | - | ||||||||||||
5667 | } else if (c == QLatin1Char('O')) { | - | ||||||||||||
5668 | input = InpO; | - | ||||||||||||
5669 | } else if (c == QLatin1Char('R')) { | - | ||||||||||||
5670 | input = InpR; | - | ||||||||||||
5671 | } else if (c == QLatin1Char('S')) { | - | ||||||||||||
5672 | input = InpS; | - | ||||||||||||
5673 | } else if (c == QLatin1Char('Y')) { | - | ||||||||||||
5674 | input = InpY; | - | ||||||||||||
5675 | } else { | - | ||||||||||||
5676 | input = InpUnknown; | - | ||||||||||||
5677 | } | - | ||||||||||||
5678 | state = table[state][input]; | - | ||||||||||||
5679 | - | |||||||||||||
5680 | switch (state) { | - | ||||||||||||
5681 | case ST: | - | ||||||||||||
5682 | parseString_s = QLatin1String("CDATA"); | - | ||||||||||||
5683 | if (!parseString()) { | - | ||||||||||||
5684 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5685 | return false; | - | ||||||||||||
5686 | } | - | ||||||||||||
5687 | break; | - | ||||||||||||
5688 | case TTI: | - | ||||||||||||
5689 | parseString_s = QLatin1String("ID"); | - | ||||||||||||
5690 | if (!parseString()) { | - | ||||||||||||
5691 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5692 | return false; | - | ||||||||||||
5693 | } | - | ||||||||||||
5694 | break; | - | ||||||||||||
5695 | case TTI2: | - | ||||||||||||
5696 | parseString_s = QLatin1String("REF"); | - | ||||||||||||
5697 | if (!parseString()) { | - | ||||||||||||
5698 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5699 | return false; | - | ||||||||||||
5700 | } | - | ||||||||||||
5701 | break; | - | ||||||||||||
5702 | case TTI3: | - | ||||||||||||
5703 | next(); // S | - | ||||||||||||
5704 | break; | - | ||||||||||||
5705 | case TTE: | - | ||||||||||||
5706 | parseString_s = QLatin1String("ENTIT"); | - | ||||||||||||
5707 | if (!parseString()) { | - | ||||||||||||
5708 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5709 | return false; | - | ||||||||||||
5710 | } | - | ||||||||||||
5711 | break; | - | ||||||||||||
5712 | case TTEY: | - | ||||||||||||
5713 | next(); // Y | - | ||||||||||||
5714 | break; | - | ||||||||||||
5715 | case TTEI: | - | ||||||||||||
5716 | parseString_s = QLatin1String("IES"); | - | ||||||||||||
5717 | if (!parseString()) { | - | ||||||||||||
5718 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5719 | return false; | - | ||||||||||||
5720 | } | - | ||||||||||||
5721 | break; | - | ||||||||||||
5722 | case N: | - | ||||||||||||
5723 | next(); // N | - | ||||||||||||
5724 | break; | - | ||||||||||||
5725 | case TTNM: | - | ||||||||||||
5726 | parseString_s = QLatin1String("MTOKEN"); | - | ||||||||||||
5727 | if (!parseString()) { | - | ||||||||||||
5728 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5729 | return false; | - | ||||||||||||
5730 | } | - | ||||||||||||
5731 | break; | - | ||||||||||||
5732 | case TTNM2: | - | ||||||||||||
5733 | next(); // S | - | ||||||||||||
5734 | break; | - | ||||||||||||
5735 | case NO: | - | ||||||||||||
5736 | parseString_s = QLatin1String("OTATION"); | - | ||||||||||||
5737 | if (!parseString()) { | - | ||||||||||||
5738 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5739 | return false; | - | ||||||||||||
5740 | } | - | ||||||||||||
5741 | break; | - | ||||||||||||
5742 | case NO2: | - | ||||||||||||
5743 | if (!eat_ws()) { | - | ||||||||||||
5744 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5745 | return false; | - | ||||||||||||
5746 | } | - | ||||||||||||
5747 | break; | - | ||||||||||||
5748 | case NO3: | - | ||||||||||||
5749 | if (!next_eat_ws()) { | - | ||||||||||||
5750 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5751 | return false; | - | ||||||||||||
5752 | } | - | ||||||||||||
5753 | break; | - | ||||||||||||
5754 | case NOName: | - | ||||||||||||
5755 | parseName_useRef = false; | - | ||||||||||||
5756 | if (!parseName()) { | - | ||||||||||||
5757 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5758 | return false; | - | ||||||||||||
5759 | } | - | ||||||||||||
5760 | break; | - | ||||||||||||
5761 | case NO4: | - | ||||||||||||
5762 | if (!eat_ws()) { | - | ||||||||||||
5763 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5764 | return false; | - | ||||||||||||
5765 | } | - | ||||||||||||
5766 | break; | - | ||||||||||||
5767 | case EN: | - | ||||||||||||
5768 | if (!next_eat_ws()) { | - | ||||||||||||
5769 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5770 | return false; | - | ||||||||||||
5771 | } | - | ||||||||||||
5772 | break; | - | ||||||||||||
5773 | case ENNmt: | - | ||||||||||||
5774 | if (!parseNmtoken()) { | - | ||||||||||||
5775 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5776 | return false; | - | ||||||||||||
5777 | } | - | ||||||||||||
5778 | break; | - | ||||||||||||
5779 | case EN2: | - | ||||||||||||
5780 | if (!eat_ws()) { | - | ||||||||||||
5781 | parseFailed(&QXmlSimpleReaderPrivate::parseAttType, state); | - | ||||||||||||
5782 | return false; | - | ||||||||||||
5783 | } | - | ||||||||||||
5784 | break; | - | ||||||||||||
5785 | case ADone: | - | ||||||||||||
5786 | next(); | - | ||||||||||||
5787 | break; | - | ||||||||||||
5788 | } | - | ||||||||||||
5789 | } | - | ||||||||||||
5790 | return false; | - | ||||||||||||
5791 | } | - | ||||||||||||
5792 | - | |||||||||||||
5793 | /* | - | ||||||||||||
5794 | Parse a AttValue [10] | - | ||||||||||||
5795 | - | |||||||||||||
5796 | Precondition: the head stands on the beginning " or ' | - | ||||||||||||
5797 | - | |||||||||||||
5798 | If this function was successful, the head stands on the first | - | ||||||||||||
5799 | character after the closing " or ' and the value of the attribute | - | ||||||||||||
5800 | is in string(). | - | ||||||||||||
5801 | */ | - | ||||||||||||
5802 | bool QXmlSimpleReaderPrivate::parseAttValue() | - | ||||||||||||
5803 | { | - | ||||||||||||
5804 | const signed char Init = 0; | - | ||||||||||||
5805 | const signed char Dq = 1; // double quotes were read | - | ||||||||||||
5806 | const signed char DqRef = 2; // read references in double quotes | - | ||||||||||||
5807 | const signed char DqC = 3; // signed character read in double quotes | - | ||||||||||||
5808 | const signed char Sq = 4; // single quotes were read | - | ||||||||||||
5809 | const signed char SqRef = 5; // read references in single quotes | - | ||||||||||||
5810 | const signed char SqC = 6; // signed character read in single quotes | - | ||||||||||||
5811 | const signed char Done = 7; | - | ||||||||||||
5812 | - | |||||||||||||
5813 | const signed char InpDq = 0; // " | - | ||||||||||||
5814 | const signed char InpSq = 1; // ' | - | ||||||||||||
5815 | const signed char InpAmp = 2; // & | - | ||||||||||||
5816 | const signed char InpLt = 3; // < | - | ||||||||||||
5817 | const signed char InpUnknown = 4; | - | ||||||||||||
5818 | - | |||||||||||||
5819 | static const signed char table[7][5] = { | - | ||||||||||||
5820 | /* InpDq InpSq InpAmp InpLt InpUnknown */ | - | ||||||||||||
5821 | { Dq, Sq, -1, -1, -1 }, // Init | - | ||||||||||||
5822 | { Done, DqC, DqRef, -1, DqC }, // Dq | - | ||||||||||||
5823 | { Done, DqC, DqRef, -1, DqC }, // DqRef | - | ||||||||||||
5824 | { Done, DqC, DqRef, -1, DqC }, // DqC | - | ||||||||||||
5825 | { SqC, Done, SqRef, -1, SqC }, // Sq | - | ||||||||||||
5826 | { SqC, Done, SqRef, -1, SqC }, // SqRef | - | ||||||||||||
5827 | { SqC, Done, SqRef, -1, SqC } // SqRef | - | ||||||||||||
5828 | }; | - | ||||||||||||
5829 | signed char state; | - | ||||||||||||
5830 | signed char input; | - | ||||||||||||
5831 | - | |||||||||||||
5832 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
5833 | state = Init; | - | ||||||||||||
5834 | } else { | - | ||||||||||||
5835 | state = parseStack->pop().state; | - | ||||||||||||
5836 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
5837 | qDebug("QXmlSimpleReader: parseAttValue (cont) in state %d", state); | - | ||||||||||||
5838 | #endif | - | ||||||||||||
5839 | if (!parseStack->isEmpty()) { | - | ||||||||||||
5840 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
5841 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
5842 | parseStack->pop(); | - | ||||||||||||
5843 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
5844 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
5845 | #endif | - | ||||||||||||
5846 | } | - | ||||||||||||
5847 | if (!(this->*function)()) { | - | ||||||||||||
5848 | parseFailed(&QXmlSimpleReaderPrivate::parseAttValue, state); | - | ||||||||||||
5849 | return false; | - | ||||||||||||
5850 | } | - | ||||||||||||
5851 | } | - | ||||||||||||
5852 | } | - | ||||||||||||
5853 | - | |||||||||||||
5854 | for (;;) { | - | ||||||||||||
5855 | switch (state) { | - | ||||||||||||
5856 | case Done: | - | ||||||||||||
5857 | return true; | - | ||||||||||||
5858 | case -1: | - | ||||||||||||
5859 | // Error | - | ||||||||||||
5860 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDCHARACTER)); | - | ||||||||||||
5861 | return false; | - | ||||||||||||
5862 | } | - | ||||||||||||
5863 | - | |||||||||||||
5864 | if (atEnd()) { | - | ||||||||||||
5865 | unexpectedEof(&QXmlSimpleReaderPrivate::parseAttValue, state); | - | ||||||||||||
5866 | return false; | - | ||||||||||||
5867 | } | - | ||||||||||||
5868 | if (c == QLatin1Char('"')) { | - | ||||||||||||
5869 | input = InpDq; | - | ||||||||||||
5870 | } else if (c == QLatin1Char('\'')) { | - | ||||||||||||
5871 | input = InpSq; | - | ||||||||||||
5872 | } else if (c == QLatin1Char('&')) { | - | ||||||||||||
5873 | input = InpAmp; | - | ||||||||||||
5874 | } else if (c == QLatin1Char('<')) { | - | ||||||||||||
5875 | input = InpLt; | - | ||||||||||||
5876 | } else { | - | ||||||||||||
5877 | input = InpUnknown; | - | ||||||||||||
5878 | } | - | ||||||||||||
5879 | state = table[state][input]; | - | ||||||||||||
5880 | - | |||||||||||||
5881 | switch (state) { | - | ||||||||||||
5882 | case Dq: | - | ||||||||||||
5883 | case Sq: | - | ||||||||||||
5884 | stringClear(); | - | ||||||||||||
5885 | next(); | - | ||||||||||||
5886 | break; | - | ||||||||||||
5887 | case DqRef: | - | ||||||||||||
5888 | case SqRef: | - | ||||||||||||
5889 | parseReference_context = InAttributeValue; | - | ||||||||||||
5890 | if (!parseReference()) { | - | ||||||||||||
5891 | parseFailed(&QXmlSimpleReaderPrivate::parseAttValue, state); | - | ||||||||||||
5892 | return false; | - | ||||||||||||
5893 | } | - | ||||||||||||
5894 | break; | - | ||||||||||||
5895 | case DqC: | - | ||||||||||||
5896 | case SqC: | - | ||||||||||||
5897 | stringAddC(); | - | ||||||||||||
5898 | next(); | - | ||||||||||||
5899 | break; | - | ||||||||||||
5900 | case Done: | - | ||||||||||||
5901 | next(); | - | ||||||||||||
5902 | break; | - | ||||||||||||
5903 | } | - | ||||||||||||
5904 | } | - | ||||||||||||
5905 | return false; | - | ||||||||||||
5906 | } | - | ||||||||||||
5907 | - | |||||||||||||
5908 | /* | - | ||||||||||||
5909 | Parse a elementdecl [45]. | - | ||||||||||||
5910 | - | |||||||||||||
5911 | Precondition: the beginning '<!E' is already read and the head | - | ||||||||||||
5912 | stands on the 'L' of '<!ELEMENT' | - | ||||||||||||
5913 | */ | - | ||||||||||||
5914 | bool QXmlSimpleReaderPrivate::parseElementDecl() | - | ||||||||||||
5915 | { | - | ||||||||||||
5916 | const signed char Init = 0; | - | ||||||||||||
5917 | const signed char Elem = 1; // parse the beginning string | - | ||||||||||||
5918 | const signed char Ws1 = 2; // whitespace required | - | ||||||||||||
5919 | const signed char Nam = 3; // parse Name | - | ||||||||||||
5920 | const signed char Ws2 = 4; // whitespace required | - | ||||||||||||
5921 | const signed char Empty = 5; // read EMPTY | - | ||||||||||||
5922 | const signed char Any = 6; // read ANY | - | ||||||||||||
5923 | const signed char Cont = 7; // read contentspec (except ANY or EMPTY) | - | ||||||||||||
5924 | const signed char Mix = 8; // read Mixed | - | ||||||||||||
5925 | const signed char Mix2 = 9; // | - | ||||||||||||
5926 | const signed char Mix3 = 10; // | - | ||||||||||||
5927 | const signed char MixN1 = 11; // | - | ||||||||||||
5928 | const signed char MixN2 = 12; // | - | ||||||||||||
5929 | const signed char MixN3 = 13; // | - | ||||||||||||
5930 | const signed char MixN4 = 14; // | - | ||||||||||||
5931 | const signed char Cp = 15; // parse cp | - | ||||||||||||
5932 | const signed char Cp2 = 16; // | - | ||||||||||||
5933 | const signed char WsD = 17; // eat whitespace before Done | - | ||||||||||||
5934 | const signed char Done = 18; | - | ||||||||||||
5935 | - | |||||||||||||
5936 | const signed char InpWs = 0; | - | ||||||||||||
5937 | const signed char InpGt = 1; // > | - | ||||||||||||
5938 | const signed char InpPipe = 2; // | | - | ||||||||||||
5939 | const signed char InpOp = 3; // ( | - | ||||||||||||
5940 | const signed char InpCp = 4; //) | - | ||||||||||||
5941 | const signed char InpHash = 5; // # | - | ||||||||||||
5942 | const signed char InpQm = 6; // ? | - | ||||||||||||
5943 | const signed char InpAst = 7; // * | - | ||||||||||||
5944 | const signed char InpPlus = 8; // + | - | ||||||||||||
5945 | const signed char InpA = 9; // A | - | ||||||||||||
5946 | const signed char InpE = 10; // E | - | ||||||||||||
5947 | const signed char InpL = 11; // L | - | ||||||||||||
5948 | const signed char InpUnknown = 12; | - | ||||||||||||
5949 | - | |||||||||||||
5950 | static const signed char table[18][13] = { | - | ||||||||||||
5951 | /* InpWs InpGt InpPipe InpOp InpCp InpHash InpQm InpAst InpPlus InpA InpE InpL InpUnknown */ | - | ||||||||||||
5952 | { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, Elem, -1 }, // Init | - | ||||||||||||
5953 | { Ws1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // Elem | - | ||||||||||||
5954 | { -1, -1, -1, -1, -1, -1, -1, -1, -1, Nam, Nam, Nam, Nam }, // Ws1 | - | ||||||||||||
5955 | { Ws2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // Nam | - | ||||||||||||
5956 | { -1, -1, -1, Cont, -1, -1, -1, -1, -1, Any, Empty, -1, -1 }, // Ws2 | - | ||||||||||||
5957 | { WsD, Done, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // Empty | - | ||||||||||||
5958 | { WsD, Done, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // Any | - | ||||||||||||
5959 | { -1, -1, -1, Cp, Cp, Mix, -1, -1, -1, Cp, Cp, Cp, Cp }, // Cont | - | ||||||||||||
5960 | { Mix2, -1, MixN1, -1, Mix3, -1, -1, -1, -1, -1, -1, -1, -1 }, // Mix | - | ||||||||||||
5961 | { -1, -1, MixN1, -1, Mix3, -1, -1, -1, -1, -1, -1, -1, -1 }, // Mix2 | - | ||||||||||||
5962 | { WsD, Done, -1, -1, -1, -1, -1, WsD, -1, -1, -1, -1, -1 }, // Mix3 | - | ||||||||||||
5963 | { -1, -1, -1, -1, -1, -1, -1, -1, -1, MixN2, MixN2, MixN2, MixN2 }, // MixN1 | - | ||||||||||||
5964 | { MixN3, -1, MixN1, -1, MixN4, -1, -1, -1, -1, -1, -1, -1, -1 }, // MixN2 | - | ||||||||||||
5965 | { -1, -1, MixN1, -1, MixN4, -1, -1, -1, -1, -1, -1, -1, -1 }, // MixN3 | - | ||||||||||||
5966 | { -1, -1, -1, -1, -1, -1, -1, WsD, -1, -1, -1, -1, -1 }, // MixN4 | - | ||||||||||||
5967 | { WsD, Done, -1, -1, -1, -1, Cp2, Cp2, Cp2, -1, -1, -1, -1 }, // Cp | - | ||||||||||||
5968 | { WsD, Done, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // Cp2 | - | ||||||||||||
5969 | { -1, Done, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } // WsD | - | ||||||||||||
5970 | }; | - | ||||||||||||
5971 | signed char state; | - | ||||||||||||
5972 | signed char input; | - | ||||||||||||
5973 | - | |||||||||||||
5974 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
5975 | state = Init; | - | ||||||||||||
5976 | } else { | - | ||||||||||||
5977 | state = parseStack->pop().state; | - | ||||||||||||
5978 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
5979 | qDebug("QXmlSimpleReader: parseElementDecl (cont) in state %d", state); | - | ||||||||||||
5980 | #endif | - | ||||||||||||
5981 | if (!parseStack->isEmpty()) { | - | ||||||||||||
5982 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
5983 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
5984 | parseStack->pop(); | - | ||||||||||||
5985 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
5986 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
5987 | #endif | - | ||||||||||||
5988 | } | - | ||||||||||||
5989 | if (!(this->*function)()) { | - | ||||||||||||
5990 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
5991 | return false; | - | ||||||||||||
5992 | } | - | ||||||||||||
5993 | } | - | ||||||||||||
5994 | } | - | ||||||||||||
5995 | - | |||||||||||||
5996 | for (;;) { | - | ||||||||||||
5997 | switch (state) { | - | ||||||||||||
5998 | case Done: | - | ||||||||||||
5999 | return true; | - | ||||||||||||
6000 | case -1: | - | ||||||||||||
6001 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDCHARACTER)); | - | ||||||||||||
6002 | return false; | - | ||||||||||||
6003 | } | - | ||||||||||||
6004 | - | |||||||||||||
6005 | if (atEnd()) { | - | ||||||||||||
6006 | unexpectedEof(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6007 | return false; | - | ||||||||||||
6008 | } | - | ||||||||||||
6009 | if (is_S(c)) { | - | ||||||||||||
6010 | input = InpWs; | - | ||||||||||||
6011 | } else if (c == QLatin1Char('>')) { | - | ||||||||||||
6012 | input = InpGt; | - | ||||||||||||
6013 | } else if (c == QLatin1Char('|')) { | - | ||||||||||||
6014 | input = InpPipe; | - | ||||||||||||
6015 | } else if (c == QLatin1Char('(')) { | - | ||||||||||||
6016 | input = InpOp; | - | ||||||||||||
6017 | } else if (c == QLatin1Char(')')) { | - | ||||||||||||
6018 | input = InpCp; | - | ||||||||||||
6019 | } else if (c == QLatin1Char('#')) { | - | ||||||||||||
6020 | input = InpHash; | - | ||||||||||||
6021 | } else if (c == QLatin1Char('?')) { | - | ||||||||||||
6022 | input = InpQm; | - | ||||||||||||
6023 | } else if (c == QLatin1Char('*')) { | - | ||||||||||||
6024 | input = InpAst; | - | ||||||||||||
6025 | } else if (c == QLatin1Char('+')) { | - | ||||||||||||
6026 | input = InpPlus; | - | ||||||||||||
6027 | } else if (c == QLatin1Char('A')) { | - | ||||||||||||
6028 | input = InpA; | - | ||||||||||||
6029 | } else if (c == QLatin1Char('E')) { | - | ||||||||||||
6030 | input = InpE; | - | ||||||||||||
6031 | } else if (c == QLatin1Char('L')) { | - | ||||||||||||
6032 | input = InpL; | - | ||||||||||||
6033 | } else { | - | ||||||||||||
6034 | input = InpUnknown; | - | ||||||||||||
6035 | } | - | ||||||||||||
6036 | state = table[state][input]; | - | ||||||||||||
6037 | - | |||||||||||||
6038 | switch (state) { | - | ||||||||||||
6039 | case Elem: | - | ||||||||||||
6040 | parseString_s = QLatin1String("LEMENT"); | - | ||||||||||||
6041 | if (!parseString()) { | - | ||||||||||||
6042 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6043 | return false; | - | ||||||||||||
6044 | } | - | ||||||||||||
6045 | break; | - | ||||||||||||
6046 | case Ws1: | - | ||||||||||||
6047 | if (!eat_ws()) { | - | ||||||||||||
6048 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6049 | return false; | - | ||||||||||||
6050 | } | - | ||||||||||||
6051 | break; | - | ||||||||||||
6052 | case Nam: | - | ||||||||||||
6053 | parseName_useRef = false; | - | ||||||||||||
6054 | if (!parseName()) { | - | ||||||||||||
6055 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6056 | return false; | - | ||||||||||||
6057 | } | - | ||||||||||||
6058 | break; | - | ||||||||||||
6059 | case Ws2: | - | ||||||||||||
6060 | if (!eat_ws()) { | - | ||||||||||||
6061 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6062 | return false; | - | ||||||||||||
6063 | } | - | ||||||||||||
6064 | break; | - | ||||||||||||
6065 | case Empty: | - | ||||||||||||
6066 | parseString_s = QLatin1String("EMPTY"); | - | ||||||||||||
6067 | if (!parseString()) { | - | ||||||||||||
6068 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6069 | return false; | - | ||||||||||||
6070 | } | - | ||||||||||||
6071 | break; | - | ||||||||||||
6072 | case Any: | - | ||||||||||||
6073 | parseString_s = QLatin1String("ANY"); | - | ||||||||||||
6074 | if (!parseString()) { | - | ||||||||||||
6075 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6076 | return false; | - | ||||||||||||
6077 | } | - | ||||||||||||
6078 | break; | - | ||||||||||||
6079 | case Cont: | - | ||||||||||||
6080 | if (!next_eat_ws()) { | - | ||||||||||||
6081 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6082 | return false; | - | ||||||||||||
6083 | } | - | ||||||||||||
6084 | break; | - | ||||||||||||
6085 | case Mix: | - | ||||||||||||
6086 | parseString_s = QLatin1String("#PCDATA"); | - | ||||||||||||
6087 | if (!parseString()) { | - | ||||||||||||
6088 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6089 | return false; | - | ||||||||||||
6090 | } | - | ||||||||||||
6091 | break; | - | ||||||||||||
6092 | case Mix2: | - | ||||||||||||
6093 | if (!eat_ws()) { | - | ||||||||||||
6094 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6095 | return false; | - | ||||||||||||
6096 | } | - | ||||||||||||
6097 | break; | - | ||||||||||||
6098 | case Mix3: | - | ||||||||||||
6099 | next(); | - | ||||||||||||
6100 | break; | - | ||||||||||||
6101 | case MixN1: | - | ||||||||||||
6102 | if (!next_eat_ws()) { | - | ||||||||||||
6103 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6104 | return false; | - | ||||||||||||
6105 | } | - | ||||||||||||
6106 | break; | - | ||||||||||||
6107 | case MixN2: | - | ||||||||||||
6108 | parseName_useRef = false; | - | ||||||||||||
6109 | if (!parseName()) { | - | ||||||||||||
6110 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6111 | return false; | - | ||||||||||||
6112 | } | - | ||||||||||||
6113 | break; | - | ||||||||||||
6114 | case MixN3: | - | ||||||||||||
6115 | if (!eat_ws()) { | - | ||||||||||||
6116 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6117 | return false; | - | ||||||||||||
6118 | } | - | ||||||||||||
6119 | break; | - | ||||||||||||
6120 | case MixN4: | - | ||||||||||||
6121 | next(); | - | ||||||||||||
6122 | break; | - | ||||||||||||
6123 | case Cp: | - | ||||||||||||
6124 | if (!parseChoiceSeq()) { | - | ||||||||||||
6125 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6126 | return false; | - | ||||||||||||
6127 | } | - | ||||||||||||
6128 | break; | - | ||||||||||||
6129 | case Cp2: | - | ||||||||||||
6130 | next(); | - | ||||||||||||
6131 | break; | - | ||||||||||||
6132 | case WsD: | - | ||||||||||||
6133 | if (!next_eat_ws()) { | - | ||||||||||||
6134 | parseFailed(&QXmlSimpleReaderPrivate::parseElementDecl, state); | - | ||||||||||||
6135 | return false; | - | ||||||||||||
6136 | } | - | ||||||||||||
6137 | break; | - | ||||||||||||
6138 | case Done: | - | ||||||||||||
6139 | next(); | - | ||||||||||||
6140 | break; | - | ||||||||||||
6141 | } | - | ||||||||||||
6142 | } | - | ||||||||||||
6143 | return false; | - | ||||||||||||
6144 | } | - | ||||||||||||
6145 | - | |||||||||||||
6146 | /* | - | ||||||||||||
6147 | Parse a NotationDecl [82]. | - | ||||||||||||
6148 | - | |||||||||||||
6149 | Precondition: the beginning '<!' is already read and the head | - | ||||||||||||
6150 | stands on the 'N' of '<!NOTATION' | - | ||||||||||||
6151 | */ | - | ||||||||||||
6152 | bool QXmlSimpleReaderPrivate::parseNotationDecl() | - | ||||||||||||
6153 | { | - | ||||||||||||
6154 | const signed char Init = 0; | - | ||||||||||||
6155 | const signed char Not = 1; // read NOTATION | - | ||||||||||||
6156 | const signed char Ws1 = 2; // eat whitespaces | - | ||||||||||||
6157 | const signed char Nam = 3; // read Name | - | ||||||||||||
6158 | const signed char Ws2 = 4; // eat whitespaces | - | ||||||||||||
6159 | const signed char ExtID = 5; // parse ExternalID | - | ||||||||||||
6160 | const signed char ExtIDR = 6; // same as ExtID, but already reported | - | ||||||||||||
6161 | const signed char Ws3 = 7; // eat whitespaces | - | ||||||||||||
6162 | const signed char Done = 8; | - | ||||||||||||
6163 | - | |||||||||||||
6164 | const signed char InpWs = 0; | - | ||||||||||||
6165 | const signed char InpGt = 1; // > | - | ||||||||||||
6166 | const signed char InpN = 2; // N | - | ||||||||||||
6167 | const signed char InpUnknown = 3; | - | ||||||||||||
6168 | - | |||||||||||||
6169 | static const signed char table[8][4] = { | - | ||||||||||||
6170 | /* InpWs InpGt InpN InpUnknown */ | - | ||||||||||||
6171 | { -1, -1, Not, -1 }, // Init | - | ||||||||||||
6172 | { Ws1, -1, -1, -1 }, // Not | - | ||||||||||||
6173 | { -1, -1, Nam, Nam }, // Ws1 | - | ||||||||||||
6174 | { Ws2, Done, -1, -1 }, // Nam | - | ||||||||||||
6175 | { -1, Done, ExtID, ExtID }, // Ws2 | - | ||||||||||||
6176 | { Ws3, Done, -1, -1 }, // ExtID | - | ||||||||||||
6177 | { Ws3, Done, -1, -1 }, // ExtIDR | - | ||||||||||||
6178 | { -1, Done, -1, -1 } // Ws3 | - | ||||||||||||
6179 | }; | - | ||||||||||||
6180 | signed char state; | - | ||||||||||||
6181 | signed char input; | - | ||||||||||||
6182 | - | |||||||||||||
6183 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
6184 | state = Init; | - | ||||||||||||
6185 | } else { | - | ||||||||||||
6186 | state = parseStack->pop().state; | - | ||||||||||||
6187 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
6188 | qDebug("QXmlSimpleReader: parseNotationDecl (cont) in state %d", state); | - | ||||||||||||
6189 | #endif | - | ||||||||||||
6190 | if (!parseStack->isEmpty()) { | - | ||||||||||||
6191 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
6192 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
6193 | parseStack->pop(); | - | ||||||||||||
6194 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
6195 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
6196 | #endif | - | ||||||||||||
6197 | } | - | ||||||||||||
6198 | if (!(this->*function)()) { | - | ||||||||||||
6199 | parseFailed(&QXmlSimpleReaderPrivate::parseNotationDecl, state); | - | ||||||||||||
6200 | return false; | - | ||||||||||||
6201 | } | - | ||||||||||||
6202 | } | - | ||||||||||||
6203 | } | - | ||||||||||||
6204 | - | |||||||||||||
6205 | for (;;) { | - | ||||||||||||
6206 | switch (state) { | - | ||||||||||||
6207 | case ExtID: | - | ||||||||||||
6208 | // call the handler | - | ||||||||||||
6209 | if (dtdHnd) { | - | ||||||||||||
6210 | if (!dtdHnd->notationDecl(name(), publicId, systemId)) { | - | ||||||||||||
6211 | reportParseError(dtdHnd->errorString()); | - | ||||||||||||
6212 | return false; | - | ||||||||||||
6213 | } | - | ||||||||||||
6214 | } | - | ||||||||||||
6215 | state = ExtIDR; | - | ||||||||||||
6216 | break; | - | ||||||||||||
6217 | case Done: | - | ||||||||||||
6218 | return true; | - | ||||||||||||
6219 | case -1: | - | ||||||||||||
6220 | // Error | - | ||||||||||||
6221 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDCHARACTER)); | - | ||||||||||||
6222 | return false; | - | ||||||||||||
6223 | } | - | ||||||||||||
6224 | - | |||||||||||||
6225 | if (atEnd()) { | - | ||||||||||||
6226 | unexpectedEof(&QXmlSimpleReaderPrivate::parseNotationDecl, state); | - | ||||||||||||
6227 | return false; | - | ||||||||||||
6228 | } | - | ||||||||||||
6229 | if (is_S(c)) { | - | ||||||||||||
6230 | input = InpWs; | - | ||||||||||||
6231 | } else if (c == QLatin1Char('>')) { | - | ||||||||||||
6232 | input = InpGt; | - | ||||||||||||
6233 | } else if (c == QLatin1Char('N')) { | - | ||||||||||||
6234 | input = InpN; | - | ||||||||||||
6235 | } else { | - | ||||||||||||
6236 | input = InpUnknown; | - | ||||||||||||
6237 | } | - | ||||||||||||
6238 | state = table[state][input]; | - | ||||||||||||
6239 | - | |||||||||||||
6240 | switch (state) { | - | ||||||||||||
6241 | case Not: | - | ||||||||||||
6242 | parseString_s = QLatin1String("NOTATION"); | - | ||||||||||||
6243 | if (!parseString()) { | - | ||||||||||||
6244 | parseFailed(&QXmlSimpleReaderPrivate::parseNotationDecl, state); | - | ||||||||||||
6245 | return false; | - | ||||||||||||
6246 | } | - | ||||||||||||
6247 | break; | - | ||||||||||||
6248 | case Ws1: | - | ||||||||||||
6249 | if (!eat_ws()) { | - | ||||||||||||
6250 | parseFailed(&QXmlSimpleReaderPrivate::parseNotationDecl, state); | - | ||||||||||||
6251 | return false; | - | ||||||||||||
6252 | } | - | ||||||||||||
6253 | break; | - | ||||||||||||
6254 | case Nam: | - | ||||||||||||
6255 | parseName_useRef = false; | - | ||||||||||||
6256 | if (!parseName()) { | - | ||||||||||||
6257 | parseFailed(&QXmlSimpleReaderPrivate::parseNotationDecl, state); | - | ||||||||||||
6258 | return false; | - | ||||||||||||
6259 | } | - | ||||||||||||
6260 | break; | - | ||||||||||||
6261 | case Ws2: | - | ||||||||||||
6262 | if (!eat_ws()) { | - | ||||||||||||
6263 | parseFailed(&QXmlSimpleReaderPrivate::parseNotationDecl, state); | - | ||||||||||||
6264 | return false; | - | ||||||||||||
6265 | } | - | ||||||||||||
6266 | break; | - | ||||||||||||
6267 | case ExtID: | - | ||||||||||||
6268 | case ExtIDR: | - | ||||||||||||
6269 | parseExternalID_allowPublicID = true; | - | ||||||||||||
6270 | if (!parseExternalID()) { | - | ||||||||||||
6271 | parseFailed(&QXmlSimpleReaderPrivate::parseNotationDecl, state); | - | ||||||||||||
6272 | return false; | - | ||||||||||||
6273 | } | - | ||||||||||||
6274 | break; | - | ||||||||||||
6275 | case Ws3: | - | ||||||||||||
6276 | if (!eat_ws()) { | - | ||||||||||||
6277 | parseFailed(&QXmlSimpleReaderPrivate::parseNotationDecl, state); | - | ||||||||||||
6278 | return false; | - | ||||||||||||
6279 | } | - | ||||||||||||
6280 | break; | - | ||||||||||||
6281 | case Done: | - | ||||||||||||
6282 | next(); | - | ||||||||||||
6283 | break; | - | ||||||||||||
6284 | } | - | ||||||||||||
6285 | } | - | ||||||||||||
6286 | return false; | - | ||||||||||||
6287 | } | - | ||||||||||||
6288 | - | |||||||||||||
6289 | /* | - | ||||||||||||
6290 | Parse choice [49] or seq [50]. | - | ||||||||||||
6291 | - | |||||||||||||
6292 | Precondition: the beginning '('S? is already read and the head | - | ||||||||||||
6293 | stands on the first non-whitespace character after it. | - | ||||||||||||
6294 | */ | - | ||||||||||||
6295 | bool QXmlSimpleReaderPrivate::parseChoiceSeq() | - | ||||||||||||
6296 | { | - | ||||||||||||
6297 | const signed char Init = 0; | - | ||||||||||||
6298 | const signed char Ws1 = 1; // eat whitespace | - | ||||||||||||
6299 | const signed char CoS = 2; // choice or set | - | ||||||||||||
6300 | const signed char Ws2 = 3; // eat whitespace | - | ||||||||||||
6301 | const signed char More = 4; // more cp to read | - | ||||||||||||
6302 | const signed char Name = 5; // read name | - | ||||||||||||
6303 | const signed char Done = 6; // | - | ||||||||||||
6304 | - | |||||||||||||
6305 | const signed char InpWs = 0; // S | - | ||||||||||||
6306 | const signed char InpOp = 1; // ( | - | ||||||||||||
6307 | const signed char InpCp = 2; //) | - | ||||||||||||
6308 | const signed char InpQm = 3; // ? | - | ||||||||||||
6309 | const signed char InpAst = 4; // * | - | ||||||||||||
6310 | const signed char InpPlus = 5; // + | - | ||||||||||||
6311 | const signed char InpPipe = 6; // | | - | ||||||||||||
6312 | const signed char InpComm = 7; // , | - | ||||||||||||
6313 | const signed char InpUnknown = 8; | - | ||||||||||||
6314 | - | |||||||||||||
6315 | static const signed char table[6][9] = { | - | ||||||||||||
6316 | /* InpWs InpOp InpCp InpQm InpAst InpPlus InpPipe InpComm InpUnknown */ | - | ||||||||||||
6317 | { -1, Ws1, -1, -1, -1, -1, -1, -1, Name }, // Init | - | ||||||||||||
6318 | { -1, CoS, -1, -1, -1, -1, -1, -1, CoS }, // Ws1 | - | ||||||||||||
6319 | { Ws2, -1, Done, Ws2, Ws2, Ws2, More, More, -1 }, // CS | - | ||||||||||||
6320 | { -1, -1, Done, -1, -1, -1, More, More, -1 }, // Ws2 | - | ||||||||||||
6321 | { -1, Ws1, -1, -1, -1, -1, -1, -1, Name }, // More (same as Init) | - | ||||||||||||
6322 | { Ws2, -1, Done, Ws2, Ws2, Ws2, More, More, -1 } // Name (same as CS) | - | ||||||||||||
6323 | }; | - | ||||||||||||
6324 | signed char state; | - | ||||||||||||
6325 | signed char input; | - | ||||||||||||
6326 | - | |||||||||||||
6327 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
6328 | state = Init; | - | ||||||||||||
6329 | } else { | - | ||||||||||||
6330 | state = parseStack->pop().state; | - | ||||||||||||
6331 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
6332 | qDebug("QXmlSimpleReader: parseChoiceSeq (cont) in state %d", state); | - | ||||||||||||
6333 | #endif | - | ||||||||||||
6334 | if (!parseStack->isEmpty()) { | - | ||||||||||||
6335 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
6336 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
6337 | parseStack->pop(); | - | ||||||||||||
6338 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
6339 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
6340 | #endif | - | ||||||||||||
6341 | } | - | ||||||||||||
6342 | if (!(this->*function)()) { | - | ||||||||||||
6343 | parseFailed(&QXmlSimpleReaderPrivate::parseChoiceSeq, state); | - | ||||||||||||
6344 | return false; | - | ||||||||||||
6345 | } | - | ||||||||||||
6346 | } | - | ||||||||||||
6347 | } | - | ||||||||||||
6348 | - | |||||||||||||
6349 | for (;;) { | - | ||||||||||||
6350 | switch (state) { | - | ||||||||||||
6351 | case Done: | - | ||||||||||||
6352 | return true; | - | ||||||||||||
6353 | case -1: | - | ||||||||||||
6354 | // Error | - | ||||||||||||
6355 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDCHARACTER)); | - | ||||||||||||
6356 | return false; | - | ||||||||||||
6357 | } | - | ||||||||||||
6358 | - | |||||||||||||
6359 | if (atEnd()) { | - | ||||||||||||
6360 | unexpectedEof(&QXmlSimpleReaderPrivate::parseChoiceSeq, state); | - | ||||||||||||
6361 | return false; | - | ||||||||||||
6362 | } | - | ||||||||||||
6363 | if (is_S(c)) { | - | ||||||||||||
6364 | input = InpWs; | - | ||||||||||||
6365 | } else if (c == QLatin1Char('(')) { | - | ||||||||||||
6366 | input = InpOp; | - | ||||||||||||
6367 | } else if (c == QLatin1Char(')')) { | - | ||||||||||||
6368 | input = InpCp; | - | ||||||||||||
6369 | } else if (c == QLatin1Char('?')) { | - | ||||||||||||
6370 | input = InpQm; | - | ||||||||||||
6371 | } else if (c == QLatin1Char('*')) { | - | ||||||||||||
6372 | input = InpAst; | - | ||||||||||||
6373 | } else if (c == QLatin1Char('+')) { | - | ||||||||||||
6374 | input = InpPlus; | - | ||||||||||||
6375 | } else if (c == QLatin1Char('|')) { | - | ||||||||||||
6376 | input = InpPipe; | - | ||||||||||||
6377 | } else if (c == QLatin1Char(',')) { | - | ||||||||||||
6378 | input = InpComm; | - | ||||||||||||
6379 | } else { | - | ||||||||||||
6380 | input = InpUnknown; | - | ||||||||||||
6381 | } | - | ||||||||||||
6382 | state = table[state][input]; | - | ||||||||||||
6383 | - | |||||||||||||
6384 | switch (state) { | - | ||||||||||||
6385 | case Ws1: | - | ||||||||||||
6386 | if (!next_eat_ws()) { | - | ||||||||||||
6387 | parseFailed(&QXmlSimpleReaderPrivate::parseChoiceSeq, state); | - | ||||||||||||
6388 | return false; | - | ||||||||||||
6389 | } | - | ||||||||||||
6390 | break; | - | ||||||||||||
6391 | case CoS: | - | ||||||||||||
6392 | if (!parseChoiceSeq()) { | - | ||||||||||||
6393 | parseFailed(&QXmlSimpleReaderPrivate::parseChoiceSeq, state); | - | ||||||||||||
6394 | return false; | - | ||||||||||||
6395 | } | - | ||||||||||||
6396 | break; | - | ||||||||||||
6397 | case Ws2: | - | ||||||||||||
6398 | if (!next_eat_ws()) { | - | ||||||||||||
6399 | parseFailed(&QXmlSimpleReaderPrivate::parseChoiceSeq, state); | - | ||||||||||||
6400 | return false; | - | ||||||||||||
6401 | } | - | ||||||||||||
6402 | break; | - | ||||||||||||
6403 | case More: | - | ||||||||||||
6404 | if (!next_eat_ws()) { | - | ||||||||||||
6405 | parseFailed(&QXmlSimpleReaderPrivate::parseChoiceSeq, state); | - | ||||||||||||
6406 | return false; | - | ||||||||||||
6407 | } | - | ||||||||||||
6408 | break; | - | ||||||||||||
6409 | case Name: | - | ||||||||||||
6410 | parseName_useRef = false; | - | ||||||||||||
6411 | if (!parseName()) { | - | ||||||||||||
6412 | parseFailed(&QXmlSimpleReaderPrivate::parseChoiceSeq, state); | - | ||||||||||||
6413 | return false; | - | ||||||||||||
6414 | } | - | ||||||||||||
6415 | break; | - | ||||||||||||
6416 | case Done: | - | ||||||||||||
6417 | next(); | - | ||||||||||||
6418 | break; | - | ||||||||||||
6419 | } | - | ||||||||||||
6420 | } | - | ||||||||||||
6421 | return false; | - | ||||||||||||
6422 | } | - | ||||||||||||
6423 | - | |||||||||||||
6424 | bool QXmlSimpleReaderPrivate::isExpandedEntityValueTooLarge(QString *errorMessage) | - | ||||||||||||
6425 | { | - | ||||||||||||
6426 | QString entityNameBuffer; | - | ||||||||||||
6427 | - | |||||||||||||
6428 | // For every entity, check how many times all entity names were referenced in its value. | - | ||||||||||||
6429 | for (QMap<QString,QString>::const_iterator toSearchIt = entities.constBegin(); | - | ||||||||||||
6430 | toSearchIt != entities.constEnd(); | - | ||||||||||||
6431 | ++toSearchIt) { | - | ||||||||||||
6432 | const QString &toSearch = toSearchIt.key(); | - | ||||||||||||
6433 | - | |||||||||||||
6434 | // Don't check the same entities twice. | - | ||||||||||||
6435 | if (!literalEntitySizes.contains(toSearch)) { | - | ||||||||||||
6436 | // The amount of characters that weren't entity names, but literals, like 'X'. | - | ||||||||||||
6437 | QString leftOvers = entities.value(toSearch); | - | ||||||||||||
6438 | // How many times was entityName referenced by toSearch? | - | ||||||||||||
6439 | for (QMap<QString,QString>::const_iterator referencedIt = entities.constBegin(); | - | ||||||||||||
6440 | referencedIt != entities.constEnd(); | - | ||||||||||||
6441 | ++referencedIt) { | - | ||||||||||||
6442 | const QString &entityName = referencedIt.key(); | - | ||||||||||||
6443 | - | |||||||||||||
6444 | for (int i = 0; i < leftOvers.size() && i != -1; ) { | - | ||||||||||||
6445 | entityNameBuffer = QLatin1Char('&') + entityName + QLatin1Char(';'); | - | ||||||||||||
6446 | - | |||||||||||||
6447 | i = leftOvers.indexOf(entityNameBuffer, i); | - | ||||||||||||
6448 | if (i != -1) { | - | ||||||||||||
6449 | leftOvers.remove(i, entityName.size() + 2); | - | ||||||||||||
6450 | // The entityName we're currently trying to find was matched in this string; increase our count. | - | ||||||||||||
6451 | ++referencesToOtherEntities[toSearch][entityName]; | - | ||||||||||||
6452 | } | - | ||||||||||||
6453 | } | - | ||||||||||||
6454 | } | - | ||||||||||||
6455 | literalEntitySizes[toSearch] = leftOvers.size(); | - | ||||||||||||
6456 | } | - | ||||||||||||
6457 | } | - | ||||||||||||
6458 | - | |||||||||||||
6459 | for (QHash<QString, QHash<QString, int> >::const_iterator entityIt = referencesToOtherEntities.constBegin(); | - | ||||||||||||
6460 | entityIt != referencesToOtherEntities.constEnd(); | - | ||||||||||||
6461 | ++entityIt) { | - | ||||||||||||
6462 | const QString &entity = entityIt.key(); | - | ||||||||||||
6463 | - | |||||||||||||
6464 | QHash<QString, int>::iterator expandedIt = expandedSizes.find(entity); | - | ||||||||||||
6465 | if (expandedIt == expandedSizes.end()) { | - | ||||||||||||
6466 | expandedIt = expandedSizes.insert(entity, literalEntitySizes.value(entity)); | - | ||||||||||||
6467 | for (QHash<QString, int>::const_iterator referenceIt = entityIt->constBegin(); | - | ||||||||||||
6468 | referenceIt != entityIt->constEnd(); | - | ||||||||||||
6469 | ++referenceIt) { | - | ||||||||||||
6470 | const QString &referenceTo = referenceIt.key(); | - | ||||||||||||
6471 | const int references = referencesToOtherEntities.value(entity).value(referenceTo); | - | ||||||||||||
6472 | // The total size of an entity's value is the expanded size of all of its referenced entities, plus its literal size. | - | ||||||||||||
6473 | *expandedIt += expandedSizes.value(referenceTo) * references + literalEntitySizes.value(referenceTo) * references; | - | ||||||||||||
6474 | } | - | ||||||||||||
6475 | - | |||||||||||||
6476 | if (*expandedIt > entityCharacterLimit) { | - | ||||||||||||
6477 | if (errorMessage) { | - | ||||||||||||
6478 | *errorMessage = QString::fromLatin1("The XML entity \"%1\" expands to a string that is too large to process (%2 characters > %3).") | - | ||||||||||||
6479 | .arg(entity, QString::number(*expandedIt), QString::number(entityCharacterLimit)); | - | ||||||||||||
6480 | } | - | ||||||||||||
6481 | return true; | - | ||||||||||||
6482 | } | - | ||||||||||||
6483 | } | - | ||||||||||||
6484 | } | - | ||||||||||||
6485 | return false; | - | ||||||||||||
6486 | } | - | ||||||||||||
6487 | - | |||||||||||||
6488 | /* | - | ||||||||||||
6489 | Parse a EntityDecl [70]. | - | ||||||||||||
6490 | - | |||||||||||||
6491 | Precondition: the beginning '<!E' is already read and the head | - | ||||||||||||
6492 | stand on the 'N' of '<!ENTITY' | - | ||||||||||||
6493 | */ | - | ||||||||||||
6494 | bool QXmlSimpleReaderPrivate::parseEntityDecl() | - | ||||||||||||
6495 | { | - | ||||||||||||
6496 | const signed char Init = 0; | - | ||||||||||||
6497 | const signed char Ent = 1; // parse "ENTITY" | - | ||||||||||||
6498 | const signed char Ws1 = 2; // white space read | - | ||||||||||||
6499 | const signed char Name = 3; // parse name | - | ||||||||||||
6500 | const signed char Ws2 = 4; // white space read | - | ||||||||||||
6501 | const signed char EValue = 5; // parse entity value | - | ||||||||||||
6502 | const signed char EValueR = 6; // same as EValue, but already reported | - | ||||||||||||
6503 | const signed char ExtID = 7; // parse ExternalID | - | ||||||||||||
6504 | const signed char Ws3 = 8; // white space read | - | ||||||||||||
6505 | const signed char Ndata = 9; // parse "NDATA" | - | ||||||||||||
6506 | const signed char Ws4 = 10; // white space read | - | ||||||||||||
6507 | const signed char NNam = 11; // parse name | - | ||||||||||||
6508 | const signed char NNamR = 12; // same as NNam, but already reported | - | ||||||||||||
6509 | const signed char PEDec = 13; // parse PEDecl | - | ||||||||||||
6510 | const signed char Ws6 = 14; // white space read | - | ||||||||||||
6511 | const signed char PENam = 15; // parse name | - | ||||||||||||
6512 | const signed char Ws7 = 16; // white space read | - | ||||||||||||
6513 | const signed char PEVal = 17; // parse entity value | - | ||||||||||||
6514 | const signed char PEValR = 18; // same as PEVal, but already reported | - | ||||||||||||
6515 | const signed char PEEID = 19; // parse ExternalID | - | ||||||||||||
6516 | const signed char PEEIDR = 20; // same as PEEID, but already reported | - | ||||||||||||
6517 | const signed char WsE = 21; // white space read | - | ||||||||||||
6518 | const signed char Done = 22; | - | ||||||||||||
6519 | const signed char EDDone = 23; // done, but also report an external, unparsed entity decl | - | ||||||||||||
6520 | - | |||||||||||||
6521 | const signed char InpWs = 0; // white space | - | ||||||||||||
6522 | const signed char InpPer = 1; // % | - | ||||||||||||
6523 | const signed char InpQuot = 2; // " or ' | - | ||||||||||||
6524 | const signed char InpGt = 3; // > | - | ||||||||||||
6525 | const signed char InpN = 4; // N | - | ||||||||||||
6526 | const signed char InpUnknown = 5; | - | ||||||||||||
6527 | - | |||||||||||||
6528 | static const signed char table[22][6] = { | - | ||||||||||||
6529 | /* InpWs InpPer InpQuot InpGt InpN InpUnknown */ | - | ||||||||||||
6530 | { -1, -1, -1, -1, Ent, -1 }, // Init | - | ||||||||||||
6531 | { Ws1, -1, -1, -1, -1, -1 }, // Ent | - | ||||||||||||
6532 | { -1, PEDec, -1, -1, Name, Name }, // Ws1 | - | ||||||||||||
6533 | { Ws2, -1, -1, -1, -1, -1 }, // Name | - | ||||||||||||
6534 | { -1, -1, EValue, -1, -1, ExtID }, // Ws2 | - | ||||||||||||
6535 | { WsE, -1, -1, Done, -1, -1 }, // EValue | - | ||||||||||||
6536 | { WsE, -1, -1, Done, -1, -1 }, // EValueR | - | ||||||||||||
6537 | { Ws3, -1, -1, EDDone,-1, -1 }, // ExtID | - | ||||||||||||
6538 | { -1, -1, -1, EDDone,Ndata, -1 }, // Ws3 | - | ||||||||||||
6539 | { Ws4, -1, -1, -1, -1, -1 }, // Ndata | - | ||||||||||||
6540 | { -1, -1, -1, -1, NNam, NNam }, // Ws4 | - | ||||||||||||
6541 | { WsE, -1, -1, Done, -1, -1 }, // NNam | - | ||||||||||||
6542 | { WsE, -1, -1, Done, -1, -1 }, // NNamR | - | ||||||||||||
6543 | { Ws6, -1, -1, -1, -1, -1 }, // PEDec | - | ||||||||||||
6544 | { -1, -1, -1, -1, PENam, PENam }, // Ws6 | - | ||||||||||||
6545 | { Ws7, -1, -1, -1, -1, -1 }, // PENam | - | ||||||||||||
6546 | { -1, -1, PEVal, -1, -1, PEEID }, // Ws7 | - | ||||||||||||
6547 | { WsE, -1, -1, Done, -1, -1 }, // PEVal | - | ||||||||||||
6548 | { WsE, -1, -1, Done, -1, -1 }, // PEValR | - | ||||||||||||
6549 | { WsE, -1, -1, Done, -1, -1 }, // PEEID | - | ||||||||||||
6550 | { WsE, -1, -1, Done, -1, -1 }, // PEEIDR | - | ||||||||||||
6551 | { -1, -1, -1, Done, -1, -1 } // WsE | - | ||||||||||||
6552 | }; | - | ||||||||||||
6553 | signed char state; | - | ||||||||||||
6554 | signed char input; | - | ||||||||||||
6555 | - | |||||||||||||
6556 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
6557 | state = Init; | - | ||||||||||||
6558 | } else { | - | ||||||||||||
6559 | state = parseStack->pop().state; | - | ||||||||||||
6560 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
6561 | qDebug("QXmlSimpleReader: parseEntityDecl (cont) in state %d", state); | - | ||||||||||||
6562 | #endif | - | ||||||||||||
6563 | if (!parseStack->isEmpty()) { | - | ||||||||||||
6564 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
6565 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
6566 | parseStack->pop(); | - | ||||||||||||
6567 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
6568 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
6569 | #endif | - | ||||||||||||
6570 | } | - | ||||||||||||
6571 | if (!(this->*function)()) { | - | ||||||||||||
6572 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6573 | return false; | - | ||||||||||||
6574 | } | - | ||||||||||||
6575 | } | - | ||||||||||||
6576 | } | - | ||||||||||||
6577 | - | |||||||||||||
6578 | for (;;) { | - | ||||||||||||
6579 | switch (state) { | - | ||||||||||||
6580 | case EValue: | - | ||||||||||||
6581 | if ( !entityExist(name())) { | - | ||||||||||||
6582 | QString errorMessage; | - | ||||||||||||
6583 | if (isExpandedEntityValueTooLarge(&errorMessage)) { | - | ||||||||||||
6584 | reportParseError(errorMessage); | - | ||||||||||||
6585 | return false; | - | ||||||||||||
6586 | } | - | ||||||||||||
6587 | - | |||||||||||||
6588 | entities.insert(name(), string()); | - | ||||||||||||
6589 | if (declHnd) { | - | ||||||||||||
6590 | if (!declHnd->internalEntityDecl(name(), string())) { | - | ||||||||||||
6591 | reportParseError(declHnd->errorString()); | - | ||||||||||||
6592 | return false; | - | ||||||||||||
6593 | } | - | ||||||||||||
6594 | } | - | ||||||||||||
6595 | } | - | ||||||||||||
6596 | state = EValueR; | - | ||||||||||||
6597 | break; | - | ||||||||||||
6598 | case NNam: | - | ||||||||||||
6599 | if ( !entityExist(name())) { | - | ||||||||||||
6600 | externEntities.insert(name(), QXmlSimpleReaderPrivate::ExternEntity(publicId, systemId, ref())); | - | ||||||||||||
6601 | if (dtdHnd) { | - | ||||||||||||
6602 | if (!dtdHnd->unparsedEntityDecl(name(), publicId, systemId, ref())) { | - | ||||||||||||
6603 | reportParseError(declHnd->errorString()); | - | ||||||||||||
6604 | return false; | - | ||||||||||||
6605 | } | - | ||||||||||||
6606 | } | - | ||||||||||||
6607 | } | - | ||||||||||||
6608 | state = NNamR; | - | ||||||||||||
6609 | break; | - | ||||||||||||
6610 | case PEVal: | - | ||||||||||||
6611 | if ( !entityExist(name())) { | - | ||||||||||||
6612 | parameterEntities.insert(name(), string()); | - | ||||||||||||
6613 | if (declHnd) { | - | ||||||||||||
6614 | if (!declHnd->internalEntityDecl(QLatin1Char('%') + name(), string())) { | - | ||||||||||||
6615 | reportParseError(declHnd->errorString()); | - | ||||||||||||
6616 | return false; | - | ||||||||||||
6617 | } | - | ||||||||||||
6618 | } | - | ||||||||||||
6619 | } | - | ||||||||||||
6620 | state = PEValR; | - | ||||||||||||
6621 | break; | - | ||||||||||||
6622 | case PEEID: | - | ||||||||||||
6623 | if ( !entityExist(name())) { | - | ||||||||||||
6624 | externParameterEntities.insert(name(), QXmlSimpleReaderPrivate::ExternParameterEntity(publicId, systemId)); | - | ||||||||||||
6625 | if (declHnd) { | - | ||||||||||||
6626 | if (!declHnd->externalEntityDecl(QLatin1Char('%') + name(), publicId, systemId)) { | - | ||||||||||||
6627 | reportParseError(declHnd->errorString()); | - | ||||||||||||
6628 | return false; | - | ||||||||||||
6629 | } | - | ||||||||||||
6630 | } | - | ||||||||||||
6631 | } | - | ||||||||||||
6632 | state = PEEIDR; | - | ||||||||||||
6633 | break; | - | ||||||||||||
6634 | case EDDone: | - | ||||||||||||
6635 | if ( !entityExist(name())) { | - | ||||||||||||
6636 | externEntities.insert(name(), QXmlSimpleReaderPrivate::ExternEntity(publicId, systemId, QString())); | - | ||||||||||||
6637 | if (declHnd) { | - | ||||||||||||
6638 | if (!declHnd->externalEntityDecl(name(), publicId, systemId)) { | - | ||||||||||||
6639 | reportParseError(declHnd->errorString()); | - | ||||||||||||
6640 | return false; | - | ||||||||||||
6641 | } | - | ||||||||||||
6642 | } | - | ||||||||||||
6643 | } | - | ||||||||||||
6644 | return true; | - | ||||||||||||
6645 | case Done: | - | ||||||||||||
6646 | return true; | - | ||||||||||||
6647 | case -1: | - | ||||||||||||
6648 | // Error | - | ||||||||||||
6649 | reportParseError(QLatin1String(XMLERR_LETTEREXPECTED)); | - | ||||||||||||
6650 | return false; | - | ||||||||||||
6651 | } | - | ||||||||||||
6652 | - | |||||||||||||
6653 | if (atEnd()) { | - | ||||||||||||
6654 | unexpectedEof(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6655 | return false; | - | ||||||||||||
6656 | } | - | ||||||||||||
6657 | if (is_S(c)) { | - | ||||||||||||
6658 | input = InpWs; | - | ||||||||||||
6659 | } else if (c == QLatin1Char('%')) { | - | ||||||||||||
6660 | input = InpPer; | - | ||||||||||||
6661 | } else if (c == QLatin1Char('"') || c == QLatin1Char('\'')) { | - | ||||||||||||
6662 | input = InpQuot; | - | ||||||||||||
6663 | } else if (c == QLatin1Char('>')) { | - | ||||||||||||
6664 | input = InpGt; | - | ||||||||||||
6665 | } else if (c == QLatin1Char('N')) { | - | ||||||||||||
6666 | input = InpN; | - | ||||||||||||
6667 | } else { | - | ||||||||||||
6668 | input = InpUnknown; | - | ||||||||||||
6669 | } | - | ||||||||||||
6670 | state = table[state][input]; | - | ||||||||||||
6671 | - | |||||||||||||
6672 | switch (state) { | - | ||||||||||||
6673 | case Ent: | - | ||||||||||||
6674 | parseString_s = QLatin1String("NTITY"); | - | ||||||||||||
6675 | if (!parseString()) { | - | ||||||||||||
6676 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6677 | return false; | - | ||||||||||||
6678 | } | - | ||||||||||||
6679 | break; | - | ||||||||||||
6680 | case Ws1: | - | ||||||||||||
6681 | if (!eat_ws()) { | - | ||||||||||||
6682 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6683 | return false; | - | ||||||||||||
6684 | } | - | ||||||||||||
6685 | break; | - | ||||||||||||
6686 | case Name: | - | ||||||||||||
6687 | parseName_useRef = false; | - | ||||||||||||
6688 | if (!parseName()) { | - | ||||||||||||
6689 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6690 | return false; | - | ||||||||||||
6691 | } | - | ||||||||||||
6692 | break; | - | ||||||||||||
6693 | case Ws2: | - | ||||||||||||
6694 | if (!eat_ws()) { | - | ||||||||||||
6695 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6696 | return false; | - | ||||||||||||
6697 | } | - | ||||||||||||
6698 | break; | - | ||||||||||||
6699 | case EValue: | - | ||||||||||||
6700 | case EValueR: | - | ||||||||||||
6701 | if (!parseEntityValue()) { | - | ||||||||||||
6702 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6703 | return false; | - | ||||||||||||
6704 | } | - | ||||||||||||
6705 | break; | - | ||||||||||||
6706 | case ExtID: | - | ||||||||||||
6707 | parseExternalID_allowPublicID = false; | - | ||||||||||||
6708 | if (!parseExternalID()) { | - | ||||||||||||
6709 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6710 | return false; | - | ||||||||||||
6711 | } | - | ||||||||||||
6712 | break; | - | ||||||||||||
6713 | case Ws3: | - | ||||||||||||
6714 | if (!eat_ws()) { | - | ||||||||||||
6715 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6716 | return false; | - | ||||||||||||
6717 | } | - | ||||||||||||
6718 | break; | - | ||||||||||||
6719 | case Ndata: | - | ||||||||||||
6720 | parseString_s = QLatin1String("NDATA"); | - | ||||||||||||
6721 | if (!parseString()) { | - | ||||||||||||
6722 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6723 | return false; | - | ||||||||||||
6724 | } | - | ||||||||||||
6725 | break; | - | ||||||||||||
6726 | case Ws4: | - | ||||||||||||
6727 | if (!eat_ws()) { | - | ||||||||||||
6728 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6729 | return false; | - | ||||||||||||
6730 | } | - | ||||||||||||
6731 | break; | - | ||||||||||||
6732 | case NNam: | - | ||||||||||||
6733 | case NNamR: | - | ||||||||||||
6734 | parseName_useRef = true; | - | ||||||||||||
6735 | if (!parseName()) { | - | ||||||||||||
6736 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6737 | return false; | - | ||||||||||||
6738 | } | - | ||||||||||||
6739 | break; | - | ||||||||||||
6740 | case PEDec: | - | ||||||||||||
6741 | next(); | - | ||||||||||||
6742 | break; | - | ||||||||||||
6743 | case Ws6: | - | ||||||||||||
6744 | if (!eat_ws()) { | - | ||||||||||||
6745 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6746 | return false; | - | ||||||||||||
6747 | } | - | ||||||||||||
6748 | break; | - | ||||||||||||
6749 | case PENam: | - | ||||||||||||
6750 | parseName_useRef = false; | - | ||||||||||||
6751 | if (!parseName()) { | - | ||||||||||||
6752 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6753 | return false; | - | ||||||||||||
6754 | } | - | ||||||||||||
6755 | break; | - | ||||||||||||
6756 | case Ws7: | - | ||||||||||||
6757 | if (!eat_ws()) { | - | ||||||||||||
6758 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6759 | return false; | - | ||||||||||||
6760 | } | - | ||||||||||||
6761 | break; | - | ||||||||||||
6762 | case PEVal: | - | ||||||||||||
6763 | case PEValR: | - | ||||||||||||
6764 | if (!parseEntityValue()) { | - | ||||||||||||
6765 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6766 | return false; | - | ||||||||||||
6767 | } | - | ||||||||||||
6768 | break; | - | ||||||||||||
6769 | case PEEID: | - | ||||||||||||
6770 | case PEEIDR: | - | ||||||||||||
6771 | parseExternalID_allowPublicID = false; | - | ||||||||||||
6772 | if (!parseExternalID()) { | - | ||||||||||||
6773 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6774 | return false; | - | ||||||||||||
6775 | } | - | ||||||||||||
6776 | break; | - | ||||||||||||
6777 | case WsE: | - | ||||||||||||
6778 | if (!eat_ws()) { | - | ||||||||||||
6779 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityDecl, state); | - | ||||||||||||
6780 | return false; | - | ||||||||||||
6781 | } | - | ||||||||||||
6782 | break; | - | ||||||||||||
6783 | case EDDone: | - | ||||||||||||
6784 | next(); | - | ||||||||||||
6785 | break; | - | ||||||||||||
6786 | case Done: | - | ||||||||||||
6787 | next(); | - | ||||||||||||
6788 | break; | - | ||||||||||||
6789 | } | - | ||||||||||||
6790 | } | - | ||||||||||||
6791 | return false; | - | ||||||||||||
6792 | } | - | ||||||||||||
6793 | - | |||||||||||||
6794 | /* | - | ||||||||||||
6795 | Parse a EntityValue [9] | - | ||||||||||||
6796 | */ | - | ||||||||||||
6797 | bool QXmlSimpleReaderPrivate::parseEntityValue() | - | ||||||||||||
6798 | { | - | ||||||||||||
6799 | const signed char Init = 0; | - | ||||||||||||
6800 | const signed char Dq = 1; // EntityValue is double quoted | - | ||||||||||||
6801 | const signed char DqC = 2; // signed character | - | ||||||||||||
6802 | const signed char DqPER = 3; // PERefence | - | ||||||||||||
6803 | const signed char DqRef = 4; // Reference | - | ||||||||||||
6804 | const signed char Sq = 5; // EntityValue is double quoted | - | ||||||||||||
6805 | const signed char SqC = 6; // signed character | - | ||||||||||||
6806 | const signed char SqPER = 7; // PERefence | - | ||||||||||||
6807 | const signed char SqRef = 8; // Reference | - | ||||||||||||
6808 | const signed char Done = 9; | - | ||||||||||||
6809 | - | |||||||||||||
6810 | const signed char InpDq = 0; // " | - | ||||||||||||
6811 | const signed char InpSq = 1; // ' | - | ||||||||||||
6812 | const signed char InpAmp = 2; // & | - | ||||||||||||
6813 | const signed char InpPer = 3; // % | - | ||||||||||||
6814 | const signed char InpUnknown = 4; | - | ||||||||||||
6815 | - | |||||||||||||
6816 | static const signed char table[9][5] = { | - | ||||||||||||
6817 | /* InpDq InpSq InpAmp InpPer InpUnknown */ | - | ||||||||||||
6818 | { Dq, Sq, -1, -1, -1 }, // Init | - | ||||||||||||
6819 | { Done, DqC, DqRef, DqPER, DqC }, // Dq | - | ||||||||||||
6820 | { Done, DqC, DqRef, DqPER, DqC }, // DqC | - | ||||||||||||
6821 | { Done, DqC, DqRef, DqPER, DqC }, // DqPER | - | ||||||||||||
6822 | { Done, DqC, DqRef, DqPER, DqC }, // DqRef | - | ||||||||||||
6823 | { SqC, Done, SqRef, SqPER, SqC }, // Sq | - | ||||||||||||
6824 | { SqC, Done, SqRef, SqPER, SqC }, // SqC | - | ||||||||||||
6825 | { SqC, Done, SqRef, SqPER, SqC }, // SqPER | - | ||||||||||||
6826 | { SqC, Done, SqRef, SqPER, SqC } // SqRef | - | ||||||||||||
6827 | }; | - | ||||||||||||
6828 | signed char state; | - | ||||||||||||
6829 | signed char input; | - | ||||||||||||
6830 | - | |||||||||||||
6831 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
6832 | state = Init; | - | ||||||||||||
6833 | } else { | - | ||||||||||||
6834 | state = parseStack->pop().state; | - | ||||||||||||
6835 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
6836 | qDebug("QXmlSimpleReader: parseEntityValue (cont) in state %d", state); | - | ||||||||||||
6837 | #endif | - | ||||||||||||
6838 | if (!parseStack->isEmpty()) { | - | ||||||||||||
6839 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
6840 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
6841 | parseStack->pop(); | - | ||||||||||||
6842 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
6843 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
6844 | #endif | - | ||||||||||||
6845 | } | - | ||||||||||||
6846 | if (!(this->*function)()) { | - | ||||||||||||
6847 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityValue, state); | - | ||||||||||||
6848 | return false; | - | ||||||||||||
6849 | } | - | ||||||||||||
6850 | } | - | ||||||||||||
6851 | } | - | ||||||||||||
6852 | - | |||||||||||||
6853 | for (;;) { | - | ||||||||||||
6854 | switch (state) { | - | ||||||||||||
6855 | case Done: | - | ||||||||||||
6856 | return true; | - | ||||||||||||
6857 | case -1: | - | ||||||||||||
6858 | // Error | - | ||||||||||||
6859 | reportParseError(QLatin1String(XMLERR_LETTEREXPECTED)); | - | ||||||||||||
6860 | return false; | - | ||||||||||||
6861 | } | - | ||||||||||||
6862 | - | |||||||||||||
6863 | if (atEnd()) { | - | ||||||||||||
6864 | unexpectedEof(&QXmlSimpleReaderPrivate::parseEntityValue, state); | - | ||||||||||||
6865 | return false; | - | ||||||||||||
6866 | } | - | ||||||||||||
6867 | if (c == QLatin1Char('"')) { | - | ||||||||||||
6868 | input = InpDq; | - | ||||||||||||
6869 | } else if (c == QLatin1Char('\'')) { | - | ||||||||||||
6870 | input = InpSq; | - | ||||||||||||
6871 | } else if (c == QLatin1Char('&')) { | - | ||||||||||||
6872 | input = InpAmp; | - | ||||||||||||
6873 | } else if (c == QLatin1Char('%')) { | - | ||||||||||||
6874 | input = InpPer; | - | ||||||||||||
6875 | } else { | - | ||||||||||||
6876 | input = InpUnknown; | - | ||||||||||||
6877 | } | - | ||||||||||||
6878 | state = table[state][input]; | - | ||||||||||||
6879 | - | |||||||||||||
6880 | switch (state) { | - | ||||||||||||
6881 | case Dq: | - | ||||||||||||
6882 | case Sq: | - | ||||||||||||
6883 | stringClear(); | - | ||||||||||||
6884 | next(); | - | ||||||||||||
6885 | break; | - | ||||||||||||
6886 | case DqC: | - | ||||||||||||
6887 | case SqC: | - | ||||||||||||
6888 | stringAddC(); | - | ||||||||||||
6889 | next(); | - | ||||||||||||
6890 | break; | - | ||||||||||||
6891 | case DqPER: | - | ||||||||||||
6892 | case SqPER: | - | ||||||||||||
6893 | parsePEReference_context = InEntityValue; | - | ||||||||||||
6894 | if (!parsePEReference()) { | - | ||||||||||||
6895 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityValue, state); | - | ||||||||||||
6896 | return false; | - | ||||||||||||
6897 | } | - | ||||||||||||
6898 | break; | - | ||||||||||||
6899 | case DqRef: | - | ||||||||||||
6900 | case SqRef: | - | ||||||||||||
6901 | parseReference_context = InEntityValue; | - | ||||||||||||
6902 | if (!parseReference()) { | - | ||||||||||||
6903 | parseFailed(&QXmlSimpleReaderPrivate::parseEntityValue, state); | - | ||||||||||||
6904 | return false; | - | ||||||||||||
6905 | } | - | ||||||||||||
6906 | break; | - | ||||||||||||
6907 | case Done: | - | ||||||||||||
6908 | next(); | - | ||||||||||||
6909 | break; | - | ||||||||||||
6910 | } | - | ||||||||||||
6911 | } | - | ||||||||||||
6912 | return false; | - | ||||||||||||
6913 | } | - | ||||||||||||
6914 | - | |||||||||||||
6915 | /* | - | ||||||||||||
6916 | Parse a comment [15]. | - | ||||||||||||
6917 | - | |||||||||||||
6918 | Precondition: the beginning '<!' of the comment is already read and the head | - | ||||||||||||
6919 | stands on the first '-' of '<!--'. | - | ||||||||||||
6920 | - | |||||||||||||
6921 | If this funktion was successful, the head-position is on the first | - | ||||||||||||
6922 | character after the comment. | - | ||||||||||||
6923 | */ | - | ||||||||||||
6924 | bool QXmlSimpleReaderPrivate::parseComment() | - | ||||||||||||
6925 | { | - | ||||||||||||
6926 | const signed char Init = 0; | - | ||||||||||||
6927 | const signed char Dash1 = 1; // the first dash was read | - | ||||||||||||
6928 | const signed char Dash2 = 2; // the second dash was read | - | ||||||||||||
6929 | const signed char Com = 3; // read comment | - | ||||||||||||
6930 | const signed char Com2 = 4; // read comment (help state) | - | ||||||||||||
6931 | const signed char ComE = 5; // finished reading comment | - | ||||||||||||
6932 | const signed char Done = 6; | - | ||||||||||||
6933 | - | |||||||||||||
6934 | const signed char InpDash = 0; // - | - | ||||||||||||
6935 | const signed char InpGt = 1; // > | - | ||||||||||||
6936 | const signed char InpUnknown = 2; | - | ||||||||||||
6937 | - | |||||||||||||
6938 | static const signed char table[6][3] = { | - | ||||||||||||
6939 | /* InpDash InpGt InpUnknown */ | - | ||||||||||||
6940 | { Dash1, -1, -1 }, // Init | - | ||||||||||||
6941 | { Dash2, -1, -1 }, // Dash1 | - | ||||||||||||
6942 | { Com2, Com, Com }, // Dash2 | - | ||||||||||||
6943 | { Com2, Com, Com }, // Com | - | ||||||||||||
6944 | { ComE, Com, Com }, // Com2 | - | ||||||||||||
6945 | { -1, Done, -1 } // ComE | - | ||||||||||||
6946 | }; | - | ||||||||||||
6947 | signed char state; | - | ||||||||||||
6948 | signed char input; | - | ||||||||||||
6949 | - | |||||||||||||
6950 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
6951 | state = Init; | - | ||||||||||||
6952 | } else { | - | ||||||||||||
6953 | state = parseStack->pop().state; | - | ||||||||||||
6954 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
6955 | qDebug("QXmlSimpleReader: parseComment (cont) in state %d", state); | - | ||||||||||||
6956 | #endif | - | ||||||||||||
6957 | if (!parseStack->isEmpty()) { | - | ||||||||||||
6958 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
6959 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
6960 | parseStack->pop(); | - | ||||||||||||
6961 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
6962 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
6963 | #endif | - | ||||||||||||
6964 | } | - | ||||||||||||
6965 | if (!(this->*function)()) { | - | ||||||||||||
6966 | parseFailed(&QXmlSimpleReaderPrivate::parseComment, state); | - | ||||||||||||
6967 | return false; | - | ||||||||||||
6968 | } | - | ||||||||||||
6969 | } | - | ||||||||||||
6970 | } | - | ||||||||||||
6971 | - | |||||||||||||
6972 | for (;;) { | - | ||||||||||||
6973 | switch (state) { | - | ||||||||||||
6974 | case Dash2: | - | ||||||||||||
6975 | stringClear(); | - | ||||||||||||
6976 | break; | - | ||||||||||||
6977 | case Com2: | - | ||||||||||||
6978 | // if next character is not a dash than don't skip it | - | ||||||||||||
6979 | if (!atEnd() && c != QLatin1Char('-')) | - | ||||||||||||
6980 | stringAddC(QLatin1Char('-')); | - | ||||||||||||
6981 | break; | - | ||||||||||||
6982 | case Done: | - | ||||||||||||
6983 | return true; | - | ||||||||||||
6984 | case -1: | - | ||||||||||||
6985 | // Error | - | ||||||||||||
6986 | reportParseError(QLatin1String(XMLERR_ERRORPARSINGCOMMENT)); | - | ||||||||||||
6987 | return false; | - | ||||||||||||
6988 | } | - | ||||||||||||
6989 | - | |||||||||||||
6990 | if (atEnd()) { | - | ||||||||||||
6991 | unexpectedEof(&QXmlSimpleReaderPrivate::parseComment, state); | - | ||||||||||||
6992 | return false; | - | ||||||||||||
6993 | } | - | ||||||||||||
6994 | if (c == QLatin1Char('-')) { | - | ||||||||||||
6995 | input = InpDash; | - | ||||||||||||
6996 | } else if (c == QLatin1Char('>')) { | - | ||||||||||||
6997 | input = InpGt; | - | ||||||||||||
6998 | } else { | - | ||||||||||||
6999 | input = InpUnknown; | - | ||||||||||||
7000 | } | - | ||||||||||||
7001 | state = table[state][input]; | - | ||||||||||||
7002 | - | |||||||||||||
7003 | switch (state) { | - | ||||||||||||
7004 | case Dash1: | - | ||||||||||||
7005 | next(); | - | ||||||||||||
7006 | break; | - | ||||||||||||
7007 | case Dash2: | - | ||||||||||||
7008 | next(); | - | ||||||||||||
7009 | break; | - | ||||||||||||
7010 | case Com: | - | ||||||||||||
7011 | stringAddC(); | - | ||||||||||||
7012 | next(); | - | ||||||||||||
7013 | break; | - | ||||||||||||
7014 | case Com2: | - | ||||||||||||
7015 | next(); | - | ||||||||||||
7016 | break; | - | ||||||||||||
7017 | case ComE: | - | ||||||||||||
7018 | next(); | - | ||||||||||||
7019 | break; | - | ||||||||||||
7020 | case Done: | - | ||||||||||||
7021 | next(); | - | ||||||||||||
7022 | break; | - | ||||||||||||
7023 | } | - | ||||||||||||
7024 | } | - | ||||||||||||
7025 | return false; | - | ||||||||||||
7026 | } | - | ||||||||||||
7027 | - | |||||||||||||
7028 | /* | - | ||||||||||||
7029 | Parse an Attribute [41]. | - | ||||||||||||
7030 | - | |||||||||||||
7031 | Precondition: the head stands on the first character of the name | - | ||||||||||||
7032 | of the attribute (i.e. all whitespaces are already parsed). | - | ||||||||||||
7033 | - | |||||||||||||
7034 | The head stand on the next character after the end quotes. The | - | ||||||||||||
7035 | variable name contains the name of the attribute and the variable | - | ||||||||||||
7036 | string contains the value of the attribute. | - | ||||||||||||
7037 | */ | - | ||||||||||||
7038 | bool QXmlSimpleReaderPrivate::parseAttribute() | - | ||||||||||||
7039 | { | - | ||||||||||||
7040 | const int Init = 0; | - | ||||||||||||
7041 | const int PName = 1; // parse name | - | ||||||||||||
7042 | const int Ws = 2; // eat ws | - | ||||||||||||
7043 | const int Eq = 3; // the '=' was read | - | ||||||||||||
7044 | const int Quotes = 4; // " or ' were read | - | ||||||||||||
7045 | - | |||||||||||||
7046 | const int InpNameBe = 0; | - | ||||||||||||
7047 | const int InpEq = 1; // = | - | ||||||||||||
7048 | const int InpDq = 2; // " | - | ||||||||||||
7049 | const int InpSq = 3; // ' | - | ||||||||||||
7050 | const int InpUnknown = 4; | - | ||||||||||||
7051 | - | |||||||||||||
7052 | static const int table[4][5] = { | - | ||||||||||||
7053 | /* InpNameBe InpEq InpDq InpSq InpUnknown */ | - | ||||||||||||
7054 | { PName, -1, -1, -1, -1 }, // Init | - | ||||||||||||
7055 | { -1, Eq, -1, -1, Ws }, // PName | - | ||||||||||||
7056 | { -1, Eq, -1, -1, -1 }, // Ws | - | ||||||||||||
7057 | { -1, -1, Quotes, Quotes, -1 } // Eq | - | ||||||||||||
7058 | }; | - | ||||||||||||
7059 | int state; | - | ||||||||||||
7060 | int input; | - | ||||||||||||
7061 | - | |||||||||||||
7062 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
7063 | state = Init; | - | ||||||||||||
7064 | } else { | - | ||||||||||||
7065 | state = parseStack->pop().state; | - | ||||||||||||
7066 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
7067 | qDebug("QXmlSimpleReader: parseAttribute (cont) in state %d", state); | - | ||||||||||||
7068 | #endif | - | ||||||||||||
7069 | if (!parseStack->isEmpty()) { | - | ||||||||||||
7070 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
7071 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
7072 | parseStack->pop(); | - | ||||||||||||
7073 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
7074 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
7075 | #endif | - | ||||||||||||
7076 | } | - | ||||||||||||
7077 | if (!(this->*function)()) { | - | ||||||||||||
7078 | parseFailed(&QXmlSimpleReaderPrivate::parseAttribute, state); | - | ||||||||||||
7079 | return false; | - | ||||||||||||
7080 | } | - | ||||||||||||
7081 | } | - | ||||||||||||
7082 | } | - | ||||||||||||
7083 | - | |||||||||||||
7084 | for (;;) { | - | ||||||||||||
7085 | switch (state) { | - | ||||||||||||
7086 | case Quotes: | - | ||||||||||||
7087 | // Done | - | ||||||||||||
7088 | return true; | - | ||||||||||||
7089 | case -1: | - | ||||||||||||
7090 | // Error | - | ||||||||||||
7091 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDCHARACTER)); | - | ||||||||||||
7092 | return false; | - | ||||||||||||
7093 | } | - | ||||||||||||
7094 | - | |||||||||||||
7095 | if (atEnd()) { | - | ||||||||||||
7096 | unexpectedEof(&QXmlSimpleReaderPrivate::parseAttribute, state); | - | ||||||||||||
7097 | return false; | - | ||||||||||||
7098 | } | - | ||||||||||||
7099 | if (determineNameChar(c) == NameBeginning) { | - | ||||||||||||
7100 | input = InpNameBe; | - | ||||||||||||
7101 | } else if (c == QLatin1Char('=')) { | - | ||||||||||||
7102 | input = InpEq; | - | ||||||||||||
7103 | } else if (c == QLatin1Char('"')) { | - | ||||||||||||
7104 | input = InpDq; | - | ||||||||||||
7105 | } else if (c == QLatin1Char('\'')) { | - | ||||||||||||
7106 | input = InpSq; | - | ||||||||||||
7107 | } else { | - | ||||||||||||
7108 | input = InpUnknown; | - | ||||||||||||
7109 | } | - | ||||||||||||
7110 | state = table[state][input]; | - | ||||||||||||
7111 | - | |||||||||||||
7112 | switch (state) { | - | ||||||||||||
7113 | case PName: | - | ||||||||||||
7114 | parseName_useRef = false; | - | ||||||||||||
7115 | if (!parseName()) { | - | ||||||||||||
7116 | parseFailed(&QXmlSimpleReaderPrivate::parseAttribute, state); | - | ||||||||||||
7117 | return false; | - | ||||||||||||
7118 | } | - | ||||||||||||
7119 | break; | - | ||||||||||||
7120 | case Ws: | - | ||||||||||||
7121 | if (!eat_ws()) { | - | ||||||||||||
7122 | parseFailed(&QXmlSimpleReaderPrivate::parseAttribute, state); | - | ||||||||||||
7123 | return false; | - | ||||||||||||
7124 | } | - | ||||||||||||
7125 | break; | - | ||||||||||||
7126 | case Eq: | - | ||||||||||||
7127 | if (!next_eat_ws()) { | - | ||||||||||||
7128 | parseFailed(&QXmlSimpleReaderPrivate::parseAttribute, state); | - | ||||||||||||
7129 | return false; | - | ||||||||||||
7130 | } | - | ||||||||||||
7131 | break; | - | ||||||||||||
7132 | case Quotes: | - | ||||||||||||
7133 | if (!parseAttValue()) { | - | ||||||||||||
7134 | parseFailed(&QXmlSimpleReaderPrivate::parseAttribute, state); | - | ||||||||||||
7135 | return false; | - | ||||||||||||
7136 | } | - | ||||||||||||
7137 | break; | - | ||||||||||||
7138 | } | - | ||||||||||||
7139 | } | - | ||||||||||||
7140 | return false; | - | ||||||||||||
7141 | } | - | ||||||||||||
7142 | - | |||||||||||||
7143 | /* | - | ||||||||||||
7144 | Parse a Name [5] and store the name in name or ref (if useRef is true). | - | ||||||||||||
7145 | */ | - | ||||||||||||
7146 | bool QXmlSimpleReaderPrivate::parseName() | - | ||||||||||||
7147 | { | - | ||||||||||||
7148 | const int Init = 0; | - | ||||||||||||
7149 | const int Name1 = 1; // parse first character of the name | - | ||||||||||||
7150 | const int Name = 2; // parse name | - | ||||||||||||
7151 | const int Done = 3; | - | ||||||||||||
7152 | - | |||||||||||||
7153 | static const int table[3][3] = { | - | ||||||||||||
7154 | /* InpNameBe InpNameCh InpUnknown */ | - | ||||||||||||
7155 | { Name1, -1, -1 }, // Init | - | ||||||||||||
7156 | { Name, Name, Done }, // Name1 | - | ||||||||||||
7157 | { Name, Name, Done } // Name | - | ||||||||||||
7158 | }; | - | ||||||||||||
7159 | int state; | - | ||||||||||||
7160 | - | |||||||||||||
7161 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
7162 | state = Init; | - | ||||||||||||
7163 | } else { | - | ||||||||||||
7164 | state = parseStack->pop().state; | - | ||||||||||||
7165 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
7166 | qDebug("QXmlSimpleReader: parseName (cont) in state %d", state); | - | ||||||||||||
7167 | #endif | - | ||||||||||||
7168 | if (!parseStack->isEmpty()) { | - | ||||||||||||
7169 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
7170 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
7171 | parseStack->pop(); | - | ||||||||||||
7172 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
7173 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
7174 | #endif | - | ||||||||||||
7175 | } | - | ||||||||||||
7176 | if (!(this->*function)()) { | - | ||||||||||||
7177 | parseFailed(&QXmlSimpleReaderPrivate::parseName, state); | - | ||||||||||||
7178 | return false; | - | ||||||||||||
7179 | } | - | ||||||||||||
7180 | } | - | ||||||||||||
7181 | } | - | ||||||||||||
7182 | - | |||||||||||||
7183 | for (;;) { | - | ||||||||||||
7184 | switch (state) { | - | ||||||||||||
7185 | case Done: | - | ||||||||||||
7186 | return true; | - | ||||||||||||
7187 | case -1: | - | ||||||||||||
7188 | // Error | - | ||||||||||||
7189 | reportParseError(QLatin1String(XMLERR_LETTEREXPECTED)); | - | ||||||||||||
7190 | return false; | - | ||||||||||||
7191 | } | - | ||||||||||||
7192 | - | |||||||||||||
7193 | if (atEnd()) { | - | ||||||||||||
7194 | unexpectedEof(&QXmlSimpleReaderPrivate::parseName, state); | - | ||||||||||||
7195 | return false; | - | ||||||||||||
7196 | } | - | ||||||||||||
7197 | - | |||||||||||||
7198 | // we can safely do the (int) cast thanks to the Q_ASSERTs earlier in this function | - | ||||||||||||
7199 | state = table[state][(int)fastDetermineNameChar(c)]; | - | ||||||||||||
7200 | - | |||||||||||||
7201 | switch (state) { | - | ||||||||||||
7202 | case Name1: | - | ||||||||||||
7203 | if (parseName_useRef) { | - | ||||||||||||
7204 | refClear(); | - | ||||||||||||
7205 | refAddC(); | - | ||||||||||||
7206 | } else { | - | ||||||||||||
7207 | nameClear(); | - | ||||||||||||
7208 | nameAddC(); | - | ||||||||||||
7209 | } | - | ||||||||||||
7210 | next(); | - | ||||||||||||
7211 | break; | - | ||||||||||||
7212 | case Name: | - | ||||||||||||
7213 | if (parseName_useRef) { | - | ||||||||||||
7214 | refAddC(); | - | ||||||||||||
7215 | } else { | - | ||||||||||||
7216 | nameAddC(); | - | ||||||||||||
7217 | } | - | ||||||||||||
7218 | next(); | - | ||||||||||||
7219 | break; | - | ||||||||||||
7220 | } | - | ||||||||||||
7221 | } | - | ||||||||||||
7222 | return false; | - | ||||||||||||
7223 | } | - | ||||||||||||
7224 | - | |||||||||||||
7225 | /* | - | ||||||||||||
7226 | Parse a Nmtoken [7] and store the name in name. | - | ||||||||||||
7227 | */ | - | ||||||||||||
7228 | bool QXmlSimpleReaderPrivate::parseNmtoken() | - | ||||||||||||
7229 | { | - | ||||||||||||
7230 | const signed char Init = 0; | - | ||||||||||||
7231 | const signed char NameF = 1; | - | ||||||||||||
7232 | const signed char Name = 2; | - | ||||||||||||
7233 | const signed char Done = 3; | - | ||||||||||||
7234 | - | |||||||||||||
7235 | const signed char InpNameCh = 0; // NameChar without InpNameBe | - | ||||||||||||
7236 | const signed char InpUnknown = 1; | - | ||||||||||||
7237 | - | |||||||||||||
7238 | static const signed char table[3][2] = { | - | ||||||||||||
7239 | /* InpNameCh InpUnknown */ | - | ||||||||||||
7240 | { NameF, -1 }, // Init | - | ||||||||||||
7241 | { Name, Done }, // NameF | - | ||||||||||||
7242 | { Name, Done } // Name | - | ||||||||||||
7243 | }; | - | ||||||||||||
7244 | signed char state; | - | ||||||||||||
7245 | signed char input; | - | ||||||||||||
7246 | - | |||||||||||||
7247 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
7248 | state = Init; | - | ||||||||||||
7249 | } else { | - | ||||||||||||
7250 | state = parseStack->pop().state; | - | ||||||||||||
7251 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
7252 | qDebug("QXmlSimpleReader: parseNmtoken (cont) in state %d", state); | - | ||||||||||||
7253 | #endif | - | ||||||||||||
7254 | if (!parseStack->isEmpty()) { | - | ||||||||||||
7255 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
7256 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
7257 | parseStack->pop(); | - | ||||||||||||
7258 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
7259 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
7260 | #endif | - | ||||||||||||
7261 | } | - | ||||||||||||
7262 | if (!(this->*function)()) { | - | ||||||||||||
7263 | parseFailed(&QXmlSimpleReaderPrivate::parseNmtoken, state); | - | ||||||||||||
7264 | return false; | - | ||||||||||||
7265 | } | - | ||||||||||||
7266 | } | - | ||||||||||||
7267 | } | - | ||||||||||||
7268 | - | |||||||||||||
7269 | for (;;) { | - | ||||||||||||
7270 | switch (state) { | - | ||||||||||||
7271 | case Done: | - | ||||||||||||
7272 | return true; | - | ||||||||||||
7273 | case -1: | - | ||||||||||||
7274 | // Error | - | ||||||||||||
7275 | reportParseError(QLatin1String(XMLERR_LETTEREXPECTED)); | - | ||||||||||||
7276 | return false; | - | ||||||||||||
7277 | } | - | ||||||||||||
7278 | - | |||||||||||||
7279 | if (atEnd()) { | - | ||||||||||||
7280 | unexpectedEof(&QXmlSimpleReaderPrivate::parseNmtoken, state); | - | ||||||||||||
7281 | return false; | - | ||||||||||||
7282 | } | - | ||||||||||||
7283 | if (determineNameChar(c) == NotName) { | - | ||||||||||||
7284 | input = InpUnknown; | - | ||||||||||||
7285 | } else { | - | ||||||||||||
7286 | input = InpNameCh; | - | ||||||||||||
7287 | } | - | ||||||||||||
7288 | state = table[state][input]; | - | ||||||||||||
7289 | - | |||||||||||||
7290 | switch (state) { | - | ||||||||||||
7291 | case NameF: | - | ||||||||||||
7292 | nameClear(); | - | ||||||||||||
7293 | nameAddC(); | - | ||||||||||||
7294 | next(); | - | ||||||||||||
7295 | break; | - | ||||||||||||
7296 | case Name: | - | ||||||||||||
7297 | nameAddC(); | - | ||||||||||||
7298 | next(); | - | ||||||||||||
7299 | break; | - | ||||||||||||
7300 | } | - | ||||||||||||
7301 | } | - | ||||||||||||
7302 | return false; | - | ||||||||||||
7303 | } | - | ||||||||||||
7304 | - | |||||||||||||
7305 | /* | - | ||||||||||||
7306 | Parse a Reference [67]. | - | ||||||||||||
7307 | - | |||||||||||||
7308 | parseReference_charDataRead is set to true if the reference must not be | - | ||||||||||||
7309 | parsed. The character(s) which the reference mapped to are appended to | - | ||||||||||||
7310 | string. The head stands on the first character after the reference. | - | ||||||||||||
7311 | - | |||||||||||||
7312 | parseReference_charDataRead is set to false if the reference must be parsed. | - | ||||||||||||
7313 | The charachter(s) which the reference mapped to are inserted at the reference | - | ||||||||||||
7314 | position. The head stands on the first character of the replacement). | - | ||||||||||||
7315 | */ | - | ||||||||||||
7316 | bool QXmlSimpleReaderPrivate::parseReference() | - | ||||||||||||
7317 | { | - | ||||||||||||
7318 | // temporary variables (only used in very local context, so they don't | - | ||||||||||||
7319 | // interfere with incremental parsing) | - | ||||||||||||
7320 | uint tmp; | - | ||||||||||||
7321 | bool ok; | - | ||||||||||||
7322 | - | |||||||||||||
7323 | const signed char Init = 0; | - | ||||||||||||
7324 | const signed char SRef = 1; // start of a reference | - | ||||||||||||
7325 | const signed char ChRef = 2; // parse CharRef | - | ||||||||||||
7326 | const signed char ChDec = 3; // parse CharRef decimal | - | ||||||||||||
7327 | const signed char ChHexS = 4; // start CharRef hexadecimal | - | ||||||||||||
7328 | const signed char ChHex = 5; // parse CharRef hexadecimal | - | ||||||||||||
7329 | const signed char Name = 6; // parse name | - | ||||||||||||
7330 | const signed char DoneD = 7; // done CharRef decimal | - | ||||||||||||
7331 | const signed char DoneH = 8; // done CharRef hexadecimal | - | ||||||||||||
7332 | const signed char DoneN = 9; // done EntityRef | - | ||||||||||||
7333 | - | |||||||||||||
7334 | const signed char InpAmp = 0; // & | - | ||||||||||||
7335 | const signed char InpSemi = 1; // ; | - | ||||||||||||
7336 | const signed char InpHash = 2; // # | - | ||||||||||||
7337 | const signed char InpX = 3; // x | - | ||||||||||||
7338 | const signed char InpNum = 4; // 0-9 | - | ||||||||||||
7339 | const signed char InpHex = 5; // a-f A-F | - | ||||||||||||
7340 | const signed char InpUnknown = 6; | - | ||||||||||||
7341 | - | |||||||||||||
7342 | static const signed char table[8][7] = { | - | ||||||||||||
7343 | /* InpAmp InpSemi InpHash InpX InpNum InpHex InpUnknown */ | - | ||||||||||||
7344 | { SRef, -1, -1, -1, -1, -1, -1 }, // Init | - | ||||||||||||
7345 | { -1, -1, ChRef, Name, Name, Name, Name }, // SRef | - | ||||||||||||
7346 | { -1, -1, -1, ChHexS, ChDec, -1, -1 }, // ChRef | - | ||||||||||||
7347 | { -1, DoneD, -1, -1, ChDec, -1, -1 }, // ChDec | - | ||||||||||||
7348 | { -1, -1, -1, -1, ChHex, ChHex, -1 }, // ChHexS | - | ||||||||||||
7349 | { -1, DoneH, -1, -1, ChHex, ChHex, -1 }, // ChHex | - | ||||||||||||
7350 | { -1, DoneN, -1, -1, -1, -1, -1 } // Name | - | ||||||||||||
7351 | }; | - | ||||||||||||
7352 | signed char state; | - | ||||||||||||
7353 | signed char input; | - | ||||||||||||
7354 | - | |||||||||||||
7355 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
7356 | parseReference_charDataRead = false; | - | ||||||||||||
7357 | state = Init; | - | ||||||||||||
7358 | } else { | - | ||||||||||||
7359 | state = parseStack->pop().state; | - | ||||||||||||
7360 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
7361 | qDebug("QXmlSimpleReader: parseReference (cont) in state %d", state); | - | ||||||||||||
7362 | #endif | - | ||||||||||||
7363 | if (!parseStack->isEmpty()) { | - | ||||||||||||
7364 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
7365 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
7366 | parseStack->pop(); | - | ||||||||||||
7367 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
7368 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
7369 | #endif | - | ||||||||||||
7370 | } | - | ||||||||||||
7371 | if (!(this->*function)()) { | - | ||||||||||||
7372 | parseFailed(&QXmlSimpleReaderPrivate::parseReference, state); | - | ||||||||||||
7373 | return false; | - | ||||||||||||
7374 | } | - | ||||||||||||
7375 | } | - | ||||||||||||
7376 | } | - | ||||||||||||
7377 | - | |||||||||||||
7378 | for (;;) { | - | ||||||||||||
7379 | switch (state) { | - | ||||||||||||
7380 | case DoneD: | - | ||||||||||||
7381 | return true; | - | ||||||||||||
7382 | case DoneH: | - | ||||||||||||
7383 | return true; | - | ||||||||||||
7384 | case DoneN: | - | ||||||||||||
7385 | return true; | - | ||||||||||||
7386 | case -1: | - | ||||||||||||
7387 | // Error | - | ||||||||||||
7388 | reportParseError(QLatin1String(XMLERR_ERRORPARSINGREFERENCE)); | - | ||||||||||||
7389 | return false; | - | ||||||||||||
7390 | } | - | ||||||||||||
7391 | - | |||||||||||||
7392 | if (atEnd()) { | - | ||||||||||||
7393 | unexpectedEof(&QXmlSimpleReaderPrivate::parseReference, state); | - | ||||||||||||
7394 | return false; | - | ||||||||||||
7395 | } | - | ||||||||||||
7396 | if (c.row()) { | - | ||||||||||||
7397 | input = InpUnknown; | - | ||||||||||||
7398 | } else if (c.cell() == '&') { | - | ||||||||||||
7399 | input = InpAmp; | - | ||||||||||||
7400 | } else if (c.cell() == ';') { | - | ||||||||||||
7401 | input = InpSemi; | - | ||||||||||||
7402 | } else if (c.cell() == '#') { | - | ||||||||||||
7403 | input = InpHash; | - | ||||||||||||
7404 | } else if (c.cell() == 'x') { | - | ||||||||||||
7405 | input = InpX; | - | ||||||||||||
7406 | } else if ('0' <= c.cell() && c.cell() <= '9') { | - | ||||||||||||
7407 | input = InpNum; | - | ||||||||||||
7408 | } else if ('a' <= c.cell() && c.cell() <= 'f') { | - | ||||||||||||
7409 | input = InpHex; | - | ||||||||||||
7410 | } else if ('A' <= c.cell() && c.cell() <= 'F') { | - | ||||||||||||
7411 | input = InpHex; | - | ||||||||||||
7412 | } else { | - | ||||||||||||
7413 | input = InpUnknown; | - | ||||||||||||
7414 | } | - | ||||||||||||
7415 | state = table[state][input]; | - | ||||||||||||
7416 | - | |||||||||||||
7417 | switch (state) { | - | ||||||||||||
7418 | case SRef: | - | ||||||||||||
7419 | refClear(); | - | ||||||||||||
7420 | next(); | - | ||||||||||||
7421 | break; | - | ||||||||||||
7422 | case ChRef: | - | ||||||||||||
7423 | next(); | - | ||||||||||||
7424 | break; | - | ||||||||||||
7425 | case ChDec: | - | ||||||||||||
7426 | refAddC(); | - | ||||||||||||
7427 | next(); | - | ||||||||||||
7428 | break; | - | ||||||||||||
7429 | case ChHexS: | - | ||||||||||||
7430 | next(); | - | ||||||||||||
7431 | break; | - | ||||||||||||
7432 | case ChHex: | - | ||||||||||||
7433 | refAddC(); | - | ||||||||||||
7434 | next(); | - | ||||||||||||
7435 | break; | - | ||||||||||||
7436 | case Name: | - | ||||||||||||
7437 | // read the name into the ref | - | ||||||||||||
7438 | parseName_useRef = true; | - | ||||||||||||
7439 | if (!parseName()) { | - | ||||||||||||
7440 | parseFailed(&QXmlSimpleReaderPrivate::parseReference, state); | - | ||||||||||||
7441 | return false; | - | ||||||||||||
7442 | } | - | ||||||||||||
7443 | break; | - | ||||||||||||
7444 | case DoneD: | - | ||||||||||||
7445 | tmp = ref().toUInt(&ok, 10); | - | ||||||||||||
7446 | if (ok) { | - | ||||||||||||
7447 | stringAddC(QChar(tmp)); | - | ||||||||||||
7448 | } else { | - | ||||||||||||
7449 | reportParseError(QLatin1String(XMLERR_ERRORPARSINGREFERENCE)); | - | ||||||||||||
7450 | return false; | - | ||||||||||||
7451 | } | - | ||||||||||||
7452 | parseReference_charDataRead = true; | - | ||||||||||||
7453 | next(); | - | ||||||||||||
7454 | break; | - | ||||||||||||
7455 | case DoneH: | - | ||||||||||||
7456 | tmp = ref().toUInt(&ok, 16); | - | ||||||||||||
7457 | if (ok) { | - | ||||||||||||
7458 | stringAddC(QChar(tmp)); | - | ||||||||||||
7459 | } else { | - | ||||||||||||
7460 | reportParseError(QLatin1String(XMLERR_ERRORPARSINGREFERENCE)); | - | ||||||||||||
7461 | return false; | - | ||||||||||||
7462 | } | - | ||||||||||||
7463 | parseReference_charDataRead = true; | - | ||||||||||||
7464 | next(); | - | ||||||||||||
7465 | break; | - | ||||||||||||
7466 | case DoneN: | - | ||||||||||||
7467 | if (!processReference()) | - | ||||||||||||
7468 | return false; | - | ||||||||||||
7469 | next(); | - | ||||||||||||
7470 | break; | - | ||||||||||||
7471 | } | - | ||||||||||||
7472 | } | - | ||||||||||||
7473 | return false; | - | ||||||||||||
7474 | } | - | ||||||||||||
7475 | - | |||||||||||||
7476 | /* | - | ||||||||||||
7477 | Helper function for parseReference() | - | ||||||||||||
7478 | */ | - | ||||||||||||
7479 | bool QXmlSimpleReaderPrivate::processReference() | - | ||||||||||||
7480 | { | - | ||||||||||||
7481 | QString reference = ref(); | - | ||||||||||||
7482 | if (reference == QLatin1String("amp")) { | - | ||||||||||||
7483 | if (parseReference_context == InEntityValue) { | - | ||||||||||||
7484 | // Bypassed | - | ||||||||||||
7485 | stringAddC(QLatin1Char('&')); stringAddC(QLatin1Char('a')); stringAddC(QLatin1Char('m')); stringAddC(QLatin1Char('p')); stringAddC(QLatin1Char(';')); | - | ||||||||||||
7486 | } else { | - | ||||||||||||
7487 | // Included or Included in literal | - | ||||||||||||
7488 | stringAddC(QLatin1Char('&')); | - | ||||||||||||
7489 | } | - | ||||||||||||
7490 | parseReference_charDataRead = true; | - | ||||||||||||
7491 | } else if (reference == QLatin1String("lt")) { | - | ||||||||||||
7492 | if (parseReference_context == InEntityValue) { | - | ||||||||||||
7493 | // Bypassed | - | ||||||||||||
7494 | stringAddC(QLatin1Char('&')); stringAddC(QLatin1Char('l')); stringAddC(QLatin1Char('t')); stringAddC(QLatin1Char(';')); | - | ||||||||||||
7495 | } else { | - | ||||||||||||
7496 | // Included or Included in literal | - | ||||||||||||
7497 | stringAddC(QLatin1Char('<')); | - | ||||||||||||
7498 | } | - | ||||||||||||
7499 | parseReference_charDataRead = true; | - | ||||||||||||
7500 | } else if (reference == QLatin1String("gt")) { | - | ||||||||||||
7501 | if (parseReference_context == InEntityValue) { | - | ||||||||||||
7502 | // Bypassed | - | ||||||||||||
7503 | stringAddC(QLatin1Char('&')); stringAddC(QLatin1Char('g')); stringAddC(QLatin1Char('t')); stringAddC(QLatin1Char(';')); | - | ||||||||||||
7504 | } else { | - | ||||||||||||
7505 | // Included or Included in literal | - | ||||||||||||
7506 | stringAddC(QLatin1Char('>')); | - | ||||||||||||
7507 | } | - | ||||||||||||
7508 | parseReference_charDataRead = true; | - | ||||||||||||
7509 | } else if (reference == QLatin1String("apos")) { | - | ||||||||||||
7510 | if (parseReference_context == InEntityValue) { | - | ||||||||||||
7511 | // Bypassed | - | ||||||||||||
7512 | stringAddC(QLatin1Char('&')); stringAddC(QLatin1Char('a')); stringAddC(QLatin1Char('p')); stringAddC(QLatin1Char('o')); stringAddC(QLatin1Char('s')); stringAddC(QLatin1Char(';')); | - | ||||||||||||
7513 | } else { | - | ||||||||||||
7514 | // Included or Included in literal | - | ||||||||||||
7515 | stringAddC(QLatin1Char('\'')); | - | ||||||||||||
7516 | } | - | ||||||||||||
7517 | parseReference_charDataRead = true; | - | ||||||||||||
7518 | } else if (reference == QLatin1String("quot")) { | - | ||||||||||||
7519 | if (parseReference_context == InEntityValue) { | - | ||||||||||||
7520 | // Bypassed | - | ||||||||||||
7521 | stringAddC(QLatin1Char('&')); stringAddC(QLatin1Char('q')); stringAddC(QLatin1Char('u')); stringAddC(QLatin1Char('o')); stringAddC(QLatin1Char('t')); stringAddC(QLatin1Char(';')); | - | ||||||||||||
7522 | } else { | - | ||||||||||||
7523 | // Included or Included in literal | - | ||||||||||||
7524 | stringAddC(QLatin1Char('"')); | - | ||||||||||||
7525 | } | - | ||||||||||||
7526 | parseReference_charDataRead = true; | - | ||||||||||||
7527 | } else { | - | ||||||||||||
7528 | QMap<QString,QString>::Iterator it; | - | ||||||||||||
7529 | it = entities.find(reference); | - | ||||||||||||
7530 | if (it != entities.end()) { | - | ||||||||||||
7531 | // "Internal General" | - | ||||||||||||
7532 | switch (parseReference_context) { | - | ||||||||||||
7533 | case InContent: | - | ||||||||||||
7534 | // Included | - | ||||||||||||
7535 | if (!insertXmlRef(*it, reference, false)) | - | ||||||||||||
7536 | return false; | - | ||||||||||||
7537 | parseReference_charDataRead = false; | - | ||||||||||||
7538 | break; | - | ||||||||||||
7539 | case InAttributeValue: | - | ||||||||||||
7540 | // Included in literal | - | ||||||||||||
7541 | if (!insertXmlRef(*it, reference, true)) | - | ||||||||||||
7542 | return false; | - | ||||||||||||
7543 | parseReference_charDataRead = false; | - | ||||||||||||
7544 | break; | - | ||||||||||||
7545 | case InEntityValue: | - | ||||||||||||
7546 | { | - | ||||||||||||
7547 | // Bypassed | - | ||||||||||||
7548 | stringAddC(QLatin1Char('&')); | - | ||||||||||||
7549 | for (int i=0; i<(int)reference.length(); i++) { | - | ||||||||||||
7550 | stringAddC(reference[i]); | - | ||||||||||||
7551 | } | - | ||||||||||||
7552 | stringAddC(QLatin1Char(';')); | - | ||||||||||||
7553 | parseReference_charDataRead = true; | - | ||||||||||||
7554 | } | - | ||||||||||||
7555 | break; | - | ||||||||||||
7556 | case InDTD: | - | ||||||||||||
7557 | // Forbidden | - | ||||||||||||
7558 | parseReference_charDataRead = false; | - | ||||||||||||
7559 | reportParseError(QLatin1String(XMLERR_INTERNALGENERALENTITYINDTD)); | - | ||||||||||||
7560 | return false; | - | ||||||||||||
7561 | } | - | ||||||||||||
7562 | } else { | - | ||||||||||||
7563 | QMap<QString,QXmlSimpleReaderPrivate::ExternEntity>::Iterator itExtern; | - | ||||||||||||
7564 | itExtern = externEntities.find(reference); | - | ||||||||||||
7565 | if (itExtern == externEntities.end()) { | - | ||||||||||||
7566 | // entity not declared | - | ||||||||||||
7567 | // ### check this case for conformance | - | ||||||||||||
7568 | if (parseReference_context == InEntityValue) { | - | ||||||||||||
7569 | // Bypassed | - | ||||||||||||
7570 | stringAddC(QLatin1Char('&')); | - | ||||||||||||
7571 | for (int i=0; i<(int)reference.length(); i++) { | - | ||||||||||||
7572 | stringAddC(reference[i]); | - | ||||||||||||
7573 | } | - | ||||||||||||
7574 | stringAddC(QLatin1Char(';')); | - | ||||||||||||
7575 | parseReference_charDataRead = true; | - | ||||||||||||
7576 | } else { | - | ||||||||||||
7577 | // if we have some char data read, report it now | - | ||||||||||||
7578 | if (parseReference_context == InContent) { | - | ||||||||||||
7579 | if (contentCharDataRead) { | - | ||||||||||||
7580 | if (reportWhitespaceCharData || !string().simplified().isEmpty()) { | - | ||||||||||||
7581 | if (contentHnd != 0 && !contentHnd->characters(string())) { | - | ||||||||||||
7582 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
7583 | return false; | - | ||||||||||||
7584 | } | - | ||||||||||||
7585 | } | - | ||||||||||||
7586 | stringClear(); | - | ||||||||||||
7587 | contentCharDataRead = false; | - | ||||||||||||
7588 | } | - | ||||||||||||
7589 | } | - | ||||||||||||
7590 | - | |||||||||||||
7591 | if (contentHnd) { | - | ||||||||||||
7592 | skipped_entity_in_content = parseReference_context == InContent; | - | ||||||||||||
7593 | if (!contentHnd->skippedEntity(reference)) { | - | ||||||||||||
7594 | skipped_entity_in_content = false; | - | ||||||||||||
7595 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
7596 | return false; // error | - | ||||||||||||
7597 | } | - | ||||||||||||
7598 | skipped_entity_in_content = false; | - | ||||||||||||
7599 | } | - | ||||||||||||
7600 | } | - | ||||||||||||
7601 | } else if ((*itExtern).notation.isNull()) { | - | ||||||||||||
7602 | // "External Parsed General" | - | ||||||||||||
7603 | switch (parseReference_context) { | - | ||||||||||||
7604 | case InContent: | - | ||||||||||||
7605 | { | - | ||||||||||||
7606 | // Included if validating | - | ||||||||||||
7607 | bool skipIt = true; | - | ||||||||||||
7608 | if (entityRes) { | - | ||||||||||||
7609 | QXmlInputSource *ret = 0; | - | ||||||||||||
7610 | if (!entityRes->resolveEntity((*itExtern).publicId, (*itExtern).systemId, ret)) { | - | ||||||||||||
7611 | delete ret; | - | ||||||||||||
7612 | reportParseError(entityRes->errorString()); | - | ||||||||||||
7613 | return false; | - | ||||||||||||
7614 | } | - | ||||||||||||
7615 | if (ret) { | - | ||||||||||||
7616 | QString xmlRefString; | - | ||||||||||||
7617 | QString buffer = ret->data(); | - | ||||||||||||
7618 | while (!buffer.isEmpty()) { | - | ||||||||||||
7619 | xmlRefString += buffer; | - | ||||||||||||
7620 | ret->fetchData(); | - | ||||||||||||
7621 | buffer = ret->data(); | - | ||||||||||||
7622 | } | - | ||||||||||||
7623 | - | |||||||||||||
7624 | delete ret; | - | ||||||||||||
7625 | if (!stripTextDecl(xmlRefString)) { | - | ||||||||||||
7626 | reportParseError(QLatin1String(XMLERR_ERRORINTEXTDECL)); | - | ||||||||||||
7627 | return false; | - | ||||||||||||
7628 | } | - | ||||||||||||
7629 | if (!insertXmlRef(xmlRefString, reference, false)) | - | ||||||||||||
7630 | return false; | - | ||||||||||||
7631 | skipIt = false; | - | ||||||||||||
7632 | } | - | ||||||||||||
7633 | } | - | ||||||||||||
7634 | if (skipIt && contentHnd) { | - | ||||||||||||
7635 | skipped_entity_in_content = true; | - | ||||||||||||
7636 | if (!contentHnd->skippedEntity(reference)) { | - | ||||||||||||
7637 | skipped_entity_in_content = false; | - | ||||||||||||
7638 | reportParseError(contentHnd->errorString()); | - | ||||||||||||
7639 | return false; // error | - | ||||||||||||
7640 | } | - | ||||||||||||
7641 | skipped_entity_in_content = false; | - | ||||||||||||
7642 | } | - | ||||||||||||
7643 | parseReference_charDataRead = false; | - | ||||||||||||
7644 | } break; | - | ||||||||||||
7645 | case InAttributeValue: | - | ||||||||||||
7646 | // Forbidden | - | ||||||||||||
7647 | parseReference_charDataRead = false; | - | ||||||||||||
7648 | reportParseError(QLatin1String(XMLERR_EXTERNALGENERALENTITYINAV)); | - | ||||||||||||
7649 | return false; | - | ||||||||||||
7650 | case InEntityValue: | - | ||||||||||||
7651 | { | - | ||||||||||||
7652 | // Bypassed | - | ||||||||||||
7653 | stringAddC(QLatin1Char('&')); | - | ||||||||||||
7654 | for (int i=0; i<(int)reference.length(); i++) { | - | ||||||||||||
7655 | stringAddC(reference[i]); | - | ||||||||||||
7656 | } | - | ||||||||||||
7657 | stringAddC(QLatin1Char(';')); | - | ||||||||||||
7658 | parseReference_charDataRead = true; | - | ||||||||||||
7659 | } | - | ||||||||||||
7660 | break; | - | ||||||||||||
7661 | case InDTD: | - | ||||||||||||
7662 | // Forbidden | - | ||||||||||||
7663 | parseReference_charDataRead = false; | - | ||||||||||||
7664 | reportParseError(QLatin1String(XMLERR_EXTERNALGENERALENTITYINDTD)); | - | ||||||||||||
7665 | return false; | - | ||||||||||||
7666 | } | - | ||||||||||||
7667 | } else { | - | ||||||||||||
7668 | // "Unparsed" | - | ||||||||||||
7669 | // ### notify for "Occurs as Attribute Value" missing (but this is no refence, anyway) | - | ||||||||||||
7670 | // Forbidden | - | ||||||||||||
7671 | parseReference_charDataRead = false; | - | ||||||||||||
7672 | reportParseError(QLatin1String(XMLERR_UNPARSEDENTITYREFERENCE)); | - | ||||||||||||
7673 | return false; // error | - | ||||||||||||
7674 | } | - | ||||||||||||
7675 | } | - | ||||||||||||
7676 | } | - | ||||||||||||
7677 | return true; // no error | - | ||||||||||||
7678 | } | - | ||||||||||||
7679 | - | |||||||||||||
7680 | - | |||||||||||||
7681 | /* | - | ||||||||||||
7682 | Parses over a simple string. | - | ||||||||||||
7683 | - | |||||||||||||
7684 | After the string was successfully parsed, the head is on the first | - | ||||||||||||
7685 | character after the string. | - | ||||||||||||
7686 | */ | - | ||||||||||||
7687 | bool QXmlSimpleReaderPrivate::parseString() | - | ||||||||||||
7688 | { | - | ||||||||||||
7689 | const signed char InpCharExpected = 0; // the character that was expected | - | ||||||||||||
7690 | const signed char InpUnknown = 1; | - | ||||||||||||
7691 | - | |||||||||||||
7692 | signed char state; // state in this function is the position in the string s | - | ||||||||||||
7693 | signed char input; | - | ||||||||||||
7694 | - | |||||||||||||
7695 | if (parseStack==0 || parseStack->isEmpty()) { | - | ||||||||||||
7696 | Done = parseString_s.length(); | - | ||||||||||||
7697 | state = 0; | - | ||||||||||||
7698 | } else { | - | ||||||||||||
7699 | state = parseStack->pop().state; | - | ||||||||||||
7700 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
7701 | qDebug("QXmlSimpleReader: parseString (cont) in state %d", state); | - | ||||||||||||
7702 | #endif | - | ||||||||||||
7703 | if (!parseStack->isEmpty()) { | - | ||||||||||||
7704 | ParseFunction function = parseStack->top().function; | - | ||||||||||||
7705 | if (function == &QXmlSimpleReaderPrivate::eat_ws) { | - | ||||||||||||
7706 | parseStack->pop(); | - | ||||||||||||
7707 | #if defined(QT_QXML_DEBUG) | - | ||||||||||||
7708 | qDebug("QXmlSimpleReader: eat_ws (cont)"); | - | ||||||||||||
7709 | #endif | - | ||||||||||||
7710 | } | - | ||||||||||||
7711 | if (!(this->*function)()) { | - | ||||||||||||
7712 | parseFailed(&QXmlSimpleReaderPrivate::parseString, state); | - | ||||||||||||
7713 | return false; | - | ||||||||||||
7714 | } | - | ||||||||||||
7715 | } | - | ||||||||||||
7716 | } | - | ||||||||||||
7717 | - | |||||||||||||
7718 | for (;;) { | - | ||||||||||||
7719 | if (state == Done) { | - | ||||||||||||
7720 | return true; | - | ||||||||||||
7721 | } | - | ||||||||||||
7722 | - | |||||||||||||
7723 | if (atEnd()) { | - | ||||||||||||
7724 | unexpectedEof(&QXmlSimpleReaderPrivate::parseString, state); | - | ||||||||||||
7725 | return false; | - | ||||||||||||
7726 | } | - | ||||||||||||
7727 | if (c == parseString_s[(int)state]) { | - | ||||||||||||
7728 | input = InpCharExpected; | - | ||||||||||||
7729 | } else { | - | ||||||||||||
7730 | input = InpUnknown; | - | ||||||||||||
7731 | } | - | ||||||||||||
7732 | if (input == InpCharExpected) { | - | ||||||||||||
7733 | state++; | - | ||||||||||||
7734 | } else { | - | ||||||||||||
7735 | // Error | - | ||||||||||||
7736 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDCHARACTER)); | - | ||||||||||||
7737 | return false; | - | ||||||||||||
7738 | } | - | ||||||||||||
7739 | - | |||||||||||||
7740 | next(); | - | ||||||||||||
7741 | } | - | ||||||||||||
7742 | return false; | - | ||||||||||||
7743 | } | - | ||||||||||||
7744 | - | |||||||||||||
7745 | /* | - | ||||||||||||
7746 | This private function inserts and reports an entity substitution. The | - | ||||||||||||
7747 | substituted string is \a data and the name of the entity reference is \a | - | ||||||||||||
7748 | name. If \a inLiteral is true, the entity is IncludedInLiteral (i.e., " and ' | - | ||||||||||||
7749 | must be quoted. Otherwise they are not quoted. | - | ||||||||||||
7750 | - | |||||||||||||
7751 | This function returns \c false on error. | - | ||||||||||||
7752 | */ | - | ||||||||||||
7753 | bool QXmlSimpleReaderPrivate::insertXmlRef(const QString &data, const QString &name, bool inLiteral) | - | ||||||||||||
7754 | { | - | ||||||||||||
7755 | if (inLiteral) { | - | ||||||||||||
7756 | QString tmp = data; | - | ||||||||||||
7757 | xmlRefStack.push(XmlRef(name, tmp.replace(QLatin1Char('\"'), | - | ||||||||||||
7758 | QLatin1String(""")).replace(QLatin1Char('\''), QLatin1String("'")))); | - | ||||||||||||
7759 | } else { | - | ||||||||||||
7760 | xmlRefStack.push(XmlRef(name, data)); | - | ||||||||||||
7761 | } | - | ||||||||||||
7762 | int n = qMax(parameterEntities.count(), entities.count()); | - | ||||||||||||
7763 | if (xmlRefStack.count() > n+1) { | - | ||||||||||||
7764 | // recursive entities | - | ||||||||||||
7765 | reportParseError(QLatin1String(XMLERR_RECURSIVEENTITIES)); | - | ||||||||||||
7766 | return false; | - | ||||||||||||
7767 | } | - | ||||||||||||
7768 | if (reportEntities && lexicalHnd) { | - | ||||||||||||
7769 | if (!lexicalHnd->startEntity(name)) { | - | ||||||||||||
7770 | reportParseError(lexicalHnd->errorString()); | - | ||||||||||||
7771 | return false; | - | ||||||||||||
7772 | } | - | ||||||||||||
7773 | } | - | ||||||||||||
7774 | return true; | - | ||||||||||||
7775 | } | - | ||||||||||||
7776 | - | |||||||||||||
7777 | /* | - | ||||||||||||
7778 | This private function moves the cursor to the next character. | - | ||||||||||||
7779 | */ | - | ||||||||||||
7780 | void QXmlSimpleReaderPrivate::next() | - | ||||||||||||
7781 | { | - | ||||||||||||
7782 | int count = xmlRefStack.size(); | - | ||||||||||||
7783 | while (count != 0) { | - | ||||||||||||
7784 | if (xmlRefStack.top().isEmpty()) { | - | ||||||||||||
7785 | xmlRefStack.pop_back(); | - | ||||||||||||
7786 | count--; | - | ||||||||||||
7787 | } else { | - | ||||||||||||
7788 | c = xmlRefStack.top().next(); | - | ||||||||||||
7789 | return; | - | ||||||||||||
7790 | } | - | ||||||||||||
7791 | } | - | ||||||||||||
7792 | - | |||||||||||||
7793 | // the following could be written nicer, but since it is a time-critical | - | ||||||||||||
7794 | // function, rather optimize for speed | - | ||||||||||||
7795 | ushort uc = c.unicode(); | - | ||||||||||||
7796 | c = inputSource->next(); | - | ||||||||||||
7797 | // If we are not incremental parsing, we just skip over EndOfData chars to give the | - | ||||||||||||
7798 | // parser an uninterrupted stream of document chars. | - | ||||||||||||
7799 | if (c == QXmlInputSource::EndOfData && parseStack == 0) | - | ||||||||||||
7800 | c = inputSource->next(); | - | ||||||||||||
7801 | if (uc == '\n') { | - | ||||||||||||
7802 | lineNr++; | - | ||||||||||||
7803 | columnNr = -1; | - | ||||||||||||
7804 | } else if (uc == '\r') { | - | ||||||||||||
7805 | if (c != QLatin1Char('\n')) { | - | ||||||||||||
7806 | lineNr++; | - | ||||||||||||
7807 | columnNr = -1; | - | ||||||||||||
7808 | } | - | ||||||||||||
7809 | } | - | ||||||||||||
7810 | ++columnNr; | - | ||||||||||||
7811 | } | - | ||||||||||||
7812 | - | |||||||||||||
7813 | /* | - | ||||||||||||
7814 | This private function moves the cursor to the next non-whitespace character. | - | ||||||||||||
7815 | This function does not move the cursor if the actual cursor position is a | - | ||||||||||||
7816 | non-whitespace charcter. | - | ||||||||||||
7817 | - | |||||||||||||
7818 | Returns \c false when you use incremental parsing and this function reaches EOF | - | ||||||||||||
7819 | with reading only whitespace characters. In this case it also poplulates the | - | ||||||||||||
7820 | parseStack with useful information. In all other cases, this function returns | - | ||||||||||||
7821 | true. | - | ||||||||||||
7822 | */ | - | ||||||||||||
7823 | bool QXmlSimpleReaderPrivate::eat_ws() | - | ||||||||||||
7824 | { | - | ||||||||||||
7825 | while (!atEnd()) { | - | ||||||||||||
7826 | if (!is_S(c)) { | - | ||||||||||||
7827 | return true; | - | ||||||||||||
7828 | } | - | ||||||||||||
7829 | next(); | - | ||||||||||||
7830 | } | - | ||||||||||||
7831 | if (parseStack != 0) { | - | ||||||||||||
7832 | unexpectedEof(&QXmlSimpleReaderPrivate::eat_ws, 0); | - | ||||||||||||
7833 | return false; | - | ||||||||||||
7834 | } | - | ||||||||||||
7835 | return true; | - | ||||||||||||
7836 | } | - | ||||||||||||
7837 | - | |||||||||||||
7838 | bool QXmlSimpleReaderPrivate::next_eat_ws() | - | ||||||||||||
7839 | { | - | ||||||||||||
7840 | next(); | - | ||||||||||||
7841 | return eat_ws(); | - | ||||||||||||
7842 | } | - | ||||||||||||
7843 | - | |||||||||||||
7844 | - | |||||||||||||
7845 | /* | - | ||||||||||||
7846 | This private function initializes the reader. \a i is the input source to | - | ||||||||||||
7847 | read the data from. | - | ||||||||||||
7848 | */ | - | ||||||||||||
7849 | void QXmlSimpleReaderPrivate::init(const QXmlInputSource *i) | - | ||||||||||||
7850 | { | - | ||||||||||||
7851 | lineNr = 0; | - | ||||||||||||
7852 | columnNr = -1; | - | ||||||||||||
7853 | inputSource = const_cast<QXmlInputSource *>(i); | - | ||||||||||||
7854 | initData(); | - | ||||||||||||
7855 | - | |||||||||||||
7856 | externParameterEntities.clear(); | - | ||||||||||||
7857 | parameterEntities.clear(); | - | ||||||||||||
7858 | externEntities.clear(); | - | ||||||||||||
7859 | entities.clear(); | - | ||||||||||||
7860 | - | |||||||||||||
7861 | tags.clear();(tags); | - | ||||||||||||
7862 | - | |||||||||||||
7863 | doctype.clear(); | - | ||||||||||||
7864 | xmlVersion.clear(); | - | ||||||||||||
7865 | encoding.clear(); | - | ||||||||||||
7866 | standalone = QXmlSimpleReaderPrivate::Unknown; | - | ||||||||||||
7867 | error.clear(); | - | ||||||||||||
7868 | } executed 2106 times by 6 tests: end of block Executed by:
| 2106 | ||||||||||||
7869 | - | |||||||||||||
7870 | /* | - | ||||||||||||
7871 | This private function initializes the XML data related variables. Especially, | - | ||||||||||||
7872 | it reads the data from the input source. | - | ||||||||||||
7873 | */ | - | ||||||||||||
7874 | void QXmlSimpleReaderPrivate::initData() | - | ||||||||||||
7875 | { | - | ||||||||||||
7876 | c = QXmlInputSource::EndOfData; | - | ||||||||||||
7877 | xmlRefStack.clear(); | - | ||||||||||||
7878 | next(); | - | ||||||||||||
7879 | } | - | ||||||||||||
7880 | - | |||||||||||||
7881 | /* | - | ||||||||||||
7882 | Returns \c true if a entity with the name \a e exists, | - | ||||||||||||
7883 | otherwise returns \c false. | - | ||||||||||||
7884 | */ | - | ||||||||||||
7885 | bool QXmlSimpleReaderPrivate::entityExist(const QString& e) const | - | ||||||||||||
7886 | { | - | ||||||||||||
7887 | if ( parameterEntities.find(e) == parameterEntities.end() && | - | ||||||||||||
7888 | externParameterEntities.find(e) == externParameterEntities.end() && | - | ||||||||||||
7889 | externEntities.find(e) == externEntities.end() && | - | ||||||||||||
7890 | entities.find(e) == entities.end()) { | - | ||||||||||||
7891 | return false; | - | ||||||||||||
7892 | } else { | - | ||||||||||||
7893 | return true; | - | ||||||||||||
7894 | } | - | ||||||||||||
7895 | } | - | ||||||||||||
7896 | - | |||||||||||||
7897 | void QXmlSimpleReaderPrivate::reportParseError(const QString& error) | - | ||||||||||||
7898 | { | - | ||||||||||||
7899 | this->error = error; | - | ||||||||||||
7900 | if (errorHnd) { | - | ||||||||||||
7901 | if (this->error.isNull()) { | - | ||||||||||||
7902 | const QXmlParseException ex(QLatin1String(XMLERR_OK), columnNr+1, lineNr+1, | - | ||||||||||||
7903 | thisPublicId, thisSystemId); | - | ||||||||||||
7904 | errorHnd->fatalError(ex); | - | ||||||||||||
7905 | } else { | - | ||||||||||||
7906 | const QXmlParseException ex(this->error, columnNr+1, lineNr+1, | - | ||||||||||||
7907 | thisPublicId, thisSystemId); | - | ||||||||||||
7908 | errorHnd->fatalError(ex); | - | ||||||||||||
7909 | } | - | ||||||||||||
7910 | } | - | ||||||||||||
7911 | } | - | ||||||||||||
7912 | - | |||||||||||||
7913 | /* | - | ||||||||||||
7914 | This private function is called when a parsing function encounters an | - | ||||||||||||
7915 | unexpected EOF. It decides what to do (depending on incremental parsing or | - | ||||||||||||
7916 | not). \a where is a pointer to the function where the error occurred and \a | - | ||||||||||||
7917 | state is the parsing state in this function. | - | ||||||||||||
7918 | */ | - | ||||||||||||
7919 | void QXmlSimpleReaderPrivate::unexpectedEof(ParseFunction where, int state) | - | ||||||||||||
7920 | { | - | ||||||||||||
7921 | if (parseStack == 0) { | - | ||||||||||||
7922 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDEOF)); | - | ||||||||||||
7923 | } else { | - | ||||||||||||
7924 | if (c == QXmlInputSource::EndOfDocument) { | - | ||||||||||||
7925 | reportParseError(QLatin1String(XMLERR_UNEXPECTEDEOF)); | - | ||||||||||||
7926 | } else { | - | ||||||||||||
7927 | pushParseState(where, state); | - | ||||||||||||
7928 | } | - | ||||||||||||
7929 | } | - | ||||||||||||
7930 | } | - | ||||||||||||
7931 | - | |||||||||||||
7932 | /* | - | ||||||||||||
7933 | This private function is called when a parse...() function returned false. It | - | ||||||||||||
7934 | determines if there was an error or if incremental parsing simply went out of | - | ||||||||||||
7935 | data and does the right thing for the case. \a where is a pointer to the | - | ||||||||||||
7936 | function where the error occurred and \a state is the parsing state in this | - | ||||||||||||
7937 | function. | - | ||||||||||||
7938 | */ | - | ||||||||||||
7939 | void QXmlSimpleReaderPrivate::parseFailed(ParseFunction where, int state) | - | ||||||||||||
7940 | { | - | ||||||||||||
7941 | if (parseStack!=0 && error.isNull()) { | - | ||||||||||||
7942 | pushParseState(where, state); | - | ||||||||||||
7943 | } | - | ||||||||||||
7944 | } | - | ||||||||||||
7945 | - | |||||||||||||
7946 | /* | - | ||||||||||||
7947 | This private function pushes the function pointer \a function and state \a | - | ||||||||||||
7948 | state to the parse stack. This is used when you are doing an incremental | - | ||||||||||||
7949 | parsing and reach the end of file too early. | - | ||||||||||||
7950 | - | |||||||||||||
7951 | Only call this function when d->parseStack!=0. | - | ||||||||||||
7952 | */ | - | ||||||||||||
7953 | void QXmlSimpleReaderPrivate::pushParseState(ParseFunction function, int state) | - | ||||||||||||
7954 | { | - | ||||||||||||
7955 | QXmlSimpleReaderPrivate::ParseState ps; | - | ||||||||||||
7956 | ps.function = function; | - | ||||||||||||
7957 | ps.state = state; | - | ||||||||||||
7958 | parseStack->push(ps); | - | ||||||||||||
7959 | } | - | ||||||||||||
7960 | - | |||||||||||||
7961 | inline static void updateValue(QString &value, const QChar *array, int &arrayPos, int &valueLen) | - | ||||||||||||
7962 | { | - | ||||||||||||
7963 | value.resize(valueLen + arrayPos); | - | ||||||||||||
7964 | memcpy(value.data() + valueLen, array, arrayPos * sizeof(QChar)); | - | ||||||||||||
7965 | valueLen += arrayPos; | - | ||||||||||||
7966 | arrayPos = 0; | - | ||||||||||||
7967 | } | - | ||||||||||||
7968 | - | |||||||||||||
7969 | // use buffers instead of QString::operator+= when single characters are read | - | ||||||||||||
7970 | const QString& QXmlSimpleReaderPrivate::string() | - | ||||||||||||
7971 | { | - | ||||||||||||
7972 | updateValue(stringValue, stringArray, stringArrayPos, stringValueLen); | - | ||||||||||||
7973 | return stringValue; | - | ||||||||||||
7974 | } | - | ||||||||||||
7975 | const QString& QXmlSimpleReaderPrivate::name() | - | ||||||||||||
7976 | { | - | ||||||||||||
7977 | updateValue(nameValue, nameArray, nameArrayPos, nameValueLen); | - | ||||||||||||
7978 | return nameValue; | - | ||||||||||||
7979 | } | - | ||||||||||||
7980 | const QString& QXmlSimpleReaderPrivate::ref() | - | ||||||||||||
7981 | { | - | ||||||||||||
7982 | updateValue(refValue, refArray, refArrayPos, refValueLen); | - | ||||||||||||
7983 | return refValue; | - | ||||||||||||
7984 | } | - | ||||||||||||
7985 | - | |||||||||||||
7986 | void QXmlSimpleReaderPrivate::stringAddC(QChar ch) | - | ||||||||||||
7987 | { | - | ||||||||||||
7988 | if (stringArrayPos == 256) | - | ||||||||||||
7989 | updateValue(stringValue, stringArray, stringArrayPos, stringValueLen); | - | ||||||||||||
7990 | stringArray[stringArrayPos++] = ch; | - | ||||||||||||
7991 | } | - | ||||||||||||
7992 | void QXmlSimpleReaderPrivate::nameAddC(QChar ch) | - | ||||||||||||
7993 | { | - | ||||||||||||
7994 | if (nameArrayPos == 256) | - | ||||||||||||
7995 | updateValue(nameValue, nameArray, nameArrayPos, nameValueLen); | - | ||||||||||||
7996 | nameArray[nameArrayPos++] = ch; | - | ||||||||||||
7997 | } | - | ||||||||||||
7998 | void QXmlSimpleReaderPrivate::refAddC(QChar ch) | - | ||||||||||||
7999 | { | - | ||||||||||||
8000 | if (refArrayPos == 256) | - | ||||||||||||
8001 | updateValue(refValue, refArray, refArrayPos, refValueLen); | - | ||||||||||||
8002 | refArray[refArrayPos++] = ch; | - | ||||||||||||
8003 | } | - | ||||||||||||
8004 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |