tst_qstringapisymmetry: Don't pretend that QByteArray contains UTF-8
The name of is_utf8_encoded type seems to imply that QByteArray and const char * contain UTF-8 encoded data. This is not always the case. When used with QByteArray API, those types are handled as containing ASCII-only. It's only when used with APIs of other classes (QString, QLatin1String) they are handled as UTF-8. This renames the check to is_bytearray_like_v and clarifies its usage. No need to handle QUtf8StringView this way because it works just fine with the current testcases. While at it, also remove unused is_latin1_encoded trait. Task-number: QTBUG-92021 Change-Id: I44e40cf3c0dd07e5b3cf1e47ff7a04f1c548aa97 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
8a66e3cfe5
commit
2c0bdd38cb
@ -1041,16 +1041,14 @@ MAKE(QAnyStringViewUsingU8) { return {QAnyStringView{u8}}; }
|
||||
MAKE(QAnyStringViewUsingU16) { return {QAnyStringView{sv}}; }
|
||||
#undef MAKE
|
||||
|
||||
template <typename> struct is_utf8_encoded : std::false_type {};
|
||||
template <> struct is_utf8_encoded<const char*> : std::true_type {};
|
||||
template <> struct is_utf8_encoded<QByteArray> : std::true_type {};
|
||||
template <> struct is_utf8_encoded<QUtf8StringView> : std::true_type {};
|
||||
|
||||
template <typename> struct is_latin1_encoded : std::false_type {};
|
||||
template <> struct is_latin1_encoded<QLatin1String> : std::true_type {};
|
||||
// Some types have ASCII-only case-insensitive compare, but are handled as containing
|
||||
// UTF-8 when implicitly converted to QString.
|
||||
template <typename> constexpr bool is_bytearray_like_v = false;
|
||||
template <> constexpr bool is_bytearray_like_v<const char *> = true;
|
||||
template <> constexpr bool is_bytearray_like_v<QByteArray> = true;
|
||||
|
||||
template <typename LHS, typename RHS>
|
||||
constexpr bool has_nothrow_member_compare_v = is_utf8_encoded<LHS>::value == is_utf8_encoded<RHS>::value;
|
||||
constexpr bool has_nothrow_member_compare_v = is_bytearray_like_v<LHS> == is_bytearray_like_v<RHS>;
|
||||
|
||||
template <typename LHS, typename RHS>
|
||||
void tst_QStringApiSymmetry::compare_impl() const
|
||||
@ -1119,11 +1117,11 @@ void tst_QStringApiSymmetry::member_compare_impl() const
|
||||
|
||||
QCOMPARE(sign(lhs.compare(rhs)), caseSensitiveCompareResult);
|
||||
QCOMPARE(sign(lhs.compare(rhs, Qt::CaseSensitive)), caseSensitiveCompareResult);
|
||||
if (is_utf8_encoded<LHS>::value && is_utf8_encoded<RHS>::value &&
|
||||
if (is_bytearray_like_v<LHS> && is_bytearray_like_v<RHS> &&
|
||||
caseSensitiveCompareResult != caseInsensitiveCompareResult &&
|
||||
(!QtPrivate::isAscii(lhsUnicode) || !QtPrivate::isAscii(rhsUnicode)))
|
||||
{
|
||||
QEXPECT_FAIL("", "Qt is missing a case-insensitive UTF-8/UTF-8 comparator", Continue);
|
||||
QEXPECT_FAIL("", "The types don't support non-ASCII case-insensitive comparison", Continue);
|
||||
}
|
||||
QCOMPARE(sign(lhs.compare(rhs, Qt::CaseInsensitive)), caseInsensitiveCompareResult);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user