Add QLatin1StringView vs QByteArrayView relational operators
... by using the new comparison helper macros. The operators are marked as QT_ASCII_CAST_WARN, like the pre-existing relational operators with QByteArray and const char *. This allows to enable related tests in tst_qstringapisymmetry. Task-number: QTBUG-117661 Task-number: QTBUG-108805 Change-Id: Ic9bcddffc25585edb7375c3e651d49d040a60454 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
de16185068
commit
05e5b87ba0
@ -8,6 +8,7 @@
|
||||
#define QLATIN1STRINGVIEW_H
|
||||
|
||||
#include <QtCore/qchar.h>
|
||||
#include <QtCore/qcompare.h>
|
||||
#include <QtCore/qnamespace.h>
|
||||
#include <QtCore/qtversionchecks.h>
|
||||
#include <QtCore/qstringview.h>
|
||||
@ -299,6 +300,17 @@ public:
|
||||
friend bool operator>=(QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; }
|
||||
|
||||
|
||||
private:
|
||||
friend bool comparesEqual(const QLatin1StringView &lhs, const QByteArrayView &rhs) noexcept
|
||||
{ return equal_helper(lhs, rhs.data(), rhs.size()); }
|
||||
friend Qt::strong_ordering
|
||||
compareThreeWay(const QLatin1StringView &lhs, const QByteArrayView &rhs) noexcept
|
||||
{
|
||||
const int res = compare_helper(lhs, rhs.data(), rhs.size());
|
||||
return Qt::compareThreeWay(res, 0);
|
||||
}
|
||||
|
||||
public:
|
||||
#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
|
||||
QT_ASCII_CAST_WARN inline bool operator==(const char *s) const;
|
||||
QT_ASCII_CAST_WARN inline bool operator!=(const char *s) const;
|
||||
@ -314,6 +326,8 @@ public:
|
||||
QT_ASCII_CAST_WARN inline bool operator<=(const QByteArray &s) const;
|
||||
QT_ASCII_CAST_WARN inline bool operator>=(const QByteArray &s) const;
|
||||
|
||||
Q_DECLARE_STRONGLY_ORDERED(QLatin1StringView, QByteArrayView, QT_ASCII_CAST_WARN)
|
||||
|
||||
QT_ASCII_CAST_WARN friend bool operator==(const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) == 0; }
|
||||
QT_ASCII_CAST_WARN friend bool operator!=(const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) != 0; }
|
||||
QT_ASCII_CAST_WARN friend bool operator< (const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) > 0; }
|
||||
@ -333,6 +347,7 @@ private:
|
||||
}
|
||||
static int compare_helper(const QLatin1StringView &s1, const char *s2) noexcept
|
||||
{ return compare_helper(s1, s2, qstrlen(s2)); }
|
||||
Q_CORE_EXPORT static bool equal_helper(QLatin1StringView s1, const char *s2, qsizetype len) noexcept;
|
||||
Q_CORE_EXPORT static int compare_helper(const QLatin1StringView &s1, const char *s2, qsizetype len) noexcept;
|
||||
Q_CORE_EXPORT static int compare_helper(const QChar *data1, qsizetype length1,
|
||||
QLatin1StringView s2,
|
||||
|
@ -6584,6 +6584,18 @@ int QString::compare_helper(const QChar *data1, qsizetype length1, const char *d
|
||||
\overload compare()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\since 6.8
|
||||
*/
|
||||
bool QLatin1StringView::equal_helper(QLatin1StringView s1, const char *s2, qsizetype len) noexcept
|
||||
{
|
||||
// because qlatin1stringview.h can't include qutf8stringview.h
|
||||
Q_ASSERT(len >= 0);
|
||||
Q_ASSERT(s2 || len == 0);
|
||||
return QtPrivate::equalStrings(s1, QUtf8StringView(s2, len));
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\since 6.6
|
||||
|
@ -280,10 +280,8 @@ private Q_SLOTS:
|
||||
void compare_QLatin1String_QLatin1String() { compare_impl<QLatin1String, QLatin1String>(); }
|
||||
void compare_QLatin1String_QByteArray_data() { compare_data(); }
|
||||
void compare_QLatin1String_QByteArray() { compare_impl<QLatin1String, QByteArray>(); }
|
||||
#ifdef AMBIGUOUS_CALL
|
||||
void compare_QLatin1String_QByteArrayView_data() { compare_data(); }
|
||||
void compare_QLatin1String_QByteArrayView() { compare_impl<QLatin1String, QByteArrayView>(); }
|
||||
#endif
|
||||
void compare_QLatin1String_const_char_star_data() { compare_data(); }
|
||||
void compare_QLatin1String_const_char_star() { compare_impl<QLatin1String, const char *>(); }
|
||||
|
||||
@ -323,8 +321,10 @@ private Q_SLOTS:
|
||||
#ifdef AMBIGUOUS_CALL
|
||||
void compare_QByteArrayView_QUtf8StringView_data() { compare_data(); }
|
||||
void compare_QByteArrayView_QUtf8StringView() { compare_impl<QByteArrayView, QUtf8StringView>(); }
|
||||
#endif
|
||||
void compare_QByteArrayView_QLatin1String_data() { compare_data(); }
|
||||
void compare_QByteArrayView_QLatin1String() { compare_impl<QByteArrayView, QLatin1String>(); }
|
||||
#ifdef AMBIGUOUS_CALL
|
||||
void compare_QByteArrayView_QByteArray_data() { compare_data(); }
|
||||
void compare_QByteArrayView_QByteArray() { compare_impl<QByteArrayView, QByteArray>(); }
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user