diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-11-01 16:03:16 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-11-11 16:32:53 +0100 |
commit | df8d26f30943610b84183a7edac64f74de4571c0 (patch) | |
tree | a5ee991ee5de990937d76dee130cf3c3e48d3c76 /src/corelib/text/qlocale.cpp | |
parent | 80aba027af3ff41f344bd5a03245900899a1f22a (diff) |
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>
Diffstat (limited to 'src/corelib/text/qlocale.cpp')
-rw-r--r-- | src/corelib/text/qlocale.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 0755cd8354..b9aaa5b338 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -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; } |