diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h index 367fdb58b2..9d35e21415 100644 --- a/src/corelib/text/qbytearrayview.h +++ b/src/corelib/text/qbytearrayview.h @@ -270,6 +270,8 @@ public: [[nodiscard]] qsizetype count(char ch) const noexcept { return QtPrivate::count(*this, QByteArrayView(&ch, 1)); } + inline int compare(QByteArrayView a, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + // // STL compatibility API: // @@ -320,6 +322,12 @@ template @@ -635,5 +636,19 @@ void tst_QByteArrayView::comparison() const QVERIFY(bb > aa); } +void tst_QByteArrayView::compare() const +{ + QByteArrayView alpha = "original"; + + QVERIFY(alpha.compare("original", Qt::CaseSensitive) == 0); + QVERIFY(alpha.compare("Original", Qt::CaseSensitive) > 0); + QVERIFY(alpha.compare("Original", Qt::CaseInsensitive) == 0); + QByteArrayView beta = "unoriginal"; + QVERIFY(alpha.compare(beta, Qt::CaseInsensitive) < 0); + beta = "Unoriginal"; + QVERIFY(alpha.compare(beta, Qt::CaseInsensitive) < 0); + QVERIFY(alpha.compare(beta, Qt::CaseSensitive) > 0); +} + QTEST_APPLESS_MAIN(tst_QByteArrayView) #include "tst_qbytearrayview.moc"