Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/xml/qxmlstream.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | - | |||||||
8 | - | |||||||
9 | enum { StreamEOF = ~0U }; | - | ||||||
10 | QXmlStreamEntityResolver::~QXmlStreamEntityResolver() | - | ||||||
11 | { | - | ||||||
12 | } | - | ||||||
13 | - | |||||||
14 | - | |||||||
15 | - | |||||||
16 | - | |||||||
17 | - | |||||||
18 | - | |||||||
19 | QString QXmlStreamEntityResolver::resolveEntity(const QString& , const QString& ) | - | ||||||
20 | { | - | ||||||
21 | return QString(); | - | ||||||
22 | } | - | ||||||
23 | QString QXmlStreamEntityResolver::resolveUndeclaredEntity(const QString & ) | - | ||||||
24 | { | - | ||||||
25 | return QString(); | - | ||||||
26 | } | - | ||||||
27 | - | |||||||
28 | - | |||||||
29 | - | |||||||
30 | QString QXmlStreamReaderPrivate::resolveUndeclaredEntity(const QString &name) | - | ||||||
31 | { | - | ||||||
32 | if (entityResolver) | - | ||||||
33 | return entityResolver->resolveUndeclaredEntity(name); | - | ||||||
34 | return QString(); | - | ||||||
35 | } | - | ||||||
36 | void QXmlStreamReader::setEntityResolver(QXmlStreamEntityResolver *resolver) | - | ||||||
37 | { | - | ||||||
38 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
39 | d->entityResolver = resolver; | - | ||||||
40 | } | - | ||||||
41 | QXmlStreamEntityResolver *QXmlStreamReader::entityResolver() const | - | ||||||
42 | { | - | ||||||
43 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
44 | return d->entityResolver; | - | ||||||
45 | } | - | ||||||
46 | QXmlStreamReader::QXmlStreamReader() | - | ||||||
47 | : d_ptr(new QXmlStreamReaderPrivate(this)) | - | ||||||
48 | { | - | ||||||
49 | } | - | ||||||
50 | - | |||||||
51 | - | |||||||
52 | - | |||||||
53 | - | |||||||
54 | - | |||||||
55 | QXmlStreamReader::QXmlStreamReader(QIODevice *device) | - | ||||||
56 | : d_ptr(new QXmlStreamReaderPrivate(this)) | - | ||||||
57 | { | - | ||||||
58 | setDevice(device); | - | ||||||
59 | } | - | ||||||
60 | - | |||||||
61 | - | |||||||
62 | - | |||||||
63 | - | |||||||
64 | - | |||||||
65 | - | |||||||
66 | QXmlStreamReader::QXmlStreamReader(const QByteArray &data) | - | ||||||
67 | : d_ptr(new QXmlStreamReaderPrivate(this)) | - | ||||||
68 | { | - | ||||||
69 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
70 | d->dataBuffer = data; | - | ||||||
71 | } | - | ||||||
72 | - | |||||||
73 | - | |||||||
74 | - | |||||||
75 | - | |||||||
76 | - | |||||||
77 | - | |||||||
78 | QXmlStreamReader::QXmlStreamReader(const QString &data) | - | ||||||
79 | : d_ptr(new QXmlStreamReaderPrivate(this)) | - | ||||||
80 | { | - | ||||||
81 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
82 | - | |||||||
83 | - | |||||||
84 | - | |||||||
85 | d->dataBuffer = d->codec->fromUnicode(data); | - | ||||||
86 | d->decoder = d->codec->makeDecoder(); | - | ||||||
87 | - | |||||||
88 | d->lockEncoding = true; | - | ||||||
89 | - | |||||||
90 | } | - | ||||||
91 | - | |||||||
92 | - | |||||||
93 | - | |||||||
94 | - | |||||||
95 | - | |||||||
96 | - | |||||||
97 | QXmlStreamReader::QXmlStreamReader(const char *data) | - | ||||||
98 | : d_ptr(new QXmlStreamReaderPrivate(this)) | - | ||||||
99 | { | - | ||||||
100 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
101 | d->dataBuffer = QByteArray(data); | - | ||||||
102 | } | - | ||||||
103 | - | |||||||
104 | - | |||||||
105 | - | |||||||
106 | - | |||||||
107 | QXmlStreamReader::~QXmlStreamReader() | - | ||||||
108 | { | - | ||||||
109 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
110 | if (d->deleteDevice) | - | ||||||
111 | delete d->device; | - | ||||||
112 | } | - | ||||||
113 | void QXmlStreamReader::setDevice(QIODevice *device) | - | ||||||
114 | { | - | ||||||
115 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
116 | if (d->deleteDevice) { | - | ||||||
117 | delete d->device; | - | ||||||
118 | d->deleteDevice = false; | - | ||||||
119 | } | - | ||||||
120 | d->device = device; | - | ||||||
121 | d->init(); | - | ||||||
122 | - | |||||||
123 | } | - | ||||||
124 | - | |||||||
125 | - | |||||||
126 | - | |||||||
127 | - | |||||||
128 | - | |||||||
129 | - | |||||||
130 | - | |||||||
131 | QIODevice *QXmlStreamReader::device() const | - | ||||||
132 | { | - | ||||||
133 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
134 | return d->device; | - | ||||||
135 | } | - | ||||||
136 | void QXmlStreamReader::addData(const QByteArray &data) | - | ||||||
137 | { | - | ||||||
138 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
139 | if (d->device) { | - | ||||||
140 | QMessageLogger(__FILE__, 491497, __PRETTY_FUNCTION__).warning("QXmlStreamReader: addData() with device()"); | - | ||||||
141 | return; | - | ||||||
142 | } | - | ||||||
143 | d->dataBuffer += data; | - | ||||||
144 | } | - | ||||||
145 | - | |||||||
146 | - | |||||||
147 | - | |||||||
148 | - | |||||||
149 | - | |||||||
150 | - | |||||||
151 | - | |||||||
152 | void QXmlStreamReader::addData(const QString &data) | - | ||||||
153 | { | - | ||||||
154 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
155 | d->lockEncoding = true; | - | ||||||
156 | - | |||||||
157 | - | |||||||
158 | - | |||||||
159 | addData(d->codec->fromUnicode(data)); | - | ||||||
160 | - | |||||||
161 | } | - | ||||||
162 | - | |||||||
163 | - | |||||||
164 | - | |||||||
165 | - | |||||||
166 | - | |||||||
167 | - | |||||||
168 | - | |||||||
169 | void QXmlStreamReader::addData(const char *data) | - | ||||||
170 | { | - | ||||||
171 | addData(QByteArray(data)); | - | ||||||
172 | } | - | ||||||
173 | - | |||||||
174 | - | |||||||
175 | - | |||||||
176 | - | |||||||
177 | - | |||||||
178 | - | |||||||
179 | - | |||||||
180 | void QXmlStreamReader::clear() | - | ||||||
181 | { | - | ||||||
182 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
183 | d->init(); | - | ||||||
184 | if (d->device) { | - | ||||||
185 | if (d->deleteDevice) | - | ||||||
186 | delete d->device; | - | ||||||
187 | d->device = 0; | - | ||||||
188 | } | - | ||||||
189 | } | - | ||||||
190 | bool QXmlStreamReader::atEnd() const | - | ||||||
191 | { | - | ||||||
192 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
193 | if (d->atEnd | - | ||||||
194 | && ((d->type == QXmlStreamReader::Invalid && d->error == PrematureEndOfDocumentError) | - | ||||||
195 | || (d->type == QXmlStreamReader::EndDocument))) { | - | ||||||
196 | if (d->device) | - | ||||||
197 | return d->device->atEnd(); | - | ||||||
198 | else | - | ||||||
199 | return !d->dataBuffer.size(); | - | ||||||
200 | } | - | ||||||
201 | return (d->atEnd || d->type == QXmlStreamReader::Invalid); | - | ||||||
202 | } | - | ||||||
203 | QXmlStreamReader::TokenType QXmlStreamReader::readNext() | - | ||||||
204 | { | - | ||||||
205 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
206 | if (d->type != Invalid) { | - | ||||||
207 | if (!d->hasCheckedStartDocument) | - | ||||||
208 | if (!d->checkStartDocument()) | - | ||||||
209 | return d->type; | - | ||||||
210 | d->parse(); | - | ||||||
211 | if (d->atEnd && d->type != EndDocument && d->type != Invalid) | - | ||||||
212 | d->raiseError(PrematureEndOfDocumentError); | - | ||||||
213 | else if (!d->atEnd && d->type == EndDocument) | - | ||||||
214 | d->raiseWellFormedError(QXmlStream::tr("Extra content at end of document.")); | - | ||||||
215 | } else if (d->error == PrematureEndOfDocumentError) { | - | ||||||
216 | - | |||||||
217 | d->type = NoToken; | - | ||||||
218 | d->atEnd = false; | - | ||||||
219 | d->token = -1; | - | ||||||
220 | return readNext(); | - | ||||||
221 | } | - | ||||||
222 | return d->type; | - | ||||||
223 | } | - | ||||||
224 | QXmlStreamReader::TokenType QXmlStreamReader::tokenType() const | - | ||||||
225 | { | - | ||||||
226 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
227 | return d->type; | - | ||||||
228 | } | - | ||||||
229 | bool QXmlStreamReader::readNextStartElement() | - | ||||||
230 | { | - | ||||||
231 | while (readNext() != Invalid) { | - | ||||||
232 | if (isEndElement()) | - | ||||||
233 | return false; | - | ||||||
234 | else if (isStartElement()) | - | ||||||
235 | return true; | - | ||||||
236 | } | - | ||||||
237 | return false; | - | ||||||
238 | } | - | ||||||
239 | void QXmlStreamReader::skipCurrentElement() | - | ||||||
240 | { | - | ||||||
241 | int depth = 1; | - | ||||||
242 | while (depth && readNext() != Invalid) { | - | ||||||
243 | if (isEndElement()) | - | ||||||
244 | --depth; | - | ||||||
245 | else if (isStartElement()) | - | ||||||
246 | ++depth; | - | ||||||
247 | } | - | ||||||
248 | } | - | ||||||
249 | static const char QXmlStreamReader_tokenTypeString_string[] = | - | ||||||
250 | "NoToken\0" | - | ||||||
251 | "Invalid\0" | - | ||||||
252 | "StartDocument\0" | - | ||||||
253 | "EndDocument\0" | - | ||||||
254 | "StartElement\0" | - | ||||||
255 | "EndElement\0" | - | ||||||
256 | "Characters\0" | - | ||||||
257 | "Comment\0" | - | ||||||
258 | "DTD\0" | - | ||||||
259 | "EntityReference\0" | - | ||||||
260 | "ProcessingInstruction\0"; | - | ||||||
261 | - | |||||||
262 | static const short QXmlStreamReader_tokenTypeString_indices[] = { | - | ||||||
263 | 0, 8, 16, 30, 42, 55, 66, 77, 85, 89, 105, 0 | - | ||||||
264 | }; | - | ||||||
265 | void QXmlStreamReader::setNamespaceProcessing(bool enable) | - | ||||||
266 | { | - | ||||||
267 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
268 | d->namespaceProcessing = enable; | - | ||||||
269 | } | - | ||||||
270 | - | |||||||
271 | bool QXmlStreamReader::namespaceProcessing() const | - | ||||||
272 | { | - | ||||||
273 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
274 | return d->namespaceProcessing; | - | ||||||
275 | } | - | ||||||
276 | - | |||||||
277 | - | |||||||
278 | - | |||||||
279 | - | |||||||
280 | - | |||||||
281 | QString QXmlStreamReader::tokenString() const | - | ||||||
282 | { | - | ||||||
283 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
284 | return QLatin1String(QXmlStreamReader_tokenTypeString_string + | - | ||||||
285 | QXmlStreamReader_tokenTypeString_indices[d->type]); | - | ||||||
286 | } | - | ||||||
287 | - | |||||||
288 | - | |||||||
289 | - | |||||||
290 | QXmlStreamPrivateTagStack::QXmlStreamPrivateTagStack() | - | ||||||
291 | { | - | ||||||
292 | tagStack.reserve(16); | - | ||||||
293 | tagStackStringStorage.reserve(32); | - | ||||||
294 | tagStackStringStorageSize = 0; | - | ||||||
295 | NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push(); | - | ||||||
296 | namespaceDeclaration.prefix = addToStringStorage(QLatin1String("xml")); | - | ||||||
297 | namespaceDeclaration.namespaceUri = addToStringStorage(QLatin1String("http://www.w3.org/XML/1998/namespace")); | - | ||||||
298 | initialTagStackStringStorageSize = tagStackStringStorageSize; | - | ||||||
299 | } | - | ||||||
300 | - | |||||||
301 | - | |||||||
302 | - | |||||||
303 | QXmlStreamReaderPrivate::QXmlStreamReaderPrivate(QXmlStreamReader *q) | - | ||||||
304 | :q_ptr(q) | - | ||||||
305 | { | - | ||||||
306 | device = 0; | - | ||||||
307 | deleteDevice = false; | - | ||||||
308 | - | |||||||
309 | decoder = 0; | - | ||||||
310 | - | |||||||
311 | stack_size = 64; | - | ||||||
312 | sym_stack = 0; | - | ||||||
313 | state_stack = 0; | - | ||||||
314 | reallocateStack(); | - | ||||||
315 | entityResolver = 0; | - | ||||||
316 | init(); | - | ||||||
317 | entityHash.insert(QLatin1String("lt"), Entity::createLiteral(QLatin1String("<"))); | - | ||||||
318 | entityHash.insert(QLatin1String("gt"), Entity::createLiteral(QLatin1String(">"))); | - | ||||||
319 | entityHash.insert(QLatin1String("amp"), Entity::createLiteral(QLatin1String("&"))); | - | ||||||
320 | entityHash.insert(QLatin1String("apos"), Entity::createLiteral(QLatin1String("'"))); | - | ||||||
321 | entityHash.insert(QLatin1String("quot"), Entity::createLiteral(QLatin1String("\""))); | - | ||||||
322 | } | - | ||||||
323 | - | |||||||
324 | void QXmlStreamReaderPrivate::init() | - | ||||||
325 | { | - | ||||||
326 | scanDtd = false; | - | ||||||
327 | token = -1; | - | ||||||
328 | token_char = 0; | - | ||||||
329 | isEmptyElement = false; | - | ||||||
330 | isWhitespace = true; | - | ||||||
331 | isCDATA = false; | - | ||||||
332 | standalone = false; | - | ||||||
333 | tos = 0; | - | ||||||
334 | resumeReduction = 0; | - | ||||||
335 | state_stack[tos++] = 0; | - | ||||||
336 | state_stack[tos] = 0; | - | ||||||
337 | putStack.clear(); | - | ||||||
338 | putStack.reserve(32); | - | ||||||
339 | textBuffer.clear(); | - | ||||||
340 | textBuffer.reserve(256); | - | ||||||
341 | tagStack.clear(); | - | ||||||
342 | tagsDone = false; | - | ||||||
343 | attributes.clear(); | - | ||||||
344 | attributes.reserve(16); | - | ||||||
345 | lineNumber = lastLineStart = characterOffset = 0; | - | ||||||
346 | readBufferPos = 0; | - | ||||||
347 | nbytesread = 0; | - | ||||||
348 | - | |||||||
349 | codec = QTextCodec::codecForMib(106); | - | ||||||
350 | delete decoder; | - | ||||||
351 | decoder = 0; | - | ||||||
352 | - | |||||||
353 | attributeStack.clear(); | - | ||||||
354 | attributeStack.reserve(16); | - | ||||||
355 | entityParser = 0; | - | ||||||
356 | hasCheckedStartDocument = false; | - | ||||||
357 | normalizeLiterals = false; | - | ||||||
358 | hasSeenTag = false; | - | ||||||
359 | atEnd = false; | - | ||||||
360 | inParseEntity = false; | - | ||||||
361 | referenceToUnparsedEntityDetected = false; | - | ||||||
362 | referenceToParameterEntityDetected = false; | - | ||||||
363 | hasExternalDtdSubset = false; | - | ||||||
364 | lockEncoding = false; | - | ||||||
365 | namespaceProcessing = true; | - | ||||||
366 | rawReadBuffer.clear(); | - | ||||||
367 | dataBuffer.clear(); | - | ||||||
368 | readBuffer.clear(); | - | ||||||
369 | tagStackStringStorageSize = initialTagStackStringStorageSize; | - | ||||||
370 | - | |||||||
371 | type = QXmlStreamReader::NoToken; | - | ||||||
372 | error = QXmlStreamReader::NoError; | - | ||||||
373 | } | - | ||||||
374 | - | |||||||
375 | - | |||||||
376 | - | |||||||
377 | - | |||||||
378 | - | |||||||
379 | void QXmlStreamReaderPrivate::parseEntity(const QString &value) | - | ||||||
380 | { | - | ||||||
381 | QXmlStreamReader * const q = q_func(); | - | ||||||
382 | - | |||||||
383 | if (value.isEmpty()) | - | ||||||
384 | return; | - | ||||||
385 | - | |||||||
386 | - | |||||||
387 | if (!entityParser) | - | ||||||
388 | entityParser = new QXmlStreamReaderPrivate(q); | - | ||||||
389 | else | - | ||||||
390 | entityParser->init(); | - | ||||||
391 | entityParser->inParseEntity = true; | - | ||||||
392 | entityParser->readBuffer = value; | - | ||||||
393 | entityParser->injectToken(PARSE_ENTITY); | - | ||||||
394 | while (!entityParser->atEnd && entityParser->type != QXmlStreamReader::Invalid) | - | ||||||
395 | entityParser->parse(); | - | ||||||
396 | if (entityParser->type == QXmlStreamReader::Invalid || entityParser->tagStack.size()) | - | ||||||
397 | raiseWellFormedError(QXmlStream::tr("Invalid entity value.")); | - | ||||||
398 | - | |||||||
399 | } | - | ||||||
400 | - | |||||||
401 | inline void QXmlStreamReaderPrivate::reallocateStack() | - | ||||||
402 | { | - | ||||||
403 | stack_size <<= 1; | - | ||||||
404 | sym_stack = reinterpret_cast<Value*> (realloc(sym_stack, stack_size * sizeof(Value))); | - | ||||||
405 | do { if (!(sym_stack)) qBadAlloc(); } while (0); | - | ||||||
406 | state_stack = reinterpret_cast<int*> (realloc(state_stack, stack_size * sizeof(int))); | - | ||||||
407 | do { if (!(state_stack)) qBadAlloc(); } while (0); | - | ||||||
408 | } | - | ||||||
409 | - | |||||||
410 | - | |||||||
411 | QXmlStreamReaderPrivate::~QXmlStreamReaderPrivate() | - | ||||||
412 | { | - | ||||||
413 | - | |||||||
414 | delete decoder; | - | ||||||
415 | - | |||||||
416 | free(sym_stack); | - | ||||||
417 | free(state_stack); | - | ||||||
418 | delete entityParser; | - | ||||||
419 | } | - | ||||||
420 | - | |||||||
421 | - | |||||||
422 | inline uint QXmlStreamReaderPrivate::filterCarriageReturn() | - | ||||||
423 | { | - | ||||||
424 | uint peekc = peekChar(); | - | ||||||
425 | if (peekc == '\n') { | - | ||||||
426 | if (putStack.size()) | - | ||||||
427 | putStack.pop(); | - | ||||||
428 | else | - | ||||||
429 | ++readBufferPos; | - | ||||||
430 | return peekc; | - | ||||||
431 | } | - | ||||||
432 | if (peekc == StreamEOF) { | - | ||||||
433 | putChar('\r'); | - | ||||||
434 | return 0; | - | ||||||
435 | } | - | ||||||
436 | return '\n'; | - | ||||||
437 | } | - | ||||||
438 | - | |||||||
439 | - | |||||||
440 | - | |||||||
441 | - | |||||||
442 | - | |||||||
443 | inline uint QXmlStreamReaderPrivate::getChar() | - | ||||||
444 | { | - | ||||||
445 | uint c; | - | ||||||
446 | if (putStack.size()) { | - | ||||||
447 | c = atEnd ? StreamEOF : putStack.pop(); | - | ||||||
448 | } else { | - | ||||||
449 | if (readBufferPos < readBuffer.size()) | - | ||||||
450 | c = readBuffer.at(readBufferPos++).unicode(); | - | ||||||
451 | else | - | ||||||
452 | c = getChar_helper(); | - | ||||||
453 | } | - | ||||||
454 | - | |||||||
455 | return c; | - | ||||||
456 | } | - | ||||||
457 | - | |||||||
458 | inline uint QXmlStreamReaderPrivate::peekChar() | - | ||||||
459 | { | - | ||||||
460 | uint c; | - | ||||||
461 | if (putStack.size()) { | - | ||||||
462 | c = putStack.top(); | - | ||||||
463 | } else if (readBufferPos < readBuffer.size()) { | - | ||||||
464 | c = readBuffer.at(readBufferPos).unicode(); | - | ||||||
465 | } else { | - | ||||||
466 | if ((c = getChar_helper()) != StreamEOF) | - | ||||||
467 | --readBufferPos; | - | ||||||
468 | } | - | ||||||
469 | - | |||||||
470 | return c; | - | ||||||
471 | } | - | ||||||
472 | bool QXmlStreamReaderPrivate::scanUntil(const char *str, short tokenToInject) | - | ||||||
473 | { | - | ||||||
474 | int pos = textBuffer.size(); | - | ||||||
475 | int oldLineNumber = lineNumber; | - | ||||||
476 | - | |||||||
477 | uint c; | - | ||||||
478 | while ((c = getChar()) != StreamEOF) { | - | ||||||
479 | - | |||||||
480 | switch (c) { | - | ||||||
481 | case '\r': | - | ||||||
482 | if ((c = filterCarriageReturn()) == 0) | - | ||||||
483 | break; | - | ||||||
484 | - | |||||||
485 | case '\n': | - | ||||||
486 | ++lineNumber; | - | ||||||
487 | lastLineStart = characterOffset + readBufferPos; | - | ||||||
488 | - | |||||||
489 | case '\t': | - | ||||||
490 | textBuffer += QChar(c); | - | ||||||
491 | continue; | - | ||||||
492 | default: | - | ||||||
493 | if (c < 0x20 || (c > 0xFFFD && c < 0x10000) || c > QChar::LastValidCodePoint ) { | - | ||||||
494 | raiseWellFormedError(QXmlStream::tr("Invalid XML character.")); | - | ||||||
495 | lineNumber = oldLineNumber; | - | ||||||
496 | return false; | - | ||||||
497 | } | - | ||||||
498 | textBuffer += QChar(c); | - | ||||||
499 | } | - | ||||||
500 | - | |||||||
501 | - | |||||||
502 | - | |||||||
503 | if (c == uint(*str)) { | - | ||||||
504 | if (!*(str + 1)) { | - | ||||||
505 | if (tokenToInject >= 0) | - | ||||||
506 | injectToken(tokenToInject); | - | ||||||
507 | return true; | - | ||||||
508 | } else { | - | ||||||
509 | if (scanString(str + 1, tokenToInject, false)) | - | ||||||
510 | return true; | - | ||||||
511 | } | - | ||||||
512 | } | - | ||||||
513 | } | - | ||||||
514 | putString(textBuffer, pos); | - | ||||||
515 | textBuffer.resize(pos); | - | ||||||
516 | lineNumber = oldLineNumber; | - | ||||||
517 | return false; | - | ||||||
518 | } | - | ||||||
519 | - | |||||||
520 | bool QXmlStreamReaderPrivate::scanString(const char *str, short tokenToInject, bool requireSpace) | - | ||||||
521 | { | - | ||||||
522 | int n = 0; | - | ||||||
523 | while (str[n]) { | - | ||||||
524 | uint c = getChar(); | - | ||||||
525 | if (c != ushort(str[n])) { | - | ||||||
526 | if (c != StreamEOF) | - | ||||||
527 | putChar(c); | - | ||||||
528 | while (n--) { | - | ||||||
529 | putChar(ushort(str[n])); | - | ||||||
530 | } | - | ||||||
531 | return false; | - | ||||||
532 | } | - | ||||||
533 | ++n; | - | ||||||
534 | } | - | ||||||
535 | for (int i = 0; i < n; ++i) | - | ||||||
536 | textBuffer += QChar(ushort(str[i])); | - | ||||||
537 | if (requireSpace) { | - | ||||||
538 | int s = fastScanSpace(); | - | ||||||
539 | if (!s || atEnd) { | - | ||||||
540 | int pos = textBuffer.size() - n - s; | - | ||||||
541 | putString(textBuffer, pos); | - | ||||||
542 | textBuffer.resize(pos); | - | ||||||
543 | return false; | - | ||||||
544 | } | - | ||||||
545 | } | - | ||||||
546 | if (tokenToInject >= 0) | - | ||||||
547 | injectToken(tokenToInject); | - | ||||||
548 | return true; | - | ||||||
549 | } | - | ||||||
550 | - | |||||||
551 | bool QXmlStreamReaderPrivate::scanAfterLangleBang() | - | ||||||
552 | { | - | ||||||
553 | switch (peekChar()) { | - | ||||||
554 | case '[': | - | ||||||
555 | return scanString(spell[CDATA_START], CDATA_START, false); | - | ||||||
556 | case 'D': | - | ||||||
557 | return scanString(spell[DOCTYPE], DOCTYPE); | - | ||||||
558 | case 'A': | - | ||||||
559 | return scanString(spell[ATTLIST], ATTLIST); | - | ||||||
560 | case 'N': | - | ||||||
561 | return scanString(spell[NOTATION], NOTATION); | - | ||||||
562 | case 'E': | - | ||||||
563 | if (scanString(spell[ELEMENT], ELEMENT)) | - | ||||||
564 | return true; | - | ||||||
565 | return scanString(spell[ENTITY], ENTITY); | - | ||||||
566 | - | |||||||
567 | default: | - | ||||||
568 | ; | - | ||||||
569 | }; | - | ||||||
570 | return false; | - | ||||||
571 | } | - | ||||||
572 | - | |||||||
573 | bool QXmlStreamReaderPrivate::scanPublicOrSystem() | - | ||||||
574 | { | - | ||||||
575 | switch (peekChar()) { | - | ||||||
576 | case 'S': | - | ||||||
577 | return scanString(spell[SYSTEM], SYSTEM); | - | ||||||
578 | case 'P': | - | ||||||
579 | return scanString(spell[PUBLIC], PUBLIC); | - | ||||||
580 | default: | - | ||||||
581 | ; | - | ||||||
582 | } | - | ||||||
583 | return false; | - | ||||||
584 | } | - | ||||||
585 | - | |||||||
586 | bool QXmlStreamReaderPrivate::scanNData() | - | ||||||
587 | { | - | ||||||
588 | if (fastScanSpace()) { | - | ||||||
589 | if (scanString(spell[NDATA], NDATA)) | - | ||||||
590 | return true; | - | ||||||
591 | putChar(' '); | - | ||||||
592 | } | - | ||||||
593 | return false; | - | ||||||
594 | } | - | ||||||
595 | - | |||||||
596 | bool QXmlStreamReaderPrivate::scanAfterDefaultDecl() | - | ||||||
597 | { | - | ||||||
598 | switch (peekChar()) { | - | ||||||
599 | case 'R': | - | ||||||
600 | return scanString(spell[REQUIRED], REQUIRED, false); | - | ||||||
601 | case 'I': | - | ||||||
602 | return scanString(spell[IMPLIED], IMPLIED, false); | - | ||||||
603 | case 'F': | - | ||||||
604 | return scanString(spell[FIXED], FIXED, false); | - | ||||||
605 | default: | - | ||||||
606 | ; | - | ||||||
607 | } | - | ||||||
608 | return false; | - | ||||||
609 | } | - | ||||||
610 | - | |||||||
611 | bool QXmlStreamReaderPrivate::scanAttType() | - | ||||||
612 | { | - | ||||||
613 | switch (peekChar()) { | - | ||||||
614 | case 'C': | - | ||||||
615 | return scanString(spell[CDATA], CDATA); | - | ||||||
616 | case 'I': | - | ||||||
617 | if (scanString(spell[ID], ID)) | - | ||||||
618 | return true; | - | ||||||
619 | if (scanString(spell[IDREF], IDREF)) | - | ||||||
620 | return true; | - | ||||||
621 | return scanString(spell[IDREFS], IDREFS); | - | ||||||
622 | case 'E': | - | ||||||
623 | if (scanString(spell[ENTITY], ENTITY)) | - | ||||||
624 | return true; | - | ||||||
625 | return scanString(spell[ENTITIES], ENTITIES); | - | ||||||
626 | case 'N': | - | ||||||
627 | if (scanString(spell[NOTATION], NOTATION)) | - | ||||||
628 | return true; | - | ||||||
629 | if (scanString(spell[NMTOKEN], NMTOKEN)) | - | ||||||
630 | return true; | - | ||||||
631 | return scanString(spell[NMTOKENS], NMTOKENS); | - | ||||||
632 | default: | - | ||||||
633 | ; | - | ||||||
634 | } | - | ||||||
635 | return false; | - | ||||||
636 | } | - | ||||||
637 | inline int QXmlStreamReaderPrivate::fastScanLiteralContent() | - | ||||||
638 | { | - | ||||||
639 | int n = 0; | - | ||||||
640 | uint c; | - | ||||||
641 | while ((c = getChar()) != StreamEOF) { | - | ||||||
642 | switch (ushort(c)) { | - | ||||||
643 | case 0xfffe: | - | ||||||
644 | case 0xffff: | - | ||||||
645 | case 0: | - | ||||||
646 | - | |||||||
647 | - | |||||||
648 | putChar(c); | - | ||||||
649 | return n; | - | ||||||
650 | case '\r': | - | ||||||
651 | if (filterCarriageReturn() == 0) | - | ||||||
652 | return n; | - | ||||||
653 | - | |||||||
654 | case '\n': | - | ||||||
655 | ++lineNumber; | - | ||||||
656 | lastLineStart = characterOffset + readBufferPos; | - | ||||||
657 | - | |||||||
658 | case ' ': | - | ||||||
659 | case '\t': | - | ||||||
660 | if (normalizeLiterals) | - | ||||||
661 | textBuffer += QLatin1Char(' '); | - | ||||||
662 | else | - | ||||||
663 | textBuffer += QChar(c); | - | ||||||
664 | ++n; | - | ||||||
665 | break; | - | ||||||
666 | case '&': | - | ||||||
667 | case '<': | - | ||||||
668 | case '\"': | - | ||||||
669 | case '\'': | - | ||||||
670 | if (!(c & 0xff0000)) { | - | ||||||
671 | putChar(c); | - | ||||||
672 | return n; | - | ||||||
673 | } | - | ||||||
674 | - | |||||||
675 | default: | - | ||||||
676 | if (c < 0x20) { | - | ||||||
677 | putChar(c); | - | ||||||
678 | return n; | - | ||||||
679 | } | - | ||||||
680 | textBuffer += QChar(c); | - | ||||||
681 | ++n; | - | ||||||
682 | } | - | ||||||
683 | } | - | ||||||
684 | return n; | - | ||||||
685 | } | - | ||||||
686 | - | |||||||
687 | inline int QXmlStreamReaderPrivate::fastScanSpace() | - | ||||||
688 | { | - | ||||||
689 | int n = 0; | - | ||||||
690 | uint c; | - | ||||||
691 | while ((c = getChar()) != StreamEOF) { | - | ||||||
692 | switch (c) { | - | ||||||
693 | case '\r': | - | ||||||
694 | if ((c = filterCarriageReturn()) == 0) | - | ||||||
695 | return n; | - | ||||||
696 | - | |||||||
697 | case '\n': | - | ||||||
698 | ++lineNumber; | - | ||||||
699 | lastLineStart = characterOffset + readBufferPos; | - | ||||||
700 | - | |||||||
701 | case ' ': | - | ||||||
702 | case '\t': | - | ||||||
703 | textBuffer += QChar(c); | - | ||||||
704 | ++n; | - | ||||||
705 | break; | - | ||||||
706 | default: | - | ||||||
707 | putChar(c); | - | ||||||
708 | return n; | - | ||||||
709 | } | - | ||||||
710 | } | - | ||||||
711 | return n; | - | ||||||
712 | } | - | ||||||
713 | - | |||||||
714 | - | |||||||
715 | - | |||||||
716 | - | |||||||
717 | - | |||||||
718 | - | |||||||
719 | - | |||||||
720 | inline int QXmlStreamReaderPrivate::fastScanContentCharList() | - | ||||||
721 | { | - | ||||||
722 | int n = 0; | - | ||||||
723 | uint c; | - | ||||||
724 | while ((c = getChar()) != StreamEOF) { | - | ||||||
725 | switch (ushort(c)) { | - | ||||||
726 | case 0xfffe: | - | ||||||
727 | case 0xffff: | - | ||||||
728 | case 0: | - | ||||||
729 | putChar(c); | - | ||||||
730 | return n; | - | ||||||
731 | case ']': { | - | ||||||
732 | isWhitespace = false; | - | ||||||
733 | int pos = textBuffer.size(); | - | ||||||
734 | textBuffer += QChar(ushort(c)); | - | ||||||
735 | ++n; | - | ||||||
736 | while ((c = getChar()) == ']') { | - | ||||||
737 | textBuffer += QChar(ushort(c)); | - | ||||||
738 | ++n; | - | ||||||
739 | } | - | ||||||
740 | if (c == 0) { | - | ||||||
741 | putString(textBuffer, pos); | - | ||||||
742 | textBuffer.resize(pos); | - | ||||||
743 | } else if (c == '>' && textBuffer.at(textBuffer.size()-2) == QLatin1Char(']')) { | - | ||||||
744 | raiseWellFormedError(QXmlStream::tr("Sequence ']]>' not allowed in content.")); | - | ||||||
745 | } else { | - | ||||||
746 | putChar(c); | - | ||||||
747 | break; | - | ||||||
748 | } | - | ||||||
749 | return n; | - | ||||||
750 | } break; dead code: break; | - | ||||||
751 | case '\r': | - | ||||||
752 | if ((c = filterCarriageReturn()) == 0) | - | ||||||
753 | return n; | - | ||||||
754 | - | |||||||
755 | case '\n': | - | ||||||
756 | ++lineNumber; | - | ||||||
757 | lastLineStart = characterOffset + readBufferPos; | - | ||||||
758 | - | |||||||
759 | case ' ': | - | ||||||
760 | case '\t': | - | ||||||
761 | textBuffer += QChar(ushort(c)); | - | ||||||
762 | ++n; | - | ||||||
763 | break; | - | ||||||
764 | case '&': | - | ||||||
765 | case '<': | - | ||||||
766 | if (!(c & 0xff0000)) { | - | ||||||
767 | putChar(c); | - | ||||||
768 | return n; | - | ||||||
769 | } | - | ||||||
770 | - | |||||||
771 | default: | - | ||||||
772 | if (c < 0x20) { | - | ||||||
773 | putChar(c); | - | ||||||
774 | return n; | - | ||||||
775 | } | - | ||||||
776 | isWhitespace = false; | - | ||||||
777 | textBuffer += QChar(ushort(c)); | - | ||||||
778 | ++n; | - | ||||||
779 | } | - | ||||||
780 | } | - | ||||||
781 | return n; | - | ||||||
782 | } | - | ||||||
783 | - | |||||||
784 | inline int QXmlStreamReaderPrivate::fastScanName(int *prefix) | - | ||||||
785 | { | - | ||||||
786 | int n = 0; | - | ||||||
787 | uint c; | - | ||||||
788 | while ((c = getChar()) != StreamEOF) { | - | ||||||
789 | switch (c) { | - | ||||||
790 | case '\n': | - | ||||||
791 | case ' ': | - | ||||||
792 | case '\t': | - | ||||||
793 | case '\r': | - | ||||||
794 | case '&': | - | ||||||
795 | case '#': | - | ||||||
796 | case '\'': | - | ||||||
797 | case '\"': | - | ||||||
798 | case '<': | - | ||||||
799 | case '>': | - | ||||||
800 | case '[': | - | ||||||
801 | case ']': | - | ||||||
802 | case '=': | - | ||||||
803 | case '%': | - | ||||||
804 | case '/': | - | ||||||
805 | case ';': | - | ||||||
806 | case '?': | - | ||||||
807 | case '!': | - | ||||||
808 | case '^': | - | ||||||
809 | case '|': | - | ||||||
810 | case ',': | - | ||||||
811 | case '(': | - | ||||||
812 | case ')': | - | ||||||
813 | case '+': | - | ||||||
814 | case '*': | - | ||||||
815 | putChar(c); | - | ||||||
816 | if (prefix && *prefix == n+1) { | - | ||||||
817 | *prefix = 0; | - | ||||||
818 | putChar(':'); | - | ||||||
819 | --n; | - | ||||||
820 | } | - | ||||||
821 | return n; | - | ||||||
822 | case ':': | - | ||||||
823 | if (prefix) { | - | ||||||
824 | if (*prefix == 0) { | - | ||||||
825 | *prefix = n+2; | - | ||||||
826 | } else { | - | ||||||
827 | putChar(c); | - | ||||||
828 | return n; | - | ||||||
829 | } | - | ||||||
830 | } else { | - | ||||||
831 | putChar(c); | - | ||||||
832 | return n; | - | ||||||
833 | } | - | ||||||
834 | - | |||||||
835 | default: | - | ||||||
836 | textBuffer += QChar(c); | - | ||||||
837 | ++n; | - | ||||||
838 | } | - | ||||||
839 | } | - | ||||||
840 | - | |||||||
841 | if (prefix) | - | ||||||
842 | *prefix = 0; | - | ||||||
843 | int pos = textBuffer.size() - n; | - | ||||||
844 | putString(textBuffer, pos); | - | ||||||
845 | textBuffer.resize(pos); | - | ||||||
846 | return 0; | - | ||||||
847 | } | - | ||||||
848 | - | |||||||
849 | enum NameChar { NameBeginning, NameNotBeginning, NotName }; | - | ||||||
850 | - | |||||||
851 | static const char Begi = static_cast<char>(NameBeginning); | - | ||||||
852 | static const char NtBg = static_cast<char>(NameNotBeginning); | - | ||||||
853 | static const char NotN = static_cast<char>(NotName); | - | ||||||
854 | - | |||||||
855 | static const char nameCharTable[128] = | - | ||||||
856 | { | - | ||||||
857 | - | |||||||
858 | NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN, | - | ||||||
859 | NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN, | - | ||||||
860 | - | |||||||
861 | NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN, | - | ||||||
862 | NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN, | - | ||||||
863 | - | |||||||
864 | NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN, | - | ||||||
865 | NotN, NotN, NotN, NotN, NotN, NtBg, NtBg, NotN, | - | ||||||
866 | - | |||||||
867 | NtBg, NtBg, NtBg, NtBg, NtBg, NtBg, NtBg, NtBg, | - | ||||||
868 | NtBg, NtBg, Begi, NotN, NotN, NotN, NotN, NotN, | - | ||||||
869 | - | |||||||
870 | NotN, Begi, Begi, Begi, Begi, Begi, Begi, Begi, | - | ||||||
871 | Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi, | - | ||||||
872 | - | |||||||
873 | Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi, | - | ||||||
874 | Begi, Begi, Begi, NotN, NotN, NotN, NotN, Begi, | - | ||||||
875 | - | |||||||
876 | NotN, Begi, Begi, Begi, Begi, Begi, Begi, Begi, | - | ||||||
877 | Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi, | - | ||||||
878 | - | |||||||
879 | Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi, | - | ||||||
880 | Begi, Begi, Begi, NotN, NotN, NotN, NotN, NotN | - | ||||||
881 | }; | - | ||||||
882 | - | |||||||
883 | static inline NameChar fastDetermineNameChar(QChar ch) | - | ||||||
884 | { | - | ||||||
885 | ushort uc = ch.unicode(); | - | ||||||
886 | if (!(uc & ~0x7f)) | - | ||||||
887 | return static_cast<NameChar>(nameCharTable[uc]); | - | ||||||
888 | - | |||||||
889 | QChar::Category cat = ch.category(); | - | ||||||
890 | - | |||||||
891 | if ((cat >= QChar::Letter_Uppercase && cat <= QChar::Letter_Other) | - | ||||||
892 | || cat == QChar::Number_Letter) | - | ||||||
893 | return NameBeginning; | - | ||||||
894 | if ((cat >= QChar::Number_DecimalDigit && cat <= QChar::Number_Other) | - | ||||||
895 | || (cat >= QChar::Mark_NonSpacing && cat <= QChar::Mark_Enclosing)) | - | ||||||
896 | return NameNotBeginning; | - | ||||||
897 | return NotName; | - | ||||||
898 | } | - | ||||||
899 | - | |||||||
900 | inline int QXmlStreamReaderPrivate::fastScanNMTOKEN() | - | ||||||
901 | { | - | ||||||
902 | int n = 0; | - | ||||||
903 | uint c; | - | ||||||
904 | while ((c = getChar()) != StreamEOF) { | - | ||||||
905 | if (fastDetermineNameChar(c) == NotName) { | - | ||||||
906 | putChar(c); | - | ||||||
907 | return n; | - | ||||||
908 | } else { | - | ||||||
909 | ++n; | - | ||||||
910 | textBuffer += QChar(c); | - | ||||||
911 | } | - | ||||||
912 | } | - | ||||||
913 | - | |||||||
914 | int pos = textBuffer.size() - n; | - | ||||||
915 | putString(textBuffer, pos); | - | ||||||
916 | textBuffer.resize(pos); | - | ||||||
917 | - | |||||||
918 | return n; | - | ||||||
919 | } | - | ||||||
920 | - | |||||||
921 | void QXmlStreamReaderPrivate::putString(const QString &s, int from) | - | ||||||
922 | { | - | ||||||
923 | putStack.reserve(s.size()); | - | ||||||
924 | for (int i = s.size()-1; i >= from; --i) | - | ||||||
925 | putStack.rawPush() = s.at(i).unicode(); | - | ||||||
926 | } | - | ||||||
927 | - | |||||||
928 | void QXmlStreamReaderPrivate::putStringLiteral(const QString &s) | - | ||||||
929 | { | - | ||||||
930 | putStack.reserve(s.size()); | - | ||||||
931 | for (int i = s.size()-1; i >= 0; --i) | - | ||||||
932 | putStack.rawPush() = ((LETTER << 16) | s.at(i).unicode()); | - | ||||||
933 | } | - | ||||||
934 | - | |||||||
935 | void QXmlStreamReaderPrivate::putReplacement(const QString &s) | - | ||||||
936 | { | - | ||||||
937 | putStack.reserve(s.size()); | - | ||||||
938 | for (int i = s.size()-1; i >= 0; --i) { | - | ||||||
939 | ushort c = s.at(i).unicode(); | - | ||||||
940 | if (c == '\n' || c == '\r') | - | ||||||
941 | putStack.rawPush() = ((LETTER << 16) | c); | - | ||||||
942 | else | - | ||||||
943 | putStack.rawPush() = c; | - | ||||||
944 | } | - | ||||||
945 | } | - | ||||||
946 | void QXmlStreamReaderPrivate::putReplacementInAttributeValue(const QString &s) | - | ||||||
947 | { | - | ||||||
948 | putStack.reserve(s.size()); | - | ||||||
949 | for (int i = s.size()-1; i >= 0; --i) { | - | ||||||
950 | ushort c = s.at(i).unicode(); | - | ||||||
951 | if (c == '&' || c == ';') | - | ||||||
952 | putStack.rawPush() = c; | - | ||||||
953 | else if (c == '\n' || c == '\r') | - | ||||||
954 | putStack.rawPush() = ' '; | - | ||||||
955 | else | - | ||||||
956 | putStack.rawPush() = ((LETTER << 16) | c); | - | ||||||
957 | } | - | ||||||
958 | } | - | ||||||
959 | - | |||||||
960 | uint QXmlStreamReaderPrivate::getChar_helper() | - | ||||||
961 | { | - | ||||||
962 | const int BUFFER_SIZE = 8192; | - | ||||||
963 | characterOffset += readBufferPos; | - | ||||||
964 | readBufferPos = 0; | - | ||||||
965 | readBuffer.resize(0); | - | ||||||
966 | - | |||||||
967 | if (decoder) | - | ||||||
968 | - | |||||||
969 | nbytesread = 0; | - | ||||||
970 | if (device) { | - | ||||||
971 | rawReadBuffer.resize(BUFFER_SIZE); | - | ||||||
972 | int nbytesreadOrMinus1 = device->read(rawReadBuffer.data() + nbytesread, BUFFER_SIZE - nbytesread); | - | ||||||
973 | nbytesread += qMax(nbytesreadOrMinus1, 0); | - | ||||||
974 | } else { | - | ||||||
975 | if (nbytesread) | - | ||||||
976 | rawReadBuffer += dataBuffer; | - | ||||||
977 | else | - | ||||||
978 | rawReadBuffer = dataBuffer; | - | ||||||
979 | nbytesread = rawReadBuffer.size(); | - | ||||||
980 | dataBuffer.clear(); | - | ||||||
981 | } | - | ||||||
982 | if (!nbytesread) { | - | ||||||
983 | atEnd = true; | - | ||||||
984 | return StreamEOF; | - | ||||||
985 | } | - | ||||||
986 | - | |||||||
987 | - | |||||||
988 | if (!decoder) { | - | ||||||
989 | if (nbytesread < 4) { | - | ||||||
990 | - | |||||||
991 | atEnd = true; | - | ||||||
992 | return StreamEOF; | - | ||||||
993 | } | - | ||||||
994 | int mib = 106; | - | ||||||
995 | - | |||||||
996 | - | |||||||
997 | uchar ch1 = rawReadBuffer.at(0); | - | ||||||
998 | uchar ch2 = rawReadBuffer.at(1); | - | ||||||
999 | uchar ch3 = rawReadBuffer.at(2); | - | ||||||
1000 | uchar ch4 = rawReadBuffer.at(3); | - | ||||||
1001 | - | |||||||
1002 | if ((ch1 == 0 && ch2 == 0 && ch3 == 0xfe && ch4 == 0xff) || | - | ||||||
1003 | (ch1 == 0xff && ch2 == 0xfe && ch3 == 0 && ch4 == 0)) | - | ||||||
1004 | mib = 1017; | - | ||||||
1005 | else if (ch1 == 0x3c && ch2 == 0x00 && ch3 == 0x00 && ch4 == 0x00) | - | ||||||
1006 | mib = 1019; | - | ||||||
1007 | else if (ch1 == 0x00 && ch2 == 0x00 && ch3 == 0x00 && ch4 == 0x3c) | - | ||||||
1008 | mib = 1018; | - | ||||||
1009 | else if ((ch1 == 0xfe && ch2 == 0xff) || (ch1 == 0xff && ch2 == 0xfe)) | - | ||||||
1010 | mib = 1015; | - | ||||||
1011 | else if (ch1 == 0x3c && ch2 == 0x00) | - | ||||||
1012 | mib = 1014; | - | ||||||
1013 | else if (ch1 == 0x00 && ch2 == 0x3c) | - | ||||||
1014 | mib = 1013; | - | ||||||
1015 | codec = QTextCodec::codecForMib(mib); | - | ||||||
1016 | ((!(codec)) ? qt_assert("codec",__FILE__,15181524) : qt_noop()); | - | ||||||
1017 | decoder = codec->makeDecoder(); | - | ||||||
1018 | } | - | ||||||
1019 | - | |||||||
1020 | decoder->toUnicode(&readBuffer, rawReadBuffer.constData(), nbytesread); | - | ||||||
1021 | - | |||||||
1022 | if(lockEncoding && decoder->hasFailure()) { | - | ||||||
1023 | raiseWellFormedError(QXmlStream::tr("Encountered incorrectly encoded content.")); | - | ||||||
1024 | readBuffer.clear(); | - | ||||||
1025 | return StreamEOF; | - | ||||||
1026 | } | - | ||||||
1027 | - | |||||||
1028 | - | |||||||
1029 | - | |||||||
1030 | - | |||||||
1031 | readBuffer.reserve(1); | - | ||||||
1032 | - | |||||||
1033 | if (readBufferPos < readBuffer.size()) { | - | ||||||
1034 | ushort c = readBuffer.at(readBufferPos++).unicode(); | - | ||||||
1035 | return c; | - | ||||||
1036 | } | - | ||||||
1037 | - | |||||||
1038 | atEnd = true; | - | ||||||
1039 | return StreamEOF; | - | ||||||
1040 | } | - | ||||||
1041 | - | |||||||
1042 | QStringRef QXmlStreamReaderPrivate::namespaceForPrefix(const QStringRef &prefix) | - | ||||||
1043 | { | - | ||||||
1044 | for (int j = namespaceDeclarations.size() - 1; j >= 0; --j) { | - | ||||||
1045 | const NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.at(j); | - | ||||||
1046 | if (namespaceDeclaration.prefix == prefix) { | - | ||||||
1047 | return namespaceDeclaration.namespaceUri; | - | ||||||
1048 | } | - | ||||||
1049 | } | - | ||||||
1050 | - | |||||||
1051 | - | |||||||
1052 | if (namespaceProcessing && !prefix.isEmpty()) | - | ||||||
1053 | raiseWellFormedError(QXmlStream::tr("Namespace prefix '%1' not declared").arg(prefix.toString())); | - | ||||||
1054 | - | |||||||
1055 | - | |||||||
1056 | return QStringRef(); | - | ||||||
1057 | } | - | ||||||
1058 | - | |||||||
1059 | - | |||||||
1060 | - | |||||||
1061 | - | |||||||
1062 | void QXmlStreamReaderPrivate::resolveTag() | - | ||||||
1063 | { | - | ||||||
1064 | int n = attributeStack.size(); | - | ||||||
1065 | - | |||||||
1066 | if (namespaceProcessing) { | - | ||||||
1067 | for (int a = 0; a < dtdAttributes.size(); ++a) { | - | ||||||
1068 | DtdAttribute &dtdAttribute = dtdAttributes[a]; | - | ||||||
1069 | if (!dtdAttribute.isNamespaceAttribute | - | ||||||
1070 | || dtdAttribute.defaultValue.isNull() | - | ||||||
1071 | || dtdAttribute.tagName != qualifiedName | - | ||||||
1072 | || dtdAttribute.attributeQualifiedName.isNull()) | - | ||||||
1073 | continue; | - | ||||||
1074 | int i = 0; | - | ||||||
1075 | while (i < n && symName(attributeStack[i].key) != dtdAttribute.attributeQualifiedName) | - | ||||||
1076 | ++i; | - | ||||||
1077 | if (i != n) | - | ||||||
1078 | continue; | - | ||||||
1079 | if (dtdAttribute.attributePrefix.isEmpty() && dtdAttribute.attributeName == QLatin1String("xmlns")) { | - | ||||||
1080 | NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push(); | - | ||||||
1081 | namespaceDeclaration.prefix.clear(); | - | ||||||
1082 | - | |||||||
1083 | const QStringRef ns(dtdAttribute.defaultValue); | - | ||||||
1084 | if(ns == QLatin1String("http://www.w3.org/2000/xmlns/") || | - | ||||||
1085 | ns == QLatin1String("http://www.w3.org/XML/1998/namespace")) | - | ||||||
1086 | raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration.")); | - | ||||||
1087 | else | - | ||||||
1088 | namespaceDeclaration.namespaceUri = ns; | - | ||||||
1089 | } else if (dtdAttribute.attributePrefix == QLatin1String("xmlns")) { | - | ||||||
1090 | NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push(); | - | ||||||
1091 | QStringRef namespacePrefix = dtdAttribute.attributeName; | - | ||||||
1092 | QStringRef namespaceUri = dtdAttribute.defaultValue; | - | ||||||
1093 | if (((namespacePrefix == QLatin1String("xml")) | - | ||||||
1094 | ^ (namespaceUri == QLatin1String("http://www.w3.org/XML/1998/namespace"))) | - | ||||||
1095 | || namespaceUri == QLatin1String("http://www.w3.org/2000/xmlns/") | - | ||||||
1096 | || namespaceUri.isEmpty() | - | ||||||
1097 | || namespacePrefix == QLatin1String("xmlns")) | - | ||||||
1098 | raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration.")); | - | ||||||
1099 | - | |||||||
1100 | namespaceDeclaration.prefix = namespacePrefix; | - | ||||||
1101 | namespaceDeclaration.namespaceUri = namespaceUri; | - | ||||||
1102 | } | - | ||||||
1103 | } | - | ||||||
1104 | } | - | ||||||
1105 | - | |||||||
1106 | tagStack.top().namespaceDeclaration.namespaceUri = namespaceUri = namespaceForPrefix(prefix); | - | ||||||
1107 | - | |||||||
1108 | attributes.resize(n); | - | ||||||
1109 | - | |||||||
1110 | for (int i = 0; i < n; ++i) { | - | ||||||
1111 | QXmlStreamAttribute &attribute = attributes[i]; | - | ||||||
1112 | Attribute &attrib = attributeStack[i]; | - | ||||||
1113 | QStringRef prefix(symPrefix(attrib.key)); | - | ||||||
1114 | QStringRef name(symString(attrib.key)); | - | ||||||
1115 | QStringRef qualifiedName(symName(attrib.key)); | - | ||||||
1116 | QStringRef value(symString(attrib.value)); | - | ||||||
1117 | - | |||||||
1118 | attribute.m_name = QXmlStreamStringRef(name); | - | ||||||
1119 | attribute.m_qualifiedName = QXmlStreamStringRef(qualifiedName); | - | ||||||
1120 | attribute.m_value = QXmlStreamStringRef(value); | - | ||||||
1121 | - | |||||||
1122 | if (!prefix.isEmpty()) { | - | ||||||
1123 | QStringRef attributeNamespaceUri = namespaceForPrefix(prefix); | - | ||||||
1124 | attribute.m_namespaceUri = QXmlStreamStringRef(attributeNamespaceUri); | - | ||||||
1125 | } | - | ||||||
1126 | - | |||||||
1127 | for (int j = 0; j < i; ++j) { | - | ||||||
1128 | if (attributes[j].name() == attribute.name() | - | ||||||
1129 | && attributes[j].namespaceUri() == attribute.namespaceUri() | - | ||||||
1130 | && (namespaceProcessing || attributes[j].qualifiedName() == attribute.qualifiedName())) | - | ||||||
1131 | raiseWellFormedError(QXmlStream::tr("Attribute '%1' redefined.").arg(attribute.qualifiedName().toString())); | - | ||||||
1132 | } | - | ||||||
1133 | } | - | ||||||
1134 | - | |||||||
1135 | for (int a = 0; a < dtdAttributes.size(); ++a) { | - | ||||||
1136 | DtdAttribute &dtdAttribute = dtdAttributes[a]; | - | ||||||
1137 | if (dtdAttribute.isNamespaceAttribute | - | ||||||
1138 | || dtdAttribute.defaultValue.isNull() | - | ||||||
1139 | || dtdAttribute.tagName != qualifiedName | - | ||||||
1140 | || dtdAttribute.attributeQualifiedName.isNull()) | - | ||||||
1141 | continue; | - | ||||||
1142 | int i = 0; | - | ||||||
1143 | while (i < n && symName(attributeStack[i].key) != dtdAttribute.attributeQualifiedName) | - | ||||||
1144 | ++i; | - | ||||||
1145 | if (i != n) | - | ||||||
1146 | continue; | - | ||||||
1147 | - | |||||||
1148 | - | |||||||
1149 | - | |||||||
1150 | QXmlStreamAttribute attribute; | - | ||||||
1151 | attribute.m_name = QXmlStreamStringRef(dtdAttribute.attributeName); | - | ||||||
1152 | attribute.m_qualifiedName = QXmlStreamStringRef(dtdAttribute.attributeQualifiedName); | - | ||||||
1153 | attribute.m_value = QXmlStreamStringRef(dtdAttribute.defaultValue); | - | ||||||
1154 | - | |||||||
1155 | if (!dtdAttribute.attributePrefix.isEmpty()) { | - | ||||||
1156 | QStringRef attributeNamespaceUri = namespaceForPrefix(dtdAttribute.attributePrefix); | - | ||||||
1157 | attribute.m_namespaceUri = QXmlStreamStringRef(attributeNamespaceUri); | - | ||||||
1158 | } | - | ||||||
1159 | attribute.m_isDefault = true; | - | ||||||
1160 | attributes.append(attribute); | - | ||||||
1161 | } | - | ||||||
1162 | - | |||||||
1163 | attributeStack.clear(); | - | ||||||
1164 | } | - | ||||||
1165 | - | |||||||
1166 | void QXmlStreamReaderPrivate::resolvePublicNamespaces() | - | ||||||
1167 | { | - | ||||||
1168 | const Tag &tag = tagStack.top(); | - | ||||||
1169 | int n = namespaceDeclarations.size() - tag.namespaceDeclarationsSize; | - | ||||||
1170 | publicNamespaceDeclarations.resize(n); | - | ||||||
1171 | for (int i = 0; i < n; ++i) { | - | ||||||
1172 | const NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.at(tag.namespaceDeclarationsSize + i); | - | ||||||
1173 | QXmlStreamNamespaceDeclaration &publicNamespaceDeclaration = publicNamespaceDeclarations[i]; | - | ||||||
1174 | publicNamespaceDeclaration.m_prefix = QXmlStreamStringRef(namespaceDeclaration.prefix); | - | ||||||
1175 | publicNamespaceDeclaration.m_namespaceUri = QXmlStreamStringRef(namespaceDeclaration.namespaceUri); | - | ||||||
1176 | } | - | ||||||
1177 | } | - | ||||||
1178 | - | |||||||
1179 | void QXmlStreamReaderPrivate::resolveDtd() | - | ||||||
1180 | { | - | ||||||
1181 | publicNotationDeclarations.resize(notationDeclarations.size()); | - | ||||||
1182 | for (int i = 0; i < notationDeclarations.size(); ++i) { | - | ||||||
1183 | const QXmlStreamReaderPrivate::NotationDeclaration ¬ationDeclaration = notationDeclarations.at(i); | - | ||||||
1184 | QXmlStreamNotationDeclaration &publicNotationDeclaration = publicNotationDeclarations[i]; | - | ||||||
1185 | publicNotationDeclaration.m_name = QXmlStreamStringRef(notationDeclaration.name); | - | ||||||
1186 | publicNotationDeclaration.m_systemId = QXmlStreamStringRef(notationDeclaration.systemId); | - | ||||||
1187 | publicNotationDeclaration.m_publicId = QXmlStreamStringRef(notationDeclaration.publicId); | - | ||||||
1188 | - | |||||||
1189 | } | - | ||||||
1190 | notationDeclarations.clear(); | - | ||||||
1191 | publicEntityDeclarations.resize(entityDeclarations.size()); | - | ||||||
1192 | for (int i = 0; i < entityDeclarations.size(); ++i) { | - | ||||||
1193 | const QXmlStreamReaderPrivate::EntityDeclaration &entityDeclaration = entityDeclarations.at(i); | - | ||||||
1194 | QXmlStreamEntityDeclaration &publicEntityDeclaration = publicEntityDeclarations[i]; | - | ||||||
1195 | publicEntityDeclaration.m_name = QXmlStreamStringRef(entityDeclaration.name); | - | ||||||
1196 | publicEntityDeclaration.m_notationName = QXmlStreamStringRef(entityDeclaration.notationName); | - | ||||||
1197 | publicEntityDeclaration.m_systemId = QXmlStreamStringRef(entityDeclaration.systemId); | - | ||||||
1198 | publicEntityDeclaration.m_publicId = QXmlStreamStringRef(entityDeclaration.publicId); | - | ||||||
1199 | publicEntityDeclaration.m_value = QXmlStreamStringRef(entityDeclaration.value); | - | ||||||
1200 | } | - | ||||||
1201 | entityDeclarations.clear(); | - | ||||||
1202 | parameterEntityHash.clear(); | - | ||||||
1203 | } | - | ||||||
1204 | - | |||||||
1205 | uint QXmlStreamReaderPrivate::resolveCharRef(int symbolIndex) | - | ||||||
1206 | { | - | ||||||
1207 | bool ok = true; | - | ||||||
1208 | uint s; | - | ||||||
1209 | - | |||||||
1210 | if (sym(symbolIndex).c == 'x') | - | ||||||
1211 | s = symString(symbolIndex, 1).toUInt(&ok, 16); | - | ||||||
1212 | else | - | ||||||
1213 | s = symString(symbolIndex).toUInt(&ok, 10); | - | ||||||
1214 | - | |||||||
1215 | ok &= (s == 0x9 || s == 0xa || s == 0xd || (s >= 0x20 && s <= 0xd7ff) | - | ||||||
1216 | || (s >= 0xe000 && s <= 0xfffd) || (s >= 0x10000 && s <= QChar::LastValidCodePoint)); | - | ||||||
1217 | - | |||||||
1218 | return ok ? s : 0; | - | ||||||
1219 | } | - | ||||||
1220 | - | |||||||
1221 | - | |||||||
1222 | void QXmlStreamReaderPrivate::checkPublicLiteral(const QStringRef &publicId) | - | ||||||
1223 | { | - | ||||||
1224 | - | |||||||
1225 | - | |||||||
1226 | const ushort *data = reinterpret_cast<const ushort *>(publicId.constData()); | - | ||||||
1227 | uchar c = 0; | - | ||||||
1228 | int i; | - | ||||||
1229 | for (i = publicId.size() - 1; i >= 0; --i) { | - | ||||||
1230 | if (data[i] < 256) | - | ||||||
1231 | switch ((c = data[i])) { | - | ||||||
1232 | case ' ': case '\n': case '\r': case '-': case '(': case ')': | - | ||||||
1233 | case '+': case ',': case '.': case '/': case ':': case '=': | - | ||||||
1234 | case '?': case ';': case '!': case '*': case '#': case '@': | - | ||||||
1235 | case '$': case '_': case '%': case '\'': case '\"': | - | ||||||
1236 | continue; | - | ||||||
1237 | default: | - | ||||||
1238 | if ((c >= 'a' && c <= 'z') | - | ||||||
1239 | || (c >= 'A' && c <= 'Z') | - | ||||||
1240 | || (c >= '0' && c <= '9')) | - | ||||||
1241 | continue; | - | ||||||
1242 | } | - | ||||||
1243 | break; | - | ||||||
1244 | } | - | ||||||
1245 | if (i >= 0) | - | ||||||
1246 | raiseWellFormedError(QXmlStream::tr("Unexpected character '%1' in public id literal.").arg(QChar(QLatin1Char(c)))); | - | ||||||
1247 | } | - | ||||||
1248 | - | |||||||
1249 | - | |||||||
1250 | - | |||||||
1251 | - | |||||||
1252 | - | |||||||
1253 | - | |||||||
1254 | bool QXmlStreamReaderPrivate::checkStartDocument() | - | ||||||
1255 | { | - | ||||||
1256 | hasCheckedStartDocument = true; | - | ||||||
1257 | - | |||||||
1258 | if (scanString(spell[XML], XML)) | - | ||||||
1259 | return true; | - | ||||||
1260 | - | |||||||
1261 | type = QXmlStreamReader::StartDocument; | - | ||||||
1262 | if (atEnd) { | - | ||||||
1263 | hasCheckedStartDocument = false; | - | ||||||
1264 | raiseError(QXmlStreamReader::PrematureEndOfDocumentError); | - | ||||||
1265 | } | - | ||||||
1266 | return false; | - | ||||||
1267 | } | - | ||||||
1268 | - | |||||||
1269 | void QXmlStreamReaderPrivate::startDocument() | - | ||||||
1270 | { | - | ||||||
1271 | QString err; | - | ||||||
1272 | if (documentVersion != QLatin1String("1.0")) { | - | ||||||
1273 | if (documentVersion.contains(QLatin1Char(' '))) | - | ||||||
1274 | err = QXmlStream::tr("Invalid XML version string."); | - | ||||||
1275 | else | - | ||||||
1276 | err = QXmlStream::tr("Unsupported XML version."); | - | ||||||
1277 | } | - | ||||||
1278 | int n = attributeStack.size(); | - | ||||||
1279 | - | |||||||
1280 | - | |||||||
1281 | - | |||||||
1282 | - | |||||||
1283 | - | |||||||
1284 | bool hasStandalone = false; | - | ||||||
1285 | - | |||||||
1286 | for (int i = 0; err.isNull() && i < n; ++i) { | - | ||||||
1287 | Attribute &attrib = attributeStack[i]; | - | ||||||
1288 | QStringRef prefix(symPrefix(attrib.key)); | - | ||||||
1289 | QStringRef key(symString(attrib.key)); | - | ||||||
1290 | QStringRef value(symString(attrib.value)); | - | ||||||
1291 | - | |||||||
1292 | if (prefix.isEmpty() && key == QLatin1String("encoding")) { | - | ||||||
1293 | const QString name(value.toString()); | - | ||||||
1294 | documentEncoding = value; | - | ||||||
1295 | - | |||||||
1296 | if(hasStandalone) | - | ||||||
1297 | err = QXmlStream::tr("The standalone pseudo attribute must appear after the encoding."); | - | ||||||
1298 | if(!QXmlUtils::isEncName(name)) | - | ||||||
1299 | err = QXmlStream::tr("%1 is an invalid encoding name.").arg(name); | - | ||||||
1300 | else { | - | ||||||
1301 | - | |||||||
1302 | - | |||||||
1303 | - | |||||||
1304 | QTextCodec *const newCodec = QTextCodec::codecForName(name.toLatin1()); | - | ||||||
1305 | if (!newCodec) | - | ||||||
1306 | err = QXmlStream::tr("Encoding %1 is unsupported").arg(name); | - | ||||||
1307 | else if (newCodec != codec && !lockEncoding) { | - | ||||||
1308 | codec = newCodec; | - | ||||||
1309 | delete decoder; | - | ||||||
1310 | decoder = codec->makeDecoder(); | - | ||||||
1311 | decoder->toUnicode(&readBuffer, rawReadBuffer.data(), nbytesread); | - | ||||||
1312 | } | - | ||||||
1313 | - | |||||||
1314 | } | - | ||||||
1315 | } else if (prefix.isEmpty() && key == QLatin1String("standalone")) { | - | ||||||
1316 | hasStandalone = true; | - | ||||||
1317 | if (value == QLatin1String("yes")) | - | ||||||
1318 | standalone = true; | - | ||||||
1319 | else if (value == QLatin1String("no")) | - | ||||||
1320 | standalone = false; | - | ||||||
1321 | else | - | ||||||
1322 | err = QXmlStream::tr("Standalone accepts only yes or no."); | - | ||||||
1323 | } else { | - | ||||||
1324 | err = QXmlStream::tr("Invalid attribute in XML declaration."); | - | ||||||
1325 | } | - | ||||||
1326 | } | - | ||||||
1327 | - | |||||||
1328 | if (!err.isNull()) | - | ||||||
1329 | raiseWellFormedError(err); | - | ||||||
1330 | attributeStack.clear(); | - | ||||||
1331 | } | - | ||||||
1332 | - | |||||||
1333 | - | |||||||
1334 | void QXmlStreamReaderPrivate::raiseError(QXmlStreamReader::Error error, const QString& message) | - | ||||||
1335 | { | - | ||||||
1336 | this->error = error; | - | ||||||
1337 | errorString = message; | - | ||||||
1338 | if (errorString.isNull()) { | - | ||||||
1339 | if (error == QXmlStreamReader::PrematureEndOfDocumentError) | - | ||||||
1340 | errorString = QXmlStream::tr("Premature end of document."); | - | ||||||
1341 | else if (error == QXmlStreamReader::CustomError) | - | ||||||
1342 | errorString = QXmlStream::tr("Invalid document."); | - | ||||||
1343 | } | - | ||||||
1344 | - | |||||||
1345 | type = QXmlStreamReader::Invalid; | - | ||||||
1346 | } | - | ||||||
1347 | - | |||||||
1348 | void QXmlStreamReaderPrivate::raiseWellFormedError(const QString &message) | - | ||||||
1349 | { | - | ||||||
1350 | raiseError(QXmlStreamReader::NotWellFormedError, message); | - | ||||||
1351 | } | - | ||||||
1352 | - | |||||||
1353 | void QXmlStreamReaderPrivate::parseError() | - | ||||||
1354 | { | - | ||||||
1355 | - | |||||||
1356 | if (token == EOF_SYMBOL) { | - | ||||||
1357 | raiseError(QXmlStreamReader::PrematureEndOfDocumentError); | - | ||||||
1358 | return; | - | ||||||
1359 | } | - | ||||||
1360 | const int nmax = 4; | - | ||||||
1361 | QString error_message; | - | ||||||
1362 | int ers = state_stack[tos]; | - | ||||||
1363 | int nexpected = 0; | - | ||||||
1364 | int expected[nmax]; | - | ||||||
1365 | if (token != ERROR) | - | ||||||
1366 | for (int tk = 0; tk < TERMINAL_COUNT; ++tk) { | - | ||||||
1367 | int k = t_action(ers, tk); | - | ||||||
1368 | if (k <= 0) | - | ||||||
1369 | continue; | - | ||||||
1370 | if (spell[tk]) { | - | ||||||
1371 | if (nexpected < nmax) | - | ||||||
1372 | expected[nexpected++] = tk; | - | ||||||
1373 | } | - | ||||||
1374 | } | - | ||||||
1375 | - | |||||||
1376 | error_message.clear (); | - | ||||||
1377 | if (nexpected && nexpected < nmax) { | - | ||||||
1378 | bool first = true; | - | ||||||
1379 | - | |||||||
1380 | for (int s = 0; s < nexpected; ++s) { | - | ||||||
1381 | if (first) | - | ||||||
1382 | error_message += QXmlStream::tr ("Expected "); | - | ||||||
1383 | else if (s == nexpected - 1) | - | ||||||
1384 | error_message += QLatin1String (nexpected > 2 ? ", or " : " or "); | - | ||||||
1385 | else | - | ||||||
1386 | error_message += QLatin1String (", "); | - | ||||||
1387 | - | |||||||
1388 | first = false; | - | ||||||
1389 | error_message += QLatin1String("\'"); | - | ||||||
1390 | error_message += QLatin1String (spell [expected[s]]); | - | ||||||
1391 | error_message += QLatin1String("\'"); | - | ||||||
1392 | } | - | ||||||
1393 | error_message += QXmlStream::tr(", but got \'"); | - | ||||||
1394 | error_message += QLatin1String(spell [token]); | - | ||||||
1395 | error_message += QLatin1String("\'"); | - | ||||||
1396 | } else { | - | ||||||
1397 | error_message += QXmlStream::tr("Unexpected \'"); | - | ||||||
1398 | error_message += QLatin1String(spell [token]); | - | ||||||
1399 | error_message += QLatin1String("\'"); | - | ||||||
1400 | } | - | ||||||
1401 | error_message += QLatin1Char('.'); | - | ||||||
1402 | - | |||||||
1403 | raiseWellFormedError(error_message); | - | ||||||
1404 | } | - | ||||||
1405 | - | |||||||
1406 | void QXmlStreamReaderPrivate::resume(int rule) { | - | ||||||
1407 | resumeReduction = rule; | - | ||||||
1408 | if (error == QXmlStreamReader::NoError) | - | ||||||
1409 | raiseError(QXmlStreamReader::PrematureEndOfDocumentError); | - | ||||||
1410 | } | - | ||||||
1411 | - | |||||||
1412 | - | |||||||
1413 | - | |||||||
1414 | - | |||||||
1415 | - | |||||||
1416 | qint64 QXmlStreamReader::lineNumber() const | - | ||||||
1417 | { | - | ||||||
1418 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1419 | return d->lineNumber + 1; | - | ||||||
1420 | } | - | ||||||
1421 | - | |||||||
1422 | - | |||||||
1423 | - | |||||||
1424 | - | |||||||
1425 | - | |||||||
1426 | qint64 QXmlStreamReader::columnNumber() const | - | ||||||
1427 | { | - | ||||||
1428 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1429 | return d->characterOffset - d->lastLineStart + d->readBufferPos; | - | ||||||
1430 | } | - | ||||||
1431 | - | |||||||
1432 | - | |||||||
1433 | - | |||||||
1434 | - | |||||||
1435 | - | |||||||
1436 | qint64 QXmlStreamReader::characterOffset() const | - | ||||||
1437 | { | - | ||||||
1438 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1439 | return d->characterOffset + d->readBufferPos; | - | ||||||
1440 | } | - | ||||||
1441 | - | |||||||
1442 | - | |||||||
1443 | - | |||||||
1444 | - | |||||||
1445 | - | |||||||
1446 | QStringRef QXmlStreamReader::text() const | - | ||||||
1447 | { | - | ||||||
1448 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1449 | return d->text; | - | ||||||
1450 | } | - | ||||||
1451 | QXmlStreamNotationDeclarations QXmlStreamReader::notationDeclarations() const | - | ||||||
1452 | { | - | ||||||
1453 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1454 | if (d->notationDeclarations.size()) | - | ||||||
1455 | const_cast<QXmlStreamReaderPrivate *>(d)->resolveDtd(); | - | ||||||
1456 | return d->publicNotationDeclarations; | - | ||||||
1457 | } | - | ||||||
1458 | QXmlStreamEntityDeclarations QXmlStreamReader::entityDeclarations() const | - | ||||||
1459 | { | - | ||||||
1460 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1461 | if (d->entityDeclarations.size()) | - | ||||||
1462 | const_cast<QXmlStreamReaderPrivate *>(d)->resolveDtd(); | - | ||||||
1463 | return d->publicEntityDeclarations; | - | ||||||
1464 | } | - | ||||||
1465 | QStringRef QXmlStreamReader::dtdName() const | - | ||||||
1466 | { | - | ||||||
1467 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1468 | if (d->type == QXmlStreamReader::DTD) | - | ||||||
1469 | return d->dtdName; | - | ||||||
1470 | return QStringRef(); | - | ||||||
1471 | } | - | ||||||
1472 | QStringRef QXmlStreamReader::dtdPublicId() const | - | ||||||
1473 | { | - | ||||||
1474 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1475 | if (d->type == QXmlStreamReader::DTD) | - | ||||||
1476 | return d->dtdPublicId; | - | ||||||
1477 | return QStringRef(); | - | ||||||
1478 | } | - | ||||||
1479 | QStringRef QXmlStreamReader::dtdSystemId() const | - | ||||||
1480 | { | - | ||||||
1481 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1482 | if (d->type == QXmlStreamReader::DTD) | - | ||||||
1483 | return d->dtdSystemId; | - | ||||||
1484 | return QStringRef(); | - | ||||||
1485 | } | - | ||||||
1486 | QXmlStreamNamespaceDeclarations QXmlStreamReader::namespaceDeclarations() const | - | ||||||
1487 | { | - | ||||||
1488 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1489 | if (d->publicNamespaceDeclarations.isEmpty() && d->type == StartElement) | - | ||||||
1490 | const_cast<QXmlStreamReaderPrivate *>(d)->resolvePublicNamespaces(); | - | ||||||
1491 | return d->publicNamespaceDeclarations; | - | ||||||
1492 | } | - | ||||||
1493 | void QXmlStreamReader::addExtraNamespaceDeclaration(const QXmlStreamNamespaceDeclaration &extraNamespaceDeclaration) | - | ||||||
1494 | { | - | ||||||
1495 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1496 | QXmlStreamReaderPrivate::NamespaceDeclaration &namespaceDeclaration = d->namespaceDeclarations.push(); | - | ||||||
1497 | namespaceDeclaration.prefix = d->addToStringStorage(extraNamespaceDeclaration.prefix()); | - | ||||||
1498 | namespaceDeclaration.namespaceUri = d->addToStringStorage(extraNamespaceDeclaration.namespaceUri()); | - | ||||||
1499 | } | - | ||||||
1500 | void QXmlStreamReader::addExtraNamespaceDeclarations(const QXmlStreamNamespaceDeclarations &extraNamespaceDeclarations) | - | ||||||
1501 | { | - | ||||||
1502 | for (int i = 0; i < extraNamespaceDeclarations.size(); ++i) | - | ||||||
1503 | addExtraNamespaceDeclaration(extraNamespaceDeclarations.at(i)); | - | ||||||
1504 | } | - | ||||||
1505 | QString QXmlStreamReader::readElementText(ReadElementTextBehaviour behaviour) | - | ||||||
1506 | { | - | ||||||
1507 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1508 | if (isStartElement()) { | - | ||||||
1509 | QString result; | - | ||||||
1510 | for(;;) { | - | ||||||
1511 | switch (readNext()) { | - | ||||||
1512 | case Characters: | - | ||||||
1513 | case EntityReference: | - | ||||||
1514 | result.insert(result.size(), d->text.unicode(), d->text.size()); | - | ||||||
1515 | break; | - | ||||||
1516 | case EndElement: | - | ||||||
1517 | return result; | - | ||||||
1518 | case ProcessingInstruction: | - | ||||||
1519 | case Comment: | - | ||||||
1520 | break; | - | ||||||
1521 | case StartElement: | - | ||||||
1522 | if (behaviour == SkipChildElements) { | - | ||||||
1523 | skipCurrentElement(); | - | ||||||
1524 | break; | - | ||||||
1525 | } else if (behaviour == IncludeChildElements) { | - | ||||||
1526 | result += readElementText(behaviour); | - | ||||||
1527 | break; | - | ||||||
1528 | } | - | ||||||
1529 | - | |||||||
1530 | default: | - | ||||||
1531 | if (d->error || behaviour == ErrorOnUnexpectedElement) { | - | ||||||
1532 | if (!d->error) | - | ||||||
1533 | d->raiseError(UnexpectedElementError, QXmlStream::tr("Expected character data.")); | - | ||||||
1534 | return result; | - | ||||||
1535 | } | - | ||||||
1536 | } | - | ||||||
1537 | } | - | ||||||
1538 | } | - | ||||||
1539 | return QString(); | - | ||||||
1540 | } | - | ||||||
1541 | - | |||||||
1542 | - | |||||||
1543 | - | |||||||
1544 | - | |||||||
1545 | - | |||||||
1546 | void QXmlStreamReader::raiseError(const QString& message) | - | ||||||
1547 | { | - | ||||||
1548 | QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1549 | d->raiseError(CustomError, message); | - | ||||||
1550 | } | - | ||||||
1551 | - | |||||||
1552 | - | |||||||
1553 | - | |||||||
1554 | - | |||||||
1555 | - | |||||||
1556 | - | |||||||
1557 | QString QXmlStreamReader::errorString() const | - | ||||||
1558 | { | - | ||||||
1559 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1560 | if (d->type == QXmlStreamReader::Invalid) | - | ||||||
1561 | return d->errorString; | - | ||||||
1562 | return QString(); | - | ||||||
1563 | } | - | ||||||
1564 | - | |||||||
1565 | - | |||||||
1566 | - | |||||||
1567 | - | |||||||
1568 | - | |||||||
1569 | QXmlStreamReader::Error QXmlStreamReader::error() const | - | ||||||
1570 | { | - | ||||||
1571 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1572 | if (d->type == QXmlStreamReader::Invalid) | - | ||||||
1573 | return d->error; | - | ||||||
1574 | return NoError; | - | ||||||
1575 | } | - | ||||||
1576 | - | |||||||
1577 | - | |||||||
1578 | - | |||||||
1579 | - | |||||||
1580 | QStringRef QXmlStreamReader::processingInstructionTarget() const | - | ||||||
1581 | { | - | ||||||
1582 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1583 | return d->processingInstructionTarget; | - | ||||||
1584 | } | - | ||||||
1585 | - | |||||||
1586 | - | |||||||
1587 | - | |||||||
1588 | - | |||||||
1589 | QStringRef QXmlStreamReader::processingInstructionData() const | - | ||||||
1590 | { | - | ||||||
1591 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1592 | return d->processingInstructionData; | - | ||||||
1593 | } | - | ||||||
1594 | QStringRef QXmlStreamReader::name() const | - | ||||||
1595 | { | - | ||||||
1596 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1597 | return d->name; | - | ||||||
1598 | } | - | ||||||
1599 | - | |||||||
1600 | - | |||||||
1601 | - | |||||||
1602 | - | |||||||
1603 | - | |||||||
1604 | - | |||||||
1605 | QStringRef QXmlStreamReader::namespaceUri() const | - | ||||||
1606 | { | - | ||||||
1607 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1608 | return d->namespaceUri; | - | ||||||
1609 | } | - | ||||||
1610 | QStringRef QXmlStreamReader::qualifiedName() const | - | ||||||
1611 | { | - | ||||||
1612 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1613 | return d->qualifiedName; | - | ||||||
1614 | } | - | ||||||
1615 | QStringRef QXmlStreamReader::prefix() const | - | ||||||
1616 | { | - | ||||||
1617 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1618 | return d->prefix; | - | ||||||
1619 | } | - | ||||||
1620 | - | |||||||
1621 | - | |||||||
1622 | - | |||||||
1623 | - | |||||||
1624 | QXmlStreamAttributes QXmlStreamReader::attributes() const | - | ||||||
1625 | { | - | ||||||
1626 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1627 | return d->attributes; | - | ||||||
1628 | } | - | ||||||
1629 | QXmlStreamAttribute::QXmlStreamAttribute() | - | ||||||
1630 | { | - | ||||||
1631 | m_isDefault = false; | - | ||||||
1632 | } | - | ||||||
1633 | - | |||||||
1634 | - | |||||||
1635 | - | |||||||
1636 | - | |||||||
1637 | QXmlStreamAttribute::~QXmlStreamAttribute() | - | ||||||
1638 | { | - | ||||||
1639 | } | - | ||||||
1640 | - | |||||||
1641 | - | |||||||
1642 | - | |||||||
1643 | - | |||||||
1644 | QXmlStreamAttribute::QXmlStreamAttribute(const QString &namespaceUri, const QString &name, const QString &value) | - | ||||||
1645 | { | - | ||||||
1646 | m_namespaceUri = QXmlStreamStringRef(QStringRef(&namespaceUri)); | - | ||||||
1647 | m_name = m_qualifiedName = QXmlStreamStringRef(QStringRef(&name)); | - | ||||||
1648 | m_value = QXmlStreamStringRef(QStringRef(&value)); | - | ||||||
1649 | m_namespaceUri = QXmlStreamStringRef(QStringRef(&namespaceUri)); | - | ||||||
1650 | } | - | ||||||
1651 | - | |||||||
1652 | - | |||||||
1653 | - | |||||||
1654 | - | |||||||
1655 | QXmlStreamAttribute::QXmlStreamAttribute(const QString &qualifiedName, const QString &value) | - | ||||||
1656 | { | - | ||||||
1657 | int colon = qualifiedName.indexOf(QLatin1Char(':')); | - | ||||||
1658 | m_name = QXmlStreamStringRef(QStringRef(&qualifiedName, | - | ||||||
1659 | colon + 1, | - | ||||||
1660 | qualifiedName.size() - (colon + 1))); | - | ||||||
1661 | m_qualifiedName = QXmlStreamStringRef(QStringRef(&qualifiedName)); | - | ||||||
1662 | m_value = QXmlStreamStringRef(QStringRef(&value)); | - | ||||||
1663 | } | - | ||||||
1664 | QXmlStreamAttribute::QXmlStreamAttribute(const QXmlStreamAttribute &other) | - | ||||||
1665 | { | - | ||||||
1666 | *this = other; | - | ||||||
1667 | } | - | ||||||
1668 | - | |||||||
1669 | - | |||||||
1670 | - | |||||||
1671 | - | |||||||
1672 | QXmlStreamAttribute& QXmlStreamAttribute::operator=(const QXmlStreamAttribute &other) | - | ||||||
1673 | { | - | ||||||
1674 | m_name = other.m_name; | - | ||||||
1675 | m_namespaceUri = other.m_namespaceUri; | - | ||||||
1676 | m_qualifiedName = other.m_qualifiedName; | - | ||||||
1677 | m_value = other.m_value; | - | ||||||
1678 | m_isDefault = other.m_isDefault; | - | ||||||
1679 | return *this; | - | ||||||
1680 | } | - | ||||||
1681 | QXmlStreamNotationDeclaration::QXmlStreamNotationDeclaration() | - | ||||||
1682 | { | - | ||||||
1683 | } | - | ||||||
1684 | - | |||||||
1685 | - | |||||||
1686 | - | |||||||
1687 | QXmlStreamNotationDeclaration::QXmlStreamNotationDeclaration(const QXmlStreamNotationDeclaration &other) | - | ||||||
1688 | { | - | ||||||
1689 | *this = other; | - | ||||||
1690 | } | - | ||||||
1691 | - | |||||||
1692 | - | |||||||
1693 | - | |||||||
1694 | - | |||||||
1695 | QXmlStreamNotationDeclaration& QXmlStreamNotationDeclaration::operator=(const QXmlStreamNotationDeclaration &other) | - | ||||||
1696 | { | - | ||||||
1697 | m_name = other.m_name; | - | ||||||
1698 | m_systemId = other.m_systemId; | - | ||||||
1699 | m_publicId = other.m_publicId; | - | ||||||
1700 | return *this; | - | ||||||
1701 | } | - | ||||||
1702 | - | |||||||
1703 | - | |||||||
1704 | - | |||||||
1705 | - | |||||||
1706 | QXmlStreamNotationDeclaration::~QXmlStreamNotationDeclaration() | - | ||||||
1707 | { | - | ||||||
1708 | } | - | ||||||
1709 | QXmlStreamNamespaceDeclaration::QXmlStreamNamespaceDeclaration() | - | ||||||
1710 | { | - | ||||||
1711 | } | - | ||||||
1712 | - | |||||||
1713 | - | |||||||
1714 | - | |||||||
1715 | - | |||||||
1716 | - | |||||||
1717 | - | |||||||
1718 | QXmlStreamNamespaceDeclaration::QXmlStreamNamespaceDeclaration(const QString &prefix, const QString &namespaceUri) | - | ||||||
1719 | { | - | ||||||
1720 | m_prefix = prefix; | - | ||||||
1721 | m_namespaceUri = namespaceUri; | - | ||||||
1722 | } | - | ||||||
1723 | - | |||||||
1724 | - | |||||||
1725 | - | |||||||
1726 | - | |||||||
1727 | QXmlStreamNamespaceDeclaration::QXmlStreamNamespaceDeclaration(const QXmlStreamNamespaceDeclaration &other) | - | ||||||
1728 | { | - | ||||||
1729 | *this = other; | - | ||||||
1730 | } | - | ||||||
1731 | - | |||||||
1732 | - | |||||||
1733 | - | |||||||
1734 | - | |||||||
1735 | QXmlStreamNamespaceDeclaration& QXmlStreamNamespaceDeclaration::operator=(const QXmlStreamNamespaceDeclaration &other) | - | ||||||
1736 | { | - | ||||||
1737 | m_prefix = other.m_prefix; | - | ||||||
1738 | m_namespaceUri = other.m_namespaceUri; | - | ||||||
1739 | return *this; | - | ||||||
1740 | } | - | ||||||
1741 | - | |||||||
1742 | - | |||||||
1743 | - | |||||||
1744 | QXmlStreamNamespaceDeclaration::~QXmlStreamNamespaceDeclaration() | - | ||||||
1745 | { | - | ||||||
1746 | } | - | ||||||
1747 | QXmlStreamEntityDeclaration::QXmlStreamEntityDeclaration() | - | ||||||
1748 | { | - | ||||||
1749 | } | - | ||||||
1750 | - | |||||||
1751 | - | |||||||
1752 | - | |||||||
1753 | - | |||||||
1754 | QXmlStreamEntityDeclaration::QXmlStreamEntityDeclaration(const QXmlStreamEntityDeclaration &other) | - | ||||||
1755 | { | - | ||||||
1756 | *this = other; | - | ||||||
1757 | } | - | ||||||
1758 | - | |||||||
1759 | - | |||||||
1760 | - | |||||||
1761 | - | |||||||
1762 | QXmlStreamEntityDeclaration& QXmlStreamEntityDeclaration::operator=(const QXmlStreamEntityDeclaration &other) | - | ||||||
1763 | { | - | ||||||
1764 | m_name = other.m_name; | - | ||||||
1765 | m_notationName = other.m_notationName; | - | ||||||
1766 | m_systemId = other.m_systemId; | - | ||||||
1767 | m_publicId = other.m_publicId; | - | ||||||
1768 | m_value = other.m_value; | - | ||||||
1769 | return *this; | - | ||||||
1770 | } | - | ||||||
1771 | - | |||||||
1772 | - | |||||||
1773 | - | |||||||
1774 | - | |||||||
1775 | QXmlStreamEntityDeclaration::~QXmlStreamEntityDeclaration() | - | ||||||
1776 | { | - | ||||||
1777 | } | - | ||||||
1778 | QStringRef QXmlStreamAttributes::value(const QString &namespaceUri, const QString &name) const | - | ||||||
1779 | { | - | ||||||
1780 | for (int i = 0; i < size(); ++i) { | - | ||||||
1781 | const QXmlStreamAttribute &attribute = at(i); | - | ||||||
1782 | if (attribute.name() == name && attribute.namespaceUri() == namespaceUri) | - | ||||||
1783 | return attribute.value(); | - | ||||||
1784 | } | - | ||||||
1785 | return QStringRef(); | - | ||||||
1786 | } | - | ||||||
1787 | - | |||||||
1788 | - | |||||||
1789 | - | |||||||
1790 | - | |||||||
1791 | - | |||||||
1792 | - | |||||||
1793 | QStringRef QXmlStreamAttributes::value(const QString &namespaceUri, QLatin1String name) const | - | ||||||
1794 | { | - | ||||||
1795 | for (int i = 0; i < size(); ++i) { | - | ||||||
1796 | const QXmlStreamAttribute &attribute = at(i); | - | ||||||
1797 | if (attribute.name() == name && attribute.namespaceUri() == namespaceUri) | - | ||||||
1798 | return attribute.value(); | - | ||||||
1799 | } | - | ||||||
1800 | return QStringRef(); | - | ||||||
1801 | } | - | ||||||
1802 | - | |||||||
1803 | - | |||||||
1804 | - | |||||||
1805 | - | |||||||
1806 | - | |||||||
1807 | - | |||||||
1808 | QStringRef QXmlStreamAttributes::value(QLatin1String namespaceUri, QLatin1String name) const | - | ||||||
1809 | { | - | ||||||
1810 | for (int i = 0; i < size(); ++i) { | - | ||||||
1811 | const QXmlStreamAttribute &attribute = at(i); | - | ||||||
1812 | if (attribute.name() == name && attribute.namespaceUri() == namespaceUri) | - | ||||||
1813 | return attribute.value(); | - | ||||||
1814 | } | - | ||||||
1815 | return QStringRef(); | - | ||||||
1816 | } | - | ||||||
1817 | QStringRef QXmlStreamAttributes::value(const QString &qualifiedName) const | - | ||||||
1818 | { | - | ||||||
1819 | for (int i = 0; i < size(); ++i) { | - | ||||||
1820 | const QXmlStreamAttribute &attribute = at(i); | - | ||||||
1821 | if (attribute.qualifiedName() == qualifiedName) | - | ||||||
1822 | return attribute.value(); | - | ||||||
1823 | } | - | ||||||
1824 | return QStringRef(); | - | ||||||
1825 | } | - | ||||||
1826 | QStringRef QXmlStreamAttributes::value(QLatin1String qualifiedName) const | - | ||||||
1827 | { | - | ||||||
1828 | for (int i = 0; i < size(); ++i) { | - | ||||||
1829 | const QXmlStreamAttribute &attribute = at(i); | - | ||||||
1830 | if (attribute.qualifiedName() == qualifiedName) | - | ||||||
1831 | return attribute.value(); | - | ||||||
1832 | } | - | ||||||
1833 | return QStringRef(); | - | ||||||
1834 | } | - | ||||||
1835 | - | |||||||
1836 | - | |||||||
1837 | - | |||||||
1838 | - | |||||||
1839 | - | |||||||
1840 | void QXmlStreamAttributes::append(const QString &namespaceUri, const QString &name, const QString &value) | - | ||||||
1841 | { | - | ||||||
1842 | append(QXmlStreamAttribute(namespaceUri, name, value)); | - | ||||||
1843 | } | - | ||||||
1844 | - | |||||||
1845 | - | |||||||
1846 | - | |||||||
1847 | - | |||||||
1848 | - | |||||||
1849 | void QXmlStreamAttributes::append(const QString &qualifiedName, const QString &value) | - | ||||||
1850 | { | - | ||||||
1851 | append(QXmlStreamAttribute(qualifiedName, value)); | - | ||||||
1852 | } | - | ||||||
1853 | bool QXmlStreamReader::isWhitespace() const | - | ||||||
1854 | { | - | ||||||
1855 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1856 | return d->type == QXmlStreamReader::Characters && d->isWhitespace; | - | ||||||
1857 | } | - | ||||||
1858 | - | |||||||
1859 | - | |||||||
1860 | - | |||||||
1861 | - | |||||||
1862 | - | |||||||
1863 | - | |||||||
1864 | bool QXmlStreamReader::isCDATA() const | - | ||||||
1865 | { | - | ||||||
1866 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1867 | return d->type == QXmlStreamReader::Characters && d->isCDATA; | - | ||||||
1868 | } | - | ||||||
1869 | bool QXmlStreamReader::isStandaloneDocument() const | - | ||||||
1870 | { | - | ||||||
1871 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1872 | return d->standalone; | - | ||||||
1873 | } | - | ||||||
1874 | QStringRef QXmlStreamReader::documentVersion() const | - | ||||||
1875 | { | - | ||||||
1876 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1877 | if (d->type == QXmlStreamReader::StartDocument) | - | ||||||
1878 | return d->documentVersion; | - | ||||||
1879 | return QStringRef(); | - | ||||||
1880 | } | - | ||||||
1881 | QStringRef QXmlStreamReader::documentEncoding() const | - | ||||||
1882 | { | - | ||||||
1883 | const QXmlStreamReaderPrivate * const d = d_func(); | - | ||||||
1884 | if (d->type == QXmlStreamReader::StartDocument) | - | ||||||
1885 | return d->documentEncoding; | - | ||||||
1886 | return QStringRef(); | - | ||||||
1887 | } | - | ||||||
1888 | class QXmlStreamWriterPrivate : public QXmlStreamPrivateTagStack { | - | ||||||
1889 | QXmlStreamWriter *q_ptr; | - | ||||||
1890 | inline QXmlStreamWriter* q_func() { return static_cast<QXmlStreamWriter *>(q_ptr); } inline const QXmlStreamWriter* q_func() const { return static_cast<const QXmlStreamWriter *>(q_ptr); } friend class QXmlStreamWriter; | - | ||||||
1891 | public: | - | ||||||
1892 | QXmlStreamWriterPrivate(QXmlStreamWriter *q); | - | ||||||
1893 | ~QXmlStreamWriterPrivate() { | - | ||||||
1894 | if (deleteDevice) | - | ||||||
1895 | delete device; | - | ||||||
1896 | - | |||||||
1897 | delete encoder; | - | ||||||
1898 | - | |||||||
1899 | } | - | ||||||
1900 | - | |||||||
1901 | void write(const QStringRef &); | - | ||||||
1902 | void write(const QString &); | - | ||||||
1903 | void writeEscaped(const QString &, bool escapeWhitespace = false); | - | ||||||
1904 | void write(const char *s, int len); | - | ||||||
1905 | template <int N> void write(const char (&s)[N]) { write(s, N - 1); } | - | ||||||
1906 | bool finishStartElement(bool contents = true); | - | ||||||
1907 | void writeStartElement(const QString &namespaceUri, const QString &name); | - | ||||||
1908 | QIODevice *device; | - | ||||||
1909 | QString *stringDevice; | - | ||||||
1910 | uint deleteDevice :1; | - | ||||||
1911 | uint inStartElement :1; | - | ||||||
1912 | uint inEmptyElement :1; | - | ||||||
1913 | uint lastWasStartElement :1; | - | ||||||
1914 | uint wroteSomething :1; | - | ||||||
1915 | uint hasError :1; | - | ||||||
1916 | uint autoFormatting :1; | - | ||||||
1917 | uint isCodecASCIICompatible :1; | - | ||||||
1918 | QByteArray autoFormattingIndent; | - | ||||||
1919 | NamespaceDeclaration emptyNamespace; | - | ||||||
1920 | int lastNamespaceDeclaration; | - | ||||||
1921 | - | |||||||
1922 | - | |||||||
1923 | QTextCodec *codec; | - | ||||||
1924 | QTextEncoder *encoder; | - | ||||||
1925 | - | |||||||
1926 | void checkIfASCIICompatibleCodec(); | - | ||||||
1927 | - | |||||||
1928 | NamespaceDeclaration &findNamespace(const QString &namespaceUri, bool writeDeclaration = false, bool noDefault = false); | - | ||||||
1929 | void writeNamespaceDeclaration(const NamespaceDeclaration &namespaceDeclaration); | - | ||||||
1930 | - | |||||||
1931 | int namespacePrefixCount; | - | ||||||
1932 | - | |||||||
1933 | void indent(int level); | - | ||||||
1934 | }; | - | ||||||
1935 | - | |||||||
1936 | - | |||||||
1937 | QXmlStreamWriterPrivate::QXmlStreamWriterPrivate(QXmlStreamWriter *q) | - | ||||||
1938 | :autoFormattingIndent(4, ' ') | - | ||||||
1939 | { | - | ||||||
1940 | q_ptr = q; | - | ||||||
1941 | device = 0; | - | ||||||
1942 | stringDevice = 0; | - | ||||||
1943 | deleteDevice = false; | - | ||||||
1944 | - | |||||||
1945 | codec = QTextCodec::codecForMib(106); | - | ||||||
1946 | encoder = codec->makeEncoder(QTextCodec::IgnoreHeader); | - | ||||||
1947 | - | |||||||
1948 | checkIfASCIICompatibleCodec(); | - | ||||||
1949 | inStartElement = inEmptyElement = false; | - | ||||||
1950 | wroteSomething = false; | - | ||||||
1951 | hasError = false; | - | ||||||
1952 | lastWasStartElement = false; | - | ||||||
1953 | lastNamespaceDeclaration = 1; | - | ||||||
1954 | autoFormatting = false; | - | ||||||
1955 | namespacePrefixCount = 0; | - | ||||||
1956 | } | - | ||||||
1957 | - | |||||||
1958 | void QXmlStreamWriterPrivate::checkIfASCIICompatibleCodec() | - | ||||||
1959 | { | - | ||||||
1960 | - | |||||||
1961 | ((!(encoder)) ? qt_assert("encoder",__FILE__,30253031) : qt_noop()); | - | ||||||
1962 | - | |||||||
1963 | QChar letterA = QLatin1Char('a'); | - | ||||||
1964 | const QByteArray bytesA = encoder->fromUnicode(&letterA, 1); | - | ||||||
1965 | const bool isCodecASCIICompatibleA = (bytesA.count() == 1) && (bytesA[0] == 0x61) ; | - | ||||||
1966 | QChar letterLess = QLatin1Char('<'); | - | ||||||
1967 | const QByteArray bytesLess = encoder->fromUnicode(&letterLess, 1); | - | ||||||
1968 | const bool isCodecASCIICompatibleLess = (bytesLess.count() == 1) && (bytesLess[0] == 0x3C) ; | - | ||||||
1969 | isCodecASCIICompatible = isCodecASCIICompatibleA && isCodecASCIICompatibleLess ; | - | ||||||
1970 | - | |||||||
1971 | - | |||||||
1972 | - | |||||||
1973 | } | - | ||||||
1974 | - | |||||||
1975 | void QXmlStreamWriterPrivate::write(const QStringRef &s) | - | ||||||
1976 | { | - | ||||||
1977 | if (device) { | - | ||||||
1978 | if (hasError) | - | ||||||
1979 | return; | - | ||||||
1980 | - | |||||||
1981 | - | |||||||
1982 | - | |||||||
1983 | QByteArray bytes = encoder->fromUnicode(s.constData(), s.size()); | - | ||||||
1984 | - | |||||||
1985 | if (device->write(bytes) != bytes.size()) | - | ||||||
1986 | hasError = true; | - | ||||||
1987 | } | - | ||||||
1988 | else if (stringDevice) | - | ||||||
1989 | s.appendTo(stringDevice); | - | ||||||
1990 | else | - | ||||||
1991 | QMessageLogger(__FILE__, 30553061, __PRETTY_FUNCTION__).warning("QXmlStreamWriter: No device"); | - | ||||||
1992 | } | - | ||||||
1993 | - | |||||||
1994 | void QXmlStreamWriterPrivate::write(const QString &s) | - | ||||||
1995 | { | - | ||||||
1996 | if (device) { | - | ||||||
1997 | if (hasError) | - | ||||||
1998 | return; | - | ||||||
1999 | - | |||||||
2000 | - | |||||||
2001 | - | |||||||
2002 | QByteArray bytes = encoder->fromUnicode(s); | - | ||||||
2003 | - | |||||||
2004 | if (device->write(bytes) != bytes.size()) | - | ||||||
2005 | hasError = true; | - | ||||||
2006 | } | - | ||||||
2007 | else if (stringDevice) | - | ||||||
2008 | stringDevice->append(s); | - | ||||||
2009 | else | - | ||||||
2010 | QMessageLogger(__FILE__, 30743080, __PRETTY_FUNCTION__).warning("QXmlStreamWriter: No device"); | - | ||||||
2011 | } | - | ||||||
2012 | - | |||||||
2013 | void QXmlStreamWriterPrivate::writeEscaped(const QString &s, bool escapeWhitespace) | - | ||||||
2014 | { | - | ||||||
2015 | QString escaped; | - | ||||||
2016 | escaped.reserve(s.size()); | - | ||||||
2017 | for ( int i = 0; i < s.size(); ++i ) { | - | ||||||
2018 | QChar c = s.at(i); | - | ||||||
2019 | if (c.unicode() == '<' ) | - | ||||||
2020 | escaped.append(QLatin1String("<")); | - | ||||||
2021 | else if (c.unicode() == '>' ) | - | ||||||
2022 | escaped.append(QLatin1String(">")); | - | ||||||
2023 | else if (c.unicode() == '&' ) | - | ||||||
2024 | escaped.append(QLatin1String("&")); | - | ||||||
2025 | else if (c.unicode() == '\"' ) | - | ||||||
2026 | escaped.append(QLatin1String(""")); | - | ||||||
2027 | else if (escapeWhitespace && c.isSpace()) { | - | ||||||
2028 | if (c.unicode() == '\n') | - | ||||||
2029 | escaped.append(QLatin1String(" ")); | - | ||||||
2030 | else if (c.unicode() == '\r') | - | ||||||
2031 | escaped.append(QLatin1String(" ")); | - | ||||||
2032 | else if (c.unicode() == '\t') | - | ||||||
2033 | escaped.append(QLatin1String("	")); | - | ||||||
2034 | else | - | ||||||
2035 | escaped += c; | - | ||||||
2036 | } else { | - | ||||||
2037 | escaped += QChar(c); | - | ||||||
2038 | } | - | ||||||
2039 | } | - | ||||||
2040 | write(escaped); | - | ||||||
2041 | } | - | ||||||
2042 | - | |||||||
2043 | - | |||||||
2044 | void QXmlStreamWriterPrivate::write(const char *s, int len) | - | ||||||
2045 | { | - | ||||||
2046 | if (device) { | - | ||||||
2047 | if (hasError) | - | ||||||
2048 | return; | - | ||||||
2049 | if (isCodecASCIICompatible) { | - | ||||||
2050 | if (device->write(s, len) != len) | - | ||||||
2051 | hasError = true; | - | ||||||
2052 | return; | - | ||||||
2053 | } | - | ||||||
2054 | } | - | ||||||
2055 | - | |||||||
2056 | write(QString::fromLatin1(s, len)); | - | ||||||
2057 | } | - | ||||||
2058 | - | |||||||
2059 | void QXmlStreamWriterPrivate::writeNamespaceDeclaration(const NamespaceDeclaration &namespaceDeclaration) { | - | ||||||
2060 | if (namespaceDeclaration.prefix.isEmpty()) { | - | ||||||
2061 | write(" xmlns=\""); | - | ||||||
2062 | write(namespaceDeclaration.namespaceUri); | - | ||||||
2063 | write("\""); | - | ||||||
2064 | } else { | - | ||||||
2065 | write(" xmlns:"); | - | ||||||
2066 | write(namespaceDeclaration.prefix); | - | ||||||
2067 | write("=\""); | - | ||||||
2068 | write(namespaceDeclaration.namespaceUri); | - | ||||||
2069 | write("\""); | - | ||||||
2070 | } | - | ||||||
2071 | } | - | ||||||
2072 | - | |||||||
2073 | bool QXmlStreamWriterPrivate::finishStartElement(bool contents) | - | ||||||
2074 | { | - | ||||||
2075 | bool hadSomethingWritten = wroteSomething; | - | ||||||
2076 | wroteSomething = contents; | - | ||||||
2077 | if (!inStartElement) | - | ||||||
2078 | return hadSomethingWritten; | - | ||||||
2079 | - | |||||||
2080 | if (inEmptyElement) { | - | ||||||
2081 | write("/>"); | - | ||||||
2082 | QXmlStreamWriterPrivate::Tag &tag = tagStack_pop(); | - | ||||||
2083 | lastNamespaceDeclaration = tag.namespaceDeclarationsSize; | - | ||||||
2084 | lastWasStartElement = false; | - | ||||||
2085 | } else { | - | ||||||
2086 | write(">"); | - | ||||||
2087 | } | - | ||||||
2088 | inStartElement = inEmptyElement = false; | - | ||||||
2089 | lastNamespaceDeclaration = namespaceDeclarations.size(); | - | ||||||
2090 | return hadSomethingWritten; | - | ||||||
2091 | } | - | ||||||
2092 | - | |||||||
2093 | QXmlStreamPrivateTagStack::NamespaceDeclaration &QXmlStreamWriterPrivate::findNamespace(const QString &namespaceUri, bool writeDeclaration, bool noDefault) | - | ||||||
2094 | { | - | ||||||
2095 | for (int j = namespaceDeclarations.size() - 1; j >= 0; --j) { | - | ||||||
2096 | NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations[j]; | - | ||||||
2097 | if (namespaceDeclaration.namespaceUri == namespaceUri) { | - | ||||||
2098 | if (!noDefault || !namespaceDeclaration.prefix.isEmpty()) | - | ||||||
2099 | return namespaceDeclaration; | - | ||||||
2100 | } | - | ||||||
2101 | } | - | ||||||
2102 | if (namespaceUri.isEmpty()) | - | ||||||
2103 | return emptyNamespace; | - | ||||||
2104 | NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push(); | - | ||||||
2105 | if (namespaceUri.isEmpty()) { | - | ||||||
2106 | namespaceDeclaration.prefix.clear(); | - | ||||||
2107 | } else { | - | ||||||
2108 | QString s; | - | ||||||
2109 | int n = ++namespacePrefixCount; | - | ||||||
2110 | for(;;) { | - | ||||||
2111 | s = QLatin1Char('n') + QString::number(n++); | - | ||||||
2112 | int j = namespaceDeclarations.size() - 2; | - | ||||||
2113 | while (j >= 0 && namespaceDeclarations.at(j).prefix != s) | - | ||||||
2114 | --j; | - | ||||||
2115 | if (j < 0) | - | ||||||
2116 | break; | - | ||||||
2117 | } | - | ||||||
2118 | namespaceDeclaration.prefix = addToStringStorage(s); | - | ||||||
2119 | } | - | ||||||
2120 | namespaceDeclaration.namespaceUri = addToStringStorage(namespaceUri); | - | ||||||
2121 | if (writeDeclaration) | - | ||||||
2122 | writeNamespaceDeclaration(namespaceDeclaration); | - | ||||||
2123 | return namespaceDeclaration; | - | ||||||
2124 | } | - | ||||||
2125 | - | |||||||
2126 | - | |||||||
2127 | - | |||||||
2128 | void QXmlStreamWriterPrivate::indent(int level) | - | ||||||
2129 | { | - | ||||||
2130 | write("\n"); | - | ||||||
2131 | for (int i = level; i > 0; --i) | - | ||||||
2132 | write(autoFormattingIndent.constData(), autoFormattingIndent.length()); | - | ||||||
2133 | } | - | ||||||
2134 | - | |||||||
2135 | - | |||||||
2136 | - | |||||||
2137 | - | |||||||
2138 | - | |||||||
2139 | - | |||||||
2140 | - | |||||||
2141 | QXmlStreamWriter::QXmlStreamWriter() | - | ||||||
2142 | : d_ptr(new QXmlStreamWriterPrivate(this)) | - | ||||||
2143 | { | - | ||||||
2144 | } | - | ||||||
2145 | - | |||||||
2146 | - | |||||||
2147 | - | |||||||
2148 | - | |||||||
2149 | QXmlStreamWriter::QXmlStreamWriter(QIODevice *device) | - | ||||||
2150 | : d_ptr(new QXmlStreamWriterPrivate(this)) | - | ||||||
2151 | { | - | ||||||
2152 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2153 | d->device = device; | - | ||||||
2154 | } | - | ||||||
2155 | - | |||||||
2156 | - | |||||||
2157 | - | |||||||
2158 | - | |||||||
2159 | - | |||||||
2160 | QXmlStreamWriter::QXmlStreamWriter(QByteArray *array) | - | ||||||
2161 | : d_ptr(new QXmlStreamWriterPrivate(this)) | - | ||||||
2162 | { | - | ||||||
2163 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2164 | d->device = new QBuffer(array); | - | ||||||
2165 | d->device->open(QIODevice::WriteOnly); | - | ||||||
2166 | d->deleteDevice = true; | - | ||||||
2167 | } | - | ||||||
2168 | - | |||||||
2169 | - | |||||||
2170 | - | |||||||
2171 | - | |||||||
2172 | QXmlStreamWriter::QXmlStreamWriter(QString *string) | - | ||||||
2173 | : d_ptr(new QXmlStreamWriterPrivate(this)) | - | ||||||
2174 | { | - | ||||||
2175 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2176 | d->stringDevice = string; | - | ||||||
2177 | } | - | ||||||
2178 | - | |||||||
2179 | - | |||||||
2180 | - | |||||||
2181 | - | |||||||
2182 | QXmlStreamWriter::~QXmlStreamWriter() | - | ||||||
2183 | { | - | ||||||
2184 | } | - | ||||||
2185 | void QXmlStreamWriter::setDevice(QIODevice *device) | - | ||||||
2186 | { | - | ||||||
2187 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2188 | if (device == d->device) | - | ||||||
2189 | return; | - | ||||||
2190 | d->stringDevice = 0; | - | ||||||
2191 | if (d->deleteDevice) { | - | ||||||
2192 | delete d->device; | - | ||||||
2193 | d->deleteDevice = false; | - | ||||||
2194 | } | - | ||||||
2195 | d->device = device; | - | ||||||
2196 | } | - | ||||||
2197 | - | |||||||
2198 | - | |||||||
2199 | - | |||||||
2200 | - | |||||||
2201 | - | |||||||
2202 | - | |||||||
2203 | - | |||||||
2204 | QIODevice *QXmlStreamWriter::device() const | - | ||||||
2205 | { | - | ||||||
2206 | const QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2207 | return d->device; | - | ||||||
2208 | } | - | ||||||
2209 | void QXmlStreamWriter::setCodec(QTextCodec *codec) | - | ||||||
2210 | { | - | ||||||
2211 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2212 | if (codec) { | - | ||||||
2213 | d->codec = codec; | - | ||||||
2214 | delete d->encoder; | - | ||||||
2215 | d->encoder = codec->makeEncoder(QTextCodec::IgnoreHeader); | - | ||||||
2216 | d->checkIfASCIICompatibleCodec(); | - | ||||||
2217 | } | - | ||||||
2218 | } | - | ||||||
2219 | void QXmlStreamWriter::setCodec(const char *codecName) | - | ||||||
2220 | { | - | ||||||
2221 | setCodec(QTextCodec::codecForName(codecName)); | - | ||||||
2222 | } | - | ||||||
2223 | - | |||||||
2224 | - | |||||||
2225 | - | |||||||
2226 | - | |||||||
2227 | - | |||||||
2228 | - | |||||||
2229 | QTextCodec *QXmlStreamWriter::codec() const | - | ||||||
2230 | { | - | ||||||
2231 | const QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2232 | return d->codec; | - | ||||||
2233 | } | - | ||||||
2234 | void QXmlStreamWriter::setAutoFormatting(bool enable) | - | ||||||
2235 | { | - | ||||||
2236 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2237 | d->autoFormatting = enable; | - | ||||||
2238 | } | - | ||||||
2239 | - | |||||||
2240 | - | |||||||
2241 | - | |||||||
2242 | - | |||||||
2243 | - | |||||||
2244 | - | |||||||
2245 | bool QXmlStreamWriter::autoFormatting() const | - | ||||||
2246 | { | - | ||||||
2247 | const QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2248 | return d->autoFormatting; | - | ||||||
2249 | } | - | ||||||
2250 | void QXmlStreamWriter::setAutoFormattingIndent(int spacesOrTabs) | - | ||||||
2251 | { | - | ||||||
2252 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2253 | d->autoFormattingIndent = QByteArray(qAbs(spacesOrTabs), spacesOrTabs >= 0 ? ' ' : '\t'); | - | ||||||
2254 | } | - | ||||||
2255 | - | |||||||
2256 | int QXmlStreamWriter::autoFormattingIndent() const | - | ||||||
2257 | { | - | ||||||
2258 | const QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2259 | return d->autoFormattingIndent.count(' ') - d->autoFormattingIndent.count('\t'); | - | ||||||
2260 | } | - | ||||||
2261 | - | |||||||
2262 | - | |||||||
2263 | - | |||||||
2264 | - | |||||||
2265 | - | |||||||
2266 | - | |||||||
2267 | - | |||||||
2268 | bool QXmlStreamWriter::hasError() const | - | ||||||
2269 | { | - | ||||||
2270 | const QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2271 | return d->hasError; | - | ||||||
2272 | } | - | ||||||
2273 | void QXmlStreamWriter::writeAttribute(const QString &qualifiedName, const QString &value) | - | ||||||
2274 | { | - | ||||||
2275 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2276 | ((!(d->inStartElement)) ? qt_assert("d->inStartElement",__FILE__,34213427) : qt_noop()); | - | ||||||
2277 | ((!(qualifiedName.count(QLatin1Char(':')) <= 1)) ? qt_assert("qualifiedName.count(QLatin1Char(':')) <= 1",__FILE__,34223428) : qt_noop()); | - | ||||||
2278 | d->write(" "); | - | ||||||
2279 | d->write(qualifiedName); | - | ||||||
2280 | d->write("=\""); | - | ||||||
2281 | d->writeEscaped(value, true); | - | ||||||
2282 | d->write("\""); | - | ||||||
2283 | } | - | ||||||
2284 | void QXmlStreamWriter::writeAttribute(const QString &namespaceUri, const QString &name, const QString &value) | - | ||||||
2285 | { | - | ||||||
2286 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2287 | ((!(d->inStartElement)) ? qt_assert("d->inStartElement",__FILE__,34413447) : qt_noop()); | - | ||||||
2288 | ((!(!name.contains(QLatin1Char(':')))) ? qt_assert("!name.contains(QLatin1Char(':'))",__FILE__,34423448) : qt_noop()); | - | ||||||
2289 | QXmlStreamWriterPrivate::NamespaceDeclaration &namespaceDeclaration = d->findNamespace(namespaceUri, true, true); | - | ||||||
2290 | d->write(" "); | - | ||||||
2291 | if (!namespaceDeclaration.prefix.isEmpty()) { | - | ||||||
2292 | d->write(namespaceDeclaration.prefix); | - | ||||||
2293 | d->write(":"); | - | ||||||
2294 | } | - | ||||||
2295 | d->write(name); | - | ||||||
2296 | d->write("=\""); | - | ||||||
2297 | d->writeEscaped(value, true); | - | ||||||
2298 | d->write("\""); | - | ||||||
2299 | } | - | ||||||
2300 | void QXmlStreamWriter::writeAttribute(const QXmlStreamAttribute& attribute) | - | ||||||
2301 | { | - | ||||||
2302 | if (attribute.namespaceUri().isEmpty()) | - | ||||||
2303 | writeAttribute(attribute.qualifiedName().toString(), | - | ||||||
2304 | attribute.value().toString()); | - | ||||||
2305 | else | - | ||||||
2306 | writeAttribute(attribute.namespaceUri().toString(), | - | ||||||
2307 | attribute.name().toString(), | - | ||||||
2308 | attribute.value().toString()); | - | ||||||
2309 | } | - | ||||||
2310 | void QXmlStreamWriter::writeAttributes(const QXmlStreamAttributes& attributes) | - | ||||||
2311 | { | - | ||||||
2312 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2313 | ((!(d->inStartElement)) ? qt_assert("d->inStartElement",__FILE__,34873493) : qt_noop()); | - | ||||||
2314 | (void)d;; | - | ||||||
2315 | for (int i = 0; i < attributes.size(); ++i) | - | ||||||
2316 | writeAttribute(attributes.at(i)); | - | ||||||
2317 | } | - | ||||||
2318 | void QXmlStreamWriter::writeCDATA(const QString &text) | - | ||||||
2319 | { | - | ||||||
2320 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2321 | d->finishStartElement(); | - | ||||||
2322 | QString copy(text); | - | ||||||
2323 | copy.replace(QLatin1String("]]>"), QLatin1String("]]]]><![CDATA[>")); | - | ||||||
2324 | d->write("<![CDATA["); | - | ||||||
2325 | d->write(copy); | - | ||||||
2326 | d->write("]]>"); | - | ||||||
2327 | } | - | ||||||
2328 | void QXmlStreamWriter::writeCharacters(const QString &text) | - | ||||||
2329 | { | - | ||||||
2330 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2331 | d->finishStartElement(); | - | ||||||
2332 | d->writeEscaped(text); | - | ||||||
2333 | } | - | ||||||
2334 | - | |||||||
2335 | - | |||||||
2336 | - | |||||||
2337 | - | |||||||
2338 | - | |||||||
2339 | - | |||||||
2340 | void QXmlStreamWriter::writeComment(const QString &text) | - | ||||||
2341 | { | - | ||||||
2342 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2343 | ((!(!text.contains(QLatin1String("--")) && !text.endsWith(QLatin1Char('-')))) ? qt_assert("!text.contains(QLatin1String(\"--\")) && !text.endsWith(QLatin1Char('-'))",__FILE__,35353541) : qt_noop()); | - | ||||||
2344 | if (!d->finishStartElement(false) && d->autoFormatting) | - | ||||||
2345 | d->indent(d->tagStack.size()); | - | ||||||
2346 | d->write("<!--"); | - | ||||||
2347 | d->write(text); | - | ||||||
2348 | d->write("-->"); | - | ||||||
2349 | d->inStartElement = d->lastWasStartElement = false; | - | ||||||
2350 | } | - | ||||||
2351 | - | |||||||
2352 | - | |||||||
2353 | - | |||||||
2354 | - | |||||||
2355 | - | |||||||
2356 | void QXmlStreamWriter::writeDTD(const QString &dtd) | - | ||||||
2357 | { | - | ||||||
2358 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2359 | d->finishStartElement(); | - | ||||||
2360 | if (d->autoFormatting) | - | ||||||
2361 | d->write("\n"); | - | ||||||
2362 | d->write(dtd); | - | ||||||
2363 | if (d->autoFormatting) | - | ||||||
2364 | d->write("\n"); | - | ||||||
2365 | } | - | ||||||
2366 | - | |||||||
2367 | - | |||||||
2368 | - | |||||||
2369 | - | |||||||
2370 | - | |||||||
2371 | - | |||||||
2372 | - | |||||||
2373 | void QXmlStreamWriter::writeEmptyElement(const QString &qualifiedName) | - | ||||||
2374 | { | - | ||||||
2375 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2376 | ((!(qualifiedName.count(QLatin1Char(':')) <= 1)) ? qt_assert("qualifiedName.count(QLatin1Char(':')) <= 1",__FILE__,35683574) : qt_noop()); | - | ||||||
2377 | d->writeStartElement(QString(), qualifiedName); | - | ||||||
2378 | d->inEmptyElement = true; | - | ||||||
2379 | } | - | ||||||
2380 | void QXmlStreamWriter::writeEmptyElement(const QString &namespaceUri, const QString &name) | - | ||||||
2381 | { | - | ||||||
2382 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2383 | ((!(!name.contains(QLatin1Char(':')))) ? qt_assert("!name.contains(QLatin1Char(':'))",__FILE__,35843590) : qt_noop()); | - | ||||||
2384 | d->writeStartElement(namespaceUri, name); | - | ||||||
2385 | d->inEmptyElement = true; | - | ||||||
2386 | } | - | ||||||
2387 | void QXmlStreamWriter::writeTextElement(const QString &qualifiedName, const QString &text) | - | ||||||
2388 | { | - | ||||||
2389 | writeStartElement(qualifiedName); | - | ||||||
2390 | writeCharacters(text); | - | ||||||
2391 | writeEndElement(); | - | ||||||
2392 | } | - | ||||||
2393 | void QXmlStreamWriter::writeTextElement(const QString &namespaceUri, const QString &name, const QString &text) | - | ||||||
2394 | { | - | ||||||
2395 | writeStartElement(namespaceUri, name); | - | ||||||
2396 | writeCharacters(text); | - | ||||||
2397 | writeEndElement(); | - | ||||||
2398 | } | - | ||||||
2399 | - | |||||||
2400 | - | |||||||
2401 | - | |||||||
2402 | - | |||||||
2403 | - | |||||||
2404 | - | |||||||
2405 | - | |||||||
2406 | void QXmlStreamWriter::writeEndDocument() | - | ||||||
2407 | { | - | ||||||
2408 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2409 | while (d->tagStack.size()) | - | ||||||
2410 | writeEndElement(); | - | ||||||
2411 | d->write("\n"); | - | ||||||
2412 | } | - | ||||||
2413 | - | |||||||
2414 | - | |||||||
2415 | - | |||||||
2416 | - | |||||||
2417 | - | |||||||
2418 | - | |||||||
2419 | void QXmlStreamWriter::writeEndElement() | - | ||||||
2420 | { | - | ||||||
2421 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2422 | if (d->tagStack.isEmpty()) | - | ||||||
2423 | return; | - | ||||||
2424 | - | |||||||
2425 | - | |||||||
2426 | if (d->inStartElement && !d->inEmptyElement) { | - | ||||||
2427 | d->write("/>"); | - | ||||||
2428 | d->lastWasStartElement = d->inStartElement = false; | - | ||||||
2429 | QXmlStreamWriterPrivate::Tag &tag = d->tagStack_pop(); | - | ||||||
2430 | d->lastNamespaceDeclaration = tag.namespaceDeclarationsSize; | - | ||||||
2431 | return; | - | ||||||
2432 | } | - | ||||||
2433 | - | |||||||
2434 | if (!d->finishStartElement(false) && !d->lastWasStartElement && d->autoFormatting) | - | ||||||
2435 | d->indent(d->tagStack.size()-1); | - | ||||||
2436 | if (d->tagStack.isEmpty()) | - | ||||||
2437 | return; | - | ||||||
2438 | d->lastWasStartElement = false; | - | ||||||
2439 | QXmlStreamWriterPrivate::Tag &tag = d->tagStack_pop(); | - | ||||||
2440 | d->lastNamespaceDeclaration = tag.namespaceDeclarationsSize; | - | ||||||
2441 | d->write("</"); | - | ||||||
2442 | if (!tag.namespaceDeclaration.prefix.isEmpty()) { | - | ||||||
2443 | d->write(tag.namespaceDeclaration.prefix); | - | ||||||
2444 | d->write(":"); | - | ||||||
2445 | } | - | ||||||
2446 | d->write(tag.name); | - | ||||||
2447 | d->write(">"); | - | ||||||
2448 | } | - | ||||||
2449 | - | |||||||
2450 | - | |||||||
2451 | - | |||||||
2452 | - | |||||||
2453 | - | |||||||
2454 | - | |||||||
2455 | void QXmlStreamWriter::writeEntityReference(const QString &name) | - | ||||||
2456 | { | - | ||||||
2457 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2458 | d->finishStartElement(); | - | ||||||
2459 | d->write("&"); | - | ||||||
2460 | d->write(name); | - | ||||||
2461 | d->write(";"); | - | ||||||
2462 | } | - | ||||||
2463 | void QXmlStreamWriter::writeNamespace(const QString &namespaceUri, const QString &prefix) | - | ||||||
2464 | { | - | ||||||
2465 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2466 | ((!(!namespaceUri.isEmpty())) ? qt_assert("!namespaceUri.isEmpty()",__FILE__,37053711) : qt_noop()); | - | ||||||
2467 | ((!(prefix != QLatin1String("xmlns"))) ? qt_assert("prefix != QLatin1String(\"xmlns\")",__FILE__,37063712) : qt_noop()); | - | ||||||
2468 | if (prefix.isEmpty()) { | - | ||||||
2469 | d->findNamespace(namespaceUri, d->inStartElement); | - | ||||||
2470 | } else { | - | ||||||
2471 | ((!(!((prefix == QLatin1String("xml")) ^ (namespaceUri == QLatin1String("http://www.w3.org/XML/1998/namespace"))))) ? qt_assert("!((prefix == QLatin1String(\"xml\")) ^ (namespaceUri == QLatin1String(\"http://www.w3.org/XML/1998/namespace\")))",__FILE__,37103716) : qt_noop()); | - | ||||||
2472 | ((!(namespaceUri != QLatin1String("http://www.w3.org/2000/xmlns/"))) ? qt_assert("namespaceUri != QLatin1String(\"http://www.w3.org/2000/xmlns/\")",__FILE__,37113717) : qt_noop()); | - | ||||||
2473 | QXmlStreamWriterPrivate::NamespaceDeclaration &namespaceDeclaration = d->namespaceDeclarations.push(); | - | ||||||
2474 | namespaceDeclaration.prefix = d->addToStringStorage(prefix); | - | ||||||
2475 | namespaceDeclaration.namespaceUri = d->addToStringStorage(namespaceUri); | - | ||||||
2476 | if (d->inStartElement) | - | ||||||
2477 | d->writeNamespaceDeclaration(namespaceDeclaration); | - | ||||||
2478 | } | - | ||||||
2479 | } | - | ||||||
2480 | void QXmlStreamWriter::writeDefaultNamespace(const QString &namespaceUri) | - | ||||||
2481 | { | - | ||||||
2482 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2483 | ((!(namespaceUri != QLatin1String("http://www.w3.org/XML/1998/namespace"))) ? qt_assert("namespaceUri != QLatin1String(\"http://www.w3.org/XML/1998/namespace\")",__FILE__,37343740) : qt_noop()); | - | ||||||
2484 | ((!(namespaceUri != QLatin1String("http://www.w3.org/2000/xmlns/"))) ? qt_assert("namespaceUri != QLatin1String(\"http://www.w3.org/2000/xmlns/\")",__FILE__,37353741) : qt_noop()); | - | ||||||
2485 | QXmlStreamWriterPrivate::NamespaceDeclaration &namespaceDeclaration = d->namespaceDeclarations.push(); | - | ||||||
2486 | namespaceDeclaration.prefix.clear(); | - | ||||||
2487 | namespaceDeclaration.namespaceUri = d->addToStringStorage(namespaceUri); | - | ||||||
2488 | if (d->inStartElement) | - | ||||||
2489 | d->writeNamespaceDeclaration(namespaceDeclaration); | - | ||||||
2490 | } | - | ||||||
2491 | - | |||||||
2492 | - | |||||||
2493 | - | |||||||
2494 | - | |||||||
2495 | - | |||||||
2496 | - | |||||||
2497 | void QXmlStreamWriter::writeProcessingInstruction(const QString &target, const QString &data) | - | ||||||
2498 | { | - | ||||||
2499 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2500 | ((!(!data.contains(QLatin1String("?>")))) ? qt_assert("!data.contains(QLatin1String(\"?>\"))",__FILE__,37513757) : qt_noop()); | - | ||||||
2501 | if (!d->finishStartElement(false) && d->autoFormatting) | - | ||||||
2502 | d->indent(d->tagStack.size()); | - | ||||||
2503 | d->write("<?"); | - | ||||||
2504 | d->write(target); | - | ||||||
2505 | if (!data.isNull()) { | - | ||||||
2506 | d->write(" "); | - | ||||||
2507 | d->write(data); | - | ||||||
2508 | } | - | ||||||
2509 | d->write("?>"); | - | ||||||
2510 | } | - | ||||||
2511 | void QXmlStreamWriter::writeStartDocument() | - | ||||||
2512 | { | - | ||||||
2513 | writeStartDocument(QLatin1String("1.0")); | - | ||||||
2514 | } | - | ||||||
2515 | - | |||||||
2516 | - | |||||||
2517 | - | |||||||
2518 | - | |||||||
2519 | - | |||||||
2520 | - | |||||||
2521 | - | |||||||
2522 | void QXmlStreamWriter::writeStartDocument(const QString &version) | - | ||||||
2523 | { | - | ||||||
2524 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2525 | d->finishStartElement(false); | - | ||||||
2526 | d->write("<?xml version=\""); | - | ||||||
2527 | d->write(version); | - | ||||||
2528 | if (d->device
| 2-35 | ||||||
2529 | d->write("\" encoding=\""); | - | ||||||
2530 | - | |||||||
2531 | - | |||||||
2532 | - | |||||||
2533 | d->write(const QByteArray name = d->codec->name().constData(),(); | - | ||||||
2534 | d->codec->write(name()..constData(), name.length()); | - | ||||||
2535 | - | |||||||
2536 | } executed 35 times by 3 tests: end of block Executed by:
| 35 | ||||||
2537 | d->write("\"?>"); | - | ||||||
2538 | } executed 37 times by 3 tests: end of block Executed by:
| 37 | ||||||
2539 | - | |||||||
2540 | - | |||||||
2541 | - | |||||||
2542 | - | |||||||
2543 | - | |||||||
2544 | - | |||||||
2545 | - | |||||||
2546 | void QXmlStreamWriter::writeStartDocument(const QString &version, bool standalone) | - | ||||||
2547 | { | - | ||||||
2548 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2549 | d->finishStartElement(false); | - | ||||||
2550 | d->write("<?xml version=\""); | - | ||||||
2551 | d->write(version); | - | ||||||
2552 | if (d->device
| 0-2 | ||||||
2553 | d->write("\" encoding=\""); | - | ||||||
2554 | - | |||||||
2555 | - | |||||||
2556 | - | |||||||
2557 | d->write(const QByteArray name = d->codec->name().constData(),(); | - | ||||||
2558 | d->codec->write(name()..constData(), name.length()); | - | ||||||
2559 | - | |||||||
2560 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||
2561 | if (standalone
| 1 | ||||||
2562 | d->write("\" standalone=\"yes\"?>"); executed 1 time by 1 test: d->write("\" standalone=\"yes\"?>"); Executed by:
| 1 | ||||||
2563 | else | - | ||||||
2564 | d->write("\" standalone=\"no\"?>"); executed 1 time by 1 test: d->write("\" standalone=\"no\"?>"); Executed by:
| 1 | ||||||
2565 | } | - | ||||||
2566 | void QXmlStreamWriter::writeStartElement(const QString &qualifiedName) | - | ||||||
2567 | { | - | ||||||
2568 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2569 | ((!(qualifiedName.count(QLatin1Char(':')) <= 1)) ? qt_assert("qualifiedName.count(QLatin1Char(':')) <= 1",__FILE__,38383846) : qt_noop()); | - | ||||||
2570 | d->writeStartElement(QString(), qualifiedName); | - | ||||||
2571 | } | - | ||||||
2572 | void QXmlStreamWriter::writeStartElement(const QString &namespaceUri, const QString &name) | - | ||||||
2573 | { | - | ||||||
2574 | QXmlStreamWriterPrivate * const d = d_func(); | - | ||||||
2575 | ((!(!name.contains(QLatin1Char(':')))) ? qt_assert("!name.contains(QLatin1Char(':'))",__FILE__,38543862) : qt_noop()); | - | ||||||
2576 | d->writeStartElement(namespaceUri, name); | - | ||||||
2577 | } | - | ||||||
2578 | - | |||||||
2579 | void QXmlStreamWriterPrivate::writeStartElement(const QString &namespaceUri, const QString &name) | - | ||||||
2580 | { | - | ||||||
2581 | if (!finishStartElement(false) && autoFormatting) | - | ||||||
2582 | indent(tagStack.size()); | - | ||||||
2583 | - | |||||||
2584 | Tag &tag = tagStack_push(); | - | ||||||
2585 | tag.name = addToStringStorage(name); | - | ||||||
2586 | tag.namespaceDeclaration = findNamespace(namespaceUri); | - | ||||||
2587 | write("<"); | - | ||||||
2588 | if (!tag.namespaceDeclaration.prefix.isEmpty()) { | - | ||||||
2589 | write(tag.namespaceDeclaration.prefix); | - | ||||||
2590 | write(":"); | - | ||||||
2591 | } | - | ||||||
2592 | write(tag.name); | - | ||||||
2593 | inStartElement = lastWasStartElement = true; | - | ||||||
2594 | - | |||||||
2595 | for (int i = lastNamespaceDeclaration; i < namespaceDeclarations.size(); ++i) | - | ||||||
2596 | writeNamespaceDeclaration(namespaceDeclarations[i]); | - | ||||||
2597 | tag.namespaceDeclarationsSize = lastNamespaceDeclaration; | - | ||||||
2598 | } | - | ||||||
2599 | void QXmlStreamWriter::writeCurrentToken(const QXmlStreamReader &reader) | - | ||||||
2600 | { | - | ||||||
2601 | switch (reader.tokenType()) { | - | ||||||
2602 | case QXmlStreamReader::NoToken: | - | ||||||
2603 | break; | - | ||||||
2604 | case QXmlStreamReader::StartDocument: | - | ||||||
2605 | writeStartDocument(); | - | ||||||
2606 | break; | - | ||||||
2607 | case QXmlStreamReader::EndDocument: | - | ||||||
2608 | writeEndDocument(); | - | ||||||
2609 | break; | - | ||||||
2610 | case QXmlStreamReader::StartElement: { | - | ||||||
2611 | QXmlStreamNamespaceDeclarations namespaceDeclarations = reader.namespaceDeclarations(); | - | ||||||
2612 | for (int i = 0; i < namespaceDeclarations.size(); ++i) { | - | ||||||
2613 | const QXmlStreamNamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.at(i); | - | ||||||
2614 | writeNamespace(namespaceDeclaration.namespaceUri().toString(), | - | ||||||
2615 | namespaceDeclaration.prefix().toString()); | - | ||||||
2616 | } | - | ||||||
2617 | writeStartElement(reader.namespaceUri().toString(), reader.name().toString()); | - | ||||||
2618 | writeAttributes(reader.attributes()); | - | ||||||
2619 | } break; | - | ||||||
2620 | case QXmlStreamReader::EndElement: | - | ||||||
2621 | writeEndElement(); | - | ||||||
2622 | break; | - | ||||||
2623 | case QXmlStreamReader::Characters: | - | ||||||
2624 | if (reader.isCDATA()) | - | ||||||
2625 | writeCDATA(reader.text().toString()); | - | ||||||
2626 | else | - | ||||||
2627 | writeCharacters(reader.text().toString()); | - | ||||||
2628 | break; | - | ||||||
2629 | case QXmlStreamReader::Comment: | - | ||||||
2630 | writeComment(reader.text().toString()); | - | ||||||
2631 | break; | - | ||||||
2632 | case QXmlStreamReader::DTD: | - | ||||||
2633 | writeDTD(reader.text().toString()); | - | ||||||
2634 | break; | - | ||||||
2635 | case QXmlStreamReader::EntityReference: | - | ||||||
2636 | writeEntityReference(reader.name().toString()); | - | ||||||
2637 | break; | - | ||||||
2638 | case QXmlStreamReader::ProcessingInstruction: | - | ||||||
2639 | writeProcessingInstruction(reader.processingInstructionTarget().toString(), | - | ||||||
2640 | reader.processingInstructionData().toString()); | - | ||||||
2641 | break; | - | ||||||
2642 | default: | - | ||||||
2643 | ((!(reader.tokenType() != QXmlStreamReader::Invalid)) ? qt_assert("reader.tokenType() != QXmlStreamReader::Invalid",__FILE__,39313939) : qt_noop()); | - | ||||||
2644 | QMessageLogger(__FILE__, 39323940, __PRETTY_FUNCTION__).warning("QXmlStreamWriter: writeCurrentToken() with invalid state."); | - | ||||||
2645 | break; | - | ||||||
2646 | } | - | ||||||
2647 | } | - | ||||||
2648 | - | |||||||
Switch to Source code | Preprocessed file |