summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale_win.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/text/qlocale_win.cpp')
-rw-r--r--src/corelib/text/qlocale_win.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp
index f61c724aee..0e0716cc65 100644
--- a/src/corelib/text/qlocale_win.cpp
+++ b/src/corelib/text/qlocale_win.cpp
@@ -18,14 +18,8 @@
#endif
#if QT_CONFIG(cpp_winrt) && !defined(Q_CC_CLANG)
-# include <winrt/base.h>
-// Workaround for Windows SDK bug.
-// See https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/issues/47
-namespace winrt::impl
-{
- template <typename Async>
- auto wait_for(Async const& async, Windows::Foundation::TimeSpan const& timeout);
-}
+# include <QtCore/private/qt_winrtbase_p.h>
+
# include <winrt/Windows.Foundation.h>
# include <winrt/Windows.Foundation.Collections.h>
# include <winrt/Windows.System.UserProfile.h>
@@ -224,7 +218,7 @@ QString QSystemLocalePrivate::substituteDigits(QString &&string)
break;
Q_ASSERT(z > '9');
ushort *const qch = reinterpret_cast<ushort *>(string.data());
- for (int i = 0, stop = string.size(); i < stop; ++i) {
+ for (qsizetype i = 0, stop = string.size(); i < stop; ++i) {
ushort &ch = qch[i];
if (ch >= '0' && ch <= '9')
ch = unicodeForDigit(ch - '0', z);
@@ -434,7 +428,7 @@ QString QSystemLocalePrivate::yearFix(int year, int fakeYear, QString &&formatte
if (formatted.contains(yearUsed))
return std::move(formatted).replace(yearUsed, sign + trueYear);
- const int twoDigits = 2 * zero.size();
+ const qsizetype twoDigits = 2 * zero.size();
tail = QStringView{yearUsed}.last(twoDigits);
if (formatted.contains(tail)) {
if (matchTwo)
@@ -485,11 +479,13 @@ QVariant QSystemLocalePrivate::toString(QTime time, QLocale::FormatType type)
DWORD flags = 0;
// keep the same conditional as timeFormat() above
- if (type == QLocale::ShortFormat)
- flags = TIME_NOSECONDS;
+ const QString format = type == QLocale::ShortFormat
+ ? getLocaleInfo(LOCALE_SSHORTTIME).toString()
+ : QString();
+ auto formatStr = reinterpret_cast<const wchar_t *>(format.isEmpty() ? nullptr : format.utf16());
wchar_t buf[255];
- if (getTimeFormat(flags, &st, NULL, buf, 255)) {
+ if (getTimeFormat(flags, &st, formatStr, buf, int(std::size(buf)))) {
QString text = QString::fromWCharArray(buf);
if (substitution() == SAlways)
text = substituteDigits(std::move(text));
@@ -662,9 +658,13 @@ QVariant QSystemLocalePrivate::uiLanguages()
#if QT_CONFIG(cpp_winrt) && !defined(Q_CC_CLANG)
using namespace winrt;
using namespace Windows::System::UserProfile;
- auto languages = GlobalizationPreferences::Languages();
- for (const auto &lang : languages)
- result << QString::fromStdString(winrt::to_string(lang));
+ QT_TRY {
+ auto languages = GlobalizationPreferences::Languages();
+ for (const auto &lang : languages)
+ result << QString::fromStdString(winrt::to_string(lang));
+ } QT_CATCH(...) {
+ // pass, just fall back to WIN32 API implementation
+ }
if (!result.isEmpty())
return result; // else just fall back to WIN32 API implementation
#endif // QT_CONFIG(cpp_winrt) && !defined(Q_CC_CLANG)
@@ -716,7 +716,7 @@ void QSystemLocalePrivate::update()
QString QSystemLocalePrivate::winToQtFormat(QStringView sys_fmt)
{
QString result;
- int i = 0;
+ qsizetype i = 0;
while (i < sys_fmt.size()) {
if (sys_fmt.at(i).unicode() == u'\'') {
@@ -1034,6 +1034,8 @@ static const char *winLangCodeToIsoName(int code)
LCID qt_inIsoNametoLCID(const char *name)
{
+ if (!name)
+ return LOCALE_USER_DEFAULT;
// handle norwegian manually, the list above will fail
if (!strncmp(name, "nb", 2))
return 0x0414;
@@ -1070,11 +1072,9 @@ static QString winIso639LangName(LCID id)
lang_code = QString::fromWCharArray(out);
if (!lang_code.isEmpty()) {
- const char *endptr;
- bool ok;
const QByteArray latin1 = std::move(lang_code).toLatin1();
- const auto i = qstrntoull(latin1.data(), latin1.size(), &endptr, 16, &ok);
- if (ok && *endptr == '\0') {
+ const auto [i, endptr] = qstrntoull(latin1.data(), latin1.size(), 16);
+ if (endptr && *endptr == '\0') {
switch (i) {
case 0x814:
result = u"nn"_s; // Nynorsk
@@ -1114,8 +1114,8 @@ static QByteArray getWinLocaleName(LCID id)
result = langEnvVar;
if (result == "C"
|| (!result.isEmpty() && qt_splitLocaleName(QString::fromLocal8Bit(result)))) {
- bool ok = false; // See if we have a Windows locale code instead of a locale name:
- long id = qstrntoll(result.data(), result.size(), 0, 0, &ok);
+ // See if we have a Windows locale code instead of a locale name:
+ auto [id, ok] = qstrntoll(result.data(), result.size(), 0);
if (!ok || id == 0 || id < INT_MIN || id > INT_MAX) // Assume real locale name
return result;
return winLangCodeToIsoName(int(id));