diff options
Diffstat (limited to 'src/corelib/tools/qstring.h')
-rw-r--r-- | src/corelib/tools/qstring.h | 167 |
1 files changed, 129 insertions, 38 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 793a859228..6599a5b18c 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -68,11 +68,9 @@ namespace std #error qstring.h must be included before any header file that defines truncate #endif -#ifdef Q_OS_MAC +#if defined(Q_OS_MAC) Q_FORWARD_DECLARE_CF_TYPE(CFString); -# ifdef __OBJC__ Q_FORWARD_DECLARE_OBJC_CLASS(NSString); -# endif #endif QT_BEGIN_NAMESPACE @@ -99,6 +97,18 @@ public: Q_DECL_CONSTEXPR int size() const Q_DECL_NOTHROW { return m_size; } Q_DECL_CONSTEXPR const char *data() const Q_DECL_NOTHROW { return m_data; } + Q_DECL_CONSTEXPR QLatin1Char at(int i) const { return QLatin1Char(m_data[i]); } + Q_DECL_CONSTEXPR QLatin1Char operator[](int i) const { return at(i); } + + Q_DECL_CONSTEXPR QLatin1String mid(int pos) const + { return QLatin1String(m_data + pos, m_size - pos); } + Q_DECL_CONSTEXPR QLatin1String mid(int pos, int n) const + { return QLatin1String(m_data + pos, n); } + Q_DECL_CONSTEXPR QLatin1String left(int n) const + { return QLatin1String(m_data, n); } + Q_DECL_CONSTEXPR QLatin1String right(int n) const + { return QLatin1String(m_data + m_size - n, n); } + inline bool operator==(const QString &s) const Q_DECL_NOTHROW; inline bool operator!=(const QString &s) const Q_DECL_NOTHROW; inline bool operator>(const QString &s) const Q_DECL_NOTHROW; @@ -593,7 +603,7 @@ public: Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW { return -s2.compare(s1, cs); } - int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; + inline int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; static int compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity = Qt::CaseSensitive) Q_DECL_NOTHROW; @@ -771,10 +781,8 @@ public: #if defined(Q_OS_MAC) || defined(Q_QDOC) static QString fromCFString(CFStringRef string); CFStringRef toCFString() const Q_DECL_CF_RETURNS_RETAINED; -# if defined(__OBJC__) || defined(Q_QDOC) static QString fromNSString(const NSString *string); NSString *toNSString() const Q_DECL_NS_RETURNS_AUTORELEASED; -# endif #endif // compatibility struct Null { }; @@ -802,6 +810,16 @@ private: Data *d; + friend inline bool operator==(QChar, const QString &) Q_DECL_NOTHROW; + friend inline bool operator< (QChar, const QString &) Q_DECL_NOTHROW; + friend inline bool operator> (QChar, const QString &) Q_DECL_NOTHROW; + 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, 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; @@ -1518,24 +1536,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; } @@ -1544,6 +1548,110 @@ 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; } + +inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } +inline int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } +inline int QStringRef::compare(const QString &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } +inline int QStringRef::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } +inline int QStringRef::compare(QLatin1String s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +{ return QString::compare_helper(constData(), length(), s, cs); } +inline int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } +inline int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } +inline int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +{ return QString::compare_helper(s1.constData(), s1.length(), s2, cs); } + +// 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; } + +// QChar <> QString +inline bool operator==(QChar lhs, const QString &rhs) Q_DECL_NOTHROW +{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) == 0; } +inline bool operator< (QChar lhs, const QString &rhs) Q_DECL_NOTHROW +{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; } +inline bool operator> (QChar lhs, const QString &rhs) Q_DECL_NOTHROW +{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) > 0; } + +inline bool operator!=(QChar lhs, const QString &rhs) Q_DECL_NOTHROW { return !(lhs == rhs); } +inline bool operator<=(QChar lhs, const QString &rhs) Q_DECL_NOTHROW { return !(lhs > rhs); } +inline bool operator>=(QChar lhs, const QString &rhs) Q_DECL_NOTHROW { return !(lhs < rhs); } + +inline bool operator==(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs == lhs; } +inline bool operator!=(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs == lhs); } +inline bool operator< (const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs > lhs; } +inline bool operator> (const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs < lhs; } +inline bool operator<=(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs < lhs); } +inline bool operator>=(const QString &lhs, QChar 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 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>=(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; } +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; } @@ -1572,23 +1680,6 @@ inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QStringRef &s2) { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) <= 0; } #endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) -inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW -{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } -inline int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW -{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } -inline int QStringRef::compare(const QString &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW -{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } -inline int QStringRef::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW -{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } -inline int QStringRef::compare(QLatin1String s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW -{ return QString::compare_helper(constData(), length(), s, cs); } -inline int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW -{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } -inline int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW -{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } -inline int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW -{ return QString::compare_helper(s1.constData(), s1.length(), s2, cs); } - inline int QString::localeAwareCompare(const QStringRef &s) const { return localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); } inline int QString::localeAwareCompare(const QString& s1, const QStringRef& s2) |