QString: skip QLocale::numberToCLocale for floating point
This is a repeat of commit 885ae61c63,
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>
bb10
parent
308f9ae8f0
commit
cc98a7d01f
|
|
@ -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;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
Loading…
Reference in New Issue