4#ifndef QUTF8STRINGVIEW_H
5#define QUTF8STRINGVIEW_H
8#pragma qt_class(QUtf8StringView)
11#include <QtCore/qstringalgorithms.h>
12#include <QtCore/qstringfwd.h>
13#include <QtCore/qarraydata.h>
14#include <QtCore/qbytearrayview.h>
15#include <QtCore/qcompare.h>
16#include <QtCore/qcontainerfwd.h>
20#include <QtCore/q20type_traits.h>
25template <
typename Char>
34template <
typename Char>
38template <
typename Pointer>
39struct IsCompatiblePointer8Helper : std::false_type {};
40template <
typename Char>
41struct IsCompatiblePointer8Helper<Char*>
42 : IsCompatibleChar8Type<Char> {};
47template <
typename T,
typename Enable =
void>
48struct IsContainerCompatibleWithQUtf8StringView : std::false_type {};
87struct wrap_char {
using type =
char; };
92#define QBasicUtf8StringView QUtf8StringView
94template <
bool UseChar8T>
121 template <
typename Char>
127 template <
typename T>
130 template <
typename T>
133 template <
typename Container>
134 static constexpr qsizetype lengthHelperContainer(
const Container &c)
noexcept
136 return qsizetype(
std::size(c));
141 template <
typename Char, size_t N>
142 static constexpr qsizetype lengthHelperContainer(
const Char (&str)[N])
noexcept
144 return QtPrivate::lengthHelperContainer(str);
147 template <
typename Char>
148 static const storage_type *castHelper(
const Char *str)
noexcept
159 template <
typename Char, if_compatible_char<Char> =
true>
164 template <
typename Char, if_compatible_char<Char> =
true>
172 template <
typename Char>
175 template <
typename Pointer, if_compatible_pointer<Pointer> =
true>
179 template <
typename Char, if_compatible_char<Char> =
true>
188 template <
typename String, if_compatible_qstring_like<String> =
true>
193 template <
typename Container, if_compatible_container<Container> =
true>
197#if defined(__cpp_char8_t) && !defined(Q_QDOC)
202 template <
typename Char, size_t Size, if_compatible_char<Char> =
true>
215 { verify(n, 1);
return m_data[n]; }
223 template <
typename...Args>
230 auto result = QContainerImplHelper::mid(size(), &pos, &n);
231 return result == QContainerImplHelper::Null ? QBasicUtf8StringView() : QBasicUtf8StringView(m_data + pos, n);
236 if (size_t(n) >= size_t(size()))
238 return QBasicUtf8StringView(m_data, n);
243 if (size_t(n) >= size_t(size()))
245 return QBasicUtf8StringView(m_data + m_size - n, n);
249 { verify(pos, 0);
return QBasicUtf8StringView{m_data + pos, m_size - pos}; }
251 { verify(pos, n);
return QBasicUtf8StringView(m_data + pos, n); }
253 { verify(0, n);
return sliced(0, n); }
255 { verify(0, n);
return sliced(m_size - n, n); }
257 { verify(0, n);
return sliced(0, m_size - n); }
260 { *
this = sliced(pos);
return *
this; }
262 { *
this = sliced(pos, n);
return *
this; }
265 { verify(0, n); m_size = n; }
266 constexpr void chop(qsizetype n)
267 { verify(0, n); m_size -= n; }
271 return QByteArrayView(
reinterpret_cast<
const char *>(data()), size()).isValidUtf8();
293#ifdef __cpp_lib_char8_t
333 return QtPrivate::MaxAllocSize - 1;
339 return QtPrivate::compareStrings(QBasicUtf8StringView<
false>(lhs.data(), lhs.size()),
340 QBasicUtf8StringView<
false>(rhs.data(), rhs.size()));
346 return lhs.size() == rhs.size()
347 && QtPrivate::equalStrings(QBasicUtf8StringView<
false>(lhs.data(), lhs.size()),
348 QBasicUtf8StringView<
false>(rhs.data(), rhs.size()));
354 return Qt::compareThreeWay(res, 0);
393#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
444#undef QBasicUtf8StringView
446template <
bool UseChar8T>
449template <
typename QStringLike, std::enable_if_t<std::is_same_v<QStringLike, QByteArray>,
bool> =
true>
451{
return q_no_char8_t::QUtf8StringView(s.begin(), s.size()); }
constexpr QBasicUtf8StringView mid(qsizetype pos, qsizetype n=-1) const
const_reverse_iterator crend() const noexcept
constexpr QBasicUtf8StringView & slice(qsizetype pos, qsizetype n)
constexpr QBasicUtf8StringView first(qsizetype n) const
constexpr bool empty() const noexcept
constexpr void truncate(qsizetype n)
value_type & const_reference
constexpr QBasicUtf8StringView(const Char *f, const Char *l)
constexpr QBasicUtf8StringView(const Pointer &str) noexcept
constexpr qsizetype size() const noexcept
constexpr QBasicUtf8StringView(const Char *str, qsizetype len)
const_reverse_iterator rbegin() const noexcept
constexpr QBasicUtf8StringView sliced(qsizetype pos) const
typename std::conditional< UseChar8T, QtPrivate::hide_char8_t, QtPrivate::wrap_char >::type::type storage_type
bool isValidUtf8() const noexcept
bool equal(QChar other) const noexcept
const_iterator begin() const noexcept
QString arg(Args &&...args) const
static constexpr QBasicUtf8StringView fromArray(const Char(&string)[Size]) noexcept
constexpr QBasicUtf8StringView & slice(qsizetype pos)
constexpr storage_type operator[](qsizetype n) const
friend Qt::strong_ordering compareThreeWay(const QBasicUtf8StringView &lhs, const QBasicUtf8StringView &rhs) noexcept
bool equal(const QByteArray &other) const noexcept
friend bool comparesEqual(const QBasicUtf8StringView &lhs, const QBasicUtf8StringView &rhs) noexcept
const_iterator cend() const noexcept
constexpr storage_type back() const
constexpr QBasicUtf8StringView sliced(qsizetype pos, qsizetype n) const
const_reverse_iterator rend() const noexcept
int compare(const QByteArray &other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
value_type * const_pointer
const_pointer const_iterator
int compare(QStringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QBasicUtf8StringView last(qsizetype n) const
static constexpr qsizetype maxSize() noexcept
constexpr QBasicUtf8StringView(std::nullptr_t) noexcept
constexpr storage_type at(qsizetype n) const
const storage_type value_type
constexpr QBasicUtf8StringView(const Char(&str)[]) noexcept
constexpr storage_type front() const
constexpr QBasicUtf8StringView left(qsizetype n) const
constexpr QBasicUtf8StringView() noexcept
const_iterator end() const noexcept
constexpr void chop(qsizetype n)
const_reverse_iterator crbegin() const noexcept
const_iterator cbegin() const noexcept
constexpr const_pointer data() const noexcept
constexpr QBasicUtf8StringView right(qsizetype n) const
constexpr QBasicUtf8StringView chopped(qsizetype n) const
q_no_char8_t::QUtf8StringView qToUtf8StringViewIgnoringNull(const QStringLike &s) noexcept
Q_DECLARE_TYPEINFO_BODY(QBasicUtf8StringView< UseChar8T >, Q_PRIMITIVE_TYPE)