diff options
author | Andreas Buhr <andreas.buhr@qt.io> | 2020-10-27 10:11:31 +0100 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2020-11-19 11:28:44 +0000 |
commit | 98666c8afc80cccb80ca4426b97ec52916c6e610 (patch) | |
tree | 003ed8422f2c8a7a6c8a2a52a0565208ffdeda1b /src | |
parent | 0732c5917d5441f901c6789056066b25cd263103 (diff) |
Change QString formatting of negative numbers in non-base-10
For bases other than 10, negative numbers have been converted
to QString by casting them to an unsigned number and
converting that. Thus QString::number(-17, 16) returned
"0xffffffffffffffef", for example.
This patch changes the behavior so that
negative numbers are converted like positive numbers.
Additinally, this patch adds unit tests for QString::number.
[ChangeLog][Important Behavior Changes]
Changed QString::number(integer, base) for negative numbers
and bases other than 10 to return the string corresponding
to the absolute value, prefixed by "-".
Fixes: QTBUG-53706
Change-Id: I0ad3ca3f035d553860b262f5bec17dc81714d8ac
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/text/qlocale.cpp | 6 |
1 files changed, 0 insertions, 6 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 3b7d4811e1..7692ea3b26 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -3491,12 +3491,6 @@ QString QLocaleData::longLongToString(qlonglong l, int precision, int base, int width, unsigned flags) const { bool negative = l < 0; - if (base != 10) { - // these are not supported by sprintf for octal and hex - flags &= ~AlwaysShowSign; - flags &= ~BlankBeforePositive; - negative = false; // neither are negative numbers - } QT_WARNING_PUSH /* "unary minus operator applied to unsigned type, result still unsigned" */ |