summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qxmlstream_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/serialization/qxmlstream_p.h')
-rw-r--r--src/corelib/serialization/qxmlstream_p.h128
1 files changed, 68 insertions, 60 deletions
diff --git a/src/corelib/serialization/qxmlstream_p.h b/src/corelib/serialization/qxmlstream_p.h
index 41b04d4c38..a29ee656e9 100644
--- a/src/corelib/serialization/qxmlstream_p.h
+++ b/src/corelib/serialization/qxmlstream_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2016 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
@@ -52,8 +16,12 @@
#include <qstringconverter.h>
#include <qxmlstream.h>
#include "qxmlstreamgrammar_p.h"
+#include <QtCore/qhash.h>
+#include <QCoreApplication> // Q_DECLARE_TR_FUNCTIONS
+
#include <memory>
+#include <optional>
#ifndef QXMLSTREAM_P_H
#define QXMLSTREAM_P_H
@@ -70,12 +38,12 @@ public:
qsizetype m_size = 0;
constexpr XmlStringRef() = default;
- constexpr inline XmlStringRef(const QString *string, int pos, int length)
- : m_string(string), m_pos(pos), m_size(length)
+ constexpr inline XmlStringRef(const QString *string, qsizetype pos, qsizetype length)
+ : m_string(string), m_pos(pos), m_size((Q_ASSERT(length >= 0), length))
{
}
XmlStringRef(const QString *string)
- : XmlStringRef(string, 0, string->length())
+ : XmlStringRef(string, 0, string->size())
{
}
@@ -87,7 +55,6 @@ public:
d.size = m_size;
return QXmlString(std::move(d));
}
- operator QStringView() const { return view(); }
void clear() { m_string = nullptr; m_pos = 0; m_size= 0; }
QStringView view() const { return m_string ? QStringView(m_string->data() + m_pos, m_size) : QStringView(); }
@@ -95,6 +62,33 @@ public:
bool isNull() const { return !m_string; }
QString toString() const { return view().toString(); }
+ using value_type = QStringView::value_type;
+ using size_type = QStringView::size_type;
+ using difference_type = QStringView::difference_type;
+ using pointer = QStringView::pointer;
+ using const_pointer = QStringView::const_pointer;
+ using reference = QStringView::reference;
+ using const_reference = QStringView::const_reference;
+ using iterator = QStringView::iterator;
+ using const_iterator = QStringView::const_iterator;
+ using reverse_iterator = QStringView::reverse_iterator;
+ using const_reverse_iterator = QStringView::const_reverse_iterator;
+
+#define MAKE_MEMBER(name) \
+ auto name () const noexcept { return view(). name (); }
+ MAKE_MEMBER(data)
+ MAKE_MEMBER(size)
+ MAKE_MEMBER(empty)
+ MAKE_MEMBER(begin)
+ MAKE_MEMBER(end)
+ MAKE_MEMBER(cbegin)
+ MAKE_MEMBER(cend)
+ MAKE_MEMBER(rbegin)
+ MAKE_MEMBER(rend)
+ MAKE_MEMBER(crbegin)
+ MAKE_MEMBER(crend)
+#undef MAKE_MEMBER
+
#define MAKE_OP(op) \
friend auto operator op(const XmlStringRef &lhs, const XmlStringRef &rhs) noexcept { return lhs.view() op rhs.view(); } \
/*end*/
@@ -124,6 +118,8 @@ using namespace QtPrivate;
template <typename T> class QXmlStreamSimpleStack
{
+ Q_DISABLE_COPY_MOVE(QXmlStreamSimpleStack)
+
T *data;
qsizetype tos, cap;
public:
@@ -170,7 +166,6 @@ public:
const T *cend() const { return end(); }
};
-
class QXmlStream
{
Q_DECLARE_TR_FUNCTIONS(QXmlStream)
@@ -189,7 +184,7 @@ public:
XmlStringRef name;
XmlStringRef qualifiedName;
NamespaceDeclaration namespaceDeclaration;
- int tagStackStringStorageSize;
+ qsizetype tagStackStringStorageSize;
qsizetype namespaceDeclarationsSize;
};
@@ -197,17 +192,17 @@ public:
QXmlStreamPrivateTagStack();
QXmlStreamSimpleStack<NamespaceDeclaration> namespaceDeclarations;
QString tagStackStringStorage;
- int tagStackStringStorageSize;
- int initialTagStackStringStorageSize;
+ qsizetype tagStackStringStorageSize;
+ qsizetype initialTagStackStringStorageSize;
bool tagsDone;
- XmlStringRef addToStringStorage(QStringView s)
+ XmlStringRef addToStringStorage(QAnyStringView s)
{
- int pos = tagStackStringStorageSize;
- int sz = s.size();
+ qsizetype pos = tagStackStringStorageSize;
if (pos != tagStackStringStorage.size())
tagStackStringStorage.resize(pos);
- tagStackStringStorage.append(s.data(), sz);
+ s.visit([&](auto s) { tagStackStringStorage.append(s); });
+ qsizetype sz = (tagStackStringStorage.size() - pos);
tagStackStringStorageSize += sz;
return XmlStringRef(&tagStackStringStorage, pos, sz);
}
@@ -246,14 +241,14 @@ public:
uchar firstByte;
qint64 nbytesread;
QString readBuffer;
- int readBufferPos;
+ qsizetype 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)
+ static inline Entity createLiteral(QLatin1StringView name, QLatin1StringView value)
{ Entity result(name, value); result.literal = result.hasBeenParsed = true; return result; }
QString name, value;
uint external : 1;
@@ -302,6 +297,17 @@ public:
QStringDecoder decoder;
bool atEnd;
+ enum class XmlContext
+ {
+ Prolog,
+ Body,
+ };
+
+ XmlContext currentContext = XmlContext::Prolog;
+ bool foundDTD = false;
+ bool isValidToken(QXmlStreamReader::TokenType type);
+ void checkToken();
+
/*!
\sa setType()
*/
@@ -389,6 +395,7 @@ public:
uint hasExternalDtdSubset : 1;
uint lockEncoding : 1;
uint namespaceProcessing : 1;
+ uint hasStandalone : 1; // TODO: expose in public API
int resumeReduction;
void resume(int rule);
@@ -405,9 +412,9 @@ public:
int tos;
int stack_size;
struct Value {
- int pos;
- int len;
- int prefix;
+ qsizetype pos; // offset into textBuffer
+ qsizetype len; // length incl. prefix (if any)
+ qint16 prefix; // prefix of a name (as in "prefix:name") limited to 4k in fastScanName()
ushort c;
};
@@ -500,11 +507,11 @@ public:
// 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();
+ qsizetype fastScanLiteralContent();
+ qsizetype fastScanSpace();
+ qsizetype fastScanContentCharList();
+ std::optional<qsizetype> fastScanName(Value *val = nullptr);
+ inline qsizetype fastScanNMTOKEN();
bool parse();
@@ -512,6 +519,7 @@ public:
void raiseError(QXmlStreamReader::Error error, const QString& message = QString());
void raiseWellFormedError(const QString &message);
+ void raiseNamePrefixTooLongError();
QXmlStreamEntityResolver *entityResolver;