diff options
Diffstat (limited to 'src/corelib/serialization/qxmlstream.g')
-rw-r--r-- | src/corelib/serialization/qxmlstream.g | 589 |
1 files changed, 106 insertions, 483 deletions
diff --git a/src/corelib/serialization/qxmlstream.g b/src/corelib/serialization/qxmlstream.g index 876157a9e6..860b7fd727 100644 --- a/src/corelib/serialization/qxmlstream.g +++ b/src/corelib/serialization/qxmlstream.g @@ -1,45 +1,8 @@ ----------------------------------------------------------------------------- --- --- Copyright (C) 2016 The Qt Company Ltd. --- Contact: https://www.qt.io/licensing/ --- --- This file is part of the QtCore module of the Qt Toolkit. --- --- $QT_BEGIN_LICENSE:LGPL$ --- Commercial License Usage --- Licensees holding valid commercial Qt licenses may use this file in --- accordance with the commercial license agreement provided with the --- Software or, alternatively, in accordance with the terms contained in --- a written agreement between you and The Qt Company. For licensing terms --- and conditions see https://www.qt.io/terms-conditions. For further --- information use the contact form at https://www.qt.io/contact-us. --- --- GNU Lesser General Public License Usage --- Alternatively, this file may be used under the terms of the GNU Lesser --- General Public License version 3 as published by the Free Software --- Foundation and appearing in the file LICENSE.LGPL3 included in the --- packaging of this file. Please review the following information to --- ensure the GNU Lesser General Public License version 3 requirements --- will be met: https://www.gnu.org/licenses/lgpl-3.0.html. --- --- GNU General Public License Usage --- Alternatively, this file may be used under the terms of the GNU --- General Public License version 2.0 or (at your option) the GNU General --- Public license version 3 or any later version approved by the KDE Free --- Qt Foundation. The licenses are as published by the Free Software --- Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 --- included in the packaging of this file. Please review the following --- information to ensure the GNU General Public License requirements will --- be met: https://www.gnu.org/licenses/gpl-2.0.html and --- https://www.gnu.org/licenses/gpl-3.0.html. --- --- $QT_END_LICENSE$ --- ----------------------------------------------------------------------------- - -%parser QXmlStreamReader_Table - -%merged_output qxmlstream_p.h +-- Copyright (C) 2020 The Qt Company Ltd. +-- SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +%parser QXmlStreamGrammar +%impl qxmlstreamparser_p.h %expect 4 @@ -89,13 +52,13 @@ %token IMPLIED "IMPLIED" %token FIXED "FIXED" --- conent spec +-- content spec %token EMPTY "EMPTY" %token ANY "ANY" %token PCDATA "PCDATA" -- error -%token ERROR +%token XML_ERROR -- entities %token PARSE_ENTITY @@ -146,412 +109,54 @@ %start document - - -/. +/.// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +// +// W A R N I N G +// ------------- +// +// This file is automatically generated from qxmlstream.g. +// Changes should be made to that file, not here. Any change to this file will +// be lost! +// +// To regenerate this file, run: +// qlalr --no-debug --no-lines --qt qxmlstream.g +// #include <QtCore/private/qglobal_p.h> +#include <qxmlstream.h> +#include "qxmlstream_p.h" +#include "qxmlutils_p.h" #include <qstringconverter.h> -template <typename T> class QXmlStreamSimpleStack { - T *data; - qsizetype tos, cap; -public: - inline QXmlStreamSimpleStack():data(nullptr), tos(-1), cap(0){} - inline ~QXmlStreamSimpleStack(){ if (data) free(data); } - - inline void reserve(qsizetype extraCapacity) { - if (tos + extraCapacity + 1 > cap) { - cap = qMax(tos + extraCapacity + 1, cap << 1 ); - void *ptr = realloc(static_cast<void *>(data), cap * sizeof(T)); - data = reinterpret_cast<T *>(ptr); - Q_CHECK_PTR(data); - } - } - - inline T &push() { reserve(1); return data[++tos]; } - inline T &rawPush() { return data[++tos]; } - inline const T &top() const { return data[tos]; } - inline T &top() { return data[tos]; } - inline T &pop() { return data[tos--]; } - inline T &operator[](qsizetype index) { return data[index]; } - inline const T &at(qsizetype index) const { return data[index]; } - inline qsizetype size() const { return tos + 1; } - inline void resize(qsizetype s) { tos = s - 1; } - inline bool isEmpty() const { return tos < 0; } - inline void clear() { tos = -1; } - - using const_iterator = const T*; - using iterator = T*; - T *begin() { return data; } - const T *begin() const { return data; } - const T *cbegin() const { return begin(); } - T *end() { return data + size(); } - const T *end() const { return data + size(); } - const T *cend() const { return end(); } -}; - - -class QXmlStream -{ - Q_DECLARE_TR_FUNCTIONS(QXmlStream) -}; - -class QXmlStreamPrivateTagStack { -public: - struct NamespaceDeclaration - { - QStringRef prefix; - QStringRef namespaceUri; - }; - - struct Tag - { - QStringRef name; - QStringRef qualifiedName; - NamespaceDeclaration namespaceDeclaration; - int tagStackStringStorageSize; - qsizetype namespaceDeclarationsSize; - }; - - - QXmlStreamPrivateTagStack(); - QXmlStreamSimpleStack<NamespaceDeclaration> namespaceDeclarations; - QString tagStackStringStorage; - int tagStackStringStorageSize; - int initialTagStackStringStorageSize; - bool tagsDone; - - inline QStringRef addToStringStorage(const QStringRef &s) { - return addToStringStorage(qToStringViewIgnoringNull(s)); - } - inline QStringRef addToStringStorage(const QString &s) { - return addToStringStorage(qToStringViewIgnoringNull(s)); - } - QStringRef addToStringStorage(QStringView s) - { - int pos = tagStackStringStorageSize; - int sz = s.size(); - if (pos != tagStackStringStorage.size()) - tagStackStringStorage.resize(pos); - tagStackStringStorage.append(s.data(), sz); - tagStackStringStorageSize += sz; - return QStringRef(&tagStackStringStorage, pos, sz); - } - - QXmlStreamSimpleStack<Tag> tagStack; +#include <memory> +#ifndef QXMLSTREAMPARSER_P_H +#define QXMLSTREAMPARSER_P_H - inline Tag &tagStack_pop() { - Tag& tag = tagStack.pop(); - tagStackStringStorageSize = tag.tagStackStringStorageSize; - namespaceDeclarations.resize(tag.namespaceDeclarationsSize); - tagsDone = tagStack.isEmpty(); - return tag; - } - inline Tag &tagStack_push() { - Tag &tag = tagStack.push(); - tag.tagStackStringStorageSize = tagStackStringStorageSize; - tag.namespaceDeclarationsSize = namespaceDeclarations.size(); - return tag; - } -}; - - -class QXmlStreamEntityResolver; -#ifndef QT_NO_XMLSTREAMREADER -class QXmlStreamReaderPrivate : public QXmlStreamReader_Table, public QXmlStreamPrivateTagStack{ - QXmlStreamReader *q_ptr; - Q_DECLARE_PUBLIC(QXmlStreamReader) -public: - QXmlStreamReaderPrivate(QXmlStreamReader *q); - ~QXmlStreamReaderPrivate(); - void init(); - - QByteArray rawReadBuffer; - QByteArray dataBuffer; - uchar firstByte; - qint64 nbytesread; - QString readBuffer; - int readBufferPos; - QXmlStreamSimpleStack<uint> putStack; - struct Entity { - Entity() = default; - Entity(const QString &name, const QString &value) - : name(name), value(value), external(false), unparsed(false), literal(false), - hasBeenParsed(false), isCurrentlyReferenced(false){} - static inline Entity createLiteral(QLatin1String name, QLatin1String value) - { Entity result(name, value); result.literal = result.hasBeenParsed = true; return result; } - QString name, value; - uint external : 1; - uint unparsed : 1; - uint literal : 1; - uint hasBeenParsed : 1; - uint isCurrentlyReferenced : 1; - }; - // these hash tables use a QStringView as a key to avoid creating QStrings - // just for lookup. The keys are usually views into Entity::name and thus - // are guaranteed to have the same lifetime as the referenced data: - QHash<QStringView, Entity> entityHash; - QHash<QStringView, Entity> parameterEntityHash; - QXmlStreamSimpleStack<Entity *>entityReferenceStack; - int entityExpansionLimit = 4096; - int entityLength = 0; - inline bool referenceEntity(Entity &entity) { - if (entity.isCurrentlyReferenced) { - raiseWellFormedError(QXmlStream::tr("Self-referencing entity detected.")); - return false; - } - // entityLength represents the amount of additional characters the - // entity expands into (can be negative for e.g. &). It's used to - // avoid DoS attacks through recursive entity expansions - entityLength += entity.value.size() - entity.name.size() - 2; - if (entityLength > entityExpansionLimit) { - raiseWellFormedError(QXmlStream::tr("Entity expands to more characters than the entity expansion limit.")); - return false; - } - entity.isCurrentlyReferenced = true; - entityReferenceStack.push() = &entity; - injectToken(ENTITY_DONE); - return true; - } - +QT_BEGIN_NAMESPACE - QIODevice *device; - bool deleteDevice; - QStringDecoder decoder; - bool atEnd; - - /*! - \sa setType() - */ - QXmlStreamReader::TokenType type; - QXmlStreamReader::Error error; - QString errorString; - QString unresolvedEntity; - - qint64 lineNumber, lastLineStart, characterOffset; - - - void write(const QString &); - void write(const char *); - - - QXmlStreamAttributes attributes; - QStringRef namespaceForPrefix(const QStringRef &prefix); - void resolveTag(); - void resolvePublicNamespaces(); - void resolveDtd(); - uint resolveCharRef(int symbolIndex); - bool checkStartDocument(); - void startDocument(); - void parseError(); - void checkPublicLiteral(const QStringRef &publicId); - - bool scanDtd; - QStringRef lastAttributeValue; - bool lastAttributeIsCData; - struct DtdAttribute { - QStringRef tagName; - QStringRef attributeQualifiedName; - QStringRef attributePrefix; - QStringRef attributeName; - QStringRef defaultValue; - bool isCDATA; - bool isNamespaceAttribute; - }; - QXmlStreamSimpleStack<DtdAttribute> dtdAttributes; - struct NotationDeclaration { - QStringRef name; - QStringRef publicId; - QStringRef systemId; - }; - QXmlStreamSimpleStack<NotationDeclaration> notationDeclarations; - QXmlStreamNotationDeclarations publicNotationDeclarations; - QXmlStreamNamespaceDeclarations publicNamespaceDeclarations; - - struct EntityDeclaration { - QStringRef name; - QStringRef notationName; - QStringRef publicId; - QStringRef systemId; - QStringRef value; - bool parameter; - bool external; - inline void clear() { - name.clear(); - notationName.clear(); - publicId.clear(); - systemId.clear(); - value.clear(); - parameter = external = false; - } - }; - QXmlStreamSimpleStack<EntityDeclaration> entityDeclarations; - QXmlStreamEntityDeclarations publicEntityDeclarations; - - QStringRef text; - - QStringRef prefix, namespaceUri, qualifiedName, name; - QStringRef processingInstructionTarget, processingInstructionData; - QStringRef dtdName, dtdPublicId, dtdSystemId; - QStringRef documentVersion, documentEncoding; - uint isEmptyElement : 1; - uint isWhitespace : 1; - uint isCDATA : 1; - uint standalone : 1; - uint hasCheckedStartDocument : 1; - uint normalizeLiterals : 1; - uint hasSeenTag : 1; - uint inParseEntity : 1; - uint referenceToUnparsedEntityDetected : 1; - uint referenceToParameterEntityDetected : 1; - uint hasExternalDtdSubset : 1; - uint lockEncoding : 1; - uint namespaceProcessing : 1; - - int resumeReduction; - void resume(int rule); - - inline bool entitiesMustBeDeclared() const { - return (!inParseEntity - && (standalone - || (!referenceToUnparsedEntityDetected - && !referenceToParameterEntityDetected // Errata 13 as of 2006-04-25 - && !hasExternalDtdSubset))); - } - - // qlalr parser - int tos; - int stack_size; - struct Value { - int pos; - int len; - int prefix; - ushort c; - }; - - Value *sym_stack; - int *state_stack; - inline void reallocateStack(); - inline Value &sym(int index) const - { return sym_stack[tos + index - 1]; } - QString textBuffer; - inline void clearTextBuffer() { - if (!scanDtd) { - textBuffer.resize(0); - textBuffer.reserve(256); - } - } - struct Attribute { - Value key; - Value value; - }; - QXmlStreamSimpleStack<Attribute> attributeStack; - - inline QStringRef symString(int index) { - const Value &symbol = sym(index); - return QStringRef(&textBuffer, symbol.pos + symbol.prefix, symbol.len - symbol.prefix); - } - QStringView symView(int index) const - { - const Value &symbol = sym(index); - return QStringView(textBuffer.data() + symbol.pos, symbol.len).mid(symbol.prefix); - } - inline QStringRef symName(int index) { - const Value &symbol = sym(index); - return QStringRef(&textBuffer, symbol.pos, symbol.len); - } - inline QStringRef symString(int index, int offset) { - const Value &symbol = sym(index); - return QStringRef(&textBuffer, symbol.pos + symbol.prefix + offset, symbol.len - symbol.prefix - offset); - } - inline QStringRef symPrefix(int index) { - const Value &symbol = sym(index); - if (symbol.prefix) - return QStringRef(&textBuffer, symbol.pos, symbol.prefix - 1); - return QStringRef(); - } - inline QStringRef symString(const Value &symbol) { - return QStringRef(&textBuffer, symbol.pos + symbol.prefix, symbol.len - symbol.prefix); - } - inline QStringRef symName(const Value &symbol) { - return QStringRef(&textBuffer, symbol.pos, symbol.len); - } - inline QStringRef symPrefix(const Value &symbol) { - if (symbol.prefix) - return QStringRef(&textBuffer, symbol.pos, symbol.prefix - 1); - return QStringRef(); - } - - inline void clearSym() { Value &val = sym(1); val.pos = textBuffer.size(); val.len = 0; } - - - short token; - uint token_char; - - uint filterCarriageReturn(); - inline uint getChar(); - inline uint peekChar(); - inline void putChar(uint c) { putStack.push() = c; } - inline void putChar(QChar c) { putStack.push() = c.unicode(); } - void putString(QStringView s, qsizetype from = 0); - void putStringLiteral(QStringView s); - void putReplacement(QStringView s); - void putReplacementInAttributeValue(QStringView s); - uint getChar_helper(); - - bool scanUntil(const char *str, short tokenToInject = -1); - bool scanString(const char *str, short tokenToInject, bool requireSpace = true); - inline void injectToken(ushort tokenToInject) { - putChar(int(tokenToInject) << 16); - } - - QString resolveUndeclaredEntity(const QString &name); - void parseEntity(const QString &value); - std::unique_ptr<QXmlStreamReaderPrivate> entityParser; - - bool scanAfterLangleBang(); - bool scanPublicOrSystem(); - bool scanNData(); - bool scanAfterDefaultDecl(); - bool scanAttType(); - - - // scan optimization functions. Not strictly necessary but LALR is - // not very well suited for scanning fast - int fastScanLiteralContent(); - int fastScanSpace(); - int fastScanContentCharList(); - int fastScanName(int *prefix = nullptr); - inline int fastScanNMTOKEN(); - - - bool parse(); - inline void consumeRule(int); - - void raiseError(QXmlStreamReader::Error error, const QString& message = QString()); - void raiseWellFormedError(const QString &message); - - QXmlStreamEntityResolver *entityResolver; - -private: - /*! \internal - Never assign to variable type directly. Instead use this function. - - This prevents errors from being ignored. - */ - inline void setType(const QXmlStreamReader::TokenType t) - { - if(type != QXmlStreamReader::Invalid) - type = t; - } -}; +#if QT_CONFIG(xmlstreamreader) bool QXmlStreamReaderPrivate::parse() { // cleanup currently reported token + using namespace Qt::StringLiterals; + switch (type) { case QXmlStreamReader::StartElement: name.clear(); @@ -562,8 +167,9 @@ bool QXmlStreamReaderPrivate::parse() attributes.clear(); if (isEmptyElement) { setType(QXmlStreamReader::EndElement); - Tag &tag = tagStack_pop(); + Tag tag = tagStack_pop(); namespaceUri = tag.namespaceDeclaration.namespaceUri; + prefix = tag.namespaceDeclaration.prefix; name = tag.name; qualifiedName = tag.qualifiedName; isEmptyElement = false; @@ -645,7 +251,7 @@ bool QXmlStreamReaderPrivate::parse() } else switch (token_char) { case 0xfffe: case 0xffff: - token = ERROR; + token = XML_ERROR; break; case '\r': token = SPACE; @@ -851,12 +457,15 @@ prolog ::=; entity_done ::= ENTITY_DONE; /. - case $rule_number: - entityReferenceStack.pop()->isCurrentlyReferenced = false; + case $rule_number: { + auto reference = entityReferenceStack.pop(); + auto it = reference.hash->find(reference.name); + Q_ASSERT(it != reference.hash->end()); + it->isCurrentlyReferenced = false; if (entityReferenceStack.isEmpty()) entityLength = 0; clearSym(); - break; + } break; ./ @@ -1055,9 +664,9 @@ attdef ::= attdef_start att_type default_decl; dtdAttribute.attributePrefix = addToStringStorage(symPrefix(1)); dtdAttribute.attributeName = addToStringStorage(symString(1)); dtdAttribute.attributeQualifiedName = addToStringStorage(symName(1)); - dtdAttribute.isNamespaceAttribute = (dtdAttribute.attributePrefix == QLatin1String("xmlns") + dtdAttribute.isNamespaceAttribute = (dtdAttribute.attributePrefix == "xmlns"_L1 || (dtdAttribute.attributePrefix.isEmpty() - && dtdAttribute.attributeName == QLatin1String("xmlns"))); + && dtdAttribute.attributeName == "xmlns"_L1)); if (lastAttributeValue.isNull()) { dtdAttribute.defaultValue.clear(); } else { @@ -1079,14 +688,14 @@ attlist_decl ::= langle_bang ATTLIST qname attdef_list space_opt RANGLE; case $rule_number: { if (referenceToUnparsedEntityDetected && !standalone) break; - int n = dtdAttributes.size(); - QStringRef tagName = addToStringStorage(symName(3)); + qsizetype n = dtdAttributes.size(); + XmlStringRef tagName = addToStringStorage(symName(3)); while (n--) { DtdAttribute &dtdAttribute = dtdAttributes[n]; if (!dtdAttribute.tagName.isNull()) break; dtdAttribute.tagName = tagName; - for (int i = 0; i < n; ++i) { + for (qsizetype i = 0; i < n; ++i) { if ((dtdAttributes[i].tagName.isNull() || dtdAttributes[i].tagName == tagName) && dtdAttributes[i].attributeQualifiedName == dtdAttribute.attributeQualifiedName) { dtdAttribute.attributeQualifiedName.clear(); // redefined, delete it @@ -1177,7 +786,7 @@ entity_decl ::= entity_decl_start entity_value space_opt RANGLE; if (!entityDeclaration.external) entityDeclaration.value = symString(2); auto &hash = entityDeclaration.parameter ? parameterEntityHash : entityHash; - if (!hash.contains(qToStringViewIgnoringNull(entityDeclaration.name))) { + if (!hash.contains(entityDeclaration.name)) { Entity entity(entityDeclaration.name.toString(), entityDeclaration.value.toString()); entity.unparsed = (!entityDeclaration.notationName.isNull()); @@ -1192,11 +801,11 @@ processing_instruction ::= LANGLE QUESTIONMARK name space; /. case $rule_number: { setType(QXmlStreamReader::ProcessingInstruction); - int pos = sym(4).pos + sym(4).len; + const qsizetype pos = sym(4).pos + sym(4).len; processingInstructionTarget = symString(3); if (scanUntil("?>")) { - processingInstructionData = QStringRef(&textBuffer, pos, textBuffer.size() - pos - 2); - if (!processingInstructionTarget.compare(QLatin1String("xml"), Qt::CaseInsensitive)) { + processingInstructionData = XmlStringRef(&textBuffer, pos, textBuffer.size() - pos - 2); + if (!processingInstructionTarget.view().compare("xml"_L1, Qt::CaseInsensitive)) { raiseWellFormedError(QXmlStream::tr("XML declaration not at start of document.")); } else if (!QXmlUtils::isNCName(processingInstructionTarget)) @@ -1214,7 +823,7 @@ processing_instruction ::= LANGLE QUESTIONMARK name QUESTIONMARK RANGLE; case $rule_number: setType(QXmlStreamReader::ProcessingInstruction); processingInstructionTarget = symString(3); - if (!processingInstructionTarget.compare(QLatin1String("xml"), Qt::CaseInsensitive)) + if (!processingInstructionTarget.view().compare("xml"_L1, Qt::CaseInsensitive)) raiseWellFormedError(QXmlStream::tr("Invalid processing instruction name.")); break; ./ @@ -1244,8 +853,8 @@ comment ::= comment_start RANGLE; /. case $rule_number: { setType(QXmlStreamReader::Comment); - int pos = sym(1).pos + 4; - text = QStringRef(&textBuffer, pos, textBuffer.size() - pos - 3); + const qsizetype pos = sym(1).pos + 4; + text = XmlStringRef(&textBuffer, pos, textBuffer.size() - pos - 3); } break; ./ @@ -1256,9 +865,9 @@ cdata ::= langle_bang CDATA_START; setType(QXmlStreamReader::Characters); isCDATA = true; isWhitespace = false; - int pos = sym(2).pos; + const qsizetype pos = sym(2).pos; if (scanUntil("]]>", -1)) { - text = QStringRef(&textBuffer, pos, textBuffer.size() - pos - 3); + text = XmlStringRef(&textBuffer, pos, textBuffer.size() - pos - 3); } else { resume($rule_number); return false; @@ -1392,7 +1001,7 @@ literal_content_start ::= SPACE; /. case $rule_number: if (normalizeLiterals) - textBuffer.data()[textBuffer.size()-1] = QLatin1Char(' '); + textBuffer.data()[textBuffer.size()-1] = u' '; break; ./ @@ -1506,14 +1115,14 @@ attribute_value_content ::= literal_content | char_ref | entity_ref_in_attribute attribute ::= qname space_opt EQ space_opt attribute_value; /. case $rule_number: { - QStringRef prefix = symPrefix(1); - if (prefix.isEmpty() && symString(1) == QLatin1String("xmlns") && namespaceProcessing) { + XmlStringRef prefix = symPrefix(1); + if (prefix.isEmpty() && symString(1) == "xmlns"_L1 && namespaceProcessing) { NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push(); namespaceDeclaration.prefix.clear(); - const QStringRef ns(symString(5)); - if(ns == QLatin1String("http://www.w3.org/2000/xmlns/") || - ns == QLatin1String("http://www.w3.org/XML/1998/namespace")) + const XmlStringRef ns(symString(5)); + if (ns.view() == "http://www.w3.org/2000/xmlns/"_L1 || + ns.view() == "http://www.w3.org/XML/1998/namespace"_L1) raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration.")); else namespaceDeclaration.namespaceUri = addToStringStorage(ns); @@ -1522,10 +1131,9 @@ attribute ::= qname space_opt EQ space_opt attribute_value; attribute.key = sym(1); attribute.value = sym(5); - QStringRef attributeQualifiedName = symName(1); + XmlStringRef attributeQualifiedName = symName(1); bool normalize = false; - for (int a = 0; a < dtdAttributes.size(); ++a) { - DtdAttribute &dtdAttribute = dtdAttributes[a]; + for (const DtdAttribute &dtdAttribute : std::as_const(dtdAttributes)) { if (!dtdAttribute.isCDATA && dtdAttribute.tagName == qualifiedName && dtdAttribute.attributeQualifiedName == attributeQualifiedName @@ -1536,10 +1144,10 @@ attribute ::= qname space_opt EQ space_opt attribute_value; } if (normalize) { // normalize attribute value (simplify and trim) - int pos = textBuffer.size(); - int n = 0; + const qsizetype pos = textBuffer.size(); + qsizetype n = 0; bool wasSpace = true; - for (int i = 0; i < attribute.value.len; ++i) { + for (qsizetype i = 0; i < attribute.value.len; ++i) { QChar c = textBuffer.at(attribute.value.pos + i); if (c.unicode() == ' ') { if (wasSpace) @@ -1557,16 +1165,16 @@ attribute ::= qname space_opt EQ space_opt attribute_value; attribute.value.pos = pos; attribute.value.len = n; } - if (prefix == QLatin1String("xmlns") && namespaceProcessing) { + if (prefix == "xmlns"_L1 && namespaceProcessing) { NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push(); - QStringRef namespacePrefix = symString(attribute.key); - QStringRef namespaceUri = symString(attribute.value); + XmlStringRef namespacePrefix = symString(attribute.key); + XmlStringRef namespaceUri = symString(attribute.value); attributeStack.pop(); - if (((namespacePrefix == QLatin1String("xml")) - ^ (namespaceUri == QLatin1String("http://www.w3.org/XML/1998/namespace"))) - || namespaceUri == QLatin1String("http://www.w3.org/2000/xmlns/") + if (((namespacePrefix == "xml"_L1) + ^ (namespaceUri == "http://www.w3.org/XML/1998/namespace"_L1)) + || namespaceUri == "http://www.w3.org/2000/xmlns/"_L1 || namespaceUri.isEmpty() - || namespacePrefix == QLatin1String("xmlns")) + || namespacePrefix == "xmlns"_L1) raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration.")); namespaceDeclaration.prefix = addToStringStorage(namespacePrefix); @@ -1619,9 +1227,10 @@ etag ::= LANGLE SLASH qname space_opt RANGLE; /. case $rule_number: { setType(QXmlStreamReader::EndElement); - Tag &tag = tagStack_pop(); + Tag tag = tagStack_pop(); namespaceUri = tag.namespaceDeclaration.namespaceUri; + prefix = tag.namespaceDeclaration.prefix; name = tag.name; qualifiedName = tag.qualifiedName; if (qualifiedName != symName(3)) @@ -1658,7 +1267,7 @@ entity_ref ::= AMPERSAND name SEMICOLON; } if (entity.literal) putStringLiteral(entity.value); - else if (referenceEntity(entity)) + else if (referenceEntity(&entityHash, entity)) putReplacement(entity.value); textBuffer.chop(2 + sym(2).len); clearSym(); @@ -1695,7 +1304,7 @@ pereference ::= PERCENT name SEMICOLON; if (entity.unparsed || entity.external) { referenceToUnparsedEntityDetected = true; } else { - if (referenceEntity(entity)) + if (referenceEntity(¶meterEntityHash, entity)) putString(entity.value); textBuffer.chop(2 + sym(2).len); clearSym(); @@ -1732,7 +1341,7 @@ entity_ref_in_attribute_value ::= AMPERSAND name SEMICOLON; } if (entity.literal) putStringLiteral(entity.value); - else if (referenceEntity(entity)) + else if (referenceEntity(&entityHash, entity)) putReplacementInAttributeValue(entity.value); textBuffer.chop(2 + sym(2).len); clearSym(); @@ -1810,7 +1419,12 @@ space_opt ::= space; qname ::= LETTER; /. case $rule_number: { - sym(1).len += fastScanName(&sym(1).prefix); + Value &val = sym(1); + if (auto res = fastScanName(&val)) + val.len += *res; + else + return false; + if (atEnd) { resume($rule_number); return false; @@ -1821,7 +1435,11 @@ qname ::= LETTER; name ::= LETTER; /. case $rule_number: - sym(1).len += fastScanName(); + if (auto res = fastScanName()) + sym(1).len += *res; + else + return false; + if (atEnd) { resume($rule_number); return false; @@ -1868,6 +1486,11 @@ nmtoken ::= COLON; } return false; } -#endif //QT_NO_XMLSTREAMREADER.xml + +#endif // feature xmlstreamreader + +QT_END_NAMESPACE + +#endif ./ |