summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale_win.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2023-11-02 11:27:29 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2023-11-03 18:27:14 +0100
commit8392e0ed94e2650ee1ce61e11de6215b6b9360c4 (patch)
treeb7ba69de3085c50e3450ea631e819f3cdfb3da72 /src/corelib/text/qlocale_win.cpp
parenta527ab6652edb3af1882cd08fa9fca92d835a4a6 (diff)
QLocale/MS: extract function to save some repetition
With one exception in a kludge-around, substituteDigits() calls were always subject to the same condition, so wrap that in a trivial method and simplify the code calling it. Change-Id: I6d8f3ca9179e32f03348cd718f9ee9de573221b9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/text/qlocale_win.cpp')
-rw-r--r--src/corelib/text/qlocale_win.cpp30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp
index d14cadffef..0cd6249b7f 100644
--- a/src/corelib/text/qlocale_win.cpp
+++ b/src/corelib/text/qlocale_win.cpp
@@ -124,6 +124,7 @@ private:
SubstitutionType substitution();
QString substituteDigits(QString &&string);
+ QString correctDigits(QString &&string);
QString yearFix(int year, int fakeYear, QString &&formatted);
static QString winToQtFormat(QStringView sys_fmt);
@@ -257,6 +258,11 @@ QString QSystemLocalePrivate::substituteDigits(QString &&string)
return std::move(string);
}
+QString QSystemLocalePrivate::correctDigits(QString &&string)
+{
+ return substitution() == SAlways ? substituteDigits(std::move(string)) : std::move(string);
+}
+
QVariant QSystemLocalePrivate::zeroDigit()
{
if (zero.isEmpty()) {
@@ -396,10 +402,7 @@ QVariant QSystemLocalePrivate::monthName(int month, QLocale::FormatType type)
wchar_t buf[255];
if (getDateFormat(flags, &st, format, buf, 255) > 2) {
// Elide the two digits of day number
- QString text = QString::fromWCharArray(buf + 2);
- if (substitution() == SAlways)
- text = substituteDigits(std::move(text));
- return nullIfEmpty(std::move(text));
+ return nullIfEmpty(correctDigits(QString::fromWCharArray(buf + 2)));
}
return {};
}
@@ -431,7 +434,7 @@ QString QSystemLocalePrivate::yearFix(int year, int fakeYear, QString &&formatte
return std::move(formatted).replace(tail.toString(), sign + trueYear.last(2));
}
- // Localized digits, perhaps ?
+ // Localized digits (regardless of SAlways), perhaps ?
// First call to substituteDigits() ensures zero is initialized:
trueYear = substituteDigits(std::move(trueYear));
if (zero != u'0') {
@@ -476,9 +479,7 @@ QVariant QSystemLocalePrivate::toString(QDate date, QLocale::FormatType type)
QString text = QString::fromWCharArray(buf);
if (fixup)
text = yearFix(year, st.wYear, std::move(text));
- if (substitution() == SAlways)
- text = substituteDigits(std::move(text));
- return nullIfEmpty(std::move(text));
+ return nullIfEmpty(correctDigits(std::move(text)));
}
return {};
}
@@ -499,12 +500,8 @@ QVariant QSystemLocalePrivate::toString(QTime time, QLocale::FormatType type)
auto formatStr = reinterpret_cast<const wchar_t *>(format.isEmpty() ? nullptr : format.utf16());
wchar_t 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));
- return nullIfEmpty(std::move(text));
- }
+ if (getTimeFormat(flags, &st, formatStr, buf, int(std::size(buf))))
+ return nullIfEmpty(correctDigits(QString::fromWCharArray(buf)));
return {};
}
@@ -664,10 +661,7 @@ QVariant QSystemLocalePrivate::toCurrencyString(const QSystemLocale::CurrencyToS
pformat, out.data(), out.size());
}
- value = QString::fromWCharArray(out.data());
- if (substitution() == SAlways)
- value = substituteDigits(std::move(value));
- return nullIfEmpty(std::move(value));
+ return nullIfEmpty(correctDigits(QString::fromWCharArray(out.data())));
}
QVariant QSystemLocalePrivate::uiLanguages()