diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index dd72677442a..42fdb49474e 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -3563,7 +3563,7 @@ Qt::LayoutDirection QLocale::textDirection() const */ QString QLocale::toUpper(const QString &str) const { -#if !defined(QT_BOOTSTRAPPED) && (QT_CONFIG(icu) || defined(Q_OS_WIN)) +#if !defined(QT_BOOTSTRAPPED) && (QT_CONFIG(icu) || defined(Q_OS_WIN) || defined(Q_OS_APPLE)) bool ok = true; QString result = d->toUpper(str, &ok); if (ok) @@ -3587,7 +3587,7 @@ QString QLocale::toUpper(const QString &str) const */ QString QLocale::toLower(const QString &str) const { -#if !defined(QT_BOOTSTRAPPED) && (QT_CONFIG(icu) || defined(Q_OS_WIN)) +#if !defined(QT_BOOTSTRAPPED) && (QT_CONFIG(icu) || defined(Q_OS_WIN) || defined(Q_OS_APPLE)) bool ok = true; const QString result = d->toLower(str, &ok); if (ok) diff --git a/src/corelib/text/qlocale_mac.mm b/src/corelib/text/qlocale_mac.mm index ff1abcd0447..87f20310980 100644 --- a/src/corelib/text/qlocale_mac.mm +++ b/src/corelib/text/qlocale_mac.mm @@ -697,4 +697,40 @@ QVariant QSystemLocale::query(QueryType type, QVariant &&in) const #endif // QT_NO_SYSTEMLOCALE +#if !QT_CONFIG(icu) + +static QString localeConvertString(const QByteArray &localeID, const QString &str, bool *ok, + bool toLowerCase) +{ + QMacAutoReleasePool pool; + Q_ASSERT(ok); + NSString *localestring = [[NSString alloc] initWithData:localeID.toNSData() + encoding:NSUTF8StringEncoding]; + NSLocale *locale = [NSLocale localeWithLocaleIdentifier:localestring]; + if (!locale) { + *ok = false; + return QString(); + } + *ok = true; + NSString *nsstring = str.toNSString(); + if (toLowerCase) + nsstring = [nsstring lowercaseStringWithLocale:locale]; + else + nsstring = [nsstring uppercaseStringWithLocale:locale]; + + return QString::fromNSString(nsstring); +} + +QString QLocalePrivate::toLower(const QString &str, bool *ok) const +{ + return localeConvertString(bcp47Name('-'), str, ok, true); +} + +QString QLocalePrivate::toUpper(const QString &str, bool *ok) const +{ + return localeConvertString(bcp47Name('-'), str, ok, false); +} + +#endif + QT_END_NAMESPACE diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h index 7434734dec1..4833c0b424c 100644 --- a/src/corelib/text/qlocale_p.h +++ b/src/corelib/text/qlocale_p.h @@ -552,10 +552,8 @@ public: [[nodiscard]] QLocale::MeasurementSystem measurementSystem() const; -#if QT_CONFIG(icu) || (defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED)) [[nodiscard]] QString toUpper(const QString &str, bool *ok) const; [[nodiscard]] QString toLower(const QString &str, bool *ok) const; -#endif // System locale has an m_data all its own; all others have m_data = locale_data + m_index const QLocaleData *const m_data; diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 0040e1b3783..fba1fd01437 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -161,7 +161,7 @@ private slots: void lcsToCode(); void codeToLcs(); -#if QT_CONFIG(icu) || defined(Q_OS_WIN) +#if QT_CONFIG(icu) || defined(Q_OS_WIN) || defined(Q_OS_APPLE) void toLowerUpper_data(); void toLowerUpper(); @@ -4777,7 +4777,7 @@ void tst_QLocale::codeToLcs() QCOMPARE(QLocale::codeToScript(QString("Hans")), QLocale::SimplifiedHanScript); } -#if QT_CONFIG(icu) || defined(Q_OS_WIN) +#if QT_CONFIG(icu) || defined(Q_OS_WIN) || defined(Q_OS_APPLE) void tst_QLocale::toLowerUpper_data() { QTest::addColumn("locale");