summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2022-02-28 16:10:32 +0100
committerSona Kurazyan <sona.kurazyan@qt.io>2022-03-17 14:27:45 +0100
commit893dd5d7bec96656a2dea67fbd0a7c9c68ac44d7 (patch)
treee74151696f4b139aa8f0adad60e168b9e84dc1ed /src/corelib/text
parentb86b22cfdeeb85c29c365a2976b59105fbc793c7 (diff)
Add QStringView::localeAwareCompare()
QString already has a localeAwareCompare(QStringView, QStringView) static method. Use it in QStringView::localeAwareCompare(QStringView). [ChangeLog][QtCore][QStringView] Added QStringView::localeAwareCompare(). Task-number: QTBUG-98431 Change-Id: Iec3865a5439d9fb653cc1150da21042186bdee98 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/text')
-rw-r--r--src/corelib/text/qstring.h2
-rw-r--r--src/corelib/text/qstringview.cpp15
-rw-r--r--src/corelib/text/qstringview.h2
3 files changed, 19 insertions, 0 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index a7f0f2451f..2b85d9eac9 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 c65d3aa4bf..6babe3450e 100644
--- a/src/corelib/text/qstringview.cpp
+++ b/src/corelib/text/qstringview.cpp
@@ -807,6 +807,21 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \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
\fn bool QStringView::startsWith(QChar ch) const
diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h
index ede684e3f5..6ca19e927f 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;