From d8538163075a2058f110bc77e7d481ef1ab7612c Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 3 Jul 2020 14:13:15 +0200 Subject: Fix handling of Suzhou numbering system This only arises when the system locale tells us to use its zero as our zero digit, since no CLDR locale uses it by default. Adapt an MS-specific QLocale::system() test to use Suzhou numbering, so as to test this. While updating the locale-restoration code to also restore the digits being set in that test, add restore code for the long time format, where previously only the short time format was restored. Add a comment to make it less likely one of those shall be missed in future. Fixes: QTBUG-85409 Change-Id: I343324bb563ee0e455dfe77d4825bf8c3082ca30 Reviewed-by: Thiago Macieira --- src/corelib/text/qlocale.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/corelib/text/qlocale.cpp') diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 5bf2f7b296..2febee62a9 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -3363,7 +3363,7 @@ QString QLocaleData::doubleToString(double d, int precision, DoubleForm form, QString converted; converted.reserve(2 * digits.size()); for (int i = 0; i < digits.length(); ++i) { - const uint digit = zeroUcs4 - '0' + digits.at(i).unicode(); + const uint digit = unicodeForDigit(digits.at(i).unicode() - '0', zeroUcs4); Q_ASSERT(QChar::requiresSurrogates(digit)); converted.append(QChar::highSurrogate(digit)); converted.append(QChar::lowSurrogate(digit)); @@ -3372,9 +3372,10 @@ QString QLocaleData::doubleToString(double d, int precision, DoubleForm form, } else { Q_ASSERT(zero.size() == 1); Q_ASSERT(!zero.at(0).isSurrogate()); - ushort z = zero.at(0).unicode() - '0'; + ushort z = zero.at(0).unicode(); + ushort *const value = reinterpret_cast(digits.data()); for (int i = 0; i < digits.length(); ++i) - reinterpret_cast(digits.data())[i] += z; + value[i] = unicodeForDigit(value[i] - '0', z); } const bool mustMarkDecimal = flags & ForcePoint; -- cgit v1.2.3