diff options
Diffstat (limited to 'src/qjsonobject.cpp')
-rw-r--r-- | src/qjsonobject.cpp | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/src/qjsonobject.cpp b/src/qjsonobject.cpp index 219790e..613d382 100644 --- a/src/qjsonobject.cpp +++ b/src/qjsonobject.cpp @@ -149,17 +149,27 @@ QJsonValue QJsonObject::value(const QString &key) const for (uint i = 0; i < o->length; ++i) { Private::Entry *e = o->entryAt(i); - if (e->value.latinKey) { - if (e->shallowLatin1Key() == key) - return QJsonValue(d, o, e->value); - } else { - if (e->shallowKey() == key) - return QJsonValue(d, o, e->value); - } + if (e->matchesKey(key)) + return QJsonValue(d, o, e->value); } return QJsonValue(QJsonValue::Undefined); } +QJsonValue QJsonObject::operator [](const QString &key) const +{ + return value(key); +} + +QJsonValueRef QJsonObject::operator [](const QString &key) +{ + int index = o ? o->indexOf(key) : -1; + if (index < 0) { + insert(key, QJsonValue()); + index = o->indexOf(key); + } + return QJsonValueRef(this, index); +} + void QJsonObject::insert(const QString &key, const QJsonValue &value) { if (value.t == QJsonValue::Undefined) { @@ -298,6 +308,31 @@ void QJsonObject::compact() const const_cast<QJsonObject *>(this)->o = static_cast<Private::Object *>(d->header->root()); } +QString QJsonObject::keyAt(int i) +{ + Q_ASSERT(o && i >= 0 && i < (int)o->length); + + Private::Entry *e = o->entryAt(i); + return e->key(); +} + +QJsonValue QJsonObject::valueAt(int i) +{ + Q_ASSERT(o && i >= 0 && i < (int)o->length); + + Private::Entry *e = o->entryAt(i); + return QJsonValue(d, o, e->value); +} + +void QJsonObject::setValueAt(int i, const QJsonValue &val) +{ + Q_ASSERT(o && i >= 0 && i < (int)o->length); + + Private::Entry *e = o->entryAt(i); + insert(e->key(), val); +} + + } // namespace QtJson QT_BEGIN_NAMESPACE |