summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstring.h
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2022-02-22 09:03:19 +0100
committerSona Kurazyan <sona.kurazyan@qt.io>2022-03-05 02:03:17 +0100
commitf39f539858417048f11a39c7b6198688e9657bea (patch)
treebe12ccdbafba280ff23658f9a24637690b6c7ba7 /src/corelib/text/qstring.h
parentbb30beb72642bf7c33f502f81e0dc7f4951ba8ec (diff)
Add numeric conversion methods to QLatin1String
[ChangeLog][QtCore][QLatin1String] Added numeric conversion methods. Task-number: QTBUG-98433 Change-Id: I414577ae715debe3d5ba9c6a160859aca790e017 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/text/qstring.h')
-rw-r--r--src/corelib/text/qstring.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index c8c25da3cc..55cf471d10 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -177,6 +177,37 @@ public:
[[nodiscard]] qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
{ return QtPrivate::lastIndexOf(*this, from, QStringView(&c, 1), cs); }
+ [[nodiscard]] short toShort(bool *ok = nullptr, int base = 10) const
+ { return QtPrivate::toIntegral<short>(QByteArrayView(*this), ok, base); }
+ [[nodiscard]] ushort toUShort(bool *ok = nullptr, int base = 10) const
+ { return QtPrivate::toIntegral<ushort>(QByteArrayView(*this), ok, base); }
+ [[nodiscard]] int toInt(bool *ok = nullptr, int base = 10) const
+ { return QtPrivate::toIntegral<int>(QByteArrayView(*this), ok, base); }
+ [[nodiscard]] uint toUInt(bool *ok = nullptr, int base = 10) const
+ { return QtPrivate::toIntegral<uint>(QByteArrayView(*this), ok, base); }
+ [[nodiscard]] long toLong(bool *ok = nullptr, int base = 10) const
+ { return QtPrivate::toIntegral<long>(QByteArrayView(*this), ok, base); }
+ [[nodiscard]] ulong toULong(bool *ok = nullptr, int base = 10) const
+ { return QtPrivate::toIntegral<ulong>(QByteArrayView(*this), ok, base); }
+ [[nodiscard]] qlonglong toLongLong(bool *ok = nullptr, int base = 10) const
+ { return QtPrivate::toIntegral<qlonglong>(QByteArrayView(*this), ok, base); }
+ [[nodiscard]] qulonglong toULongLong(bool *ok = nullptr, int base = 10) const
+ { return QtPrivate::toIntegral<qulonglong>(QByteArrayView(*this), ok, base); }
+ [[nodiscard]] float toFloat(bool *ok = nullptr) const
+ {
+ const auto r = QtPrivate::toFloat(*this);
+ if (ok)
+ *ok = bool(r);
+ return r.value_or(0.0f);
+ }
+ [[nodiscard]] double toDouble(bool *ok = nullptr) const
+ {
+ const auto r = QtPrivate::toDouble(*this);
+ if (ok)
+ *ok = bool(r);
+ return r.value_or(0.0);
+ }
+
using value_type = const char;
using reference = value_type&;
using const_reference = reference;