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>
This commit is contained in:
Marc Mutz 2015-12-13 05:08:21 +01:00
parent a7b0427508
commit 0683c9291f
2 changed files with 39 additions and 22 deletions

View File

@ -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; }

View File

@ -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