summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qjsonobject.cpp
diff options
context:
space:
mode:
authorMat Sutcliffe <oktal3700@gmail.com>2019-07-12 20:22:49 +0100
committerMat Sutcliffe <oktal3700@gmail.com>2019-07-20 12:04:31 +0100
commit7f8e3aab2d5aca5349fd0f0da6245465dc7db5e0 (patch)
tree658a61cfcb1df2def13f59d0eebe6d5afad01791 /src/corelib/serialization/qjsonobject.cpp
parenta4e9fa03cabfc11105e700e38184a70888da4e7a (diff)
JSON: add some QStringView overloads
[ChangeLog][QtCore][JSON] Added overloads of functions taking key strings as QStringView; in QJsonObject, QJsonValue and QJsonDocument. Change-Id: I78b40aba8200003acfae257ff06f5f15737005e7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Diffstat (limited to 'src/corelib/serialization/qjsonobject.cpp')
-rw-r--r--src/corelib/serialization/qjsonobject.cpp109
1 files changed, 107 insertions, 2 deletions
diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp
index e800d76ab6..19a16d8537 100644
--- a/src/corelib/serialization/qjsonobject.cpp
+++ b/src/corelib/serialization/qjsonobject.cpp
@@ -377,6 +377,7 @@ bool QJsonObject::isEmpty() const
return !o->length;
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns a QJsonValue representing the value for the key \a key.
@@ -386,6 +387,16 @@ bool QJsonObject::isEmpty() const
*/
QJsonValue QJsonObject::value(const QString &key) const
{
+ return value(QStringView(key));
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonValue QJsonObject::value(QStringView key) const
+{
if (!d)
return QJsonValue(QJsonValue::Undefined);
@@ -412,6 +423,7 @@ QJsonValue QJsonObject::value(QLatin1String key) const
return QJsonValue(d, o, o->entryAt(i)->value);
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns a QJsonValue representing the value for the key \a key.
@@ -423,8 +435,16 @@ QJsonValue QJsonObject::value(QLatin1String key) const
*/
QJsonValue QJsonObject::operator [](const QString &key) const
{
- return value(key);
+ return (*this)[QStringView(key)];
}
+#endif
+
+/*!
+ \fn QJsonValue QJsonObject::operator [](QStringView key) const
+
+ \overload
+ \since 5.14
+*/
/*!
\fn QJsonValue QJsonObject::operator [](QLatin1String key) const
@@ -433,6 +453,7 @@ QJsonValue QJsonObject::operator [](const QString &key) const
\since 5.7
*/
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns a reference to the value for \a key.
@@ -446,6 +467,16 @@ QJsonValue QJsonObject::operator [](const QString &key) const
*/
QJsonValueRef QJsonObject::operator [](const QString &key)
{
+ return (*this)[QStringView(key)];
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonValueRef QJsonObject::operator [](QStringView key)
+{
bool keyExists = false;
int index = o ? o->indexOf(key, &keyExists) : 0;
if (!keyExists) {
@@ -465,6 +496,7 @@ QJsonValueRef QJsonObject::operator [](QLatin1String key)
return operator[](QString(key));
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Inserts a new item with the key \a key and a value of \a value.
@@ -480,6 +512,16 @@ QJsonValueRef QJsonObject::operator [](QLatin1String key)
*/
QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &value)
{
+ return insert(QStringView(key), value);
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonObject::iterator QJsonObject::insert(QStringView key, const QJsonValue &value)
+{
if (value.t == QJsonValue::Undefined) {
remove(key);
return end();
@@ -492,7 +534,7 @@ QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &
/*!
\internal
*/
-QJsonObject::iterator QJsonObject::insertAt(int pos, const QString &key, const QJsonValue &value, bool keyExists)
+QJsonObject::iterator QJsonObject::insertAt(int pos, QStringView key, const QJsonValue &value, bool keyExists)
{
QJsonValue val = value;
@@ -530,6 +572,7 @@ QJsonObject::iterator QJsonObject::insertAt(int pos, const QString &key, const Q
return iterator(this, pos);
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Removes \a key from the object.
@@ -537,6 +580,16 @@ QJsonObject::iterator QJsonObject::insertAt(int pos, const QString &key, const Q
*/
void QJsonObject::remove(const QString &key)
{
+ remove(QStringView(key));
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+void QJsonObject::remove(QStringView key)
+{
if (!d)
return;
@@ -548,6 +601,7 @@ void QJsonObject::remove(const QString &key)
removeAt(index);
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Removes \a key from the object.
@@ -559,6 +613,16 @@ void QJsonObject::remove(const QString &key)
*/
QJsonValue QJsonObject::take(const QString &key)
{
+ return take(QStringView(key));
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonValue QJsonObject::take(QStringView key)
+{
if (!o)
return QJsonValue(QJsonValue::Undefined);
@@ -573,6 +637,7 @@ QJsonValue QJsonObject::take(const QString &key)
return v;
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns \c true if the object contains key \a key.
@@ -580,6 +645,16 @@ QJsonValue QJsonObject::take(const QString &key)
*/
bool QJsonObject::contains(const QString &key) const
{
+ return contains(QStringView(key));
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+bool QJsonObject::contains(QStringView key) const
+{
if (!o)
return false;
@@ -656,6 +731,7 @@ QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it)
return it;
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns an iterator pointing to the item with key \a key in the
map.
@@ -665,6 +741,16 @@ QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it)
*/
QJsonObject::iterator QJsonObject::find(const QString &key)
{
+ return find(QStringView(key));
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonObject::iterator QJsonObject::find(QStringView key)
+{
bool keyExists = false;
int index = o ? o->indexOf(key, &keyExists) : 0;
if (!keyExists)
@@ -687,10 +773,18 @@ QJsonObject::iterator QJsonObject::find(QLatin1String key)
return iterator(this, index);
}
+#if QT_STRINGVIEW_LEVEL < 2
/*! \fn QJsonObject::const_iterator QJsonObject::find(const QString &key) const
\overload
*/
+#endif
+
+/*! \fn QJsonObject::const_iterator QJsonObject::find(QStringView key) const
+
+ \overload
+ \since 5.14
+*/
/*! \fn QJsonObject::const_iterator QJsonObject::find(QLatin1String key) const
@@ -698,6 +792,7 @@ QJsonObject::iterator QJsonObject::find(QLatin1String key)
\since 5.7
*/
+#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns a const iterator pointing to the item with key \a key in the
map.
@@ -707,6 +802,16 @@ QJsonObject::iterator QJsonObject::find(QLatin1String key)
*/
QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const
{
+ return constFind(QStringView(key));
+}
+#endif
+
+/*!
+ \overload
+ \since 5.14
+*/
+QJsonObject::const_iterator QJsonObject::constFind(QStringView key) const
+{
bool keyExists = false;
int index = o ? o->indexOf(key, &keyExists) : 0;
if (!keyExists)