Make QString/QLatin1String comparisons hidden friends
Leaving most member comparisons untouched though. Change-Id: I8267f85927ec8315d511ac38757bc8d8aaaa5672 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
c91327645b
commit
a6b7d6937b
@ -3536,32 +3536,32 @@ QString &QString::replace(QChar c, QLatin1String after, Qt::CaseSensitivity cs)
|
||||
|
||||
|
||||
/*!
|
||||
\relates QString
|
||||
Returns \c true if string \a s1 is equal to string \a s2; otherwise
|
||||
returns \c false.
|
||||
\fn bool QString::operator==(const QString &s1, const QString &s2)
|
||||
\overload operator==()
|
||||
|
||||
\sa {Comparing Strings}
|
||||
Returns \c true if string \a s1 is equal to string \a s2; otherwise
|
||||
returns \c false.
|
||||
|
||||
\sa {Comparing Strings}
|
||||
*/
|
||||
bool operator==(const QString &s1, const QString &s2) noexcept
|
||||
{
|
||||
if (s1.d.size != s2.d.size)
|
||||
return false;
|
||||
|
||||
return QtPrivate::compareStrings(s1, s2, Qt::CaseSensitive) == 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn bool QString::operator==(const QString &s1, QLatin1String s2)
|
||||
|
||||
\overload operator==()
|
||||
Returns \c true if this string is equal to \a other; otherwise
|
||||
|
||||
Returns \c true if \a s1 is equal to \a s2; otherwise
|
||||
returns \c false.
|
||||
*/
|
||||
bool QString::operator==(QLatin1String other) const noexcept
|
||||
{
|
||||
if (size() != other.size())
|
||||
return false;
|
||||
|
||||
return QtPrivate::compareStrings(*this, other, Qt::CaseSensitive) == 0;
|
||||
}
|
||||
/*!
|
||||
\fn bool QString::operator==(QLatin1String s1, const QString &s2)
|
||||
|
||||
\overload operator==()
|
||||
|
||||
Returns \c true if \a s1 is equal to \a s2; otherwise
|
||||
returns \c false.
|
||||
*/
|
||||
|
||||
/*! \fn bool QString::operator==(const QByteArray &other) const
|
||||
|
||||
@ -3598,27 +3598,33 @@ bool QString::operator==(QLatin1String other) const noexcept
|
||||
*/
|
||||
|
||||
/*!
|
||||
\relates QString
|
||||
\fn bool QString::operator<(const QString &s1, const QString &s2)
|
||||
|
||||
\overload operator<()
|
||||
|
||||
Returns \c true if string \a s1 is lexically less than string
|
||||
\a s2; otherwise returns \c false.
|
||||
|
||||
\sa {Comparing Strings}
|
||||
*/
|
||||
bool operator<(const QString &s1, const QString &s2) noexcept
|
||||
{
|
||||
return QtPrivate::compareStrings(s1, s2, Qt::CaseSensitive) < 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload operator<()
|
||||
\fn bool QString::operator<(const QString &s1, QLatin1String s2)
|
||||
|
||||
Returns \c true if this string is lexically less than the parameter
|
||||
string called \a other; otherwise returns \c false.
|
||||
\overload operator<()
|
||||
|
||||
Returns \c true if \a s1 is lexically less than \a s2;
|
||||
otherwise returns \c false.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QString::operator<(QLatin1String s1, const QString &s2)
|
||||
|
||||
\overload operator<()
|
||||
|
||||
Returns \c true if \a s1 is lexically less than \a s2;
|
||||
otherwise returns \c false.
|
||||
*/
|
||||
bool QString::operator<(QLatin1String other) const noexcept
|
||||
{
|
||||
return QtPrivate::compareStrings(*this, other, Qt::CaseSensitive) < 0;
|
||||
}
|
||||
|
||||
/*! \fn bool QString::operator<(const QByteArray &other) const
|
||||
|
||||
@ -3662,12 +3668,22 @@ bool QString::operator<(QLatin1String other) const noexcept
|
||||
\sa {Comparing Strings}
|
||||
*/
|
||||
|
||||
/*! \fn bool QString::operator<=(QLatin1String other) const
|
||||
|
||||
Returns \c true if this string is lexically less than or equal to
|
||||
parameter string \a other. Otherwise returns \c false.
|
||||
/*!
|
||||
\fn bool QString::operator<=(const QString &s1, QLatin1String s2)
|
||||
|
||||
\overload operator<=()
|
||||
|
||||
Returns \c true if \a s1 is lexically less than or equal to \a s2;
|
||||
otherwise returns \c false.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QString::operator<=(QLatin1String s1, const QString &s2)
|
||||
|
||||
\overload operator<=()
|
||||
|
||||
Returns \c true if \a s1 is lexically less than or equal to \a s2;
|
||||
otherwise returns \c false.
|
||||
*/
|
||||
|
||||
/*! \fn bool QString::operator<=(const QByteArray &other) const
|
||||
@ -3710,15 +3726,22 @@ bool QString::operator<(QLatin1String other) const noexcept
|
||||
*/
|
||||
|
||||
/*!
|
||||
\overload operator>()
|
||||
\fn bool QString::operator>(const QString &s1, QLatin1String s2)
|
||||
|
||||
Returns \c true if this string is lexically greater than the parameter
|
||||
string \a other; otherwise returns \c false.
|
||||
\overload operator>()
|
||||
|
||||
Returns \c true if \a s1 is lexically greater than \a s2;
|
||||
otherwise returns \c false.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QString::operator>(QLatin1String s1, const QString &s2)
|
||||
|
||||
\overload operator>()
|
||||
|
||||
Returns \c true if \a s1 is lexically greater than \a s2;
|
||||
otherwise returns \c false.
|
||||
*/
|
||||
bool QString::operator>(QLatin1String other) const noexcept
|
||||
{
|
||||
return QtPrivate::compareStrings(*this, other, Qt::CaseSensitive) > 0;
|
||||
}
|
||||
|
||||
/*! \fn bool QString::operator>(const QByteArray &other) const
|
||||
|
||||
@ -3759,12 +3782,22 @@ bool QString::operator>(QLatin1String other) const noexcept
|
||||
\sa {Comparing Strings}
|
||||
*/
|
||||
|
||||
/*! \fn bool QString::operator>=(QLatin1String other) const
|
||||
|
||||
Returns \c true if this string is lexically greater than or equal to parameter
|
||||
string \a other. Otherwise returns \c false.
|
||||
/*!
|
||||
\fn bool QString::operator>=(const QString &s1, QLatin1String s2)
|
||||
|
||||
\overload operator>=()
|
||||
|
||||
Returns \c true if \a s1 is lexically greater than or equal to \a s2;
|
||||
otherwise returns \c false.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QString::operator>=(QLatin1String s1, const QString &s2)
|
||||
|
||||
\overload operator>=()
|
||||
|
||||
Returns \c true if \a s1 is lexically greater than or equal to \a s2;
|
||||
otherwise returns \c false.
|
||||
*/
|
||||
|
||||
/*! \fn bool QString::operator>=(const QByteArray &other) const
|
||||
@ -3806,9 +3839,9 @@ bool QString::operator>(QLatin1String other) const noexcept
|
||||
\sa {Comparing Strings}
|
||||
*/
|
||||
|
||||
/*! \fn bool QString::operator!=(QLatin1String other) const
|
||||
/*! \fn bool QString::operator!=(const QString &s1, QLatin1String s2)
|
||||
|
||||
Returns \c true if this string is not equal to parameter string \a other.
|
||||
Returns \c true if string \a s1 is not equal to string \a s2.
|
||||
Otherwise returns \c false.
|
||||
|
||||
\overload operator!=()
|
||||
@ -5972,8 +6005,8 @@ int QString::compare_helper(const QChar *data1, qsizetype length1, const char *d
|
||||
\internal
|
||||
\since 4.5
|
||||
*/
|
||||
int QString::compare_helper(const QChar *data1, qsizetype length1, QLatin1String s2,
|
||||
Qt::CaseSensitivity cs) noexcept
|
||||
int QLatin1String::compare_helper(const QChar *data1, qsizetype length1, QLatin1String s2,
|
||||
Qt::CaseSensitivity cs) noexcept
|
||||
{
|
||||
Q_ASSERT(length1 >= 0);
|
||||
Q_ASSERT(data1 || length1 == 0);
|
||||
@ -9253,14 +9286,6 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size)
|
||||
'\\f', '\\r', and ' '.
|
||||
*/
|
||||
|
||||
/*! \fn bool QLatin1String::operator==(const QString &other) const
|
||||
|
||||
Returns \c true if this string is equal to string \a other;
|
||||
otherwise returns \c false.
|
||||
|
||||
\sa {Comparing Strings}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QLatin1String::operator==(const char *other) const
|
||||
\since 4.3
|
||||
@ -9293,14 +9318,6 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size)
|
||||
\sa QT_NO_CAST_FROM_ASCII
|
||||
*/
|
||||
|
||||
/*! \fn bool QLatin1String::operator!=(const QString &other) const
|
||||
|
||||
Returns \c true if this string is not equal to string \a other;
|
||||
otherwise returns \c false.
|
||||
|
||||
\sa {Comparing Strings}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QLatin1String::operator!=(const char *other) const
|
||||
\since 4.3
|
||||
@ -9333,15 +9350,6 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size)
|
||||
\sa QT_NO_CAST_FROM_ASCII
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QLatin1String::operator>(const QString &other) const
|
||||
|
||||
Returns \c true if this string is lexically greater than string \a
|
||||
other; otherwise returns \c false.
|
||||
|
||||
\sa {Comparing Strings}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QLatin1String::operator>(const char *other) const
|
||||
\since 4.3
|
||||
@ -9374,15 +9382,6 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size)
|
||||
\sa QT_NO_CAST_FROM_ASCII
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QLatin1String::operator<(const QString &other) const
|
||||
|
||||
Returns \c true if this string is lexically less than the \a other
|
||||
string; otherwise returns \c false.
|
||||
|
||||
\sa {Comparing Strings}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QLatin1String::operator<(const char *other) const
|
||||
\since 4.3
|
||||
@ -9415,15 +9414,6 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size)
|
||||
\sa QT_NO_CAST_FROM_ASCII
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QLatin1String::operator>=(const QString &other) const
|
||||
|
||||
Returns \c true if this string is lexically greater than or equal
|
||||
to string \a other; otherwise returns \c false.
|
||||
|
||||
\sa {Comparing Strings}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QLatin1String::operator>=(const char *other) const
|
||||
\since 4.3
|
||||
@ -9456,14 +9446,6 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size)
|
||||
\sa QT_NO_CAST_FROM_ASCII
|
||||
*/
|
||||
|
||||
/*! \fn bool QLatin1String::operator<=(const QString &other) const
|
||||
|
||||
Returns \c true if this string is lexically less than or equal
|
||||
to string \a other; otherwise returns \c false.
|
||||
|
||||
\sa {Comparing Strings}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QLatin1String::operator<=(const char *other) const
|
||||
\since 4.3
|
||||
@ -9496,39 +9478,32 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size)
|
||||
\sa QT_NO_CAST_FROM_ASCII
|
||||
*/
|
||||
|
||||
|
||||
/*! \fn bool operator==(QLatin1String s1, QLatin1String s2)
|
||||
\relates QLatin1String
|
||||
/*! \fn bool QLatin1String::operator==(QLatin1String s1, QLatin1String s2)
|
||||
|
||||
Returns \c true if string \a s1 is lexically equal to string \a s2; otherwise
|
||||
returns \c false.
|
||||
*/
|
||||
/*! \fn bool operator!=(QLatin1String s1, QLatin1String s2)
|
||||
\relates QLatin1String
|
||||
/*! \fn bool QLatin1String::operator!=(QLatin1String s1, QLatin1String s2)
|
||||
|
||||
Returns \c true if string \a s1 is lexically unequal to string \a s2; otherwise
|
||||
returns \c false.
|
||||
*/
|
||||
/*! \fn bool operator<(QLatin1String s1, QLatin1String s2)
|
||||
\relates QLatin1String
|
||||
/*! \fn bool QLatin1String::operator<(QLatin1String s1, QLatin1String s2)
|
||||
|
||||
Returns \c true if string \a s1 is lexically smaller than string \a s2; otherwise
|
||||
returns \c false.
|
||||
*/
|
||||
/*! \fn bool operator<=(QLatin1String s1, QLatin1String s2)
|
||||
\relates QLatin1String
|
||||
/*! \fn bool QLatin1String::operator<=(QLatin1String s1, QLatin1String s2)
|
||||
|
||||
Returns \c true if string \a s1 is lexically smaller than or equal to string \a s2; otherwise
|
||||
returns \c false.
|
||||
*/
|
||||
/*! \fn bool operator>(QLatin1String s1, QLatin1String s2)
|
||||
\relates QLatin1String
|
||||
/*! \fn bool QLatin1String::operator>(QLatin1String s1, QLatin1String s2)
|
||||
|
||||
Returns \c true if string \a s1 is lexically greater than string \a s2; otherwise
|
||||
returns \c false.
|
||||
*/
|
||||
/*! \fn bool operator>=(QLatin1String s1, QLatin1String s2)
|
||||
\relates QLatin1String
|
||||
/*! \fn bool QLatin1String::operator>=(QLatin1String s1, QLatin1String s2)
|
||||
|
||||
Returns \c true if string \a s1 is lexically greater than or equal to
|
||||
string \a s2; otherwise returns \c false.
|
||||
|
@ -221,12 +221,55 @@ public:
|
||||
-> decltype(qTokenize(*this, std::forward<Needle>(needle), flags...))
|
||||
{ return qTokenize(*this, std::forward<Needle>(needle), flags...); }
|
||||
|
||||
inline bool operator==(const QString &s) const noexcept;
|
||||
inline bool operator!=(const QString &s) const noexcept;
|
||||
inline bool operator>(const QString &s) const noexcept;
|
||||
inline bool operator<(const QString &s) const noexcept;
|
||||
inline bool operator>=(const QString &s) const noexcept;
|
||||
inline bool operator<=(const QString &s) const noexcept;
|
||||
friend inline bool operator==(QLatin1String s1, QLatin1String s2) noexcept
|
||||
{ return s1.size() == s2.size() && (!s1.size() || !memcmp(s1.latin1(), s2.latin1(), s1.size())); }
|
||||
friend inline bool operator!=(QLatin1String s1, QLatin1String s2) noexcept
|
||||
{ return !(s1 == s2); }
|
||||
friend inline bool operator<(QLatin1String s1, QLatin1String s2) noexcept
|
||||
{
|
||||
const qsizetype len = qMin(s1.size(), s2.size());
|
||||
const int r = len ? memcmp(s1.latin1(), s2.latin1(), len) : 0;
|
||||
return r < 0 || (r == 0 && s1.size() < s2.size());
|
||||
}
|
||||
friend inline bool operator>(QLatin1String s1, QLatin1String s2) noexcept
|
||||
{ return s2 < s1; }
|
||||
friend inline bool operator<=(QLatin1String s1, QLatin1String s2) noexcept
|
||||
{ return !(s1 > s2); }
|
||||
friend inline bool operator>=(QLatin1String s1, QLatin1String s2) noexcept
|
||||
{ return !(s1 < s2); }
|
||||
|
||||
// QChar <> QLatin1String
|
||||
friend inline bool operator==(QChar lhs, QLatin1String rhs) noexcept { return rhs.size() == 1 && lhs == rhs.front(); }
|
||||
friend inline bool operator< (QChar lhs, QLatin1String rhs) noexcept { return compare_helper(&lhs, 1, rhs) < 0; }
|
||||
friend inline bool operator> (QChar lhs, QLatin1String rhs) noexcept { return compare_helper(&lhs, 1, rhs) > 0; }
|
||||
friend inline bool operator!=(QChar lhs, QLatin1String rhs) noexcept { return !(lhs == rhs); }
|
||||
friend inline bool operator<=(QChar lhs, QLatin1String rhs) noexcept { return !(lhs > rhs); }
|
||||
friend inline bool operator>=(QChar lhs, QLatin1String rhs) noexcept { return !(lhs < rhs); }
|
||||
|
||||
friend inline bool operator==(QLatin1String lhs, QChar rhs) noexcept { return rhs == lhs; }
|
||||
friend inline bool operator!=(QLatin1String lhs, QChar rhs) noexcept { return !(rhs == lhs); }
|
||||
friend inline bool operator< (QLatin1String lhs, QChar rhs) noexcept { return rhs > lhs; }
|
||||
friend inline bool operator> (QLatin1String lhs, QChar rhs) noexcept { return rhs < lhs; }
|
||||
friend inline bool operator<=(QLatin1String lhs, QChar rhs) noexcept { return !(rhs < lhs); }
|
||||
friend inline bool operator>=(QLatin1String lhs, QChar rhs) noexcept { return !(rhs > lhs); }
|
||||
|
||||
// QStringView <> QLatin1String
|
||||
friend inline bool operator==(QStringView lhs, QLatin1String rhs) noexcept
|
||||
{ return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); }
|
||||
friend inline bool operator!=(QStringView lhs, QLatin1String rhs) noexcept { return !(lhs == rhs); }
|
||||
friend inline bool operator< (QStringView lhs, QLatin1String rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; }
|
||||
friend inline bool operator<=(QStringView lhs, QLatin1String rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; }
|
||||
friend inline bool operator> (QStringView lhs, QLatin1String rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; }
|
||||
friend inline bool operator>=(QStringView lhs, QLatin1String rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; }
|
||||
|
||||
friend inline bool operator==(QLatin1String lhs, QStringView rhs) noexcept
|
||||
{ return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); }
|
||||
friend inline bool operator!=(QLatin1String lhs, QStringView rhs) noexcept { return !(lhs == rhs); }
|
||||
friend inline bool operator< (QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; }
|
||||
friend inline bool operator<=(QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; }
|
||||
friend inline bool operator> (QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; }
|
||||
friend inline bool operator>=(QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; }
|
||||
|
||||
|
||||
#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
|
||||
QT_ASCII_CAST_WARN inline bool operator==(const char *s) const;
|
||||
@ -252,6 +295,9 @@ private:
|
||||
Q_ASSERT(n >= 0);
|
||||
Q_ASSERT(n <= size() - pos);
|
||||
}
|
||||
Q_CORE_EXPORT static int compare_helper(const QChar *data1, qsizetype length1,
|
||||
QLatin1String s2,
|
||||
Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept;
|
||||
qsizetype m_size;
|
||||
const char *m_data;
|
||||
};
|
||||
@ -781,19 +827,50 @@ public:
|
||||
static QString number(qulonglong, int base=10);
|
||||
static QString number(double, char f='g', int prec=6);
|
||||
|
||||
friend Q_CORE_EXPORT bool operator==(const QString &s1, const QString &s2) noexcept;
|
||||
friend Q_CORE_EXPORT bool operator<(const QString &s1, const QString &s2) noexcept;
|
||||
friend inline bool operator>(const QString &s1, const QString &s2) noexcept { return s2 < s1; }
|
||||
friend inline bool operator!=(const QString &s1, const QString &s2) noexcept { return !(s1 == s2); }
|
||||
friend inline bool operator<=(const QString &s1, const QString &s2) noexcept { return !(s1 > s2); }
|
||||
friend inline bool operator>=(const QString &s1, const QString &s2) noexcept { return !(s1 < s2); }
|
||||
friend bool operator==(const QString &s1, const QString &s2) noexcept
|
||||
{ return (s1.size() == s2.size()) && QtPrivate::compareStrings(s1, s2, Qt::CaseSensitive) == 0; }
|
||||
friend bool operator< (const QString &s1, const QString &s2) noexcept
|
||||
{ return QtPrivate::compareStrings(s1, s2, Qt::CaseSensitive) < 0; }
|
||||
friend bool operator> (const QString &s1, const QString &s2) noexcept { return s2 < s1; }
|
||||
friend bool operator!=(const QString &s1, const QString &s2) noexcept { return !(s1 == s2); }
|
||||
friend bool operator<=(const QString &s1, const QString &s2) noexcept { return !(s1 > s2); }
|
||||
friend bool operator>=(const QString &s1, const QString &s2) noexcept { return !(s1 < s2); }
|
||||
|
||||
bool operator==(QLatin1String s) const noexcept;
|
||||
bool operator<(QLatin1String s) const noexcept;
|
||||
bool operator>(QLatin1String s) const noexcept;
|
||||
inline bool operator!=(QLatin1String s) const noexcept { return !operator==(s); }
|
||||
inline bool operator<=(QLatin1String s) const noexcept { return !operator>(s); }
|
||||
inline bool operator>=(QLatin1String s) const noexcept { return !operator<(s); }
|
||||
friend bool operator==(const QString &s1, QLatin1String s2) noexcept
|
||||
{ return (s1.size() == s2.size()) && QtPrivate::compareStrings(s1, s2, Qt::CaseSensitive) == 0; }
|
||||
friend bool operator< (const QString &s1, QLatin1String s2) noexcept
|
||||
{ return QtPrivate::compareStrings(s1, s2, Qt::CaseSensitive) < 0; }
|
||||
friend bool operator> (const QString &s1, QLatin1String s2) noexcept
|
||||
{ return QtPrivate::compareStrings(s1, s2, Qt::CaseSensitive) > 0; }
|
||||
friend bool operator!=(const QString &s1, QLatin1String s2) noexcept { return !(s1 == s2); }
|
||||
friend bool operator<=(const QString &s1, QLatin1String s2) noexcept { return !(s1 > s2); }
|
||||
friend bool operator>=(const QString &s1, QLatin1String s2) noexcept { return !(s1 < s2); }
|
||||
|
||||
friend bool operator==(QLatin1String s1, const QString &s2) noexcept { return s2 == s1; }
|
||||
friend bool operator< (QLatin1String s1, const QString &s2) noexcept { return s2 > s1; }
|
||||
friend bool operator> (QLatin1String s1, const QString &s2) noexcept { return s2 < s1; }
|
||||
friend bool operator!=(QLatin1String s1, const QString &s2) noexcept { return s2 != s1; }
|
||||
friend bool operator<=(QLatin1String s1, const QString &s2) noexcept { return s2 >= s1; }
|
||||
friend bool operator>=(QLatin1String s1, const QString &s2) noexcept { return s2 <= s1; }
|
||||
|
||||
// QChar <> QString
|
||||
friend inline bool operator==(QChar lhs, const QString &rhs) noexcept
|
||||
{ return rhs.size() == 1 && lhs == rhs.front(); }
|
||||
friend inline bool operator< (QChar lhs, const QString &rhs) noexcept
|
||||
{ return compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; }
|
||||
friend inline bool operator> (QChar lhs, const QString &rhs) noexcept
|
||||
{ return compare_helper(&lhs, 1, rhs.data(), rhs.size()) > 0; }
|
||||
|
||||
friend inline bool operator!=(QChar lhs, const QString &rhs) noexcept { return !(lhs == rhs); }
|
||||
friend inline bool operator<=(QChar lhs, const QString &rhs) noexcept { return !(lhs > rhs); }
|
||||
friend inline bool operator>=(QChar lhs, const QString &rhs) noexcept { return !(lhs < rhs); }
|
||||
|
||||
friend inline bool operator==(const QString &lhs, QChar rhs) noexcept { return rhs == lhs; }
|
||||
friend inline bool operator!=(const QString &lhs, QChar rhs) noexcept { return !(rhs == lhs); }
|
||||
friend inline bool operator< (const QString &lhs, QChar rhs) noexcept { return rhs > lhs; }
|
||||
friend inline bool operator> (const QString &lhs, QChar rhs) noexcept { return rhs < lhs; }
|
||||
friend inline bool operator<=(const QString &lhs, QChar rhs) noexcept { return !(rhs < lhs); }
|
||||
friend inline bool operator>=(const QString &lhs, QChar rhs) noexcept { return !(rhs > lhs); }
|
||||
|
||||
// ASCII compatibility
|
||||
#if defined(QT_RESTRICTED_CAST_FROM_ASCII)
|
||||
@ -937,13 +1014,6 @@ private:
|
||||
DataPointer d;
|
||||
static const char16_t _empty;
|
||||
|
||||
friend inline bool operator==(QChar, const QString &) noexcept;
|
||||
friend inline bool operator< (QChar, const QString &) noexcept;
|
||||
friend inline bool operator> (QChar, const QString &) noexcept;
|
||||
friend inline bool operator==(QChar, QLatin1String) noexcept;
|
||||
friend inline bool operator< (QChar, QLatin1String) noexcept;
|
||||
friend inline bool operator> (QChar, QLatin1String) noexcept;
|
||||
|
||||
void reallocData(qsizetype alloc, Data::ArrayOptions options);
|
||||
void reallocGrowData(qsizetype alloc, Data::ArrayOptions options);
|
||||
static int compare_helper(const QChar *data1, qsizetype length1,
|
||||
@ -952,9 +1022,6 @@ private:
|
||||
static int compare_helper(const QChar *data1, qsizetype length1,
|
||||
const char *data2, qsizetype length2,
|
||||
Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
||||
static int compare_helper(const QChar *data1, qsizetype length1,
|
||||
QLatin1String s2,
|
||||
Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept;
|
||||
static int localeAwareCompare_helper(const QChar *data1, qsizetype length1,
|
||||
const QChar *data2, qsizetype length2);
|
||||
static QString toLower_helper(const QString &str);
|
||||
@ -1207,36 +1274,6 @@ inline bool QString::contains(QChar c, Qt::CaseSensitivity cs) const
|
||||
inline bool QString::contains(QStringView s, Qt::CaseSensitivity cs) const noexcept
|
||||
{ return indexOf(s, 0, cs) != -1; }
|
||||
|
||||
inline bool operator==(QLatin1String s1, QLatin1String s2) noexcept
|
||||
{ return s1.size() == s2.size() && (!s1.size() || !memcmp(s1.latin1(), s2.latin1(), s1.size())); }
|
||||
inline bool operator!=(QLatin1String s1, QLatin1String s2) noexcept
|
||||
{ return !operator==(s1, s2); }
|
||||
inline bool operator<(QLatin1String s1, QLatin1String s2) noexcept
|
||||
{
|
||||
const qsizetype len = qMin(s1.size(), s2.size());
|
||||
const int r = len ? memcmp(s1.latin1(), s2.latin1(), len) : 0;
|
||||
return r < 0 || (r == 0 && s1.size() < s2.size());
|
||||
}
|
||||
inline bool operator>(QLatin1String s1, QLatin1String s2) noexcept
|
||||
{ return operator<(s2, s1); }
|
||||
inline bool operator<=(QLatin1String s1, QLatin1String s2) noexcept
|
||||
{ return !operator>(s1, s2); }
|
||||
inline bool operator>=(QLatin1String s1, QLatin1String s2) noexcept
|
||||
{ return !operator<(s1, s2); }
|
||||
|
||||
inline bool QLatin1String::operator==(const QString &s) const noexcept
|
||||
{ return s == *this; }
|
||||
inline bool QLatin1String::operator!=(const QString &s) const noexcept
|
||||
{ return s != *this; }
|
||||
inline bool QLatin1String::operator>(const QString &s) const noexcept
|
||||
{ return s < *this; }
|
||||
inline bool QLatin1String::operator<(const QString &s) const noexcept
|
||||
{ return s > *this; }
|
||||
inline bool QLatin1String::operator>=(const QString &s) const noexcept
|
||||
{ return s <= *this; }
|
||||
inline bool QLatin1String::operator<=(const QString &s) const noexcept
|
||||
{ return s >= *this; }
|
||||
|
||||
#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
|
||||
inline bool QString::operator==(const char *s) const
|
||||
{ return QString::compare_helper(constData(), size(), s, -1) == 0; }
|
||||
@ -1400,44 +1437,6 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QString::SectionFlags)
|
||||
inline int QString::compare(QStringView s, Qt::CaseSensitivity cs) const noexcept
|
||||
{ return -s.compare(*this, cs); }
|
||||
|
||||
// QChar <> QString
|
||||
inline bool operator==(QChar lhs, const QString &rhs) noexcept
|
||||
{ return rhs.size() == 1 && lhs == rhs.front(); }
|
||||
inline bool operator< (QChar lhs, const QString &rhs) noexcept
|
||||
{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; }
|
||||
inline bool operator> (QChar lhs, const QString &rhs) noexcept
|
||||
{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) > 0; }
|
||||
|
||||
inline bool operator!=(QChar lhs, const QString &rhs) noexcept { return !(lhs == rhs); }
|
||||
inline bool operator<=(QChar lhs, const QString &rhs) noexcept { return !(lhs > rhs); }
|
||||
inline bool operator>=(QChar lhs, const QString &rhs) noexcept { return !(lhs < rhs); }
|
||||
|
||||
inline bool operator==(const QString &lhs, QChar rhs) noexcept { return rhs == lhs; }
|
||||
inline bool operator!=(const QString &lhs, QChar rhs) noexcept { return !(rhs == lhs); }
|
||||
inline bool operator< (const QString &lhs, QChar rhs) noexcept { return rhs > lhs; }
|
||||
inline bool operator> (const QString &lhs, QChar rhs) noexcept { return rhs < lhs; }
|
||||
inline bool operator<=(const QString &lhs, QChar rhs) noexcept { return !(rhs < lhs); }
|
||||
inline bool operator>=(const QString &lhs, QChar rhs) noexcept { return !(rhs > lhs); }
|
||||
|
||||
// QChar <> QLatin1String
|
||||
inline bool operator==(QChar lhs, QLatin1String rhs) noexcept
|
||||
{ return rhs.size() == 1 && lhs == rhs.front(); }
|
||||
inline bool operator< (QChar lhs, QLatin1String rhs) noexcept
|
||||
{ return QString::compare_helper(&lhs, 1, rhs) < 0; }
|
||||
inline bool operator> (QChar lhs, QLatin1String rhs) noexcept
|
||||
{ return QString::compare_helper(&lhs, 1, rhs) > 0; }
|
||||
|
||||
inline bool operator!=(QChar lhs, QLatin1String rhs) noexcept { return !(lhs == rhs); }
|
||||
inline bool operator<=(QChar lhs, QLatin1String rhs) noexcept { return !(lhs > rhs); }
|
||||
inline bool operator>=(QChar lhs, QLatin1String rhs) noexcept { return !(lhs < rhs); }
|
||||
|
||||
inline bool operator==(QLatin1String lhs, QChar rhs) noexcept { return rhs == lhs; }
|
||||
inline bool operator!=(QLatin1String lhs, QChar rhs) noexcept { return !(rhs == lhs); }
|
||||
inline bool operator< (QLatin1String lhs, QChar rhs) noexcept { return rhs > lhs; }
|
||||
inline bool operator> (QLatin1String lhs, QChar rhs) noexcept { return rhs < lhs; }
|
||||
inline bool operator<=(QLatin1String lhs, QChar rhs) noexcept { return !(rhs < lhs); }
|
||||
inline bool operator>=(QLatin1String lhs, QChar rhs) noexcept { return !(rhs > lhs); }
|
||||
|
||||
// QStringView <> QStringView
|
||||
inline bool operator==(QStringView lhs, QStringView rhs) noexcept { return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); }
|
||||
inline bool operator!=(QStringView lhs, QStringView rhs) noexcept { return !(lhs == rhs); }
|
||||
@ -1461,21 +1460,6 @@ inline bool operator<=(QChar lhs, QStringView rhs) noexcept { return QStringView
|
||||
inline bool operator> (QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) > rhs; }
|
||||
inline bool operator>=(QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) >= rhs; }
|
||||
|
||||
// QStringView <> QLatin1String
|
||||
inline bool operator==(QStringView lhs, QLatin1String rhs) noexcept { return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); }
|
||||
inline bool operator!=(QStringView lhs, QLatin1String rhs) noexcept { return !(lhs == rhs); }
|
||||
inline bool operator< (QStringView lhs, QLatin1String rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; }
|
||||
inline bool operator<=(QStringView lhs, QLatin1String rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; }
|
||||
inline bool operator> (QStringView lhs, QLatin1String rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; }
|
||||
inline bool operator>=(QStringView lhs, QLatin1String rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; }
|
||||
|
||||
inline bool operator==(QLatin1String lhs, QStringView rhs) noexcept { return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); }
|
||||
inline bool operator!=(QLatin1String lhs, QStringView rhs) noexcept { return !(lhs == rhs); }
|
||||
inline bool operator< (QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; }
|
||||
inline bool operator<=(QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; }
|
||||
inline bool operator> (QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; }
|
||||
inline bool operator>=(QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; }
|
||||
|
||||
inline int QString::localeAwareCompare(QStringView s) const
|
||||
{ return localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); }
|
||||
inline int QString::localeAwareCompare(QStringView s1, QStringView s2)
|
||||
|
Loading…
Reference in New Issue
Block a user