diff options
Diffstat (limited to 'src/corelib/json')
-rw-r--r-- | src/corelib/json/qjson_p.h | 4 | ||||
-rw-r--r-- | src/corelib/json/qjsonarray.cpp | 13 | ||||
-rw-r--r-- | src/corelib/json/qjsonarray.h | 8 | ||||
-rw-r--r-- | src/corelib/json/qjsondocument.cpp | 2 | ||||
-rw-r--r-- | src/corelib/json/qjsondocument.h | 2 | ||||
-rw-r--r-- | src/corelib/json/qjsonobject.cpp | 26 | ||||
-rw-r--r-- | src/corelib/json/qjsonobject.h | 10 | ||||
-rw-r--r-- | src/corelib/json/qjsonvalue.cpp | 26 | ||||
-rw-r--r-- | src/corelib/json/qjsonwriter.cpp | 4 |
9 files changed, 64 insertions, 31 deletions
diff --git a/src/corelib/json/qjson_p.h b/src/corelib/json/qjson_p.h index 17f49d41c8..7f5a2d88a1 100644 --- a/src/corelib/json/qjson_p.h +++ b/src/corelib/json/qjson_p.h @@ -280,7 +280,7 @@ static inline int compressedNumber(double d) if (non_int) return INT_MAX; - bool neg = (val >> 63); + bool neg = (val >> 63) != 0; val &= fraction_mask; val |= ((quint64)1 << 52); int res = (int)(val >> (52 - exp)); @@ -543,7 +543,7 @@ public: offset tableOffset; // content follows here - inline bool isObject() const { return is_object; } + inline bool isObject() const { return !!is_object; } inline bool isArray() const { return !isObject(); } inline offset *table() const { return (offset *) (((char *) this) + tableOffset); } diff --git a/src/corelib/json/qjsonarray.cpp b/src/corelib/json/qjsonarray.cpp index 77a3d0a2b8..bb33dbde74 100644 --- a/src/corelib/json/qjsonarray.cpp +++ b/src/corelib/json/qjsonarray.cpp @@ -271,6 +271,7 @@ QVariantList QJsonArray::toVariantList() const QVariantList list; if (a) { + list.reserve(a->length); for (int i = 0; i < (int)a->length; ++i) list.append(QJsonValue(d, a, a->at(i)).toVariant()); } @@ -532,8 +533,8 @@ bool QJsonArray::contains(const QJsonValue &value) const \a i must be a valid index position in the array (i.e., \c{0 <= i < size()}). - The return value is of type \keyword QJsonValueRef, a helper class for QJsonArray - and QJsonObject. When you get an object of type \keyword QJsonValueRef, you can + The return value is of type QJsonValueRef, a helper class for QJsonArray + and QJsonObject. When you get an object of type QJsonValueRef, you can use it as if it were a reference to a QJsonValue. If you assign to it, the assignment will apply to the character in the QJsonArray of QJsonObject from which you got the reference. @@ -738,8 +739,8 @@ bool QJsonArray::operator!=(const QJsonArray &other) const You can change the value of an item by using operator*() on the left side of an assignment. - The return value is of type \keyword QJsonValueRef, a helper class for QJsonArray - and QJsonObject. When you get an object of type \keyword QJsonValueRef, you can + The return value is of type QJsonValueRef, a helper class for QJsonArray + and QJsonObject. When you get an object of type QJsonValueRef, you can use it as if it were a reference to a QJsonValue. If you assign to it, the assignment will apply to the character in the QJsonArray of QJsonObject from which you got the reference. @@ -758,8 +759,8 @@ bool QJsonArray::operator!=(const QJsonArray &other) const This function is provided to make QJsonArray iterators behave like C++ pointers. - The return value is of type \keyword QJsonValueRef, a helper class for QJsonArray - and QJsonObject. When you get an object of type \keyword QJsonValueRef, you can + The return value is of type QJsonValueRef, a helper class for QJsonArray + and QJsonObject. When you get an object of type QJsonValueRef, you can use it as if it were a reference to a QJsonValue. If you assign to it, the assignment will apply to the character in the QJsonArray of QJsonObject from which you got the reference. diff --git a/src/corelib/json/qjsonarray.h b/src/corelib/json/qjsonarray.h index 6148642106..611e1f4193 100644 --- a/src/corelib/json/qjsonarray.h +++ b/src/corelib/json/qjsonarray.h @@ -107,7 +107,7 @@ public: typedef QJsonValueRef reference; typedef QJsonValueRefPtr pointer; - inline iterator() : a(0), i(0) { } + inline iterator() : a(Q_NULLPTR), i(0) { } explicit inline iterator(QJsonArray *array, int index) : a(array), i(index) { } inline QJsonValueRef operator*() const { return QJsonValueRef(a, i); } @@ -152,9 +152,11 @@ public: typedef QJsonValue reference; typedef QJsonValuePtr pointer; - inline const_iterator() : a(0), i(0) { } + inline const_iterator() : a(Q_NULLPTR), i(0) { } explicit inline const_iterator(const QJsonArray *array, int index) : a(array), i(index) { } - inline const_iterator(const const_iterator &o) : a(o.a), i(o.i) {} +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + inline const_iterator(const const_iterator &o) : a(o.a), i(o.i) {} // ### Qt 6: Removed so class can be trivially-copyable +#endif inline const_iterator(const iterator &o) : a(o.a), i(o.i) {} inline QJsonValue operator*() const { return a->at(i); } diff --git a/src/corelib/json/qjsondocument.cpp b/src/corelib/json/qjsondocument.cpp index f5bad32233..3ef006d82d 100644 --- a/src/corelib/json/qjsondocument.cpp +++ b/src/corelib/json/qjsondocument.cpp @@ -574,7 +574,7 @@ QDebug operator<<(QDebug dbg, const QJsonDocument &o) QJsonPrivate::Writer::objectToJson(static_cast<QJsonPrivate::Object *>(o.d->header->root()), json, 0, true); dbg.nospace() << "QJsonDocument(" << json.constData() // print as utf-8 string without extra quotation marks - << ")"; + << ')'; return dbg; } #endif diff --git a/src/corelib/json/qjsondocument.h b/src/corelib/json/qjsondocument.h index 285b42c6c8..d7a88b2f15 100644 --- a/src/corelib/json/qjsondocument.h +++ b/src/corelib/json/qjsondocument.h @@ -106,7 +106,7 @@ public: Compact }; - static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = 0); + static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = Q_NULLPTR); #ifdef Q_QDOC QByteArray toJson(JsonFormat format = Indented) const; diff --git a/src/corelib/json/qjsonobject.cpp b/src/corelib/json/qjsonobject.cpp index ae44cd9ff9..27f937e750 100644 --- a/src/corelib/json/qjsonobject.cpp +++ b/src/corelib/json/qjsonobject.cpp @@ -274,7 +274,7 @@ QStringList QJsonObject::keys() const return QStringList(); QStringList keys; - + keys.reserve(o->length); for (uint i = 0; i < o->length; ++i) { QJsonPrivate::Entry *e = o->entryAt(i); keys.append(e->key()); @@ -679,8 +679,11 @@ QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const /*! \typedef QJsonObject::iterator::iterator_category - A synonym for \e {std::bidirectional_iterator_tag} indicating - this iterator is a bidirectional iterator. + A synonym for \e {std::random_access_iterator_tag} indicating + this iterator is a random-access iterator. + + \note In Qt versions before 5.6, this was set by mistake to + \e {std::bidirectional_iterator_tag}. */ /*! \typedef QJsonObject::iterator::reference @@ -693,6 +696,11 @@ QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const \internal */ +/*! \typedef QJsonObject::iterator::pointer + + \internal +*/ + /*! \fn QJsonObject::iterator::iterator() Constructs an uninitialized iterator. @@ -881,8 +889,11 @@ QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const /*! \typedef QJsonObject::const_iterator::iterator_category - A synonym for \e {std::bidirectional_iterator_tag} indicating - this iterator is a bidirectional iterator. + A synonym for \e {std::random_access_iterator_tag} indicating + this iterator is a random-access iterator. + + \note In Qt versions before 5.6, this was set by mistake to + \e {std::bidirectional_iterator_tag}. */ /*! \typedef QJsonObject::const_iterator::reference @@ -895,6 +906,11 @@ QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const \internal */ +/*! \typedef QJsonObject::const_iterator::pointer + + \internal +*/ + /*! \fn QJsonObject::const_iterator::const_iterator() Constructs an uninitialized iterator. diff --git a/src/corelib/json/qjsonobject.h b/src/corelib/json/qjsonobject.h index 5f24ac3ac8..8535da4a6c 100644 --- a/src/corelib/json/qjsonobject.h +++ b/src/corelib/json/qjsonobject.h @@ -100,12 +100,13 @@ public: int i; public: - typedef std::bidirectional_iterator_tag iterator_category; + typedef std::random_access_iterator_tag iterator_category; typedef int difference_type; typedef QJsonValue value_type; typedef QJsonValueRef reference; + typedef QJsonValuePtr pointer; - Q_DECL_CONSTEXPR inline iterator() : o(0), i(0) {} + Q_DECL_CONSTEXPR inline iterator() : o(Q_NULLPTR), i(0) {} Q_DECL_CONSTEXPR inline iterator(QJsonObject *obj, int index) : o(obj), i(index) {} inline QString key() const { return o->keyAt(i); } @@ -142,12 +143,13 @@ public: int i; public: - typedef std::bidirectional_iterator_tag iterator_category; + typedef std::random_access_iterator_tag iterator_category; typedef int difference_type; typedef QJsonValue value_type; typedef QJsonValue reference; + typedef QJsonValuePtr pointer; - Q_DECL_CONSTEXPR inline const_iterator() : o(0), i(0) {} + Q_DECL_CONSTEXPR inline const_iterator() : o(Q_NULLPTR), i(0) {} Q_DECL_CONSTEXPR inline const_iterator(const QJsonObject *obj, int index) : o(obj), i(index) {} inline const_iterator(const iterator &other) diff --git a/src/corelib/json/qjsonvalue.cpp b/src/corelib/json/qjsonvalue.cpp index ae6a3678bd..76e5ae562f 100644 --- a/src/corelib/json/qjsonvalue.cpp +++ b/src/corelib/json/qjsonvalue.cpp @@ -173,7 +173,7 @@ QJsonValue::QJsonValue(int n) QJsonValue::QJsonValue(qint64 n) : d(0), t(Double) { - this->dbl = n; + this->dbl = double(n); } /*! @@ -420,6 +420,18 @@ QJsonValue QJsonValue::fromVariant(const QVariant &variant) return QJsonValue(QJsonObject::fromVariantMap(variant.toMap())); case QVariant::Hash: return QJsonValue(QJsonObject::fromVariantHash(variant.toHash())); +#ifndef QT_BOOTSTRAPPED + case QMetaType::QJsonValue: + return variant.toJsonValue(); + case QMetaType::QJsonObject: + return variant.toJsonObject(); + case QMetaType::QJsonArray: + return variant.toJsonArray(); + case QMetaType::QJsonDocument: { + QJsonDocument doc = variant.toJsonDocument(); + return doc.isArray() ? QJsonValue(doc.array()) : QJsonValue(doc.object()); + } +#endif default: break; } @@ -515,7 +527,7 @@ bool QJsonValue::toBool(bool defaultValue) const int QJsonValue::toInt(int defaultValue) const { if (t == Double && int(dbl) == dbl) - return dbl; + return int(dbl); return defaultValue; } @@ -738,23 +750,23 @@ QDebug operator<<(QDebug dbg, const QJsonValue &o) dbg << "QJsonValue(null)"; break; case QJsonValue::Bool: - dbg.nospace() << "QJsonValue(bool, " << o.toBool() << ")"; + dbg.nospace() << "QJsonValue(bool, " << o.toBool() << ')'; break; case QJsonValue::Double: - dbg.nospace() << "QJsonValue(double, " << o.toDouble() << ")"; + dbg.nospace() << "QJsonValue(double, " << o.toDouble() << ')'; break; case QJsonValue::String: - dbg.nospace() << "QJsonValue(string, " << o.toString() << ")"; + dbg.nospace() << "QJsonValue(string, " << o.toString() << ')'; break; case QJsonValue::Array: dbg.nospace() << "QJsonValue(array, "; dbg << o.toArray(); - dbg << ")"; + dbg << ')'; break; case QJsonValue::Object: dbg.nospace() << "QJsonValue(object, "; dbg << o.toObject(); - dbg << ")"; + dbg << ')'; break; } return dbg; diff --git a/src/corelib/json/qjsonwriter.cpp b/src/corelib/json/qjsonwriter.cpp index 99f83554c2..45a05e93a3 100644 --- a/src/corelib/json/qjsonwriter.cpp +++ b/src/corelib/json/qjsonwriter.cpp @@ -137,13 +137,13 @@ static void valueToJson(const QJsonPrivate::Base *b, const QJsonPrivate::Value & json += compact ? "[" : "[\n"; arrayContentToJson(static_cast<QJsonPrivate::Array *>(v.base(b)), json, indent + (compact ? 0 : 1), compact); json += QByteArray(4*indent, ' '); - json += "]"; + json += ']'; break; case QJsonValue::Object: json += compact ? "{" : "{\n"; objectContentToJson(static_cast<QJsonPrivate::Object *>(v.base(b)), json, indent + (compact ? 0 : 1), compact); json += QByteArray(4*indent, ' '); - json += "}"; + json += '}'; break; case QJsonValue::Null: default: |