From 4c931155043af6bbd9c36475fa8d3cb14e65f644 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Mon, 12 Feb 2024 16:41:42 +0100 Subject: [PATCH] Add QUtf8StringView vs QLatin1StringView relational operators ... by using the new comparison helper macros. This allows to remove dummy comparison operators from tst_qstringapisymmetry. This is also a pre-requisite for a follow-up commit that introduces relational operators between QLatin1StringView and QByteArrayView. Task-number: QTBUG-117661 Task-number: QTBUG-108805 Change-Id: I5837b457a777fddff1071bc252982e68d004fa94 Reviewed-by: Thiago Macieira --- src/corelib/text/qstring.h | 6 ++++++ src/corelib/text/qutf8stringview.h | 16 ++++++++++++++++ .../tst_qstringapisymmetry.cpp | 1 - 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 8216cd51746..158cfcc3572 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -1141,6 +1141,12 @@ template return QtPrivate::compareStrings(*this, other, cs); } +template +[[nodiscard]] bool QBasicUtf8StringView::equal(QLatin1StringView other) const noexcept +{ + return QtPrivate::equalStrings(*this, other); +} + // // QAnyStringView inline members that require QString: // diff --git a/src/corelib/text/qutf8stringview.h b/src/corelib/text/qutf8stringview.h index bd83da8946b..377fee84696 100644 --- a/src/corelib/text/qutf8stringview.h +++ b/src/corelib/text/qutf8stringview.h @@ -11,6 +11,7 @@ #include #include // for QContainerImplHelper #include +#include #include #include @@ -297,6 +298,8 @@ public: [[nodiscard]] int compare(QLatin1StringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + [[nodiscard]] bool equal(QLatin1StringView other) const noexcept; + private: [[nodiscard]] static inline int compare(QBasicUtf8StringView lhs, QBasicUtf8StringView rhs) noexcept { @@ -327,6 +330,19 @@ private: { return QBasicUtf8StringView::compare(lhs, rhs) > 0; } #endif + friend bool + comparesEqual(const QBasicUtf8StringView &lhs, const QLatin1StringView &rhs) noexcept + { + return lhs.equal(rhs); + } + friend Qt::strong_ordering + compareThreeWay(const QBasicUtf8StringView &lhs, const QLatin1StringView &rhs) noexcept + { + const int res = lhs.compare(rhs); + return Qt::compareThreeWay(res, 0); + } + Q_DECLARE_STRONGLY_ORDERED(QBasicUtf8StringView, QLatin1StringView) + Q_ALWAYS_INLINE constexpr void verify([[maybe_unused]] qsizetype pos = 0, [[maybe_unused]] qsizetype n = 1) const { diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index 641c2effee6..ef862c9e6f4 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -78,7 +78,6 @@ MAKE_ALL(const char*, QUtf8StringView) MAKE_ALL(QUtf8StringView, QChar) MAKE_ALL(QUtf8StringView, char16_t) MAKE_ALL(QUtf8StringView, QStringView) -MAKE_ALL(QUtf8StringView, QLatin1String) #undef MAKE_ALL #undef MAKE_RELOP