Add QString::compare(QStringView, CaseSensitivity)
There was a QStringView::compare(QString, CaseSensitivity) but it's good that the symmetric also exists Change-Id: Ic789f11d41eb8cfa393cb51c19bd1f89bb87d912 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
5cc5b43d0f
commit
64fe66e7be
@ -6225,7 +6225,17 @@ QString& QString::fill(QChar ch, int size)
|
||||
sensitivity setting \a cs.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn int QString::compare(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
|
||||
|
||||
\since 5.12
|
||||
\overload compare()
|
||||
|
||||
Performs a comparison of this with \a s, using the case
|
||||
sensitivity setting \a cs.
|
||||
*/
|
||||
|
||||
#if QT_STRINGVIEW_LEVEL < 2
|
||||
/*!
|
||||
\overload compare()
|
||||
\since 4.2
|
||||
@ -6241,6 +6251,7 @@ int QString::compare(const QString &other, Qt::CaseSensitivity cs) const Q_DECL_
|
||||
{
|
||||
return qt_compare_strings(*this, other, cs);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\internal
|
||||
@ -6267,6 +6278,7 @@ int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const Q_DECL_N
|
||||
return qt_compare_strings(*this, other, cs);
|
||||
}
|
||||
|
||||
#if QT_STRINGVIEW_LEVEL < 2
|
||||
/*!
|
||||
\fn int QString::compare(const QStringRef &ref, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
|
||||
\overload compare()
|
||||
@ -6275,6 +6287,7 @@ int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const Q_DECL_N
|
||||
an integer less than, equal to, or greater than zero if the string
|
||||
is less than, equal to, or greater than \a ref.
|
||||
*/
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
@ -608,8 +608,12 @@ public:
|
||||
QString &setUnicode(const QChar *unicode, int size);
|
||||
inline QString &setUtf16(const ushort *utf16, int size);
|
||||
|
||||
#if QT_STRINGVIEW_LEVEL < 2
|
||||
int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
|
||||
inline int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
|
||||
#endif
|
||||
int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
|
||||
inline int compare(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
|
||||
|
||||
static inline int compare(const QString &s1, const QString &s2,
|
||||
Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW
|
||||
@ -622,7 +626,6 @@ public:
|
||||
Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW
|
||||
{ return -s2.compare(s1, cs); }
|
||||
|
||||
inline int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
|
||||
static int compare(const QString &s1, const QStringRef &s2,
|
||||
Qt::CaseSensitivity = Qt::CaseSensitive) Q_DECL_NOTHROW;
|
||||
|
||||
@ -1638,8 +1641,12 @@ inline bool operator> (const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW
|
||||
inline bool operator<=(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs >= lhs; }
|
||||
inline bool operator>=(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs <= lhs; }
|
||||
|
||||
#if QT_STRINGVIEW_LEVEL < 2
|
||||
inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
|
||||
{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
|
||||
#endif
|
||||
inline int QString::compare(QStringView s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
|
||||
{ return -s.compare(*this, cs); }
|
||||
inline int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW
|
||||
{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
|
||||
inline int QStringRef::compare(const QString &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
|
||||
|
@ -6238,11 +6238,14 @@ void tst_QString::compare()
|
||||
QStringRef r1(&s1, 0, s1.length());
|
||||
QStringRef r2(&s2, 0, s2.length());
|
||||
|
||||
const QStringView v2(s2);
|
||||
|
||||
QCOMPARE(sign(QString::compare(s1, s2)), csr);
|
||||
QCOMPARE(sign(QStringRef::compare(r1, r2)), csr);
|
||||
QCOMPARE(sign(s1.compare(s2)), csr);
|
||||
QCOMPARE(sign(s1.compare(r2)), csr);
|
||||
QCOMPARE(sign(r1.compare(r2)), csr);
|
||||
QCOMPARE(sign(s1.compare(v2)), csr);
|
||||
|
||||
QCOMPARE(sign(s1.compare(s2, Qt::CaseSensitive)), csr);
|
||||
QCOMPARE(sign(s1.compare(s2, Qt::CaseInsensitive)), cir);
|
||||
@ -6250,6 +6253,8 @@ void tst_QString::compare()
|
||||
QCOMPARE(sign(s1.compare(r2, Qt::CaseInsensitive)), cir);
|
||||
QCOMPARE(sign(r1.compare(r2, Qt::CaseSensitive)), csr);
|
||||
QCOMPARE(sign(r1.compare(r2, Qt::CaseInsensitive)), cir);
|
||||
QCOMPARE(sign(s1.compare(v2, Qt::CaseSensitive)), csr);
|
||||
QCOMPARE(sign(s1.compare(v2, Qt::CaseInsensitive)), cir);
|
||||
|
||||
QCOMPARE(sign(QString::compare(s1, s2, Qt::CaseSensitive)), csr);
|
||||
QCOMPARE(sign(QString::compare(s1, s2, Qt::CaseInsensitive)), cir);
|
||||
|
Loading…
Reference in New Issue
Block a user