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>bb10
parent
728cc964f3
commit
b2f79cceb1
|
|
@ -9717,6 +9717,23 @@ QString &QString::setRawData(const QChar *unicode, int size)
|
|||
\sa front(), at(), operator[]()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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>()
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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); }
|
||||
|
|
|
|||
|
|
@ -275,23 +275,22 @@ private Q_SLOTS:
|
|||
void member_compare_QString_const_char_star_data() { member_compare_data(); }
|
||||
void member_compare_QString_const_char_star() { member_compare_impl<QString, const char *>(); }
|
||||
|
||||
#ifdef NOT_YET_IMPLEMENTED // QChar doesn't implicitly convert to QStringView
|
||||
void member_compare_QStringView_QChar_data() { member_compare_data(false); }
|
||||
void member_compare_QStringView_QChar() { member_compare_impl<QStringView, QChar>(); }
|
||||
#endif
|
||||
void member_compare_QStringView_QStringRef_data() { member_compare_data(); }
|
||||
void member_compare_QStringView_QStringRef() { member_compare_impl<QStringView, QStringRef>(); }
|
||||
void member_compare_QStringView_QString_data() { member_compare_data(); }
|
||||
void member_compare_QStringView_QString() { member_compare_impl<QStringView, QString>(); }
|
||||
void member_compare_QStringView_QStringView_data() { member_compare_data(); }
|
||||
void member_compare_QStringView_QStringView() { member_compare_impl<QStringView, QStringView>(); }
|
||||
#ifdef NOT_YET_IMPLEMENTED
|
||||
void member_compare_QStringView_QLatin1String_data() { member_compare_data(); }
|
||||
void member_compare_QStringView_QLatin1String() { member_compare_impl<QStringView, QLatin1String>(); }
|
||||
#ifdef NOT_YET_IMPLEMENTED
|
||||
void member_compare_QStringView_QByteArray_data() { member_compare_data(); }
|
||||
void member_compare_QStringView_QByteArray() { member_compare_impl<QStringView, QByteArray>(); }
|
||||
void member_compare_QStringView_const_char_star_data() { member_compare_data(); }
|
||||
void member_compare_QStringView_const_char_star() { member_compare_impl<QStringView, const char *>(); }
|
||||
#endif
|
||||
|
||||
void member_compare_QLatin1String_QChar_data() { member_compare_data(false); }
|
||||
void member_compare_QLatin1String_QChar() { member_compare_impl<QLatin1String, QChar>(); }
|
||||
|
|
@ -303,6 +302,7 @@ private Q_SLOTS:
|
|||
void member_compare_QLatin1String_QStringView() { member_compare_impl<QLatin1String, QStringView>(); }
|
||||
void member_compare_QLatin1String_QLatin1String_data() { member_compare_data(); }
|
||||
void member_compare_QLatin1String_QLatin1String() { member_compare_impl<QLatin1String, QLatin1String>(); }
|
||||
#ifdef NOT_YET_IMPLEMENTED
|
||||
void member_compare_QLatin1String_QByteArray_data() { member_compare_data(); }
|
||||
void member_compare_QLatin1String_QByteArray() { member_compare_impl<QLatin1String, QByteArray>(); }
|
||||
void member_compare_QLatin1String_const_char_star_data() { member_compare_data(); }
|
||||
|
|
@ -725,6 +725,8 @@ void tst_QStringApiSymmetry::compare_data(bool hasConceptOfNullAndEmpty)
|
|||
ROW("0", "");
|
||||
ROW("0", "1");
|
||||
ROW("0", "0");
|
||||
ROW("10", "0");
|
||||
ROW("01", "1");
|
||||
ROW("\xE4", "\xE4"); // ä <> ä
|
||||
ROW("\xE4", "\xC4"); // ä <> Ä
|
||||
#undef ROW
|
||||
|
|
|
|||
Loading…
Reference in New Issue