From d753941817f4c623a4e202234535426708bb6eb6 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 23 Feb 2023 16:48:30 +0100 Subject: Use isAsciiDigit() in a few more places in qlocale.cpp Use the function now in qtools_p.h in several more places. (A later commit rewrites the remainder away.) Change-Id: I782f0dceffe0e6e76753643a889011a834bc3ff0 Reviewed-by: Thiago Macieira --- src/corelib/text/qlocale.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/corelib/text') diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 2bb9a1eaf5..c86f995bc0 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -3541,8 +3541,7 @@ QString QLocaleData::doubleToString(double d, int precision, DoubleForm form, if (zero == u"0") { // No need to convert digits. - Q_ASSERT(std::all_of(buf.cbegin(), buf.cbegin() + length, [](char ch) - { return '0' <= ch && ch <= '9'; })); + Q_ASSERT(std::all_of(buf.cbegin(), buf.cbegin() + length, isAsciiDigit)); // That check is taken care of in unicodeForDigits, below. } else if (zero.size() == 2 && zero.at(0).isHighSurrogate()) { const char32_t zeroUcs4 = QChar::surrogateToUcs4(zero.at(0), zero.at(1)); @@ -3893,7 +3892,7 @@ bool QLocaleData::numberToCLocale(QStringView s, QLocale::NumberOptions number_o // After the exponent there can only be '+', '-' or digits. // If we find a '0' directly after some non-digit, then that is a // leading zero, acceptable only if it is the whole exponent. - if (idx < length - 1 && (last < '0' || last > '9')) + if (idx < length - 1 && !isAsciiDigit(last)) return false; } @@ -3904,7 +3903,7 @@ bool QLocaleData::numberToCLocale(QStringView s, QLocale::NumberOptions number_o } if (!number_options.testFlag(QLocale::RejectGroupSeparator)) { - if (out >= '0' && out <= '9') { + if (isAsciiDigit(out)) { if (start_of_digits_idx == -1) start_of_digits_idx = idx; ++digitsInGroup; @@ -3988,7 +3987,7 @@ bool QLocaleData::validateChars(QStringView str, NumberMode numMode, QByteArray return false; break; case Exponent: - if (last < '0' || last > '9') { + if (!isAsciiDigit(last)) { // This is the first digit in the exponent (there may have beena '+' // or '-' in before). If it's a zero, the exponent is zero-padded. if (c == '0' && (number_options & QLocale::RejectLeadingZeroInExponent)) @@ -4020,7 +4019,7 @@ bool QLocaleData::validateChars(QStringView str, NumberMode numMode, QByteArray case ',': // Grouping is only allowed after a digit in the whole-number portion: if ((number_options & QLocale::RejectGroupSeparator) || state != Whole - || last < '0' || last > '9') { + || !isAsciiDigit(last)) { return false; } // We could check grouping sizes are correct, but fixup()s are -- cgit v1.2.3