summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2020-08-25 13:24:07 +0200
committerThiago Macieira <thiago.macieira@intel.com>2020-08-26 14:37:43 +0000
commit7d35e31efb1a58c529ffefc4a5941511024eeabc (patch)
treed8ceca462facc6a97ef2f448a2ad91c5938411c6 /src
parentfe4b246446f721085946e399b96a42eccfcecca8 (diff)
Add back QByteArray's relational operators taking QString
QString still has the overloads of relational operators taking QByteArray. Add back QByteArray's relational operators taking QString for symmetry. See also the comments of d7ccd8cb4565c8643b158891c9de3187c1586dc9 for more details. [ChangeLog][EDITORIAL] Remove the changelog about QString/QByteArray operators being removed. They're back. Change-Id: I22c95e727285cf8a5ef79b3a4f9d45cb66319252 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qbytearray.cpp84
-rw-r--r--src/corelib/text/qbytearray.h9
-rw-r--r--src/corelib/text/qstring.h12
3 files changed, 105 insertions, 0 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index bcbbdc234f..041fb06554 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -2991,6 +2991,90 @@ 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 operator==(const QByteArray &a1, const QByteArray &a2)
\relates QByteArray
diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h
index 68945ec6c4..a625b1846f 100644
--- a/src/corelib/text/qbytearray.h
+++ b/src/corelib/text/qbytearray.h
@@ -308,6 +308,15 @@ public:
Q_REQUIRED_RESULT QByteArray repeated(int times) const;
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
+ inline QT_ASCII_CAST_WARN bool operator==(const QString &s2) const;
+ inline QT_ASCII_CAST_WARN bool operator!=(const QString &s2) const;
+ inline QT_ASCII_CAST_WARN bool operator<(const QString &s2) const;
+ inline QT_ASCII_CAST_WARN bool operator>(const QString &s2) const;
+ inline QT_ASCII_CAST_WARN bool operator<=(const QString &s2) const;
+ inline QT_ASCII_CAST_WARN bool operator>=(const QString &s2) const;
+#endif
+
short toShort(bool *ok = nullptr, int base = 10) const;
ushort toUShort(bool *ok = nullptr, int base = 10) const;
int toInt(bool *ok = nullptr, int base = 10) const;
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index 1e0d7f480a..7f5e460275 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -1259,6 +1259,18 @@ inline QT_ASCII_CAST_WARN bool QString::operator<=(const QByteArray &s) const
inline QT_ASCII_CAST_WARN bool QString::operator>=(const QByteArray &s) const
{ return QString::compare_helper(constData(), size(), s.constData(), s.size()) >= 0; }
+inline bool QByteArray::operator==(const QString &s) const
+{ return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) == 0; }
+inline bool QByteArray::operator!=(const QString &s) const
+{ return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) != 0; }
+inline bool QByteArray::operator<(const QString &s) const
+{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) > 0; }
+inline bool QByteArray::operator>(const QString &s) const
+{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) < 0; }
+inline bool QByteArray::operator<=(const QString &s) const
+{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) >= 0; }
+inline bool QByteArray::operator>=(const QString &s) const
+{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) <= 0; }
#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
#if !defined(QT_USE_FAST_OPERATOR_PLUS) && !defined(QT_USE_QSTRINGBUILDER)