From e48b4d2b7c1d99ba8962a9c10a1508d16dc33fbf Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 14 Apr 2022 19:29:40 +0200 Subject: Implement support for '0b' prefix in toInt() etc [ChangeLog][QtCore][QByteArray/QByteArrayView/QLatin1String/QString/QStringView] The string-to-integer conversion functions (toInt() etc) now support the 0b prefix for binary literals. That means that base = 0 will recognize 0b to mean base = 2 and an explicit base = 2 argument will make toInt() (etc) skip an optional 0b. [ChangeLog][QtCore][Important Behavior Changes] Due to the newly-introduced support for 0b (binary) prefixes in integer parsing, some strings that were previously rejected as invalid now parse as valid. E.g., Qt 6.3 with autodetected bases would have tried to parse "0b1" as an octal value and fail, whereas 6.4 will parse it as the binary literal and return 1. Fixes: QTBUG-85002 Change-Id: Id4eff72d63619080e5afece4d059b6ffd52f28c8 Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot --- .../auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index c92cb0ad92..6a8f62d4b7 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -2654,14 +2654,13 @@ void tst_QStringApiSymmetry::toNumberWithBases_data() const char prefix[3]; int base; } bases[] = { - { "", 2 }, // should be {"0b", 2}, but Qt lacks support for the 0b prefix (QTBUG-85002) + { "0b", 2 }, { "0", 8 }, { "", 10 }, { "0x", 16 }, }; const auto check = [&](const char *input, qint64 n2, qint64 n8, qint64 n10, qint64 n16, bool result) { - for (const auto &e : bases) { const QString data = QLatin1StringView(e.prefix) + QString::fromUtf8(input); const auto row = [&](int base) { @@ -2678,8 +2677,6 @@ void tst_QStringApiSymmetry::toNumberWithBases_data() << data << base << select(e.base /* NOT base! */) << result; }; row(e.base); // explicit base - if (e.base == 2) - continue; // Qt doesn't know 0b (yet, QTBUG-85002), so nothing to auto-detect row(0); // automatically detected base } }; -- cgit v1.2.3