diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-01-15 23:48:52 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-01-18 01:31:33 +0100 |
commit | 9ffcab65629539c0335c78d9896153d9c31f475e (patch) | |
tree | 5276bfbe28dc2dcb5db1eba15051adf370ebfc32 /src/corelib/tools/qversionnumber.h | |
parent | 1a440e557b0efa9758f7d41112f09016ad385bab (diff) |
QVersionNumber: port fromString() to QAnyStringView
We can handle the UTF-8 case by reinterpreting it as Latin-1.
This way, the suffixIndex stays valid as a return value.
As a drive-by, optimize away toLatin1() calls by using a QVLA.
We really need a better way of converting UTF-16 -> L1 than
qt_to_latin1()...
[ChangeLog][QtCore][QVersionNumber] fromString() now takes
QAnyStringView (was: QString, QStringView, QLatin1String)
and a qsizetype pointer (was: int pointer).
Change-Id: I86abaadba2792658fbf93ccd1e0b86e3302c697c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qversionnumber.h')
-rw-r--r-- | src/corelib/tools/qversionnumber.h | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index 175abe4e61..ad8367c135 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -275,13 +275,28 @@ public: [[nodiscard]] Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2); [[nodiscard]] Q_CORE_EXPORT QString toString() const; -#if QT_STRINGVIEW_LEVEL < 2 - [[nodiscard]] Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(const QString &string, qsizetype *suffixIndex = nullptr); + [[nodiscard]] Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(QAnyStringView string, qsizetype *suffixIndex = nullptr); + +#if QT_DEPRECATED_SINCE(6, 4) && QT_POINTER_SIZE != 4 + Q_WEAK_OVERLOAD + QT_DEPRECATED_VERSION_X_6_4("Use the 'qsizetype *suffixIndex' overload.") + [[nodiscard]] static QVersionNumber fromString(QAnyStringView string, int *suffixIndex) + { + QT_WARNING_PUSH + // fromString() writes to *n unconditionally, but GCC can't know that + QT_WARNING_DISABLE_GCC("-Wmaybe-uninitialized") + qsizetype n; + auto r = fromString(string, &n); + if (suffixIndex) { + Q_ASSERT(int(n) == n); + *suffixIndex = int(n); + } + return r; + QT_WARNING_POP + } #endif - [[nodiscard]] Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(QLatin1String string, qsizetype *suffixIndex = nullptr); - [[nodiscard]] Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(QStringView string, qsizetype *suffixIndex = nullptr); -#if QT_REMOVED_SINCE(6, 4) && QT_POINTER_SIZE != 4 +#if QT_REMOVED_SINCE(6, 4) [[nodiscard]] Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(const QString &string, int *suffixIndex); [[nodiscard]] Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(QLatin1String string, int *suffixIndex); [[nodiscard]] Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(QStringView string, int *suffixIndex); @@ -305,7 +320,6 @@ public: [[nodiscard]] friend bool operator!=(const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept { return compare(lhs, rhs) != 0; } - private: #ifndef QT_NO_DATASTREAM friend Q_CORE_EXPORT QDataStream& operator>>(QDataStream &in, QVersionNumber &version); |