summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-12-13 05:08:21 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-04-05 15:23:30 +0000
commit0683c9291f9c1ffe0625fdadee198840047f0e92 (patch)
tree9ae5a4ffb7f4b2630698b016f7d5f592f1f05fab
parenta7b04275082d065f392e7f18c54ea9b41507ae40 (diff)
QChar: add missing relational operators against QLatin1String/QStringRef
For QChar <> QStringRef, equality and inequality were already provided (via QChar -> QString implicit conversions, to be fixed in a separate patch). Missing were the less/greater than (or equal) operators. Added. For QChar <> QLatin1String, all relational operators were missing. Added, too. [ChangeLog][QtCore][QChar] Added missing operator{<,>,<=,>=} comparing against QLatin1String and QStringRef. [ChangeLog][QtCore][QChar] Added missing operator{==,!=} comparing against QLatin1String. Change-Id: I9941fe7e7281ea560b3bd5970cb9651ffadc1495 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
-rw-r--r--src/corelib/tools/qstring.h39
-rw-r--r--tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp22
2 files changed, 39 insertions, 22 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index e223c44b75..3413a87085 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -814,6 +814,12 @@ private:
Data *d;
+ friend inline bool operator< (QChar, const QStringRef &) Q_DECL_NOTHROW;
+ friend inline bool operator> (QChar, const QStringRef &) Q_DECL_NOTHROW;
+ friend inline bool operator==(QChar, QLatin1String) Q_DECL_NOTHROW;
+ friend inline bool operator< (QChar, QLatin1String) Q_DECL_NOTHROW;
+ friend inline bool operator> (QChar, QLatin1String) Q_DECL_NOTHROW;
+
void reallocData(uint alloc, bool grow = false);
void expand(int i);
QString multiArg(int numArgs, const QString **args) const;
@@ -1583,6 +1589,39 @@ inline bool operator> (const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW
inline bool operator<=(const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs >= lhs; }
inline bool operator>=(const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs <= lhs; }
+// QChar <> QStringRef
+inline bool operator< (QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; }
+inline bool operator> (QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) > 0; }
+
+inline bool operator<=(QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return !(lhs > rhs); }
+inline bool operator>=(QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return !(lhs < rhs); }
+
+inline bool operator< (const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs > lhs; }
+inline bool operator> (const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs < lhs; }
+inline bool operator<=(const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs < lhs); }
+inline bool operator>=(const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs > lhs); }
+
+// QChar <> QLatin1String
+inline bool operator==(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs.latin1(), rhs.size()) == 0; }
+inline bool operator< (QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs.latin1(), rhs.size()) < 0; }
+inline bool operator> (QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs.latin1(), rhs.size()) > 0; }
+
+inline bool operator!=(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW { return !(lhs == rhs); }
+inline bool operator<=(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW { return !(lhs > rhs); }
+inline bool operator>=(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW { return !(lhs < rhs); }
+
+inline bool operator==(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return rhs == lhs; }
+inline bool operator!=(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs == lhs); }
+inline bool operator< (QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return rhs > lhs; }
+inline bool operator> (QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return rhs < lhs; }
+inline bool operator<=(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs < lhs); }
+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)
inline QT_ASCII_CAST_WARN bool QStringRef::operator==(const char *s) const
{ return QString::compare_helper(constData(), size(), s, -1) == 0; }
diff --git a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp
index 1557bd6076..f0d7cb5698 100644
--- a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp
+++ b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp
@@ -44,28 +44,6 @@ template <typename T>
QString toQString(const T &t) { return QString(t); }
QString toQString(const QStringRef &ref) { return ref.toString(); }
-// FIXME: these are missing at the time of writing, add them, then remove the dummies here:
-#define MAKE_RELOP(op, A1, A2) \
- static bool operator op (const A1 &lhs, const A2 &rhs) \
- { return toQString(lhs) op toQString(rhs); } \
- /*end*/
-#define MAKE_LESS_ETC(A1, A2) \
- MAKE_RELOP(<, A1, A2) \
- MAKE_RELOP(>, A1, A2) \
- MAKE_RELOP(<=, A1, A2) \
- MAKE_RELOP(>=, A1, A2) \
- /*end*/
-MAKE_RELOP(==, QChar, QLatin1String)
-MAKE_RELOP(!=, QChar, QLatin1String)
-MAKE_LESS_ETC(QChar, QLatin1String)
-
-MAKE_LESS_ETC(QChar, QStringRef)
-MAKE_LESS_ETC(QStringRef, QChar)
-
-#undef MAKE_LESS_ETC
-#undef MAKE_RELOP
-// END FIXME
-
class tst_QStringApiSymmetry : public QObject
{
Q_OBJECT