summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qbytearray.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-08-09 18:18:19 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-08-30 17:46:00 +0200
commit4e9efb0b6096c35edc0b98650cf64acb367d5ba8 (patch)
tree05d874684b243439a7906548108ec18f7ba195b2 /src/corelib/text/qbytearray.cpp
parent6db5fd5918e9c2fb73d61de13356307248c4f2e9 (diff)
Teach QByteArrayView how to parse numbers
Now that we don't need '\0'-termination on the data, this is possible. Moved QByteArray's tests to tst_QByteArrayApiSymmetry and added some more test-cases. [ChangeLog][QtCore][QByteArrayView] Added numeric parsing methods. Change-Id: Ic0df91ecfe5dbf6f008d344dd0464d7927f32273 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/text/qbytearray.cpp')
-rw-r--r--src/corelib/text/qbytearray.cpp52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index 320f744c4f..a1b0f30d01 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -3571,6 +3571,11 @@ qlonglong QByteArray::toLongLong(bool *ok, int base) const
return toIntegral_helper<qlonglong>(*this, ok, base);
}
+qlonglong QByteArrayView::toLongLong(bool *ok, int base) const
+{
+ return toIntegral_helper<qlonglong>(*this, ok, base);
+}
+
/*!
Returns the byte array converted to an \c {unsigned long long} using base \a
base, which is ten by default. Bases 0 and 2 through 36 are supported, using
@@ -3598,6 +3603,11 @@ qulonglong QByteArray::toULongLong(bool *ok, int base) const
return toIntegral_helper<qulonglong>(*this, ok, base);
}
+qulonglong QByteArrayView::toULongLong(bool *ok, int base) const
+{
+ return toIntegral_helper<qulonglong>(*this, ok, base);
+}
+
/*!
Returns the byte array converted to an \c int using base \a base, which is
ten by default. Bases 0 and 2 through 36 are supported, using letters for
@@ -3627,6 +3637,11 @@ int QByteArray::toInt(bool *ok, int base) const
return toIntegral_helper<int>(*this, ok, base);
}
+int QByteArrayView::toInt(bool *ok, int base) const
+{
+ return toIntegral_helper<int>(*this, ok, base);
+}
+
/*!
Returns the byte array converted to an \c {unsigned int} using base \a base,
which is ten by default. Bases 0 and 2 through 36 are supported, using
@@ -3654,6 +3669,11 @@ uint QByteArray::toUInt(bool *ok, int base) const
return toIntegral_helper<uint>(*this, ok, base);
}
+uint QByteArrayView::toUInt(bool *ok, int base) const
+{
+ return toIntegral_helper<uint>(*this, ok, base);
+}
+
/*!
\since 4.1
@@ -3684,6 +3704,11 @@ long QByteArray::toLong(bool *ok, int base) const
return toIntegral_helper<long>(*this, ok, base);
}
+long QByteArrayView::toLong(bool *ok, int base) const
+{
+ return toIntegral_helper<long>(*this, ok, base);
+}
+
/*!
\since 4.1
@@ -3712,6 +3737,11 @@ ulong QByteArray::toULong(bool *ok, int base) const
return toIntegral_helper<ulong>(*this, ok, base);
}
+ulong QByteArrayView::toULong(bool *ok, int base) const
+{
+ return toIntegral_helper<ulong>(*this, ok, base);
+}
+
/*!
Returns the byte array converted to a \c short using base \a base, which is
ten by default. Bases 0 and 2 through 36 are supported, using letters for
@@ -3739,6 +3769,11 @@ short QByteArray::toShort(bool *ok, int base) const
return toIntegral_helper<short>(*this, ok, base);
}
+short QByteArrayView::toShort(bool *ok, int base) const
+{
+ return toIntegral_helper<short>(*this, ok, base);
+}
+
/*!
Returns the byte array converted to an \c {unsigned short} using base \a
base, which is ten by default. Bases 0 and 2 through 36 are supported, using
@@ -3766,6 +3801,10 @@ ushort QByteArray::toUShort(bool *ok, int base) const
return toIntegral_helper<ushort>(*this, ok, base);
}
+ushort QByteArrayView::toUShort(bool *ok, int base) const
+{
+ return toIntegral_helper<ushort>(*this, ok, base);
+}
/*!
Returns the byte array converted to a \c double value.
@@ -3794,10 +3833,14 @@ ushort QByteArray::toUShort(bool *ok, int base) const
double QByteArray::toDouble(bool *ok) const
{
+ return QByteArrayView(*this).toDouble(ok);
+}
+
+double QByteArrayView::toDouble(bool *ok) const
+{
bool nonNullOk = false;
int processed = 0;
- double d = qt_asciiToDouble(constData(), size(),
- nonNullOk, processed, WhitespacesAllowed);
+ double d = qt_asciiToDouble(data(), size(), nonNullOk, processed, WhitespacesAllowed);
if (ok)
*ok = nonNullOk;
return d;
@@ -3833,6 +3876,11 @@ float QByteArray::toFloat(bool *ok) const
return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
}
+float QByteArrayView::toFloat(bool *ok) const
+{
+ return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
+}
+
/*!
\since 5.2