QStringRef: add missing relational operators against QByteArray
QStringRef op QByteArray was ambiguous between bool QStringRef::operator op(const char*) const bool operator op(const QStringRef&, const QString&) QByteArray op QStringRef was ambiguous between bool operator op(const QString&, const QStringRef&) bool operator op(const char*, const QStringRef&) Fix by providing more overloads. [ChangeLog][QtCore] Disambiguated the relational operators comparing QByteArray with QStringRef (and vice versa). Change-Id: I1cfa9ecfdd8b4102e652593faf35f6098289bc34 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>bb10
parent
f0d9eed064
commit
a7ae92e67d
|
|
@ -9396,6 +9396,24 @@ QStringRef QStringRef::appendTo(QString *string) const
|
|||
\sa QString::compare()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\overload
|
||||
\fn int QStringRef::compare(const QByteArray &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
|
||||
\since 5.8
|
||||
|
||||
Compares this string with \a other and returns an
|
||||
integer less than, equal to, or greater than zero if this string
|
||||
is less than, equal to, or greater than the \a other byte array,
|
||||
interpreted as a UTF-8 sequence.
|
||||
|
||||
If \a cs is Qt::CaseSensitive, the comparison is case sensitive;
|
||||
otherwise the comparison is case insensitive.
|
||||
|
||||
Equivalent to \c {compare(*this, other, cs)}.
|
||||
|
||||
\sa QString::compare()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn int QStringRef::localeAwareCompare(const QStringRef &s1, const QString & s2)
|
||||
\since 4.5
|
||||
|
|
|
|||
|
|
@ -1501,6 +1501,10 @@ public:
|
|||
int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
|
||||
int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
|
||||
int compare(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
|
||||
#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
|
||||
int compare(const QByteArray &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
|
||||
{ return QString::compare_helper(unicode(), size(), s.data(), qstrnlen(s.data(), s.size()), cs); }
|
||||
#endif
|
||||
static int compare(const QStringRef &s1, const QString &s2,
|
||||
Qt::CaseSensitivity = Qt::CaseSensitive) Q_DECL_NOTHROW;
|
||||
static int compare(const QStringRef &s1, const QStringRef &s2,
|
||||
|
|
@ -1653,6 +1657,22 @@ inline bool operator<=(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return !(r
|
|||
inline bool operator>=(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs > lhs); }
|
||||
|
||||
#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
|
||||
// QStringRef <> QByteArray
|
||||
inline QT_ASCII_CAST_WARN bool operator==(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) == 0; }
|
||||
inline QT_ASCII_CAST_WARN bool operator!=(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) != 0; }
|
||||
inline QT_ASCII_CAST_WARN bool operator< (const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) < 0; }
|
||||
inline QT_ASCII_CAST_WARN bool operator> (const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) > 0; }
|
||||
inline QT_ASCII_CAST_WARN bool operator<=(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) <= 0; }
|
||||
inline QT_ASCII_CAST_WARN bool operator>=(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) >= 0; }
|
||||
|
||||
inline QT_ASCII_CAST_WARN bool operator==(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) == 0; }
|
||||
inline QT_ASCII_CAST_WARN bool operator!=(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) != 0; }
|
||||
inline QT_ASCII_CAST_WARN bool operator< (const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) > 0; }
|
||||
inline QT_ASCII_CAST_WARN bool operator> (const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) < 0; }
|
||||
inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) >= 0; }
|
||||
inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) <= 0; }
|
||||
|
||||
// QStringRef <> const char *
|
||||
inline QT_ASCII_CAST_WARN bool QStringRef::operator==(const char *s) const
|
||||
{ return QString::compare_helper(constData(), size(), s, -1) == 0; }
|
||||
inline QT_ASCII_CAST_WARN bool QStringRef::operator!=(const char *s) const
|
||||
|
|
|
|||
|
|
@ -58,9 +58,6 @@ QString toQString(const QStringRef &ref) { return ref.toString(); }
|
|||
MAKE_RELOP(>=, A1, A2) \
|
||||
/*end*/
|
||||
|
||||
MAKE_ALL(QStringRef, QByteArray)
|
||||
MAKE_ALL(QByteArray, QStringRef)
|
||||
|
||||
MAKE_ALL(QByteArray, QChar)
|
||||
MAKE_ALL(QByteArray, QLatin1String)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue