QLocale: update qt_asciiToDouble to use qsizetype

No need to change the output variable from int to qsizetype. That would
complicate the use of libdouble-conversion, which uses ints.

Change-Id: Iea47e0f8fc8b40378df7fffd1624bfdba1189d81
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Thiago Macieira 2020-07-24 10:18:37 -07:00 committed by Edward Welbourne
parent 2ab4fe2ac8
commit caa40f57d4
2 changed files with 19 additions and 13 deletions

View File

@ -278,7 +278,7 @@ void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision, cha
--length;
}
double qt_asciiToDouble(const char *num, int numLen, bool &ok, int &processed,
double qt_asciiToDouble(const char *num, qsizetype numLen, bool &ok, int &processed,
StrayCharacterMode strayCharMode)
{
auto string_equals = [](const char *needle, const char *haystack, qsizetype haystackLen) {
@ -329,7 +329,14 @@ double qt_asciiToDouble(const char *num, int numLen, bool &ok, int &processed,
| double_conversion::StringToDoubleConverter::ALLOW_TRAILING_SPACES;
}
double_conversion::StringToDoubleConverter conv(conv_flags, 0.0, qt_qnan(), nullptr, nullptr);
d = conv.StringToDouble(num, numLen, &processed);
if (int(numLen) != numLen) {
// a number over 2 GB in length is silly, just assume it isn't valid
ok = false;
processed = 0;
return 0.0;
} else {
d = conv.StringToDouble(num, numLen, &processed);
}
if (!qIsFinite(d)) {
ok = false;
@ -487,19 +494,12 @@ QString qulltoa(qulonglong number, int base, const QStringView zero)
return QString(reinterpret_cast<QChar *>(p), end - p);
}
double qstrtod(const char *s00, const char **se, bool *ok)
{
const int len = static_cast<int>(strlen(s00));
Q_ASSERT(len >= 0);
return qstrntod(s00, len, se, ok);
}
/*!
\internal
Converts the initial portion of the string pointed to by \a s00 to a double, using the 'C' locale.
*/
double qstrntod(const char *s00, int len, const char **se, bool *ok)
double qstrntod(const char *s00, qsizetype len, const char **se, bool *ok)
{
int processed = 0;
bool nonNullOk = false;

View File

@ -62,7 +62,8 @@ enum StrayCharacterMode {
WhitespacesAllowed
};
double qt_asciiToDouble(const char *num, int numLen, bool &ok, int &processed,
// API note: this function can't process a number with more than 2.1 billion digits
double qt_asciiToDouble(const char *num, qsizetype numLen, bool &ok, int &processed,
StrayCharacterMode strayCharMode = TrailingJunkProhibited);
void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision, char *buf, int bufSize,
bool &sign, int &length, int &decpt);
@ -106,8 +107,13 @@ inline UcsInt unicodeForDigit(uint digit, UcsInt zero)
return zero + digit;
}
Q_CORE_EXPORT double qstrtod(const char *s00, char const **se, bool *ok);
Q_CORE_EXPORT double qstrntod(const char *s00, int len, char const **se, bool *ok);
Q_CORE_EXPORT double qstrntod(const char *s00, qsizetype len, char const **se, bool *ok);
inline double qstrtod(const char *s00, char const **se, bool *ok)
{
qsizetype len = qsizetype(strlen(s00));
return qstrntod(s00, len, se, ok);
}
qlonglong qstrtoll(const char *nptr, const char **endptr, int base, bool *ok);
qulonglong qstrtoull(const char *nptr, const char **endptr, int base, bool *ok);