QString: use comparison helper macros - comparison with byte arrays [2/3]

Use the comparison helper macros to replace the member relational
operators for comparison with QByteArray and const char *.

As QString and QByteArray are exported, we cannot simply remove the
inline methods, so wrap them into QT_CORE_REMOVED_SINCE.

Add relational operators with QByteArrayView.

Provide more unit-tests for the comparison with the byte array types.

This enables operator<=> for QString vs byte arrays in C++20 builds.

Task-number: QTBUG-117661
Change-Id: I305343e1b6c5d78b10f2976573db4e904ba6b44b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Ivan Solovev 2024-02-19 18:29:48 +01:00
parent 755581e2e7
commit 42b6fdfb52
7 changed files with 206 additions and 166 deletions

View File

@ -928,6 +928,8 @@ QUrl QUrl::fromEncoded(const QByteArray &input, ParsingMode mode)
#if QT_CORE_REMOVED_SINCE(6, 8)
#include "qbytearray.h" // inlined API
#include "qdatastream.h" // inlined API
QDataStream &QDataStream::operator<<(bool i)
@ -978,6 +980,7 @@ int QObject::startTimer(std::chrono::milliseconds time, Qt::TimerType timerType)
return startTimer(nanoseconds{time}, timerType);
}
#include "qstring.h" // inlined API
// #include "qotherheader.h"
// // implement removed functions from qotherheader.h

View File

@ -3382,90 +3382,6 @@ QDataStream &operator>>(QDataStream &in, QByteArray &ba)
}
#endif // QT_NO_DATASTREAM
/*! \fn bool QByteArray::operator==(const QString &str) const
Returns \c true if this byte array is equal to the UTF-8 encoding of \a str;
otherwise returns \c false.
The comparison is case sensitive.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications. You
then need to call QString::fromUtf8(), QString::fromLatin1(),
or QString::fromLocal8Bit() explicitly if you want to convert the byte
array to a QString before doing the comparison.
*/
/*! \fn bool QByteArray::operator!=(const QString &str) const
Returns \c true if this byte array is not equal to the UTF-8 encoding of \a
str; otherwise returns \c false.
The comparison is case sensitive.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications. You
then need to call QString::fromUtf8(), QString::fromLatin1(),
or QString::fromLocal8Bit() explicitly if you want to convert the byte
array to a QString before doing the comparison.
*/
/*! \fn bool QByteArray::operator<(const QString &str) const
Returns \c true if this byte array is lexically less than the UTF-8 encoding
of \a str; otherwise returns \c false.
The comparison is case sensitive.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications. You
then need to call QString::fromUtf8(), QString::fromLatin1(),
or QString::fromLocal8Bit() explicitly if you want to convert the byte
array to a QString before doing the comparison.
*/
/*! \fn bool QByteArray::operator>(const QString &str) const
Returns \c true if this byte array is lexically greater than the UTF-8
encoding of \a str; otherwise returns \c false.
The comparison is case sensitive.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications. You
then need to call QString::fromUtf8(), QString::fromLatin1(),
or QString::fromLocal8Bit() explicitly if you want to convert the byte
array to a QString before doing the comparison.
*/
/*! \fn bool QByteArray::operator<=(const QString &str) const
Returns \c true if this byte array is lexically less than or equal to the
UTF-8 encoding of \a str; otherwise returns \c false.
The comparison is case sensitive.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications. You
then need to call QString::fromUtf8(), QString::fromLatin1(),
or QString::fromLocal8Bit() explicitly if you want to convert the byte
array to a QString before doing the comparison.
*/
/*! \fn bool QByteArray::operator>=(const QString &str) const
Returns \c true if this byte array is greater than or equal to the UTF-8
encoding of \a str; otherwise returns \c false.
The comparison is case sensitive.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications. You
then need to call QString::fromUtf8(), QString::fromLatin1(),
or QString::fromLocal8Bit() explicitly if you want to convert the byte
array to a QString before doing the comparison.
*/
/*! \fn bool QByteArray::operator==(const QByteArray &a1, const QByteArray &a2)
\overload

View File

@ -359,13 +359,15 @@ public:
[[nodiscard]] QByteArray repeated(qsizetype times) const;
#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
#if QT_CORE_REMOVED_SINCE(6, 8)
QT_ASCII_CAST_WARN inline bool operator==(const QString &s2) const;
QT_ASCII_CAST_WARN inline bool operator!=(const QString &s2) const;
QT_ASCII_CAST_WARN inline bool operator<(const QString &s2) const;
QT_ASCII_CAST_WARN inline bool operator>(const QString &s2) const;
QT_ASCII_CAST_WARN inline bool operator<=(const QString &s2) const;
QT_ASCII_CAST_WARN inline bool operator>=(const QString &s2) const;
#endif
#endif // QT_CORE_REMOVED_SINCE(6, 8)
#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
friend inline bool operator==(const QByteArray &a1, const QByteArray &a2) noexcept
{ return QByteArrayView(a1) == QByteArrayView(a2); }
friend inline bool operator==(const QByteArray &a1, const char *a2) noexcept

View File

@ -1705,6 +1705,9 @@ void qtWarnAboutInvalidRegularExpression(const QString &pattern, const char *whe
\compares strong
\compareswith strong QChar QLatin1StringView {const char16_t *}
\endcompareswith
\compareswith strong QByteArray QByteArrayView {const char *}
When comparing with byte arrays, their content is interpreted as utf-8.
\endcompareswith
QString stores a string of 16-bit \l{QChar}s, where each QChar
corresponds to one UTF-16 code unit. (Unicode characters
@ -4085,28 +4088,26 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
returns \c false.
*/
/*! \fn bool QString::operator==(const QByteArray &other) const
/*! \fn bool QString::operator==(const QString &lhs, const QByteArray &rhs)
\overload operator==()
The \a other byte array is converted to a QString using the
fromUtf8() function.
The \a rhs byte array is converted to a QUtf8StringView.
You can disable this operator by defining
\l QT_NO_CAST_FROM_ASCII when you compile your applications. This
can be useful if you want to ensure that all user-visible strings
go through QObject::tr(), for example.
Returns \c true if this string is lexically equal to the parameter
string \a other. Otherwise returns \c false.
Returns \c true if string \a lhs is lexically equal to \a rhs.
Otherwise returns \c false.
*/
/*! \fn bool QString::operator==(const char *other) const
/*! \fn bool QString::operator==(const QString &lhs, const char * const &rhs)
\overload operator==()
The \a other const char pointer is converted to a QString using
the fromUtf8() function.
The \a rhs const char pointer is converted to a QUtf8StringView.
You can disable this operator by defining
\l QT_NO_CAST_FROM_ASCII when you compile your applications. This
@ -4143,13 +4144,13 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
otherwise returns \c false.
*/
/*! \fn bool QString::operator<(const QByteArray &other) const
/*! \fn bool QString::operator<(const QString &lhs, const QByteArray &rhs)
\overload operator<()
The \a other byte array is converted to a QString using the
fromUtf8() function. If any NUL characters ('\\0') are embedded
in the byte array, they will be included in the transformation.
The \a rhs byte array is converted to a QUtf8StringView.
If any NUL characters ('\\0') are embedded in the byte array, they will be
included in the transformation.
You can disable this operator
\l QT_NO_CAST_FROM_ASCII when you compile your applications. This
@ -4157,15 +4158,14 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
go through QObject::tr(), for example.
*/
/*! \fn bool QString::operator<(const char *other) const
/*! \fn bool QString::operator<(const QString &lhs, const char * const &rhs)
Returns \c true if this string is lexically less than string \a other.
Returns \c true if string \a lhs is lexically less than string \a rhs.
Otherwise returns \c false.
\overload operator<()
The \a other const char pointer is converted to a QString using
the fromUtf8() function.
The \a rhs const char pointer is converted to a QUtf8StringView.
You can disable this operator by defining
\l QT_NO_CAST_FROM_ASCII when you compile your applications. This
@ -4199,13 +4199,13 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
otherwise returns \c false.
*/
/*! \fn bool QString::operator<=(const QByteArray &other) const
/*! \fn bool QString::operator<=(const QString &lhs, const QByteArray &rhs)
\overload operator<=()
The \a other byte array is converted to a QString using the
fromUtf8() function. If any NUL characters ('\\0') are embedded
in the byte array, they will be included in the transformation.
The \a rhs byte array is converted to a QUtf8StringView.
If any NUL characters ('\\0') are embedded in the byte array, they will be
included in the transformation.
You can disable this operator by defining
\l QT_NO_CAST_FROM_ASCII when you compile your applications. This
@ -4213,12 +4213,11 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
go through QObject::tr(), for example.
*/
/*! \fn bool QString::operator<=(const char *other) const
/*! \fn bool QString::operator<=(const QString &lhs, const char * const &rhs)
\overload operator<=()
The \a other const char pointer is converted to a QString using
the fromUtf8() function.
The \a rhs const char pointer is converted to a QUtf8StringView.
You can disable this operator by defining
\l QT_NO_CAST_FROM_ASCII when you compile your applications. This
@ -4252,13 +4251,13 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
otherwise returns \c false.
*/
/*! \fn bool QString::operator>(const QByteArray &other) const
/*! \fn bool QString::operator>(const QString &lhs, const QByteArray &rhs)
\overload operator>()
The \a other byte array is converted to a QString using the
fromUtf8() function. If any NUL characters ('\\0') are embedded
in the byte array, they will be included in the transformation.
The \a rhs byte array is converted to a QUtf8StringView.
If any NUL characters ('\\0') are embedded in the byte array, they will be
included in the transformation.
You can disable this operator by defining
\l QT_NO_CAST_FROM_ASCII when you compile your applications. This
@ -4266,12 +4265,11 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
go through QObject::tr(), for example.
*/
/*! \fn bool QString::operator>(const char *other) const
/*! \fn bool QString::operator>(const QString &lhs, const char * const &rhs)
\overload operator>()
The \a other const char pointer is converted to a QString using
the fromUtf8() function.
The \a rhs const char pointer is converted to a QUtf8StringView.
You can disable this operator by defining \l QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want
@ -4305,13 +4303,13 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
otherwise returns \c false.
*/
/*! \fn bool QString::operator>=(const QByteArray &other) const
/*! \fn bool QString::operator>=(const QString &lhs, const QByteArray &rhs)
\overload operator>=()
The \a other byte array is converted to a QString using the
fromUtf8() function. If any NUL characters ('\\0') are embedded in
the byte array, they will be included in the transformation.
The \a rhs byte array is converted to a QUtf8StringView.
If any NUL characters ('\\0') are embedded in the byte array, they will be
included in the transformation.
You can disable this operator by defining \l QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want
@ -4319,12 +4317,11 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
for example.
*/
/*! \fn bool QString::operator>=(const char *other) const
/*! \fn bool QString::operator>=(const QString &lhs, const char * const &rhs)
\overload operator>=()
The \a other const char pointer is converted to a QString using
the fromUtf8() function.
The \a rhs const char pointer is converted to a QUtf8StringView.
You can disable this operator by defining \l QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want
@ -4348,13 +4345,13 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
\overload operator!=()
*/
/*! \fn bool QString::operator!=(const QByteArray &other) const
/*! \fn bool QString::operator!=(const QString &lhs, const QByteArray &rhs)
\overload operator!=()
The \a other byte array is converted to a QString using the
fromUtf8() function. If any NUL characters ('\\0') are embedded
in the byte array, they will be included in the transformation.
The \a rhs byte array is converted to a QUtf8StringView.
If any NUL characters ('\\0') are embedded in the byte array, they will be
included in the transformation.
You can disable this operator by defining \l QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want
@ -4362,12 +4359,11 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
for example.
*/
/*! \fn bool QString::operator!=(const char *other) const
/*! \fn bool QString::operator!=(const QString &lhs, const char * const &rhs)
\overload operator!=()
The \a other const char pointer is converted to a QString using
the fromUtf8() function.
The \a rhs const char pointer is converted to a QUtf8StringView.
You can disable this operator by defining
\l QT_NO_CAST_FROM_ASCII when you compile your applications. This
@ -4375,6 +4371,90 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
go through QObject::tr(), for example.
*/
/*! \fn bool QString::operator==(const QByteArray &lhs, const QString &rhs)
Returns \c true if byte array \a lhs is equal to the UTF-8 encoding of
\a rhs; otherwise returns \c false.
The comparison is case sensitive.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications. You
then need to call QString::fromUtf8(), QString::fromLatin1(),
or QString::fromLocal8Bit() explicitly if you want to convert the byte
array to a QString before doing the comparison.
*/
/*! \fn bool QString::operator!=(const QByteArray &lhs, const QString &rhs)
Returns \c true if byte array \a lhs is not equal to the UTF-8 encoding of
\a rhs; otherwise returns \c false.
The comparison is case sensitive.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications. You
then need to call QString::fromUtf8(), QString::fromLatin1(),
or QString::fromLocal8Bit() explicitly if you want to convert the byte
array to a QString before doing the comparison.
*/
/*! \fn bool QString::operator<(const QByteArray &lhs, const QString &rhs)
Returns \c true if byte array \a lhs is lexically less than the UTF-8 encoding
of \a rhs; otherwise returns \c false.
The comparison is case sensitive.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications. You
then need to call QString::fromUtf8(), QString::fromLatin1(),
or QString::fromLocal8Bit() explicitly if you want to convert the byte
array to a QString before doing the comparison.
*/
/*! \fn bool QString::operator>(const QByteArray &lhs, const QString &rhs)
Returns \c true if byte array \a lhs is lexically greater than the UTF-8
encoding of \a rhs; otherwise returns \c false.
The comparison is case sensitive.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications. You
then need to call QString::fromUtf8(), QString::fromLatin1(),
or QString::fromLocal8Bit() explicitly if you want to convert the byte
array to a QString before doing the comparison.
*/
/*! \fn bool QString::operator<=(const QByteArray &lhs, const QString &rhs)
Returns \c true if byte array \a lhs is lexically less than or equal to the
UTF-8 encoding of \a rhs; otherwise returns \c false.
The comparison is case sensitive.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications. You
then need to call QString::fromUtf8(), QString::fromLatin1(),
or QString::fromLocal8Bit() explicitly if you want to convert the byte
array to a QString before doing the comparison.
*/
/*! \fn bool QString::operator>=(const QByteArray &lhs, const QString &rhs)
Returns \c true if byte array \a lhs is greater than or equal to the UTF-8
encoding of \a rhs; otherwise returns \c false.
The comparison is case sensitive.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications. You
then need to call QString::fromUtf8(), QString::fromLatin1(),
or QString::fromLocal8Bit() explicitly if you want to convert the byte
array to a QString before doing the comparison.
*/
/*!
\include qstring.qdocinc {qstring-first-index-of} {string} {str}
@ -6405,61 +6485,61 @@ QString& QString::fill(QChar ch, qsizetype size)
*/
/*!
\fn bool QString::operator==(const char *s1, const QString &s2)
\fn bool QString::operator==(const char * const &lhs, const QString &rhs)
\overload operator==()
Returns \c true if \a s1 is equal to \a s2; otherwise returns \c false.
Note that no string is equal to \a s1 being 0.
Returns \c true if \a lhs is equal to \a rhs; otherwise returns \c false.
Note that no string is equal to \a lhs being 0.
Equivalent to \c {s1 != 0 && compare(s1, s2) == 0}.
Equivalent to \c {lhs != 0 && compare(lhs, rhs) == 0}.
*/
/*!
\fn bool QString::operator!=(const char *s1, const QString &s2)
\fn bool QString::operator!=(const char * const &lhs, const QString &rhs)
Returns \c true if \a s1 is not equal to \a s2; otherwise returns
Returns \c true if \a lhs is not equal to \a rhs; otherwise returns
\c false.
For \a s1 != 0, this is equivalent to \c {compare(} \a s1, \a s2
\c {) != 0}. Note that no string is equal to \a s1 being 0.
For \a lhs != 0, this is equivalent to \c {compare(} \a lhs, \a rhs
\c {) != 0}. Note that no string is equal to \a lhs being 0.
*/
/*!
\fn bool QString::operator<(const char *s1, const QString &s2)
\fn bool QString::operator<(const char * const &lhs, const QString &rhs)
Returns \c true if \a s1 is lexically less than \a s2; otherwise
returns \c false. For \a s1 != 0, this is equivalent to \c
{compare(s1, s2) < 0}.
Returns \c true if \a lhs is lexically less than \a rhs; otherwise
returns \c false. For \a lhs != 0, this is equivalent to \c
{compare(lhs, rhs) < 0}.
\sa {Comparing Strings}
*/
/*!
\fn bool QString::operator<=(const char *s1, const QString &s2)
\fn bool QString::operator<=(const char * const &lhs, const QString &rhs)
Returns \c true if \a s1 is lexically less than or equal to \a s2;
otherwise returns \c false. For \a s1 != 0, this is equivalent to \c
{compare(s1, s2) <= 0}.
Returns \c true if \a lhs is lexically less than or equal to \a rhs;
otherwise returns \c false. For \a lhs != 0, this is equivalent to \c
{compare(lhs, rhs) <= 0}.
\sa {Comparing Strings}
*/
/*!
\fn bool QString::operator>(const char *s1, const QString &s2)
\fn bool QString::operator>(const char * const &lhs, const QString &rhs)
Returns \c true if \a s1 is lexically greater than \a s2; otherwise
returns \c false. Equivalent to \c {compare(s1, s2) > 0}.
Returns \c true if \a lhs is lexically greater than \a rhs; otherwise
returns \c false. Equivalent to \c {compare(lhs, rhs) > 0}.
\sa {Comparing Strings}
*/
/*!
\fn bool QString::operator>=(const char *s1, const QString &s2)
\fn bool QString::operator>=(const char * const &lhs, const QString &rhs)
Returns \c true if \a s1 is lexically greater than or equal to \a s2;
otherwise returns \c false. For \a s1 != 0, this is equivalent to \c
{compare(s1, s2) >= 0}.
Returns \c true if \a lhs is lexically greater than or equal to \a rhs;
otherwise returns \c false. For \a lhs != 0, this is equivalent to \c
{compare(lhs, rhs) >= 0}.
\sa {Comparing Strings}
*/

View File

@ -855,6 +855,7 @@ public:
QT_ASCII_CAST_WARN inline QString &operator+=(const QByteArray &s)
{ return append(QUtf8StringView(s)); }
#if QT_CORE_REMOVED_SINCE(6, 8)
QT_ASCII_CAST_WARN inline bool operator==(const char *s) const;
QT_ASCII_CAST_WARN inline bool operator!=(const char *s) const;
QT_ASCII_CAST_WARN inline bool operator<(const char *s) const;
@ -868,20 +869,41 @@ public:
QT_ASCII_CAST_WARN inline bool operator>(const QByteArray &s) const;
QT_ASCII_CAST_WARN inline bool operator<=(const QByteArray &s) const;
QT_ASCII_CAST_WARN inline bool operator>=(const QByteArray &s) const;
#else
friend bool comparesEqual(const QString &lhs, QByteArrayView rhs) noexcept
{
return QString::compare_helper(lhs.constData(), lhs.size(),
rhs.constData(), rhs.size()) == 0;
}
friend Qt::strong_ordering
compareThreeWay(const QString &lhs, QByteArrayView rhs) noexcept
{
const int res = QString::compare_helper(lhs.constData(), lhs.size(),
rhs.constData(), rhs.size());
return Qt::compareThreeWay(res, 0);
}
Q_DECLARE_STRONGLY_ORDERED(QString, QByteArrayView, QT_ASCII_CAST_WARN)
QT_ASCII_CAST_WARN friend bool operator==(const char *s1, const QString &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) == 0; }
QT_ASCII_CAST_WARN friend bool operator!=(const char *s1, const QString &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) != 0; }
QT_ASCII_CAST_WARN friend bool operator< (const char *s1, const QString &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) > 0; }
QT_ASCII_CAST_WARN friend bool operator> (const char *s1, const QString &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) < 0; }
QT_ASCII_CAST_WARN friend bool operator<=(const char *s1, const QString &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) >= 0; }
QT_ASCII_CAST_WARN friend bool operator>=(const char *s1, const QString &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) <= 0; }
#endif
friend bool comparesEqual(const QString &lhs, const QByteArray &rhs) noexcept
{ return comparesEqual(lhs, QByteArrayView(rhs)); }
friend Qt::strong_ordering
compareThreeWay(const QString &lhs, const QByteArray &rhs) noexcept
{
return compareThreeWay(lhs, QByteArrayView(rhs));
}
Q_DECLARE_STRONGLY_ORDERED(QString, QByteArray, QT_ASCII_CAST_WARN)
friend bool comparesEqual(const QString &lhs, const char *rhs) noexcept
{ return comparesEqual(lhs, QByteArrayView(rhs)); }
friend Qt::strong_ordering
compareThreeWay(const QString &lhs, const char *rhs) noexcept
{
return compareThreeWay(lhs, QByteArrayView(rhs));
}
Q_DECLARE_STRONGLY_ORDERED(QString, const char *, QT_ASCII_CAST_WARN)
#endif // QT_CORE_REMOVED_SINCE(6, 8)
#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
typedef QChar *iterator;
typedef const QChar *const_iterator;
@ -1306,6 +1328,7 @@ bool QString::contains(QStringView s, Qt::CaseSensitivity cs) const noexcept
{ return indexOf(s, 0, cs) != -1; }
#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
#if QT_CORE_REMOVED_SINCE(6, 8)
bool QString::operator==(const char *s) const
{ return QString::compare_helper(constData(), size(), s, -1) == 0; }
bool QString::operator!=(const char *s) const
@ -1344,6 +1367,7 @@ bool QByteArray::operator<=(const QString &s) const
{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) >= 0; }
bool QByteArray::operator>=(const QString &s) const
{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) <= 0; }
#endif // QT_CORE_REMOVED_SINCE(6, 8)
#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
#if !defined(QT_USE_FAST_OPERATOR_PLUS) && !defined(QT_USE_QSTRINGBUILDER)

View File

@ -8041,6 +8041,11 @@ void tst_QString::comparisonCompiles()
QTestPrivate::testAllComparisonOperatorsCompile<QString, QChar>();
QTestPrivate::testAllComparisonOperatorsCompile<QString, QLatin1StringView>();
QTestPrivate::testAllComparisonOperatorsCompile<QString, const char16_t *>();
#if !defined(QT_RESTRICTED_CAST_FROM_ASCII) && !defined(QT_NO_CAST_FROM_ASCII)
QTestPrivate::testAllComparisonOperatorsCompile<QString, QByteArrayView>();
QTestPrivate::testAllComparisonOperatorsCompile<QString, QByteArray>();
QTestPrivate::testAllComparisonOperatorsCompile<QString, const char *>();
#endif
}
void tst_QString::compare_data()
@ -8268,6 +8273,17 @@ void tst_QString::comparisonMacros()
const QLatin1StringView l1s2{ba};
QT_TEST_ALL_COMPARISON_OPS(s1, l1s2, expectedOrdering);
}
const QByteArray u8s2 = s2.toUtf8();
#if !defined(QT_RESTRICTED_CAST_FROM_ASCII) && !defined(QT_NO_CAST_FROM_ASCII)
QT_TEST_ALL_COMPARISON_OPS(s1, u8s2, expectedOrdering);
const QByteArrayView u8s2view{u8s2.begin(), u8s2.size()};
QT_TEST_ALL_COMPARISON_OPS(s1, u8s2view, expectedOrdering);
if (!s2.contains(QChar(u'\0'))) {
const char *u8data = u8s2.constData();
QT_TEST_ALL_COMPARISON_OPS(s1, u8data, expectedOrdering);
}
#endif // !defined(QT_RESTRICTED_CAST_FROM_ASCII) && !defined(QT_NO_CAST_FROM_ASCII)
}
void tst_QString::resize()

View File

@ -74,7 +74,6 @@ MAKE_ALL(QString, QUtf8StringView)
MAKE_ALL(QUtf8StringView, QChar)
MAKE_ALL(QUtf8StringView, char16_t)
MAKE_ALL(QUtf8StringView, QStringView)
#undef MAKE_ALL
#undef MAKE_RELOP