diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2020-06-09 12:02:57 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2021-07-30 22:54:28 +0200 |
commit | 615a9cf99150cfee34c14cfed0aa9583f5993934 (patch) | |
tree | 80f69ace058792b1faf39f27ef6f6de97fbe52a8 /src/corelib/plugin | |
parent | 09fba5cf3657c19c38e897a11a015d45b4328ae3 (diff) |
QUuid: port to QAnyStringView
Remove the QString/QStringView/QLatin1String/const char* overloads
from the API, but not the ABI.
As a drive-by, replace a use of QStringView::left() by truncate(), as
suggested by a comment.
[ChangeLog][QtCore][QUuid] The from-string constructor and the
fromString() function now take QAnyStringView (was: overload set with
a subset of QString, QByteArray, const char*, QLatin1String,
QStringView each).
Change-Id: If7fa26cfbef9280480c78b669d9f5f14118995ed
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/plugin')
-rw-r--r-- | src/corelib/plugin/quuid.cpp | 61 | ||||
-rw-r--r-- | src/corelib/plugin/quuid.h | 7 |
2 files changed, 26 insertions, 42 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index ea78fff5b3..33fac4b892 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -365,6 +365,8 @@ static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCrypto */ /*! + \fn QUuid::QUuid(QAnyStringView text) + Creates a QUuid object from the string \a text, which must be formatted as five hex fields separated by '-', e.g., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where each 'x' is a hex @@ -373,14 +375,15 @@ static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCrypto toString() for an explanation of how the five hex fields map to the public data members in QUuid. + \note In Qt versions prior to 6.3, this constructor was an overload + set consisting of QString, QByteArray and \c{const char*} + instead of one constructor taking QAnyStringView. + \sa toString(), QUuid() */ -QUuid::QUuid(const QString &text) - : QUuid(fromString(text)) -{ -} /*! + \fn static QUuid::fromString(QAnyStringView text) \since 5.10 Creates a QUuid object from the string \a text, which must be @@ -391,12 +394,16 @@ QUuid::QUuid(const QString &text) toString() for an explanation of how the five hex fields map to the public data members in QUuid. + \note In Qt versions prior to 6.3, this function was an overload + set consisting of QStringView and QLatin1String instead of + one function taking QAnyStringView. + \sa toString(), QUuid() */ -QUuid QUuid::fromString(QStringView text) noexcept +static QUuid uuidFromString(QStringView text) noexcept { if (text.size() > MaxStringUuidLength) - text = text.left(MaxStringUuidLength); // text.truncate(MaxStringUuidLength); + text.truncate(MaxStringUuidLength); char latin1[MaxStringUuidLength + 1]; char *dst = latin1; @@ -409,21 +416,7 @@ QUuid QUuid::fromString(QStringView text) noexcept return _q_uuidFromHex(latin1); } -/*! - \since 5.10 - \overload - - Creates a QUuid object from the string \a text, which must be - formatted as five hex fields separated by '-', e.g., - "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where each 'x' is a hex - digit. The curly braces shown here are optional, but it is normal to - include them. If the conversion fails, a null UUID is returned. See - toString() for an explanation of how the five hex fields map to the - public data members in QUuid. - - \sa toString(), QUuid() -*/ -QUuid QUuid::fromString(QLatin1String text) noexcept +static QUuid uuidFromString(QLatin1String text) noexcept { if (Q_UNLIKELY(text.size() < MaxStringUuidLength - 2 || (text.front() == QLatin1Char('{') && text.size() < MaxStringUuidLength - 1))) { @@ -434,30 +427,16 @@ QUuid QUuid::fromString(QLatin1String text) noexcept return _q_uuidFromHex(text.data()); } -/*! - \internal -*/ -QUuid::QUuid(const char *text) - : QUuid(_q_uuidFromHex(text)) +Q_ALWAYS_INLINE +// can treat UTF-8 the same as Latin-1: +static QUuid uuidFromString(QUtf8StringView text) noexcept { + return uuidFromString(QLatin1String(text.data(), text.size())); } -/*! - Creates a QUuid object from the QByteArray \a text, which must be - formatted as five hex fields separated by '-', e.g., - "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where each 'x' is a hex - digit. The curly braces shown here are optional, but it is normal to - include them. If the conversion fails, a null UUID is created. See - toByteArray() for an explanation of how the five hex fields map to the - public data members in QUuid. - - \since 4.8 - - \sa toByteArray(), QUuid() -*/ -QUuid::QUuid(const QByteArray &text) - : QUuid(fromString(QLatin1String(text.data(), text.size()))) +QUuid QUuid::fromString(QAnyStringView text) noexcept { + return text.visit([] (auto text) { return uuidFromString(text); }); } /*! diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index 9192542684..9229d5b694 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -97,12 +97,17 @@ public: uchar b4, uchar b5, uchar b6, uchar b7, uchar b8) noexcept : data1(l), data2(w1), data3(w2), data4{b1, b2, b3, b4, b5, b6, b7, b8} {} + explicit QUuid(QAnyStringView string) noexcept + : QUuid{fromString(string)} {} + static QUuid fromString(QAnyStringView string) noexcept; +#if QT_REMOVED_SINCE(6, 3) explicit QUuid(const QString &); static QUuid fromString(QStringView string) noexcept; static QUuid fromString(QLatin1String string) noexcept; explicit QUuid(const char *); - QString toString(StringFormat mode = WithBraces) const; explicit QUuid(const QByteArray &); +#endif + QString toString(StringFormat mode = WithBraces) const; QByteArray toByteArray(StringFormat mode = WithBraces) const; QByteArray toRfc4122() const; #if QT_REMOVED_SINCE(6, 3) |