diff options
Diffstat (limited to 'src/corelib/serialization/qjsondocument.cpp')
-rw-r--r-- | src/corelib/serialization/qjsondocument.cpp | 77 |
1 files changed, 24 insertions, 53 deletions
diff --git a/src/corelib/serialization/qjsondocument.cpp b/src/corelib/serialization/qjsondocument.cpp index 6b015d759d..e2528f18dc 100644 --- a/src/corelib/serialization/qjsondocument.cpp +++ b/src/corelib/serialization/qjsondocument.cpp @@ -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 #include <qjsondocument.h> #include <qjsonobject.h> @@ -43,6 +7,8 @@ #include <qjsonarray.h> #include <qstringlist.h> #include <qvariant.h> +#include <qmap.h> +#include <qhash.h> #include <qdebug.h> #include <qcbormap.h> #include <qcborarray.h> @@ -58,11 +24,14 @@ QT_BEGIN_NAMESPACE \inmodule QtCore \ingroup json \ingroup shared + \ingroup qtserialization \reentrant \since 5.0 \brief The QJsonDocument class provides a way to read and write JSON documents. + \compares equality + QJsonDocument is a class that wraps a complete JSON document and can read this document from, and write it to, a UTF-8 encoded text-based representation. @@ -77,7 +46,7 @@ QT_BEGIN_NAMESPACE and isObject(). The array or object contained in the document can be retrieved using array() or object() and then read or manipulated. - \sa {JSON Support in Qt}, {JSON Save Game Example} + \sa {JSON Support in Qt}, {Saving and Loading a Game} */ @@ -214,6 +183,7 @@ QJsonDocument &QJsonDocument::operator =(const QJsonDocument &other) Swaps the document \a other with this. This operation is very fast and never fails. */ +#ifndef QT_NO_VARIANT /*! Creates a QJsonDocument from the QVariant \a variant. @@ -264,6 +234,7 @@ QVariant QJsonDocument::toVariant() const return QJsonArray(container).toVariantList(); return QJsonObject(container).toVariantMap(); } +#endif // !QT_NO_VARIANT /*! \enum QJsonDocument::JsonFormat @@ -285,7 +256,7 @@ QVariant QJsonDocument::toVariant() const \sa fromJson(), JsonFormat */ -#if !defined(QT_JSON_READONLY) || defined(Q_CLANG_QDOC) +#if !defined(QT_JSON_READONLY) || defined(Q_QDOC) QByteArray QJsonDocument::toJson(JsonFormat format) const { QByteArray json; @@ -314,7 +285,7 @@ QByteArray QJsonDocument::toJson(JsonFormat format) const */ QJsonDocument QJsonDocument::fromJson(const QByteArray &json, QJsonParseError *error) { - QJsonPrivate::Parser parser(json.constData(), json.length()); + QJsonPrivate::Parser parser(json.constData(), json.size()); QJsonDocument result; const QCborValue val = parser.parse(error); if (val.isArray() || val.isMap()) { @@ -425,7 +396,6 @@ void QJsonDocument::setArray(const QJsonArray &array) d->value = QCborValue::fromJsonValue(array); } -#if QT_STRINGVIEW_LEVEL < 2 /*! Returns a QJsonValue representing the value for the key \a key. @@ -442,7 +412,6 @@ const QJsonValue QJsonDocument::operator[](const QString &key) const { return (*this)[QStringView(key)]; } -#endif /*! \overload @@ -460,7 +429,7 @@ const QJsonValue QJsonDocument::operator[](QStringView key) const \overload \since 5.10 */ -const QJsonValue QJsonDocument::operator[](QLatin1String key) const +const QJsonValue QJsonDocument::operator[](QLatin1StringView key) const { if (!isObject()) return QJsonValue(QJsonValue::Undefined); @@ -489,20 +458,22 @@ const QJsonValue QJsonDocument::operator[](qsizetype i) const } /*! - Returns \c true if the \a other document is equal to this document. - */ -bool QJsonDocument::operator==(const QJsonDocument &other) const + \fn bool QJsonDocument::operator==(const QJsonDocument &lhs, const QJsonDocument &rhs) + + Returns \c true if the \a lhs document is equal to \a rhs document, \c false otherwise. +*/ +bool comparesEqual(const QJsonDocument &lhs, const QJsonDocument &rhs) noexcept { - if (d && other.d) - return d->value == other.d->value; - return !d == !other.d; + if (lhs.d && rhs.d) + return lhs.d->value == rhs.d->value; + return !lhs.d == !rhs.d; } /*! - \fn bool QJsonDocument::operator!=(const QJsonDocument &other) const + \fn bool QJsonDocument::operator!=(const QJsonDocument &lhs, const QJsonDocument &rhs) - returns \c true if \a other is not equal to this document - */ + Returns \c true if the \a lhs document is not equal to \a rhs document, \c false otherwise. +*/ /*! returns \c true if this document is null. |