aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4stringobject.cpp
diff options
context:
space:
mode:
authorJohnny Jazeix <jazeix@gmail.com>2023-04-17 08:38:38 +0200
committerJohnny Jazeix <jazeix@gmail.com>2024-11-22 17:39:29 +0100
commitb8d3d18b0517c54044e9b300da5fd014dd869d9c (patch)
treec905c7954bab560b4f3e2145148d8f8f8cec24d6 /src/qml/jsruntime/qv4stringobject.cpp
parentbf7261d67dd1f29764ed0cc2a6392e3782770115 (diff)
V4: make JS functions toLocale{Lower,Upper}Case aware of the locale
We now call the toUpper/toLower function for the correct locale. It fixes the case of the Turkish uppercase i is İ not I. Fixes: QTBUG-112898 Change-Id: Ibd0174656e0aa561747490f3e6d52c639bd06b63 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4stringobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4stringobject.cpp56
1 files changed, 54 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp
index 31219228f0..f7c7eae199 100644
--- a/src/qml/jsruntime/qv4stringobject.cpp
+++ b/src/qml/jsruntime/qv4stringobject.cpp
@@ -1101,9 +1101,55 @@ ReturnedValue StringPrototype::method_toLowerCase(const FunctionObject *b, const
return Encode(v4->newString(value.toLower()));
}
+static const QLocale *getLocaleDataResource(const QV4::Value &val)
+{
+ if (const QV4::QQmlValueTypeWrapper *wrapper = val.as<QQmlValueTypeWrapper>())
+ return wrapper->cast<const QLocale>();
+
+ return nullptr;
+}
+
+static QLocale getLocaleFromArgs(const FunctionObject *b, const QV4::Value *argv, int argc)
+{
+ if (argc == 0)
+ return QLocale();
+
+ ExecutionEngine *v4 = b->engine();
+ Scope scope(b);
+ QString stringifiedLocale;
+ // First argument is a string, we check if it is a valid locale
+ if (const QV4::String *that = argv[0].as<QV4::String>()) {
+ stringifiedLocale = that->toQString();
+ } else if (const QLocale *locale = getLocaleDataResource(argv[0])) {
+ return *locale;
+ } else if (argv[0].isObject()) {
+ // First argument is an array, we check if the first element is
+ // a string and a valid locale.
+ ScopedObject arrayLike(scope, argv[0].toObject(scope.engine));
+ ScopedValue kValue(scope);
+ if (arrayLike->getLength() > 0) {
+ kValue = arrayLike->get(uint(0));
+ if (kValue->isString())
+ stringifiedLocale = kValue->toQString();
+ else if (const QLocale *locale = getLocaleDataResource(kValue))
+ return *locale;
+ }
+ } else {
+ v4->throwTypeError();
+ }
+
+ return QLocale(stringifiedLocale);
+}
+
ReturnedValue StringPrototype::method_toLocaleLowerCase(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
{
- return method_toLowerCase(b, thisObject, argv, argc);
+ ExecutionEngine *v4 = b->engine();
+ const QString value = getThisString(v4, thisObject);
+ if (v4->hasException)
+ return QV4::Encode::undefined();
+
+ QLocale locale = getLocaleFromArgs(b, argv, argc);
+ return Encode(v4->newString(locale.toLower(value)));
}
ReturnedValue StringPrototype::method_toUpperCase(const FunctionObject *b, const Value *thisObject, const Value *, int)
@@ -1118,7 +1164,13 @@ ReturnedValue StringPrototype::method_toUpperCase(const FunctionObject *b, const
ReturnedValue StringPrototype::method_toLocaleUpperCase(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
{
- return method_toUpperCase(b, thisObject, argv, argc);
+ ExecutionEngine *v4 = b->engine();
+ const QString value = getThisString(v4, thisObject);
+ if (v4->hasException)
+ return QV4::Encode::undefined();
+
+ QLocale locale = getLocaleFromArgs(b, argv, argc);
+ return Encode(v4->newString(locale.toUpper(value)));
}
ReturnedValue StringPrototype::method_trim(const FunctionObject *b, const Value *thisObject, const Value *, int)