diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index a7f0f2451fc..2b85d9eac94 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -1555,6 +1555,8 @@ inline int QString::localeAwareCompare(QStringView s) const { return localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); } inline int QString::localeAwareCompare(QStringView s1, QStringView s2) { return localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); } +inline int QStringView::localeAwareCompare(QStringView other) const +{ return QString::localeAwareCompare(*this, other); } namespace QtPrivate { // used by qPrintable() and qUtf8Printable() macros diff --git a/src/corelib/text/qstringview.cpp b/src/corelib/text/qstringview.cpp index c65d3aa4bf9..6babe3450ec 100644 --- a/src/corelib/text/qstringview.cpp +++ b/src/corelib/text/qstringview.cpp @@ -806,6 +806,21 @@ QT_BEGIN_NAMESPACE \sa compare() */ +/*! + \fn int QStringView::localeAwareCompare(QStringView other) const + \since 6.4 + + Compares this string view with the \a other string view and returns + an integer less than, equal to, or greater than zero if this string + view is less than, equal to, or greater than the \a other string view. + + The comparison is performed in a locale- and also platform-dependent + manner. Use this function to present sorted lists of strings to the + user. + + \sa {Comparing Strings} +*/ + /*! \fn bool QStringView::startsWith(QStringView str, Qt::CaseSensitivity cs) const \fn bool QStringView::startsWith(QLatin1String l1, Qt::CaseSensitivity cs) const diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index ede684e3f51..6ca19e927f7 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -309,6 +309,8 @@ public: [[nodiscard]] int compare(QChar c, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::compareStrings(*this, QStringView(&c, 1), cs); } + [[nodiscard]] inline int localeAwareCompare(QStringView other) const; + [[nodiscard]] bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::startsWith(*this, s, cs); } [[nodiscard]] inline bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index 41657ef02bd..08b2e61115b 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -440,6 +440,10 @@ private Q_SLOTS: void member_localeAwareCompare_QString_QString() { member_localeAwareCompare_impl(); } void member_localeAwareCompare_QString_QStringView_data() { member_localeAwareCompare_data(); } void member_localeAwareCompare_QString_QStringView() { member_localeAwareCompare_impl(); } + void member_localeAwareCompare_QStringView_QString_data() { member_localeAwareCompare_data(); } + void member_localeAwareCompare_QStringView_QString() { member_localeAwareCompare_impl(); } + void member_localeAwareCompare_QStringView_QStringView_data() { member_localeAwareCompare_data(); } + void member_localeAwareCompare_QStringView_QStringView() { member_localeAwareCompare_impl(); } private: void startsWith_data(bool rhsIsQChar = false);