From 0683c9291f9c1ffe0625fdadee198840047f0e92 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 13 Dec 2015 05:08:21 +0100 Subject: 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 --- src/corelib/tools/qstring.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/corelib/tools/qstring.h') 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; } -- cgit v1.2.3