summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-03-21 23:34:07 +0200
committerAhmad Samir <a.samirh78@gmail.com>2023-04-22 20:04:31 +0200
commit56aa065ab57d55cc832c45b8c260153447c57188 (patch)
treeae026c99a3825bd841231fa9716c0bd54dd71cca /src/corelib/text/qlocale.cpp
parent18f5dc3746b7362c3741ef7e0332fa18d85a3d80 (diff)
QLocaleData: de-duplicate some code
Not using structured bindings because those functions will be changed to return QSimpleParsedNumber directly. Change-Id: Ic52b6754da14b86d8ddc5f399262f227e05527ce Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qlocale.cpp')
-rw-r--r--src/corelib/text/qlocale.cpp59
1 files changed, 21 insertions, 38 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp
index f8c98c4c16..6923e35736 100644
--- a/src/corelib/text/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -4328,57 +4328,40 @@ qulonglong QLocaleData::stringToUnsLongLong(QStringView str, int base, bool *ok,
return bytearrayToUnsLongLong(QByteArrayView(buff.constData(), buff.size()), base, ok);
}
-qlonglong QLocaleData::bytearrayToLongLong(QByteArrayView num, int base, bool *ok)
+static bool checkParsed(QByteArrayView num, qsizetype used)
{
- const qsizetype len = num.size();
- auto [l, used] = qstrntoll(num.data(), len, base);
- if (used <= 0) {
- if (ok != nullptr)
- *ok = false;
- return 0;
- }
+ if (used <= 0)
+ return false;
+ const qsizetype len = num.size();
if (used < len && num[used] != '\0') {
while (used < len && ascii_isspace(num[used]))
++used;
}
- if (used < len && num[used] != '\0') {
+ if (used < len && num[used] != '\0')
// we stopped at a non-digit character after converting some digits
- if (ok != nullptr)
- *ok = false;
- return 0;
- }
+ return false;
- if (ok != nullptr)
- *ok = true;
- return l;
+ return true;
}
-qulonglong QLocaleData::bytearrayToUnsLongLong(QByteArrayView num, int base, bool *ok)
+qlonglong QLocaleData::bytearrayToLongLong(QByteArrayView num, int base, bool *ok)
{
- const qsizetype len = num.size();
- auto [l, used] = qstrntoull(num.data(), len, base);
- if (used <= 0) {
- if (ok != nullptr)
- *ok = false;
- return 0;
- }
-
- if (used < len && num[used] != '\0') {
- while (used < len && ascii_isspace(num[used]))
- ++used;
- }
-
- if (used < len && num[used] != '\0') {
- if (ok != nullptr)
- *ok = false;
- return 0;
- }
+ auto r = qstrntoll(num.data(), num.size(), base);
+ const bool parsed = checkParsed(num, r.used);
+ if (ok)
+ *ok = parsed;
+ return parsed ? r.result : 0;
+}
- if (ok != nullptr)
- *ok = true;
- return l;
+qulonglong QLocaleData::bytearrayToUnsLongLong(QByteArrayView num, int base, bool *ok)
+{
+ auto r = qstrntoull(num.data(), num.size(), base);
+ const bool parsed = checkParsed(num, r.used);
+ if (ok)
+ *ok = parsed;
+ return parsed ? r.result : 0;
}
/*!