QStringView: Add compare() member function
There was no public API for doing case-insensitive comparisons of QStringView. Task-number: QTBUG-69389 Change-Id: I1b021eefec35e135b97fb87704c8dc137232d83d Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
5624e3c97d
commit
019dd88d2c
@ -680,6 +680,20 @@ QT_BEGIN_NAMESPACE
|
|||||||
'\\f', '\\r', and ' '.
|
'\\f', '\\r', and ' '.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn int QStringView::compare(QStringView other, 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.
|
||||||
|
|
||||||
|
If \a cs is Qt::CaseSensitive, the comparison is case sensitive;
|
||||||
|
otherwise the comparison is case insensitive.
|
||||||
|
|
||||||
|
\sa operator==(), operator<(), operator>()
|
||||||
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool QStringView::startsWith(QStringView str, Qt::CaseSensitivity cs) const
|
\fn bool QStringView::startsWith(QStringView str, Qt::CaseSensitivity cs) const
|
||||||
\fn bool QStringView::startsWith(QLatin1String l1, Qt::CaseSensitivity cs) const
|
\fn bool QStringView::startsWith(QLatin1String l1, Qt::CaseSensitivity cs) const
|
||||||
|
@ -250,6 +250,9 @@ public:
|
|||||||
|
|
||||||
Q_REQUIRED_RESULT QStringView trimmed() const Q_DECL_NOTHROW { return QtPrivate::trimmed(*this); }
|
Q_REQUIRED_RESULT QStringView trimmed() const Q_DECL_NOTHROW { return QtPrivate::trimmed(*this); }
|
||||||
|
|
||||||
|
Q_REQUIRED_RESULT int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW
|
||||||
|
{ return QtPrivate::compareStrings(*this, other, cs); }
|
||||||
|
|
||||||
Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW
|
Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW
|
||||||
{ return QtPrivate::startsWith(*this, s, cs); }
|
{ return QtPrivate::startsWith(*this, s, cs); }
|
||||||
Q_REQUIRED_RESULT inline bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
|
Q_REQUIRED_RESULT inline bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
|
||||||
|
@ -217,6 +217,8 @@ private Q_SLOTS:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void comparison();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename String>
|
template <typename String>
|
||||||
void conversion_tests(String arg) const;
|
void conversion_tests(String arg) const;
|
||||||
@ -615,5 +617,23 @@ void tst_QStringView::conversion_tests(String string) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QStringView::comparison()
|
||||||
|
{
|
||||||
|
const QStringView aa = QStringViewLiteral("aa");
|
||||||
|
const QStringView upperAa = QStringViewLiteral("AA");
|
||||||
|
const QStringView bb = QStringViewLiteral("bb");
|
||||||
|
|
||||||
|
QVERIFY(aa == aa);
|
||||||
|
QVERIFY(aa != bb);
|
||||||
|
QVERIFY(aa < bb);
|
||||||
|
QVERIFY(bb > aa);
|
||||||
|
|
||||||
|
QCOMPARE(aa.compare(aa), 0);
|
||||||
|
QVERIFY(aa.compare(upperAa) != 0);
|
||||||
|
QCOMPARE(aa.compare(upperAa, Qt::CaseInsensitive), 0);
|
||||||
|
QVERIFY(aa.compare(bb) < 0);
|
||||||
|
QVERIFY(bb.compare(aa) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_APPLESS_MAIN(tst_QStringView)
|
QTEST_APPLESS_MAIN(tst_QStringView)
|
||||||
#include "tst_qstringview.moc"
|
#include "tst_qstringview.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user