summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qbytearrayview.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-02-22 16:06:08 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-03-04 19:49:15 +0100
commit1775029c9b34dde6c5d5ca2d15b25556ad7bc7c8 (patch)
treec0881c4e142a23d6d0ac916ed58412331bf72bbd /src/corelib/text/qbytearrayview.h
parent1931689c7df579375b904a71c6f9e0844492cbe2 (diff)
Prepare for QByteArrayView number parsing modernization
Remove the unholy bool out parameter and make QtPrivate::to{Double, Float,{Signed,Unsigned}Integer}() return a struct instead. The struct contains what we'll most likely need for a full QParsedNumber in the future: the value, an error code (always zero atm), and a pointer to the first character that wasn't parsed (always nullptr atm), so we don't need to change the ABI when QParsedNumber eventually lands. As an immediate positive contribution, even without the backend ported away from bool out parameters, the functions can now be marked as PURE and, in case of the FP versions, also noexcept (the int versions have a narrow contract d/t the base argument, which, unlike the return value, can be fixed later, by overloading). Pick-to: 6.3 Change-Id: I67945af80a9b53d6f170502a6df3384895e82d3e Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qbytearrayview.h')
-rw-r--r--src/corelib/text/qbytearrayview.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h
index 03acaa50d8..57d4711fdb 100644
--- a/src/corelib/text/qbytearrayview.h
+++ b/src/corelib/text/qbytearrayview.h
@@ -261,9 +261,19 @@ public:
[[nodiscard]] qulonglong toULongLong(bool *ok = nullptr, int base = 10) const
{ return QtPrivate::toIntegral<qulonglong>(*this, ok, base); }
[[nodiscard]] float toFloat(bool *ok = nullptr) const
- { return QtPrivate::toFloat(*this, ok); }
+ {
+ const auto r = QtPrivate::toFloat(*this);
+ if (ok)
+ *ok = bool(r);
+ return r.value_or(0.0f);
+ }
[[nodiscard]] double toDouble(bool *ok = nullptr) const
- { return QtPrivate::toDouble(*this, ok); }
+ {
+ const auto r = QtPrivate::toDouble(*this);
+ if (ok)
+ *ok = bool(r);
+ return r.value_or(0.0);
+ }
[[nodiscard]] bool startsWith(QByteArrayView other) const noexcept
{ return QtPrivate::startsWith(*this, other); }