diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-11-10 23:10:35 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-11-16 16:15:31 -0800 |
commit | cc98a7d01f19ea99f97b59dc66181c0d560e2cc8 (patch) | |
tree | b813e5afd5fda74a27e14a489f03396f41c46d02 /src | |
parent | 308f9ae8f041e0cac47fdca55f1172a7d3ea892d (diff) |
QString: skip QLocale::numberToCLocale for floating point
This is a repeat of commit 885ae61c6378e06a965f543d2ecbd162c6224347,
which applied a direct QString-to-Latin1 conversion to integral parsing
to avoid going through the expensive QLocale::numberToCLocale. But we
also need to lowercase the input.
Change-Id: Ieba79baf5ac34264a988fffd1726762a411e3bd6
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/text/qstring.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index f954e8b25d..b3e147c0ba 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -7487,7 +7487,22 @@ double QString::toDouble(bool *ok) const double QStringView::toDouble(bool *ok) const { - return QLocaleData::c()->stringToDouble(*this, ok, QLocale::RejectGroupSeparator); + QStringView string = qt_trimmed(*this); + QVarLengthArray<uchar> latin1(string.size()); + qt_to_latin1(latin1.data(), string.utf16(), string.size()); + + // We need lowetcased "inf" and "nan". + // This mangles the string, but nothing can become a number or letter + // that isn't already a number or letter. + for (uchar &c : latin1) { + if (c >= 'A') + c |= 0x20; + } + + auto r = qt_asciiToDouble(reinterpret_cast<const char *>(latin1.data()), string.size()); + if (ok != nullptr) + *ok = r.ok(); + return r.result; } /*! |