summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qxmlstreamparser_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/serialization/qxmlstreamparser_p.h')
-rw-r--r--src/corelib/serialization/qxmlstreamparser_p.h108
1 files changed, 42 insertions, 66 deletions
diff --git a/src/corelib/serialization/qxmlstreamparser_p.h b/src/corelib/serialization/qxmlstreamparser_p.h
index a5d8312390..1363bf4d41 100644
--- a/src/corelib/serialization/qxmlstreamparser_p.h
+++ b/src/corelib/serialization/qxmlstreamparser_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQml 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$
-**
-****************************************************************************/
+// 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
//
@@ -74,12 +38,14 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_XMLSTREAMREADER
+#if QT_CONFIG(xmlstreamreader)
bool QXmlStreamReaderPrivate::parse()
{
// cleanup currently reported token
+ using namespace Qt::StringLiterals;
+
switch (type) {
case QXmlStreamReader::StartElement:
name.clear();
@@ -92,6 +58,7 @@ bool QXmlStreamReaderPrivate::parse()
setType(QXmlStreamReader::EndElement);
Tag tag = tagStack_pop();
namespaceUri = tag.namespaceDeclaration.namespaceUri;
+ prefix = tag.namespaceDeclaration.prefix;
name = tag.name;
qualifiedName = tag.qualifiedName;
isEmptyElement = false;
@@ -173,7 +140,7 @@ bool QXmlStreamReaderPrivate::parse()
} else switch (token_char) {
case 0xfffe:
case 0xffff:
- token = ERROR;
+ token = XML_ERROR;
break;
case '\r':
token = SPACE;
@@ -466,9 +433,9 @@ bool QXmlStreamReaderPrivate::parse()
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 {
@@ -483,14 +450,14 @@ bool QXmlStreamReaderPrivate::parse()
case 88: {
if (referenceToUnparsedEntityDetected && !standalone)
break;
- int n = dtdAttributes.size();
+ 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
@@ -571,11 +538,11 @@ bool QXmlStreamReaderPrivate::parse()
case 96: {
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 = XmlStringRef(&textBuffer, pos, textBuffer.size() - pos - 2);
- if (!processingInstructionTarget.view().compare(QLatin1String("xml"), Qt::CaseInsensitive)) {
+ if (!processingInstructionTarget.view().compare("xml"_L1, Qt::CaseInsensitive)) {
raiseWellFormedError(QXmlStream::tr("XML declaration not at start of document."));
}
else if (!QXmlUtils::isNCName(processingInstructionTarget))
@@ -590,7 +557,7 @@ bool QXmlStreamReaderPrivate::parse()
case 97:
setType(QXmlStreamReader::ProcessingInstruction);
processingInstructionTarget = symString(3);
- if (!processingInstructionTarget.view().compare(QLatin1String("xml"), Qt::CaseInsensitive))
+ if (!processingInstructionTarget.view().compare("xml"_L1, Qt::CaseInsensitive))
raiseWellFormedError(QXmlStream::tr("Invalid processing instruction name."));
break;
@@ -610,7 +577,7 @@ bool QXmlStreamReaderPrivate::parse()
case 100: {
setType(QXmlStreamReader::Comment);
- int pos = sym(1).pos + 4;
+ const qsizetype pos = sym(1).pos + 4;
text = XmlStringRef(&textBuffer, pos, textBuffer.size() - pos - 3);
} break;
@@ -618,7 +585,7 @@ bool QXmlStreamReaderPrivate::parse()
setType(QXmlStreamReader::Characters);
isCDATA = true;
isWhitespace = false;
- int pos = sym(2).pos;
+ const qsizetype pos = sym(2).pos;
if (scanUntil("]]>", -1)) {
text = XmlStringRef(&textBuffer, pos, textBuffer.size() - pos - 3);
} else {
@@ -692,7 +659,7 @@ bool QXmlStreamReaderPrivate::parse()
case 173:
if (normalizeLiterals)
- textBuffer.data()[textBuffer.size()-1] = QLatin1Char(' ');
+ textBuffer.data()[textBuffer.size()-1] = u' ';
break;
case 174:
@@ -748,13 +715,13 @@ bool QXmlStreamReaderPrivate::parse()
case 229: {
XmlStringRef prefix = symPrefix(1);
- if (prefix.isEmpty() && symString(1) == QLatin1String("xmlns") && namespaceProcessing) {
+ if (prefix.isEmpty() && symString(1) == "xmlns"_L1 && namespaceProcessing) {
NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
namespaceDeclaration.prefix.clear();
const XmlStringRef ns(symString(5));
- if (ns.view() == QLatin1String("http://www.w3.org/2000/xmlns/") ||
- ns.view() == QLatin1String("http://www.w3.org/XML/1998/namespace"))
+ 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);
@@ -765,8 +732,7 @@ bool QXmlStreamReaderPrivate::parse()
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
@@ -777,10 +743,10 @@ bool QXmlStreamReaderPrivate::parse()
}
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)
@@ -798,16 +764,16 @@ bool QXmlStreamReaderPrivate::parse()
attribute.value.pos = pos;
attribute.value.len = n;
}
- if (prefix == QLatin1String("xmlns") && namespaceProcessing) {
+ if (prefix == "xmlns"_L1 && namespaceProcessing) {
NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
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);
@@ -843,6 +809,7 @@ bool QXmlStreamReaderPrivate::parse()
Tag tag = tagStack_pop();
namespaceUri = tag.namespaceDeclaration.namespaceUri;
+ prefix = tag.namespaceDeclaration.prefix;
name = tag.name;
qualifiedName = tag.qualifiedName;
if (qualifiedName != symName(3))
@@ -980,7 +947,12 @@ bool QXmlStreamReaderPrivate::parse()
break;
case 262: {
- 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(262);
return false;
@@ -988,7 +960,11 @@ bool QXmlStreamReaderPrivate::parse()
} break;
case 263:
- sym(1).len += fastScanName();
+ if (auto res = fastScanName())
+ sym(1).len += *res;
+ else
+ return false;
+
if (atEnd) {
resume(263);
return false;
@@ -1022,7 +998,7 @@ bool QXmlStreamReaderPrivate::parse()
return false;
}
-#endif
+#endif // feature xmlstreamreader
QT_END_NAMESPACE