summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/json/qjson_p.h23
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp24
2 files changed, 44 insertions, 3 deletions
diff --git a/src/corelib/json/qjson_p.h b/src/corelib/json/qjson_p.h
index 92330175ba..2cb26b95a1 100644
--- a/src/corelib/json/qjson_p.h
+++ b/src/corelib/json/qjson_p.h
@@ -354,7 +354,7 @@ public:
return !memcmp(d->utf16, str.d->utf16, d->length*sizeof(ushort));
}
inline bool operator<(const String &other) const;
- inline bool operator >=(const String &other) const { return other < *this; }
+ inline bool operator >=(const String &other) const { return !(*this < other); }
inline QString toString() const {
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
@@ -414,12 +414,29 @@ public:
val = d->length - str.d->length;
return val >= 0;
}
+ inline bool operator<(const String &str) const
+ {
+ const qle_ushort *uc = (qle_ushort *) str.d->utf16;
+ if (!uc || *uc == 0)
+ return false;
+
+ const uchar *c = (uchar *)d->latin1;
+ const uchar *e = c + qMin((int)d->length, (int)str.d->length);
+ while (c < e) {
+ if (*c != *uc)
+ break;
+ ++c;
+ ++uc;
+ }
+ return (c == e ? (int)d->length < (int)str.d->length : *c < *uc);
+
+ }
inline bool operator ==(const String &str) const {
return (str == *this);
}
inline bool operator >=(const String &str) const {
- return (str < *this);
+ return !(*this < str);
}
inline QString toString() const {
@@ -456,7 +473,7 @@ inline bool String::operator <(const String &other) const
a++,b++;
if (l==-1)
return (alen < blen);
- return (ushort)*a - (ushort)*b;
+ return (ushort)*a < (ushort)*b;
}
inline bool String::operator<(const Latin1String &str) const
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index d4ce123fcc..ba19e4855d 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -149,6 +149,8 @@ private Q_SLOTS:
void arrayInitializerList();
void objectInitializerList();
+
+ void unicodeKeys();
private:
QString testDataDir;
};
@@ -2753,5 +2755,27 @@ void tst_QtJson::objectInitializerList()
#endif
}
+void tst_QtJson::unicodeKeys()
+{
+ QByteArray json = "{"
+ "\"x\u2090_1\": \"hello_1\","
+ "\"y\u2090_2\": \"hello_2\","
+ "\"T\u2090_3\": \"hello_3\","
+ "\"xyz_4\": \"hello_4\","
+ "\"abc_5\": \"hello_5\""
+ "}";
+
+ QJsonParseError error;
+ QJsonDocument doc = QJsonDocument::fromJson(json, &error);
+ QVERIFY(error.error == QJsonParseError::NoError);
+ QJsonObject o = doc.object();
+
+ QCOMPARE(o.keys().size(), 5);
+ Q_FOREACH (const QString &key, o.keys()) {
+ QString suffix = key.mid(key.indexOf(QLatin1Char('_')));
+ QCOMPARE(o[key].toString(), QString("hello") + suffix);
+ }
+}
+
QTEST_MAIN(tst_QtJson)
#include "tst_qtjson.moc"