QLocaleData::numberToCLocale(): cache last character

Remember last iteration's character, if only to align with
validateChars(); this replaces some calls to result->last(), that all
happen where last can't have been a grouping character, so it's OK to
let last be set to ',' as far as these points in code are concerned.

Change-Id: I24112c25e5620bb0b056aaeb78c7a2a18b09e8fb
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Edward Welbourne 2022-11-01 16:03:16 +01:00
parent 80aba027af
commit df8d26f309
1 changed files with 5 additions and 3 deletions

View File

@ -3907,6 +3907,7 @@ bool QLocaleData::numberToCLocale(QStringView s, QLocale::NumberOptions number_o
qsizetype decpt_idx = -1;
qsizetype exponent_idx = -1;
char last = '\0';
while (idx < length) {
const QStringView in = QStringView(uc + idx, uc[idx].isHighSurrogate() ? 2 : 1);
@ -3934,7 +3935,7 @@ bool QLocaleData::numberToCLocale(QStringView s, QLocale::NumberOptions number_o
if (exponent_idx != -1 && out == '0' && idx < length - 1) {
// 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.
if (result->last() < '0' || result->last() > '9')
if (last < '0' || last > '9')
return false;
}
}
@ -3942,7 +3943,7 @@ bool QLocaleData::numberToCLocale(QStringView s, QLocale::NumberOptions number_o
if (number_options.testFlag(QLocale::RejectTrailingZeroesAfterDot)) {
// If we've seen a decimal point and the last character after the exponent is 0, then
// that is a trailing zero.
if (decpt_idx >= 0 && idx == exponent_idx && result->last() == '0')
if (decpt_idx >= 0 && idx == exponent_idx && last == '0')
return false;
}
@ -3985,6 +3986,7 @@ bool QLocaleData::numberToCLocale(QStringView s, QLocale::NumberOptions number_o
return false;
}
last = out;
if (out != ',') // Leave group separators out of the result.
result->append(out);
idx += in.size();
@ -4004,7 +4006,7 @@ bool QLocaleData::numberToCLocale(QStringView s, QLocale::NumberOptions number_o
if (number_options.testFlag(QLocale::RejectTrailingZeroesAfterDot)) {
// In decimal form, the last character can be a trailing zero if we've seen a decpt.
if (decpt_idx != -1 && exponent_idx == -1 && result->last() == '0')
if (decpt_idx != -1 && exponent_idx == -1 && last == '0')
return false;
}