diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2024-02-29 16:18:23 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2024-03-02 00:12:55 +0100 |
commit | 2bc9ad0e5dd75cf69f4a8bf94a6a917de2b4e8c4 (patch) | |
tree | 118c169f5e025f59525002b79c82d63852f7c957 /src/corelib/text | |
parent | 868a5342bb3af21bd9d078c420a43f4a57cb61a1 (diff) |
QAnyStringView: use new comparison helper macros
Also extend unit-test to use new test helper functions.
Remove the now-redundant test for three-way comparison, because it is
covered by the test helper functions.
Task-number: QTBUG-117661
Change-Id: I242b560c281245e04e34353c80000a20998fc677
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qanystringview.cpp | 18 | ||||
-rw-r--r-- | src/corelib/text/qanystringview.h | 26 |
2 files changed, 21 insertions, 23 deletions
diff --git a/src/corelib/text/qanystringview.cpp b/src/corelib/text/qanystringview.cpp index df117c3fc4..4129257c02 100644 --- a/src/corelib/text/qanystringview.cpp +++ b/src/corelib/text/qanystringview.cpp @@ -17,6 +17,12 @@ QT_BEGIN_NAMESPACE \ingroup tools \ingroup string-processing + \compares strong + \compareswith strong char16_t QChar {const char16_t *} {const char *} \ + QByteArray QByteArrayView QString QStringView QUtf8StringView \ + QLatin1StringView + \endcompareswith + A QAnyStringView references a contiguous portion of a string it does not own. It acts as an interface type to all kinds of strings, without the need to construct a QString first. @@ -582,12 +588,12 @@ QT_BEGIN_NAMESPACE */ /*! - \fn bool QAnyStringView::operator==(QAnyStringView lhs, QAnyStringView rhs) - \fn bool QAnyStringView::operator!=(QAnyStringView lhs, QAnyStringView rhs) - \fn bool QAnyStringView::operator<=(QAnyStringView lhs, QAnyStringView rhs) - \fn bool QAnyStringView::operator>=(QAnyStringView lhs, QAnyStringView rhs) - \fn bool QAnyStringView::operator<(QAnyStringView lhs, QAnyStringView rhs) - \fn bool QAnyStringView::operator>(QAnyStringView lhs, QAnyStringView rhs) + \fn bool QAnyStringView::operator==(const QAnyStringView &lhs, const QAnyStringView & rhs) + \fn bool QAnyStringView::operator!=(const QAnyStringView & lhs, const QAnyStringView & rhs) + \fn bool QAnyStringView::operator<=(const QAnyStringView & lhs, const QAnyStringView & rhs) + \fn bool QAnyStringView::operator>=(const QAnyStringView & lhs, const QAnyStringView & rhs) + \fn bool QAnyStringView::operator<(const QAnyStringView & lhs, const QAnyStringView & rhs) + \fn bool QAnyStringView::operator>(const QAnyStringView & lhs, const QAnyStringView & rhs) Operators that compare \a lhs to \a rhs. diff --git a/src/corelib/text/qanystringview.h b/src/corelib/text/qanystringview.h index d74d371e2d..b7f3650275 100644 --- a/src/corelib/text/qanystringview.h +++ b/src/corelib/text/qanystringview.h @@ -4,6 +4,7 @@ #ifndef QANYSTRINGVIEW_H #define QANYSTRINGVIEW_H +#include <QtCore/qcompare.h> #include <QtCore/qlatin1stringview.h> #include <QtCore/qstringview.h> #include <QtCore/qutf8stringview.h> @@ -301,24 +302,15 @@ public: { return size(); } private: - [[nodiscard]] friend inline bool operator==(QAnyStringView lhs, QAnyStringView rhs) noexcept + friend bool comparesEqual(const QAnyStringView &lhs, const QAnyStringView &rhs) noexcept { return QAnyStringView::equal(lhs, rhs); } - [[nodiscard]] friend inline bool operator!=(QAnyStringView lhs, QAnyStringView rhs) noexcept - { return !QAnyStringView::equal(lhs, rhs); } - -#if defined(__cpp_impl_three_way_comparison) && !defined(Q_QDOC) - [[nodiscard]] friend inline auto operator<=>(QAnyStringView lhs, QAnyStringView rhs) noexcept - { return QAnyStringView::compare(lhs, rhs) <=> 0; } -#else - [[nodiscard]] friend inline bool operator<=(QAnyStringView lhs, QAnyStringView rhs) noexcept - { return QAnyStringView::compare(lhs, rhs) <= 0; } - [[nodiscard]] friend inline bool operator>=(QAnyStringView lhs, QAnyStringView rhs) noexcept - { return QAnyStringView::compare(lhs, rhs) >= 0; } - [[nodiscard]] friend inline bool operator<(QAnyStringView lhs, QAnyStringView rhs) noexcept - { return QAnyStringView::compare(lhs, rhs) < 0; } - [[nodiscard]] friend inline bool operator>(QAnyStringView lhs, QAnyStringView rhs) noexcept - { return QAnyStringView::compare(lhs, rhs) > 0; } -#endif + friend Qt::strong_ordering + compareThreeWay(const QAnyStringView &lhs, const QAnyStringView &rhs) noexcept + { + const int res = QAnyStringView::compare(lhs, rhs); + return Qt::compareThreeWay(res, 0); + } + Q_DECLARE_STRONGLY_ORDERED(QAnyStringView) #ifndef QT_NO_DEBUG_STREAM Q_CORE_EXPORT friend QDebug operator<<(QDebug d, QAnyStringView s); |