Skip to content

Commit

Permalink
Port from qlocale_data_p.h's isZero() to qIsNull()
Browse files Browse the repository at this point in the history
... 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 <[email protected]>
  • Loading branch information
marcmutz committed Sep 18, 2024
1 parent 743403c commit c85d896
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/corelib/text/qlocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/corelib/text/qlocale_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision,
else if (precision == QLocale::FloatingPointShortest)
precision = std::numeric_limits<double>::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';
Expand Down Expand Up @@ -356,7 +356,7 @@ QSimpleParsedNumber<double> 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.
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/corelib/text/qlocale_tools_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c85d896

Please sign in to comment.