From 8005fa3524916a56a555f44d4418eb1cd12db645 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 13 Dec 2015 05:08:21 +0100 Subject: QStringRef: add missing relational operators against QLatin1String/QString Equality and inequality were already provided. Missing were the less/greater than (or equal) operators. Added. Moved existing functions around and more similar to the new ones, to make the whole code section a bit more manageable. [ChangeLog][QtCore][QStringRef] Added missing operator{<,>,<=,>=} comparing against QLatin1String and QString. Change-Id: Idb3c4fa9b38421637987226f3cc1b77f5d4a6309 Reviewed-by: Lars Knoll --- src/corelib/tools/qstring.h | 46 ++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 90a56828e2..a1ca957fb2 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -1524,24 +1524,10 @@ inline QStringRef::QStringRef(const QString *aString, int aPosition, int aSize) inline QStringRef::QStringRef(const QString *aString) :m_string(aString), m_position(0), m_size(aString?aString->size() : 0){} +// QStringRef <> QStringRef Q_CORE_EXPORT bool operator==(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW; inline bool operator!=(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW { return !(s1 == s2); } -Q_CORE_EXPORT bool operator==(const QString &s1, const QStringRef &s2) Q_DECL_NOTHROW; -inline bool operator!=(const QString &s1, const QStringRef &s2) Q_DECL_NOTHROW -{ return !(s1 == s2); } -inline bool operator==(const QStringRef &s1, const QString &s2) Q_DECL_NOTHROW -{ return s2 == s1; } -inline bool operator!=(const QStringRef &s1, const QString &s2) Q_DECL_NOTHROW -{ return s2 != s1; } -Q_CORE_EXPORT bool operator==(QLatin1String s1, const QStringRef &s2) Q_DECL_NOTHROW; -inline bool operator!=(QLatin1String s1, const QStringRef &s2) Q_DECL_NOTHROW -{ return !(s1 == s2); } -inline bool operator==(const QStringRef &s1, QLatin1String s2) Q_DECL_NOTHROW -{ return s2 == s1; } -inline bool operator!=(const QStringRef &s1, QLatin1String s2) Q_DECL_NOTHROW -{ return s2 != s1; } - Q_CORE_EXPORT bool operator<(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW; inline bool operator>(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW { return s2 < s1; } @@ -1550,6 +1536,36 @@ inline bool operator<=(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHRO inline bool operator>=(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW { return !(s1 < s2); } +// QString <> QStringRef +Q_CORE_EXPORT bool operator==(const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW; +inline bool operator!=(const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) != 0; } +inline bool operator< (const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) < 0; } +inline bool operator> (const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) > 0; } +inline bool operator<=(const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) <= 0; } +inline bool operator>=(const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) >= 0; } + +inline bool operator==(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs == lhs; } +inline bool operator!=(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs != lhs; } +inline bool operator< (const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs > lhs; } +inline bool operator> (const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs < lhs; } +inline bool operator<=(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs >= lhs; } +inline bool operator>=(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs <= lhs; } + +// QLatin1String <> QStringRef +Q_CORE_EXPORT bool operator==(QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW; +inline bool operator!=(QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) != 0; } +inline bool operator< (QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) > 0; } +inline bool operator> (QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) < 0; } +inline bool operator<=(QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) >= 0; } +inline bool operator>=(QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) <= 0; } + +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; } +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; } +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; } + #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