39 #ifndef QANYSTRINGVIEW_H
40 #define QANYSTRINGVIEW_H
42 #include <QtCore/qstringview.h>
43 #include <QtCore/qutf8stringview.h>
45 #ifdef __cpp_impl_three_way_comparison
61 template <
typename Char>
62 using if_compatible_char = std::enable_if_t<std::disjunction_v<
67 template <
typename Po
inter>
68 using if_compatible_pointer = std::enable_if_t<std::disjunction_v<
75 using if_compatible_container = std::enable_if_t<std::disjunction_v<
84 template <
typename Char>
85 static constexpr std::size_t encodeType(
qsizetype sz) noexcept
91 return std::size_t(sz) |
uint(
sizeof(
Char) ==
sizeof(char16_t)) * Tag::Utf16;
94 template <
typename Char>
97 #if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
98 if (__builtin_constant_p(*
str)) {
100 while (*
str++ !=
u'\0')
105 if constexpr (
sizeof(
Char) ==
sizeof(char16_t))
111 template <
typename Container>
117 template <
typename Char,
size_t N>
130 :
m_data{
d}, m_size{std::size_t(
n) | (sizeAndType & TypeMask)} {}
133 :
m_data{
nullptr}, m_size{0} {}
137 template <
typename Char, if_compatible_
char<Char> = true>
142 template <
typename Char, if_compatible_
char<Char> = true>
147 template <
typename Char,
size_t N>
150 template <
typename Char>
154 template <
typename Po
inter, if_compatible_po
inter<Po
inter> = true>
165 template <
typename A,
typename B>
169 template <
typename Container, if_compatible_container<Container> = true>
173 template <
typename Char, if_compatible_
char<Char> = true>
180 std::enable_if_t<std::is_same_v<Char, char32_t>,
bool> =
true>
187 template <
bool UseChar8T>
191 template <
typename Char,
size_t Size, if_compatible_
char<Char> = true>
196 template <
typename Visitor>
211 [[nodiscard]] constexpr
QChar back()
const;
214 {
return size() * charSize(); }
230 #if defined(__cpp_impl_three_way_comparison) && !defined(Q_QDOC)
246 static_assert(std::is_same_v<std::size_t, size_t>);
247 static_assert(
sizeof(
size_t) ==
sizeof(
qsizetype));
248 static constexpr
size_t SizeMask = (std::numeric_limits<size_t>::max)() / 4;
249 static constexpr
size_t Latin1Flag = SizeMask + 1;
250 static constexpr
size_t TwoByteCodePointFlag = Latin1Flag << 1;
251 static constexpr
size_t TypeMask = (std::numeric_limits<size_t>::max)() & ~SizeMask;
252 static_assert(TypeMask == (Latin1Flag|TwoByteCodePointFlag));
263 Utf16 = TwoByteCodePointFlag,
267 [[nodiscard]] constexpr
bool isUtf16()
const noexcept {
return tag() == Tag::Utf16; }
268 [[nodiscard]] constexpr
bool isUtf8()
const noexcept {
return tag() == Tag::Utf8; }
269 [[nodiscard]] constexpr
bool isLatin1()
const noexcept {
return tag() == Tag::Latin1; }
270 [[nodiscard]] constexpr
QStringView asStringView()
const
274 [[nodiscard]]
inline constexpr
QLatin1String asLatin1StringView()
const;
275 [[nodiscard]] constexpr
size_t charSize()
const noexcept {
return isUtf16() ? 2 : 1; }
292 template <
typename QStringLike, std::enable_if_t<std::disjunction_v<
293 std::is_same<QStringLike, QString>,
294 std::is_same<QStringLike, QByteArray>
small capitals from c petite p scientific f u
constexpr QAnyStringView(const QChar &c) noexcept
constexpr QChar back() const
friend bool operator!=(QAnyStringView lhs, QAnyStringView rhs) noexcept
constexpr static QAnyStringView fromArray(const Char(&string)[Size]) noexcept
friend bool operator>=(QAnyStringView lhs, QAnyStringView rhs) noexcept
constexpr const void * data() const noexcept
constexpr qsizetype size() const noexcept
constexpr QAnyStringView(const Char *str, qsizetype len)
static Q_CORE_EXPORT int compare(QAnyStringView lhs, QAnyStringView rhs, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
constexpr bool isEmpty() const noexcept
constexpr QAnyStringView(const Char &c) noexcept
static Q_CORE_EXPORT bool equal(QAnyStringView lhs, QAnyStringView rhs) noexcept
constexpr qsizetype size_bytes() const noexcept
constexpr bool isNull() const noexcept
constexpr QAnyStringView() noexcept
const char16_t * m_data_utf16
constexpr QAnyStringView(const Char *f, const Char *l)
constexpr QChar front() const
constexpr QAnyStringView(std::nullptr_t) noexcept
constexpr QAnyStringView(QStringView v) noexcept
constexpr decltype(auto) visit(Visitor &&v) const
constexpr QAnyStringView(const Container &c) noexcept
friend bool operator>(QAnyStringView lhs, QAnyStringView rhs) noexcept
constexpr QAnyStringView(Char c, Container &&capacity={})
friend bool operator<(QAnyStringView lhs, QAnyStringView rhs) noexcept
friend bool operator<=(QAnyStringView lhs, QAnyStringView rhs) noexcept
constexpr bool empty() const noexcept
constexpr QAnyStringView(const Pointer &str) noexcept
constexpr qsizetype length() const noexcept
friend bool operator==(QAnyStringView lhs, QAnyStringView rhs) noexcept
constexpr QAnyStringView(QBasicUtf8StringView< UseChar8T > v) noexcept
The QByteArray class provides an array of bytes.
The QChar class provides a 16-bit Unicode character.
static constexpr auto fromUcs4(char32_t c) noexcept
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
The QString class provides a Unicode character string.
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QStrin...
auto it unsigned count const
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype qustrlen(const char16_t *str) noexcept
IsCompatibleChar8TypeHelper< std::remove_cv_t< std::remove_reference_t< Char > >> IsCompatibleChar8Type
int distance(TestIterator &a, TestIterator &b)
PCRE2_SIZE PRIV() strlen(PCRE2_SPTR str)
Q_DECLARE_TYPEINFO(QAnyStringView, Q_PRIMITIVE_TYPE)
QAnyStringView qToAnyStringViewIgnoringNull(const QStringLike &s) noexcept
GLsizei const GLfloat * v
[13]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QT_BEGIN_NAMESPACE typedef char Char
QBasicUtf8StringView< false > QUtf8StringView
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
QDomElement find(const QString &tagName, const QDomElement &e)