3#ifndef QUTF8STRINGVIEW_H
4#define QUTF8STRINGVIEW_H
7#pragma qt_class(QUtf8StringView)
10#include <QtCore/qstringalgorithms.h>
11#include <QtCore/qstringfwd.h>
12#include <QtCore/qarraydata.h>
13#include <QtCore/qbytearrayview.h>
14#include <QtCore/qcompare.h>
18#include <QtCore/q20type_traits.h>
23template <
typename Char>
26 std::is_same<Char, char8_t>,
28 std::is_same<Char, char>,
29 std::is_same<Char, uchar>,
30 std::is_same<Char, signed char>
32template <
typename Char>
34 = IsCompatibleChar8TypeHelper<q20::remove_cvref_t<Char>>;
36template <
typename Po
inter>
38template <
typename Char>
40 : IsCompatibleChar8Type<Char> {};
41template <
typename Po
inter>
43 = IsCompatiblePointer8Helper<q20::remove_cvref_t<Pointer>>;
45template <
typename T,
typename Enable =
void>
51 IsCompatiblePointer8<decltype(std::data(std::declval<const T &>()))>,
54 decltype(std::size(std::declval<const T &>())),
58 IsCompatibleChar8Type<typename std::iterator_traits<
59 decltype(std::begin(std::declval<const T &>()))>::value_type
62 decltype( std::begin(std::declval<const T &>()) != std::end(std::declval<const T &>()) ),
67 std::negation<std::is_same<std::decay_t<T>, QByteArray>>,
70 std::negation<std::is_same<std::decay_t<T>, QLatin1StringView>>,
73 std::negation<std::disjunction<
74 std::is_same<std::decay_t<T>, QBasicUtf8StringView<true>>,
75 std::is_same<std::decay_t<T>, QBasicUtf8StringView<false>>
77 >>> : std::true_type {};
90#define QBasicUtf8StringView QUtf8StringView
92template <
bool UseChar8T>
119 template <
typename Char>
120 using if_compatible_char = std::enable_if_t<QtPrivate::IsCompatibleChar8Type<Char>::value,
bool>;
122 template <
typename Po
inter>
123 using if_compatible_pointer = std::enable_if_t<QtPrivate::IsCompatiblePointer8<Pointer>::value,
bool>;
125 template <
typename T>
126 using if_compatible_qstring_like = std::enable_if_t<std::is_same_v<T, QByteArray>,
bool>;
128 template <
typename T>
129 using if_compatible_container = std::enable_if_t<QtPrivate::IsContainerCompatibleWithQUtf8StringView<T>::value,
bool>;
131 template <
typename Container>
132 static constexpr qsizetype lengthHelperContainer(
const Container &
c)
noexcept
139 template <
typename Char,
size_t N>
140 static constexpr qsizetype lengthHelperContainer(
const Char (&
str)[N])
noexcept
142 const auto it = std::char_traits<Char>::find(
str, N,
Char(0));
147 template <
typename Char>
155 : m_data(
nullptr), m_size(0) {}
159 template <
typename Char, if_compatible_
char<Char> = true>
161 : m_data(castHelper(
str)),
164 template <
typename Char, if_compatible_
char<Char> = true>
169 template <
typename Char,
size_t N>
172 template <
typename Char>
175 template <
typename Po
inter, if_compatible_po
inter<Po
inter> = true>
178 str ? std::char_traits<std::remove_cv_t<std::remove_pointer_t<Pointer>>>
::length(
str) : 0) {}
185 template <
typename String, if_compatible_q
string_like<String> = true>
190 template <
typename Container, if_compatible_container<Container> = true>
194#if defined(__cpp_char8_t) && !defined(Q_QDOC)
199 template <
typename Char,
size_t Size, if_compatible_
char<Char> = true>
208 [[nodiscard]]
const char8_t *utf8() const noexcept {
return reinterpret_cast<const char8_t*
>(m_data); }
212 { verify(
n, 1);
return m_data[
n]; }
230 if (
size_t(
n) >=
size_t(
size()))
237 if (
size_t(
n) >=
size_t(
size()))
247 { verify(0,
n);
return sliced(0,
n); }
249 { verify(0,
n);
return sliced(m_size -
n,
n); }
251 { verify(0,
n);
return sliced(0, m_size -
n); }
254 { verify(0,
n); m_size =
n; }
256 { verify(0,
n); m_size -=
n; }
275 [[nodiscard]]
constexpr bool empty() const noexcept {
return size() == 0; }
279 [[nodiscard]]
Q_IMPLICIT operator std::basic_string_view<storage_type>() const noexcept
280 {
return std::basic_string_view<storage_type>(
data(),
size_t(
size())); }
285 [[nodiscard]]
constexpr bool isNull() const noexcept {
return !m_data; }
286 [[nodiscard]]
constexpr bool isEmpty() const noexcept {
return empty(); }
314 QBasicUtf8StringView<false>(rhs.data(), rhs.size()));
320 return lhs.size() == rhs.size()
322 QBasicUtf8StringView<false>(rhs.data(), rhs.size()));
335 return lhs.equal(rhs);
340 const int res = lhs.compare(rhs);
347 {
return lhs.equal(rhs); }
351 const int res = lhs.compare(rhs);
357 {
return lhs.equal(rhs); }
361 const int res = lhs.compare(rhs);
367#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
371 return lhs.size() == rhs.size()
373 QBasicUtf8StringView<false>(rhs.data(), rhs.size()));
379 QBasicUtf8StringView<false>(rhs.data(), rhs.size()));
387 return lhs.equal(rhs);
392 const int res = lhs.compare(rhs);
422#undef QBasicUtf8StringView
424template <
bool UseChar8T>
427template <
typename QStringLike, std::enable_if_t<std::is_same_v<QStringLike, QByteArray>,
bool> = true>
429{
return q_no_char8_t::QUtf8StringView(
s.begin(),
s.size()); }
friend bool comparesEqual(const QBasicUtf8StringView &lhs, const QByteArray &rhs) noexcept
constexpr QBasicUtf8StringView mid(qsizetype pos, qsizetype n=-1) const
const_reverse_iterator crend() const noexcept
constexpr QBasicUtf8StringView first(qsizetype n) const
constexpr bool empty() const noexcept
friend bool comparesEqual(const QBasicUtf8StringView &lhs, const QStringView &rhs) noexcept
constexpr bool isNull() const noexcept
int compare(QBasicUtf8StringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr void truncate(qsizetype n)
value_type & const_reference
constexpr QBasicUtf8StringView(const Char *f, const Char *l)
constexpr QBasicUtf8StringView(const Container &c) noexcept
constexpr QBasicUtf8StringView(const Pointer &str) noexcept
friend Qt::strong_ordering compareThreeWay(const QBasicUtf8StringView &lhs, const QLatin1StringView &rhs) noexcept
friend Qt::strong_ordering compareThreeWay(const QBasicUtf8StringView &lhs, const char *rhs) 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
constexpr qsizetype length() const noexcept
constexpr bool isEmpty() const noexcept
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
friend bool comparesEqual(const QBasicUtf8StringView &lhs, const QByteArrayView &rhs) noexcept
static constexpr QBasicUtf8StringView fromArray(const Char(&string)[Size]) noexcept
constexpr storage_type operator[](qsizetype n) const
friend Qt::strong_ordering compareThreeWay(const QBasicUtf8StringView &lhs, const QByteArray &rhs) noexcept
friend Qt::strong_ordering compareThreeWay(const QBasicUtf8StringView &lhs, const QBasicUtf8StringView &rhs) noexcept
friend bool comparesEqual(const QBasicUtf8StringView &lhs, const QBasicUtf8StringView &rhs) noexcept
const_iterator cend() const noexcept
constexpr storage_type back() const
friend Qt::strong_ordering compareThreeWay(const QBasicUtf8StringView &lhs, const QChar &rhs) noexcept
constexpr QBasicUtf8StringView sliced(qsizetype pos, qsizetype n) const
QBasicUtf8StringView(const String &str) noexcept
const_reverse_iterator rend() const noexcept
friend Qt::strong_ordering compareThreeWay(const QBasicUtf8StringView &lhs, const QByteArrayView &rhs) noexcept
std::reverse_iterator< iterator > reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
value_type * const_pointer
const_pointer const_iterator
constexpr QBasicUtf8StringView last(qsizetype n) const
constexpr QBasicUtf8StringView(std::nullptr_t) noexcept
constexpr storage_type at(qsizetype n) const
const storage_type value_type
constexpr storage_type front() const
constexpr QBasicUtf8StringView left(qsizetype n) const
constexpr QBasicUtf8StringView() noexcept
const_iterator end() const noexcept
friend bool comparesEqual(const QBasicUtf8StringView &lhs, const QLatin1StringView &rhs) noexcept
constexpr void chop(qsizetype n)
const_reverse_iterator crbegin() const noexcept
friend Qt::strong_ordering compareThreeWay(const QBasicUtf8StringView &lhs, const QStringView &rhs) noexcept
const_iterator cbegin() const noexcept
constexpr const_pointer data() const noexcept
constexpr QBasicUtf8StringView right(qsizetype n) const
constexpr QBasicUtf8StringView chopped(qsizetype n) const
constexpr QByteArrayView() noexcept
bool isValidUtf8() const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isNull() const
Returns true if this string is null; otherwise returns false.
\inmodule QtCore \title Classes and helpers for defining comparison operators \keyword qtcompare
QSet< QString >::iterator it
Combined button and popup list for selecting options.
IsCompatiblePointer8Helper< q20::remove_cvref_t< Pointer > > IsCompatiblePointer8
std::disjunction< std::is_same< Char, char >, std::is_same< Char, uchar >, std::is_same< Char, signed char > > IsCompatibleChar8TypeHelper
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool equalStrings(QStringView lhs, QStringView rhs) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
IsCompatibleChar8TypeHelper< q20::remove_cvref_t< Char > > IsCompatibleChar8Type
constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcept
#define Q_DECLARE_STRONGLY_ORDERED(...)
GLsizei const GLfloat * v
[13]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
#define QT_ASCII_CAST_WARN
#define Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS)
q_no_char8_t::QUtf8StringView qToUtf8StringViewIgnoringNull(const QStringLike &s) noexcept