Strings: get rid of the last std::char_traits use
LLVM's libc++ became pedantic and insists on only accepting instantiations for one of the standard Char types, so remove all uses of it with a template parameter. Complements dc2ae08e02730ab795445bc047221aa56914f723. Pick-to: 6.7 Fixes: QTBUG-126214 Task-number: QTBUG-122753 Change-Id: I8c5c4dba62924541bfb0fffd17d7d8ddc78338bb Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io> (cherry picked from commit ab05e05f60253b9be615c09aa340ee75f2e5bcaf) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
28b9a653ea
commit
fce7a45268
@ -137,7 +137,7 @@ private:
|
||||
static constexpr qsizetype lengthHelperPointer(const Char *str) noexcept
|
||||
{
|
||||
if (q20::is_constant_evaluated())
|
||||
return qsizetype(std::char_traits<Char>::length(str));
|
||||
return QtPrivate::lengthHelperPointer(str);
|
||||
if constexpr (sizeof(Char) == sizeof(char16_t))
|
||||
return QtPrivate::qustrlen(reinterpret_cast<const char16_t*>(str));
|
||||
else
|
||||
|
@ -68,7 +68,15 @@ struct IsContainerCompatibleWithQByteArrayView<T, std::enable_if_t<
|
||||
template <typename Char>
|
||||
static constexpr qsizetype lengthHelperPointer(const Char *data) noexcept
|
||||
{
|
||||
return qsizetype(std::char_traits<Char>::length(data));
|
||||
// std::char_traits can only be used with one of the regular char types
|
||||
// (char, char16_t, wchar_t, but not uchar or QChar), so we roll the loop
|
||||
// out by ourselves.
|
||||
qsizetype i = 0;
|
||||
if (!data)
|
||||
return i;
|
||||
while (data[i] != Char(0))
|
||||
++i;
|
||||
return i;
|
||||
}
|
||||
|
||||
} // namespace QtPrivate
|
||||
|
@ -108,7 +108,7 @@ private:
|
||||
static constexpr qsizetype lengthHelperPointer(const Char *str) noexcept
|
||||
{
|
||||
if (q20::is_constant_evaluated())
|
||||
return std::char_traits<Char>::length(str);
|
||||
return QtPrivate::lengthHelperPointer(str);
|
||||
return QtPrivate::qustrlen(reinterpret_cast<const char16_t *>(str));
|
||||
}
|
||||
static qsizetype lengthHelperPointer(const QChar *str) noexcept
|
||||
|
@ -134,14 +134,12 @@ private:
|
||||
return qsizetype(std::size(c));
|
||||
}
|
||||
|
||||
// Note: Do not replace with std::size(const Char (&)[N]), cause the result
|
||||
// Note: Do not replace with std::size(const Char (&)[N]), because the result
|
||||
// will be of by one.
|
||||
template <typename Char, size_t N>
|
||||
static constexpr qsizetype lengthHelperContainer(const Char (&str)[N]) noexcept
|
||||
{
|
||||
const auto it = std::char_traits<Char>::find(str, N, Char(0));
|
||||
const auto end = it ? it : std::next(str, N);
|
||||
return qsizetype(std::distance(str, end));
|
||||
return QtPrivate::lengthHelperContainer(str);
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
@ -174,8 +172,7 @@ public:
|
||||
#else
|
||||
template <typename Pointer, if_compatible_pointer<Pointer> = true>
|
||||
constexpr QBasicUtf8StringView(const Pointer &str) noexcept
|
||||
: QBasicUtf8StringView(str,
|
||||
str ? std::char_traits<std::remove_cv_t<std::remove_pointer_t<Pointer>>>::length(str) : 0) {}
|
||||
: QBasicUtf8StringView(str, QtPrivate::lengthHelperPointer(str)) {}
|
||||
#endif
|
||||
|
||||
#ifdef Q_QDOC
|
||||
|
Loading…
x
Reference in New Issue
Block a user