diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-07-29 09:44:04 +0300 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2020-03-05 07:50:02 +0000 |
commit | b2f79cceb11dfd15ac9eea631bc18ad6b036eb91 (patch) | |
tree | e62b5eb13af680134fb1cc40ff28e28cb4d511a9 /src/corelib | |
parent | 728cc964f3f25d23c72317a119b839701f5941e8 (diff) |
QLatin1String/QStringView: add (missing) member compare()
[ChangeLog][QtCore][QLatin1String] Added compare().
[ChangeLog][QtCore][QStringView] Added compare() overloads
taking QLatin1String, QChar.
Change-Id: Ie2aa400299cb63495e65ce29b2a32133066de826
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/text/qstring.cpp | 17 | ||||
-rw-r--r-- | src/corelib/text/qstring.h | 11 | ||||
-rw-r--r-- | src/corelib/text/qstringview.cpp | 26 | ||||
-rw-r--r-- | src/corelib/text/qstringview.h | 5 |
4 files changed, 53 insertions, 6 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index f64f148f49..210a8afc53 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -9718,6 +9718,23 @@ QString &QString::setRawData(const QChar *unicode, int size) */ /*! + \fn int QLatin1String::compare(QStringView str, Qt::CaseSensitivity cs) const + \fn int QLatin1String::compare(QLatin1String l1, Qt::CaseSensitivity cs) const + \fn int QLatin1String::compare(QChar ch) const + \fn int QLatin1String::compare(QChar ch, Qt::CaseSensitivity cs) const + \since 5.14 + + Returns an integer that compares to zero as this Latin-1 string compares to the + string-view \a str, Latin-1 string \a l1, or character \a ch, respectively. + + If \a cs is Qt::CaseSensitive (the default), the comparison is case sensitive; + otherwise the comparison is case-insensitive. + + \sa operator==(), operator<(), operator>() +*/ + + +/*! \fn bool QLatin1String::startsWith(QStringView str, Qt::CaseSensitivity cs) const \since 5.10 \fn bool QLatin1String::startsWith(QLatin1String l1, Qt::CaseSensitivity cs) const diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index d615e6646c..99b41c8ebf 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -111,6 +111,15 @@ public: Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QLatin1Char front() const { return at(0); } Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QLatin1Char back() const { return at(size() - 1); } + Q_REQUIRED_RESULT int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::compareStrings(*this, other, cs); } + Q_REQUIRED_RESULT int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::compareStrings(*this, other, cs); } + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR int compare(QChar c) const noexcept + { return isEmpty() || front() == c ? size() - 1 : uchar(m_data[0]) - c.unicode() ; } + Q_REQUIRED_RESULT int compare(QChar c, Qt::CaseSensitivity cs) const noexcept + { return QtPrivate::compareStrings(*this, QStringView(&c, 1), cs); } + Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::startsWith(*this, s, cs); } Q_REQUIRED_RESULT bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept @@ -233,6 +242,8 @@ Q_DECL_CONSTEXPR bool QtPrivate::isLatin1(QLatin1String) noexcept // // QStringView members that require QLatin1String: // +int QStringView::compare(QLatin1String s, Qt::CaseSensitivity cs) const noexcept +{ return QtPrivate::compareStrings(*this, s, cs); } bool QStringView::startsWith(QLatin1String s, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::startsWith(*this, s, cs); } bool QStringView::endsWith(QLatin1String s, Qt::CaseSensitivity cs) const noexcept diff --git a/src/corelib/text/qstringview.cpp b/src/corelib/text/qstringview.cpp index 08dade7e68..9df656dc59 100644 --- a/src/corelib/text/qstringview.cpp +++ b/src/corelib/text/qstringview.cpp @@ -692,15 +692,29 @@ QT_BEGIN_NAMESPACE */ /*! - \fn int QStringView::compare(QStringView other, Qt::CaseSensitivity cs) const + \fn int QStringView::compare(QStringView str, Qt::CaseSensitivity cs) const \since 5.12 - 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 other string-view. + Returns an integer that compares to zero as this string-view compares to the + string-view \a str. - If \a cs is Qt::CaseSensitive, the comparison is case sensitive; - otherwise the comparison is case insensitive. + If \a cs is Qt::CaseSensitive (the default), the comparison is case sensitive; + otherwise the comparison is case-insensitive. + + \sa operator==(), operator<(), operator>() +*/ + +/*! + \fn int QStringView::compare(QLatin1String l1, Qt::CaseSensitivity cs) const + \fn int QStringView::compare(QChar ch) const + \fn int QStringView::compare(QChar ch, Qt::CaseSensitivity cs) const + \since 5.14 + + Returns an integer that compares to zero as this string-view compares to the + Latin-1 string \a l1, or character \a ch, respectively. + + If \a cs is Qt::CaseSensitive (the default), the comparison is case sensitive; + otherwise the comparison is case-insensitive. \sa operator==(), operator<(), operator>() */ diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index 06391ffef4..83418970a5 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -257,6 +257,11 @@ public: Q_REQUIRED_RESULT int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::compareStrings(*this, other, cs); } + Q_REQUIRED_RESULT inline int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR int compare(QChar c) const noexcept + { return empty() || front() == c ? size() - 1 : *utf16() - c.unicode() ; } + Q_REQUIRED_RESULT int compare(QChar c, Qt::CaseSensitivity cs) const noexcept + { return QtPrivate::compareStrings(*this, QStringView(&c, 1), cs); } Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::startsWith(*this, s, cs); } |