From c85d8962576cdd6dbfce0508b585ab34cd94ebed Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 17 Sep 2024 15:26:57 +0200 Subject: [PATCH] Port from qlocale_data_p.h's isZero() to qIsNull() ... and mark the former for removal in 6.12 (LTS+1). I couldn't find more in-tree users than the ones this patch ports, but it doesn't cost much to defer removal of the function, so do it. Change-Id: I8a8762e65907d3f66c20cd733ecb55f7ac876960 Reviewed-by: Thiago Macieira --- src/corelib/text/qlocale.cpp | 2 +- src/corelib/text/qlocale_tools.cpp | 6 +++--- src/corelib/text/qlocale_tools_p.h | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 4bfc77efa66..552a34bdd19 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -3827,7 +3827,7 @@ QString QLocaleData::doubleToString(double d, int precision, DoubleForm form, bool negative = false; qt_doubleToAscii(d, form, precision, buf.data(), bufSize, negative, length, decpt); - const QString prefix = signPrefix(negative && !isZero(d), flags); + const QString prefix = signPrefix(negative && !qIsNull(d), flags); QString numStr; if (length == 3 diff --git a/src/corelib/text/qlocale_tools.cpp b/src/corelib/text/qlocale_tools.cpp index 00d473099d6..6bd7ef13b1b 100644 --- a/src/corelib/text/qlocale_tools.cpp +++ b/src/corelib/text/qlocale_tools.cpp @@ -117,7 +117,7 @@ void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision, else if (precision == QLocale::FloatingPointShortest) precision = std::numeric_limits::max_digits10; // snprintf lacks "shortest" mode - if (isZero(d)) { + if (qIsNull(d)) { // Negative zero is expected as simple "0", not "-0". We cannot do d < 0, though. sign = false; buf[0] = '0'; @@ -356,7 +356,7 @@ QSimpleParsedNumber qt_asciiToDouble(const char *num, qsizetype numLen, Q_ASSERT(strayCharMode == TrailingJunkAllowed || processed == numLen); // Check if underflow has occurred. - if (isZero(d)) { + if (qIsNull(d)) { for (int i = 0; i < processed; ++i) { if (num[i] >= '1' && num[i] <= '9') { // if a digit before any 'e' is not 0, then a non-zero number was intended. @@ -721,7 +721,7 @@ static T dtoString(double d, QLocaleData::DoubleForm form, int precision, bool u T result; result.reserve(total); - if (negative && !isZero(d)) // We don't return "-0" + if (negative && !qIsNull(d)) // We don't return "-0" result.append(Char('-')); if (!qt_is_finite(d)) { result.append(view); diff --git a/src/corelib/text/qlocale_tools_p.h b/src/corelib/text/qlocale_tools_p.h index f862c3e312d..5dd6a64073c 100644 --- a/src/corelib/text/qlocale_tools_p.h +++ b/src/corelib/text/qlocale_tools_p.h @@ -63,10 +63,13 @@ void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision, int base = 10); #endif +#if QT_VERSION < QT_VERSION_CHECK(6, 12, 0) +[[deprecated("Use qIsNull(double) instead.")]] [[nodiscard]] constexpr inline bool isZero(double d) { return qIsNull(d); } +#endif // Enough space for the digits before the decimal separator: [[nodiscard]] inline int wholePartSpace(double d)