summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qxmlstream.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/serialization/qxmlstream.h')
-rw-r--r--src/corelib/serialization/qxmlstream.h344
1 files changed, 190 insertions, 154 deletions
diff --git a/src/corelib/serialization/qxmlstream.h b/src/corelib/serialization/qxmlstream.h
index 44f33b111b..8a12c6d611 100644
--- a/src/corelib/serialization/qxmlstream.h
+++ b/src/corelib/serialization/qxmlstream.h
@@ -1,89 +1,48 @@
-/****************************************************************************
-**
-** 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
#ifndef QXMLSTREAM_H
#define QXMLSTREAM_H
#include <QtCore/qiodevice.h>
-#ifndef QT_NO_XMLSTREAM
+#if QT_CONFIG(xmlstream)
+#include <QtCore/qcompare.h>
#include <QtCore/qlist.h>
#include <QtCore/qscopedpointer.h>
#include <QtCore/qstring.h>
QT_BEGIN_NAMESPACE
+namespace QtPrivate {
-class Q_CORE_EXPORT QXmlStreamStringRef {
- QString m_string;
- int m_position, m_size;
+class QXmlString {
+ QStringPrivate m_string;
public:
- inline QXmlStreamStringRef():m_position(0), m_size(0){}
- inline QXmlStreamStringRef(const QStringRef &aString)
- :m_string(aString.string()?*aString.string():QString()), m_position(aString.position()), m_size(aString.size()){}
- QXmlStreamStringRef(const QString &aString) : m_string(aString), m_position(0), m_size(m_string.size()) {}
- QXmlStreamStringRef(QString &&aString) noexcept : m_string(std::move(aString)), m_position(0), m_size(m_string.size()) {}
+ QXmlString(QStringPrivate &&d) : m_string(std::move(d)) {}
+ QXmlString(const QString &s) : m_string(s.data_ptr()) {}
+ QXmlString & operator=(const QString &s) { m_string = s.data_ptr(); return *this; }
+ QXmlString & operator=(QString &&s) { m_string.swap(s.data_ptr()); return *this; }
+ inline constexpr QXmlString() {}
- void swap(QXmlStreamStringRef &other) noexcept
+ void swap(QXmlString &other) noexcept
{
- qSwap(m_string, other.m_string);
- qSwap(m_position, other.m_position);
- qSwap(m_size, other.m_size);
+ m_string.swap(other.m_string);
}
- inline void clear() { m_string.clear(); m_position = m_size = 0; }
- inline operator QStringRef() const { return QStringRef(&m_string, m_position, m_size); }
- inline const QString *string() const { return &m_string; }
- inline int position() const { return m_position; }
- inline int size() const { return m_size; }
+ inline operator QStringView() const { return QStringView(m_string.data(), m_string.size); }
+ inline qsizetype size() const { return m_string.size; }
};
-Q_DECLARE_SHARED(QXmlStreamStringRef)
+
+}
+Q_DECLARE_SHARED(QtPrivate::QXmlString)
class QXmlStreamReaderPrivate;
class QXmlStreamAttributes;
class Q_CORE_EXPORT QXmlStreamAttribute {
- QXmlStreamStringRef m_name, m_namespaceUri, m_qualifiedName, m_value;
-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
- void *reserved;
-#endif
+ QtPrivate::QXmlString m_name, m_namespaceUri, m_qualifiedName, m_value;
uint m_isDefault : 1;
friend class QXmlStreamReaderPrivate;
friend class QXmlStreamAttributes;
@@ -92,50 +51,60 @@ public:
QXmlStreamAttribute(const QString &qualifiedName, const QString &value);
QXmlStreamAttribute(const QString &namespaceUri, const QString &name, const QString &value);
- inline QStringRef namespaceUri() const { return m_namespaceUri; }
- inline QStringRef name() const { return m_name; }
- inline QStringRef qualifiedName() const { return m_qualifiedName; }
- inline QStringRef prefix() const {
- return QStringRef(m_qualifiedName.string(),
- m_qualifiedName.position(),
- qMax(0, m_qualifiedName.size() - m_name.size() - 1));
+ inline QStringView namespaceUri() const { return m_namespaceUri; }
+ inline QStringView name() const { return m_name; }
+ inline QStringView qualifiedName() const { return m_qualifiedName; }
+ inline QStringView prefix() const {
+ return QStringView(m_qualifiedName).left(qMax(0, m_qualifiedName.size() - m_name.size() - 1));
}
- inline QStringRef value() const { return m_value; }
+ inline QStringView value() const { return m_value; }
inline bool isDefault() const { return m_isDefault; }
- inline bool operator==(const QXmlStreamAttribute &other) const {
- return (value() == other.value()
- && (namespaceUri().isNull() ? (qualifiedName() == other.qualifiedName())
- : (namespaceUri() == other.namespaceUri() && name() == other.name())));
- }
+#if QT_CORE_REMOVED_SINCE(6, 8)
+ inline bool operator==(const QXmlStreamAttribute &other) const
+ { return comparesEqual(*this, other); }
inline bool operator!=(const QXmlStreamAttribute &other) const
- { return !operator==(other); }
+ { return !operator==(other); }
+#endif
+
+private:
+ friend bool comparesEqual(const QXmlStreamAttribute &lhs,
+ const QXmlStreamAttribute &rhs) noexcept
+ {
+ return (lhs.value() == rhs.value()
+ && (lhs.namespaceUri().isNull() ? (lhs.qualifiedName() == rhs.qualifiedName())
+ : (lhs.namespaceUri() == rhs.namespaceUri()
+ && lhs.name() == rhs.name())));
+ }
+ Q_DECLARE_EQUALITY_COMPARABLE(QXmlStreamAttribute)
};
-Q_DECLARE_TYPEINFO(QXmlStreamAttribute, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QXmlStreamAttribute, Q_RELOCATABLE_TYPE);
-class Q_CORE_EXPORT QXmlStreamAttributes : public QList<QXmlStreamAttribute>
+// We export each out-of-line method individually to prevent MSVC from
+// exporting the whole QList class.
+class QXmlStreamAttributes : public QList<QXmlStreamAttribute>
{
public:
inline QXmlStreamAttributes() {}
- QStringRef value(const QString &namespaceUri, const QString &name) const;
- QStringRef value(const QString &namespaceUri, QLatin1String name) const;
- QStringRef value(QLatin1String namespaceUri, QLatin1String name) const;
- QStringRef value(const QString &qualifiedName) const;
- QStringRef value(QLatin1String qualifiedName) const;
- void append(const QString &namespaceUri, const QString &name, const QString &value);
- void append(const QString &qualifiedName, const QString &value);
-
- inline bool hasAttribute(const QString &qualifiedName) const
- {
- return !value(qualifiedName).isNull();
- }
+#if QT_CORE_REMOVED_SINCE(6, 6)
+ Q_CORE_EXPORT QStringView value(const QString &namespaceUri, const QString &name) const;
+ Q_CORE_EXPORT QStringView value(const QString &namespaceUri, QLatin1StringView name) const;
+ Q_CORE_EXPORT QStringView value(QLatin1StringView namespaceUri, QLatin1StringView name) const;
+ Q_CORE_EXPORT QStringView value(const QString &qualifiedName) const;
+ Q_CORE_EXPORT QStringView value(QLatin1StringView qualifiedName) const;
+#endif
+ Q_CORE_EXPORT QStringView value(QAnyStringView namespaceUri, QAnyStringView name) const noexcept;
+ Q_CORE_EXPORT QStringView value(QAnyStringView qualifiedName) const noexcept;
+
+ Q_CORE_EXPORT void append(const QString &namespaceUri, const QString &name, const QString &value);
+ Q_CORE_EXPORT void append(const QString &qualifiedName, const QString &value);
- inline bool hasAttribute(QLatin1String qualifiedName) const
+ bool hasAttribute(QAnyStringView qualifiedName) const
{
return !value(qualifiedName).isNull();
}
- inline bool hasAttribute(const QString &namespaceUri, const QString &name) const
+ bool hasAttribute(QAnyStringView namespaceUri, QAnyStringView name) const
{
return !value(namespaceUri, name).isNull();
}
@@ -144,91 +113,110 @@ public:
};
class Q_CORE_EXPORT QXmlStreamNamespaceDeclaration {
- QXmlStreamStringRef m_prefix, m_namespaceUri;
-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
- void *reserved;
-#endif
+ QtPrivate::QXmlString m_prefix, m_namespaceUri;
friend class QXmlStreamReaderPrivate;
public:
QXmlStreamNamespaceDeclaration();
QXmlStreamNamespaceDeclaration(const QString &prefix, const QString &namespaceUri);
- inline QStringRef prefix() const { return m_prefix; }
- inline QStringRef namespaceUri() const { return m_namespaceUri; }
- inline bool operator==(const QXmlStreamNamespaceDeclaration &other) const {
- return (prefix() == other.prefix() && namespaceUri() == other.namespaceUri());
- }
+ inline QStringView prefix() const { return m_prefix; }
+ inline QStringView namespaceUri() const { return m_namespaceUri; }
+#if QT_CORE_REMOVED_SINCE(6, 8)
+ inline bool operator==(const QXmlStreamNamespaceDeclaration &other) const
+ { return comparesEqual(*this, other); }
inline bool operator!=(const QXmlStreamNamespaceDeclaration &other) const
- { return !operator==(other); }
+ { return !operator==(other); }
+#endif
+private:
+ friend bool comparesEqual(const QXmlStreamNamespaceDeclaration &lhs,
+ const QXmlStreamNamespaceDeclaration &rhs) noexcept
+ {
+ return (lhs.prefix() == rhs.prefix() && lhs.namespaceUri() == rhs.namespaceUri());
+ }
+ Q_DECLARE_EQUALITY_COMPARABLE(QXmlStreamNamespaceDeclaration)
};
-Q_DECLARE_TYPEINFO(QXmlStreamNamespaceDeclaration, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QXmlStreamNamespaceDeclaration, Q_RELOCATABLE_TYPE);
typedef QList<QXmlStreamNamespaceDeclaration> QXmlStreamNamespaceDeclarations;
class Q_CORE_EXPORT QXmlStreamNotationDeclaration {
- QXmlStreamStringRef m_name, m_systemId, m_publicId;
-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
- void *reserved;
-#endif
+ QtPrivate::QXmlString m_name, m_systemId, m_publicId;
friend class QXmlStreamReaderPrivate;
public:
QXmlStreamNotationDeclaration();
- inline QStringRef name() const { return m_name; }
- inline QStringRef systemId() const { return m_systemId; }
- inline QStringRef publicId() const { return m_publicId; }
- inline bool operator==(const QXmlStreamNotationDeclaration &other) const {
- return (name() == other.name() && systemId() == other.systemId()
- && publicId() == other.publicId());
- }
+ inline QStringView name() const { return m_name; }
+ inline QStringView systemId() const { return m_systemId; }
+ inline QStringView publicId() const { return m_publicId; }
+#if QT_CORE_REMOVED_SINCE(6, 8)
+ inline bool operator==(const QXmlStreamNotationDeclaration &other) const
+ { return comparesEqual(*this, other); }
inline bool operator!=(const QXmlStreamNotationDeclaration &other) const
- { return !operator==(other); }
+ { return !operator==(other); }
+#endif
+private:
+ friend bool comparesEqual(const QXmlStreamNotationDeclaration &lhs,
+ const QXmlStreamNotationDeclaration &rhs) noexcept
+ {
+ return (lhs.name() == rhs.name() && lhs.systemId() == rhs.systemId()
+ && lhs.publicId() == rhs.publicId());
+ }
+ Q_DECLARE_EQUALITY_COMPARABLE(QXmlStreamNotationDeclaration)
};
-Q_DECLARE_TYPEINFO(QXmlStreamNotationDeclaration, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QXmlStreamNotationDeclaration, Q_RELOCATABLE_TYPE);
typedef QList<QXmlStreamNotationDeclaration> QXmlStreamNotationDeclarations;
class Q_CORE_EXPORT QXmlStreamEntityDeclaration {
- QXmlStreamStringRef m_name, m_notationName, m_systemId, m_publicId, m_value;
-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
- void *reserved;
-#endif
+ QtPrivate::QXmlString m_name, m_notationName, m_systemId, m_publicId, m_value;
friend class QXmlStreamReaderPrivate;
public:
QXmlStreamEntityDeclaration();
- inline QStringRef name() const { return m_name; }
- inline QStringRef notationName() const { return m_notationName; }
- inline QStringRef systemId() const { return m_systemId; }
- inline QStringRef publicId() const { return m_publicId; }
- inline QStringRef value() const { return m_value; }
- inline bool operator==(const QXmlStreamEntityDeclaration &other) const {
- return (name() == other.name()
- && notationName() == other.notationName()
- && systemId() == other.systemId()
- && publicId() == other.publicId()
- && value() == other.value());
- }
+ inline QStringView name() const { return m_name; }
+ inline QStringView notationName() const { return m_notationName; }
+ inline QStringView systemId() const { return m_systemId; }
+ inline QStringView publicId() const { return m_publicId; }
+ inline QStringView value() const { return m_value; }
+#if QT_CORE_REMOVED_SINCE(6, 8)
+ inline bool operator==(const QXmlStreamEntityDeclaration &other) const
+ { return comparesEqual(*this, other); }
inline bool operator!=(const QXmlStreamEntityDeclaration &other) const
- { return !operator==(other); }
+ { return !operator==(other); }
+#endif
+
+private:
+ friend bool comparesEqual(const QXmlStreamEntityDeclaration &lhs,
+ const QXmlStreamEntityDeclaration &rhs) noexcept
+ {
+ return (lhs.name() == rhs.name()
+ && lhs.notationName() == rhs.notationName()
+ && lhs.systemId() == rhs.systemId()
+ && lhs.publicId() == rhs.publicId()
+ && lhs.value() == rhs.value());
+ }
+ Q_DECLARE_EQUALITY_COMPARABLE(QXmlStreamEntityDeclaration)
};
-Q_DECLARE_TYPEINFO(QXmlStreamEntityDeclaration, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QXmlStreamEntityDeclaration, Q_RELOCATABLE_TYPE);
typedef QList<QXmlStreamEntityDeclaration> QXmlStreamEntityDeclarations;
class Q_CORE_EXPORT QXmlStreamEntityResolver
{
+ Q_DISABLE_COPY_MOVE(QXmlStreamEntityResolver)
public:
+ QXmlStreamEntityResolver() = default;
virtual ~QXmlStreamEntityResolver();
virtual QString resolveEntity(const QString& publicId, const QString& systemId);
virtual QString resolveUndeclaredEntity(const QString &name);
};
-#ifndef QT_NO_XMLSTREAMREADER
-class Q_CORE_EXPORT QXmlStreamReader {
+#if QT_CONFIG(xmlstreamreader)
+class Q_CORE_EXPORT QXmlStreamReader
+{
QDOC_PROPERTY(bool namespaceProcessing READ namespaceProcessing WRITE setNamespaceProcessing)
public:
enum TokenType {
@@ -248,16 +236,27 @@ public:
QXmlStreamReader();
explicit QXmlStreamReader(QIODevice *device);
+#if QT_CORE_REMOVED_SINCE(6, 5)
explicit QXmlStreamReader(const QByteArray &data);
explicit QXmlStreamReader(const QString &data);
explicit QXmlStreamReader(const char * data);
+#endif // QT_CORE_REMOVED_SINCE(6, 5)
+ Q_WEAK_OVERLOAD
+ explicit QXmlStreamReader(const QByteArray &data)
+ : QXmlStreamReader(data, PrivateConstructorTag{}) { }
+ explicit QXmlStreamReader(QAnyStringView data);
~QXmlStreamReader();
void setDevice(QIODevice *device);
QIODevice *device() const;
+#if QT_CORE_REMOVED_SINCE(6, 5)
void addData(const QByteArray &data);
void addData(const QString &data);
void addData(const char *data);
+#endif // QT_CORE_REMOVED_SINCE(6, 5)
+ Q_WEAK_OVERLOAD
+ void addData(const QByteArray &data) { addDataImpl(data); }
+ void addData(QAnyStringView data);
void clear();
@@ -286,8 +285,9 @@ public:
inline bool isProcessingInstruction() const { return tokenType() == ProcessingInstruction; }
bool isStandaloneDocument() const;
- QStringRef documentVersion() const;
- QStringRef documentEncoding() const;
+ bool hasStandaloneDeclaration() const;
+ QStringView documentVersion() const;
+ QStringView documentEncoding() const;
qint64 lineNumber() const;
qint64 columnNumber() const;
@@ -302,24 +302,24 @@ public:
};
QString readElementText(ReadElementTextBehaviour behaviour = ErrorOnUnexpectedElement);
- QStringRef name() const;
- QStringRef namespaceUri() const;
- QStringRef qualifiedName() const;
- QStringRef prefix() const;
+ QStringView name() const;
+ QStringView namespaceUri() const;
+ QStringView qualifiedName() const;
+ QStringView prefix() const;
- QStringRef processingInstructionTarget() const;
- QStringRef processingInstructionData() const;
+ QStringView processingInstructionTarget() const;
+ QStringView processingInstructionData() const;
- QStringRef text() const;
+ QStringView text() const;
QXmlStreamNamespaceDeclarations namespaceDeclarations() const;
void addExtraNamespaceDeclaration(const QXmlStreamNamespaceDeclaration &extraNamespaceDeclaraction);
void addExtraNamespaceDeclarations(const QXmlStreamNamespaceDeclarations &extraNamespaceDeclaractions);
QXmlStreamNotationDeclarations notationDeclarations() const;
QXmlStreamEntityDeclarations entityDeclarations() const;
- QStringRef dtdName() const;
- QStringRef dtdPublicId() const;
- QStringRef dtdSystemId() const;
+ QStringView dtdName() const;
+ QStringView dtdPublicId() const;
+ QStringView dtdSystemId() const;
int entityExpansionLimit() const;
void setEntityExpansionLimit(int limit);
@@ -344,14 +344,18 @@ public:
QXmlStreamEntityResolver *entityResolver() const;
private:
+ struct PrivateConstructorTag { };
+ QXmlStreamReader(const QByteArray &data, PrivateConstructorTag);
+ void addDataImpl(const QByteArray &data);
+
Q_DISABLE_COPY(QXmlStreamReader)
Q_DECLARE_PRIVATE(QXmlStreamReader)
QScopedPointer<QXmlStreamReaderPrivate> d_ptr;
};
-#endif // QT_NO_XMLSTREAMREADER
+#endif // feature xmlstreamreader
-#ifndef QT_NO_XMLSTREAMWRITER
+#if QT_CONFIG(xmlstreamwriter)
class QXmlStreamWriterPrivate;
@@ -375,11 +379,17 @@ public:
void setAutoFormattingIndent(int spacesOrTabs);
int autoFormattingIndent() const;
+#if QT_CORE_REMOVED_SINCE(6,5)
void writeAttribute(const QString &qualifiedName, const QString &value);
void writeAttribute(const QString &namespaceUri, const QString &name, const QString &value);
+#endif
+ void writeAttribute(QAnyStringView qualifiedName, QAnyStringView value);
+ void writeAttribute(QAnyStringView namespaceUri, QAnyStringView name, QAnyStringView value);
+
void writeAttribute(const QXmlStreamAttribute& attribute);
void writeAttributes(const QXmlStreamAttributes& attributes);
+#if QT_CORE_REMOVED_SINCE(6,5)
void writeCDATA(const QString &text);
void writeCharacters(const QString &text);
void writeComment(const QString &text);
@@ -391,22 +401,47 @@ public:
void writeTextElement(const QString &qualifiedName, const QString &text);
void writeTextElement(const QString &namespaceUri, const QString &name, const QString &text);
+#endif
+ void writeCDATA(QAnyStringView text);
+ void writeCharacters(QAnyStringView text);
+ void writeComment(QAnyStringView text);
+
+ void writeDTD(QAnyStringView dtd);
+
+ void writeEmptyElement(QAnyStringView qualifiedName);
+ void writeEmptyElement(QAnyStringView namespaceUri, QAnyStringView name);
+
+ void writeTextElement(QAnyStringView qualifiedName, QAnyStringView text);
+ void writeTextElement(QAnyStringView namespaceUri, QAnyStringView name, QAnyStringView text);
+
void writeEndDocument();
void writeEndElement();
+#if QT_CORE_REMOVED_SINCE(6,5)
void writeEntityReference(const QString &name);
- void writeNamespace(const QString &namespaceUri, const QString &prefix = QString());
+ void writeNamespace(const QString &namespaceUri, const QString &prefix);
void writeDefaultNamespace(const QString &namespaceUri);
- void writeProcessingInstruction(const QString &target, const QString &data = QString());
+ void writeProcessingInstruction(const QString &target, const QString &data);
+#endif
+ void writeEntityReference(QAnyStringView name);
+ void writeNamespace(QAnyStringView namespaceUri, QAnyStringView prefix = {});
+ void writeDefaultNamespace(QAnyStringView namespaceUri);
+ void writeProcessingInstruction(QAnyStringView target, QAnyStringView data = {});
void writeStartDocument();
+#if QT_CORE_REMOVED_SINCE(6,5)
void writeStartDocument(const QString &version);
void writeStartDocument(const QString &version, bool standalone);
void writeStartElement(const QString &qualifiedName);
void writeStartElement(const QString &namespaceUri, const QString &name);
+#endif
+ void writeStartDocument(QAnyStringView version);
+ void writeStartDocument(QAnyStringView version, bool standalone);
+ void writeStartElement(QAnyStringView qualifiedName);
+ void writeStartElement(QAnyStringView namespaceUri, QAnyStringView name);
-#ifndef QT_NO_XMLSTREAMREADER
+#if QT_CONFIG(xmlstreamreader)
void writeCurrentToken(const QXmlStreamReader &reader);
#endif
@@ -417,9 +452,10 @@ private:
Q_DECLARE_PRIVATE(QXmlStreamWriter)
QScopedPointer<QXmlStreamWriterPrivate> d_ptr;
};
-#endif // QT_NO_XMLSTREAMWRITER
+#endif // feature xmlstreamwriter
QT_END_NAMESPACE
-#endif // QT_NO_XMLSTREAM
+#endif // feature xmlstream
+
#endif // QXMLSTREAM_H