diff options
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/text/qbytearray.h | 8 | ||||
-rw-r--r-- | src/corelib/text/qstring.cpp | 23 | ||||
-rw-r--r-- | src/corelib/text/qstring.h | 4 |
3 files changed, 31 insertions, 4 deletions
diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index 36cf580cd9..e3bb9ea937 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -240,8 +240,8 @@ public: int count(const char *a) const; int count(const QByteArray &a) const; - inline int compare(const char *c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline int compare(const QByteArray &a, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + inline int compare(const char *c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + inline int compare(const QByteArray &a, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; Q_REQUIRED_RESULT QByteArray left(int len) const; Q_REQUIRED_RESULT QByteArray right(int len) const; @@ -663,12 +663,12 @@ inline bool QByteArray::contains(const QByteArray &a) const { return indexOf(a) != -1; } inline bool QByteArray::contains(char c) const { return indexOf(c) != -1; } -inline int QByteArray::compare(const char *c, Qt::CaseSensitivity cs) const +inline int QByteArray::compare(const char *c, Qt::CaseSensitivity cs) const noexcept { return cs == Qt::CaseSensitive ? qstrcmp(*this, c) : qstrnicmp(data(), size(), c, -1); } -inline int QByteArray::compare(const QByteArray &a, Qt::CaseSensitivity cs) const +inline int QByteArray::compare(const QByteArray &a, Qt::CaseSensitivity cs) const noexcept { return cs == Qt::CaseSensitive ? qstrcmp(*this, a) : qstrnicmp(data(), size(), a.data(), a.size()); diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 68dec7cfff..f64f148f49 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -6276,6 +6276,16 @@ QString& QString::fill(QChar ch, int size) sensitivity setting \a cs. */ +/*! + \fn int QString::compare(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + + \since 5.14 + \overload compare() + + Performs a comparison of this with \a ch, using the case + sensitivity setting \a cs. +*/ + #if QT_STRINGVIEW_LEVEL < 2 /*! \overload compare() @@ -11075,6 +11085,19 @@ QStringRef QStringRef::appendTo(QString *string) const /*! \overload + \fn int QStringRef::compare(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + \since 5.14 + + Compares this string with \a ch and returns an + integer less than, equal to, or greater than zero if this string + is less than, equal to, or greater than \a ch, interpreted as a string of length one. + + If \a cs is Qt::CaseSensitive, the comparison is case sensitive; + otherwise the comparison is case insensitive. +*/ + +/*! + \overload \fn int QStringRef::compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const \since 4.5 diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index bfc190e9e9..d615e6646c 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -732,6 +732,8 @@ public: #endif int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; inline int compare(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + int compare(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return compare(QStringView{&ch, 1}, cs); } static inline int compare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept @@ -1749,6 +1751,8 @@ public: int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + int compare(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::compareStrings(*this, QStringView(&c, 1), cs); } int compare(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) int compare(const QByteArray &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |