7#include <QtCore/qchar.h>
8#include <QtCore/qbytearray.h>
9#include <QtCore/qstringliteral.h>
10#include <QtCore/qstringalgorithms.h>
13#include <QtCore/q20type_traits.h>
15#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
31template <
typename Char>
33 : std::integral_constant<bool,
34 std::is_same<Char, QChar>::value ||
35 std::is_same<Char, ushort>::value ||
36 std::is_same<Char, char16_t>::value ||
37 (std::is_same<Char, wchar_t>::value && sizeof(wchar_t) == sizeof(QChar))> {};
38template <
typename Char>
42template <
typename Po
inter>
44template <
typename Char>
47template <
typename Po
inter>
51template <
typename T,
typename Enable =
void>
57 IsCompatiblePointer<decltype( std::data(std::declval<const T &>()) )>,
59 std::is_convertible<decltype( std::size(std::declval<const T &>()) ), qsizetype>,
61 IsCompatibleCharType<typename std::iterator_traits<decltype( std::begin(std::declval<const T &>()) )>::value_type>,
63 decltype( std::begin(std::declval<const T &>()) != std::end(std::declval<const T &>()) ),
67 std::negation<std::is_same<std::decay_t<T>, QString>>,
70 std::negation<std::is_same<std::decay_t<T>, QStringView>>
71 >>> : std::true_type {};
93 template <
typename Char>
94 using if_compatible_char =
typename std::enable_if<QtPrivate::IsCompatibleCharType<Char>::value,
bool>
::type;
96 template <
typename Po
inter>
97 using if_compatible_pointer =
typename std::enable_if<QtPrivate::IsCompatiblePointer<Pointer>::value,
bool>
::type;
100 using if_compatible_qstring_like =
typename std::enable_if<std::is_same<T, QString>::value,
bool>
::type;
102 template <
typename T>
103 using if_compatible_container =
typename std::enable_if<QtPrivate::IsContainerCompatibleWithQStringView<T>::value,
bool>
::type;
105 template <
typename Char>
108#if defined(QT_SUPPORTS_IS_CONSTANT_EVALUATED)
109 if (qIsConstantEvaluated())
110 return std::char_traits<Char>::length(
str);
119 template <
typename Char>
130 template <
typename Char, if_compatible_
char<Char> = true>
132#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED)
133 : m_data(castHelper(
str)),
137 m_data(castHelper(
str))
141 template <
typename Char, if_compatible_
char<Char> = true>
146 template <
typename Char,
size_t N>
149 template <
typename Char>
153 template <
typename Po
inter, if_compatible_po
inter<Po
inter> = true>
161 template <
typename String, if_compatible_q
string_like<String> = true>
166 template <
typename Container, if_compatible_container<Container> = true>
170 template <
typename Char,
size_t Size, if_compatible_
char<Char> = true>
175#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
193 template <
typename...Args>
211 if (
size_t(
n) >=
size_t(
size()))
217 if (
size_t(
n) >=
size_t(
size()))
240 template <
typename Needle,
typename...Flags>
241 [[nodiscard]]
constexpr inline auto tokenize(Needle &&needle,
Flags...flags) const
244 {
return qTokenize(*
this, std::forward<Needle>(needle),
flags...); }
251 {
return size() >= 1 ? compare_single_char_helper(*
utf16() -
c.unicode()) : -1; }
302#if QT_CONFIG(regularexpression)
311 template <
typename T = QRegularExpressionMatch, std::enable_if_t<std::is_same_v<T, QRegularExpressionMatch>,
bool> = false>
323 return QtPrivate::contains(*
this, re, rmatch);
336 [[nodiscard]]
inline short toShort(
bool *
ok =
nullptr,
int base = 10)
const;
338 [[nodiscard]]
inline int toInt(
bool *
ok =
nullptr,
int base = 10)
const;
340 [[nodiscard]]
inline long toLong(
bool *
ok =
nullptr,
int base = 10)
const;
344 [[nodiscard]] Q_CORE_EXPORT
float toFloat(
bool *
ok =
nullptr)
const;
345 [[nodiscard]] Q_CORE_EXPORT
double toDouble(
bool *
ok =
nullptr)
const;
350 [[nodiscard]] Q_CORE_EXPORT
354 [[nodiscard]] Q_CORE_EXPORT
358#if QT_CONFIG(regularexpression)
359 [[nodiscard]] Q_CORE_EXPORT
399 [[nodiscard]]
constexpr bool empty() const noexcept {
return size() == 0; }
408 [[nodiscard]]
constexpr bool isNull() const noexcept {
return !m_data; }
409 [[nodiscard]]
constexpr bool isEmpty() const noexcept {
return empty(); }
415#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED)
423 constexpr int compare_single_char_helper(
int diff)
const noexcept
424 {
return diff ? diff :
size() > 1 ? 1 : 0; }
428template <
typename QStringLike,
typename std::enable_if<
429 std::is_same<QStringLike, QString>::value,
441 [[nodiscard]]
constexpr qsizetype size()
const noexcept {
return chars[1] ? 2 : 1; }
442 [[nodiscard]]
constexpr const char16_t *
begin()
const noexcept {
return chars; }
443 [[nodiscard]]
constexpr const char16_t *
end()
const noexcept {
return begin() +
size(); }
447 R{{char16_t(
c), u
'\0'}} ;
static constexpr auto fromUcs4(char32_t c) noexcept
static constexpr char16_t highSurrogate(char32_t ucs4) noexcept
Returns the high surrogate part of a UCS-4-encoded code point.
static constexpr char16_t lowSurrogate(char32_t ucs4) noexcept
Returns the low surrogate part of a UCS-4-encoded code point.
\inmodule QtCore \reentrant
\inmodule QtCore \reentrant
const_iterator cend() const noexcept
Same as end().
friend bool operator!=(QStringView lhs, QStringView rhs) noexcept
bool startsWith(QChar c) const noexcept
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
qsizetype lastIndexOf(QStringView s, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Q_CORE_EXPORT double toDouble(bool *ok=nullptr) const
Returns the string view converted to a double value.
constexpr void truncate(qsizetype n) noexcept
Truncates this string view to length length.
bool isRightToLeft() const noexcept
const_iterator cbegin() const noexcept
Same as begin().
int compare(QChar c, Qt::CaseSensitivity cs) const noexcept
Q_CORE_EXPORT float toFloat(bool *ok=nullptr) const
Returns the string view converted to a float value.
value_type & reference
Alias for {value_type &}.
friend bool operator>=(QStringView lhs, QChar rhs) noexcept
friend bool operator!=(QChar lhs, QStringView rhs) noexcept
bool startsWith(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
bool startsWith(QChar c, Qt::CaseSensitivity cs) const noexcept
Returns true if this string view starts with.
friend bool operator<=(QChar lhs, QStringView rhs) noexcept
constexpr const storage_type * utf16() const noexcept
bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept
Returns true if this string view ends with.
qsizetype count(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
const QChar value_type
Alias for {const QChar}.
int localeAwareCompare(QStringView other) const
constexpr void chop(qsizetype n) noexcept
Truncates this string view by length characters.
constexpr auto tokenize(Needle &&needle, Flags...flags) const noexcept(noexcept(qTokenize(std::declval< const QStringView & >(), std::forward< Needle >(needle), flags...))) -> decltype(qTokenize(*this, std::forward< Needle >(needle), flags...))
constexpr bool isEmpty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
ushort toUShort(bool *ok=nullptr, int base=10) const
Returns the string view converted to an {unsigned short} using base base, which is 10 by default and ...
const_pointer const_iterator
This typedef provides an STL-style const iterator for QStringView.
QString arg(Args &&...args) const
const_reverse_iterator rbegin() const noexcept
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first character i...
constexpr qsizetype size() const noexcept
Returns the size of this string view, in UTF-16 code units (that is, surrogate pairs count as two for...
friend bool operator<(QStringView lhs, QStringView rhs) noexcept
friend bool operator==(QStringView lhs, QStringView rhs) noexcept
const_iterator constEnd() const noexcept
constexpr QStringView first(qsizetype n) const noexcept
constexpr QStringView chopped(qsizetype n) const noexcept
Returns the substring of length size() - length starting at the beginning of this object.
const_reverse_iterator crend() const noexcept
Same as rend().
value_type & const_reference
Alias for {value_type &}.
qsizetype count(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr Q_ALWAYS_INLINE QStringView(const Container &c) noexcept
constexpr QChar last() const
Returns the last character in the string view.
constexpr QStringView left(qsizetype n) const noexcept
const_pointer data() const noexcept
qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
const_iterator begin() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the st...
QList< uint > toUcs4() const
Returns a UCS-4/UTF-32 representation of the string view as a QList<uint>.
friend bool operator>(QStringView lhs, QStringView rhs) noexcept
QByteArray toLatin1() const
Returns a Latin-1 representation of the string as a QByteArray.
bool endsWith(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
pointer iterator
This typedef provides an STL-style const iterator for QStringView.
QByteArray toUtf8() const
Returns a UTF-8 representation of the string view as a QByteArray.
Q_CORE_EXPORT QList< QStringView > split(QStringView sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the view into substring views wherever sep occurs, and returns the list of those string views.
QByteArray toLocal8Bit() const
Returns a local 8-bit representation of the string as a QByteArray.
bool endsWith(QChar c) const noexcept
bool contains(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
const_reverse_iterator rend() const noexcept
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past the last character...
std::ptrdiff_t difference_type
Alias for {std::ptrdiff_t}.
QString toString() const
Returns a deep copy of this string view's data as a QString.
int toInt(bool *ok=nullptr, int base=10) const
Returns the string view converted to an int using base base, which is 10 by default and must be betwe...
qlonglong toLongLong(bool *ok=nullptr, int base=10) const
Returns the string view converted to a {long long} using base base, which is 10 by default and must b...
std::reverse_iterator< const_iterator > const_reverse_iterator
This typedef provides an STL-style const reverse iterator for QStringView.
constexpr qsizetype length() const noexcept
Same as size().
constexpr QStringView last(qsizetype n) const noexcept
constexpr QStringView() noexcept
Constructs a null string view.
constexpr QChar operator[](qsizetype n) const
Returns the character at position n in this string view.
friend bool operator<=(QStringView lhs, QChar rhs) noexcept
value_type * pointer
Alias for {value_type *}.
constexpr bool empty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
ulong toULong(bool *ok=nullptr, int base=10) const
Returns the string view converted to an {unsigned long} using base base, which is 10 by default and m...
constexpr QChar back() const
Returns the last character in the string view.
bool isValidUtf16() const noexcept
constexpr bool isNull() const noexcept
Returns whether this string view is null - that is, whether {data() == nullptr}.
int compare(QStringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
qulonglong toULongLong(bool *ok=nullptr, int base=10) const
Returns the string view converted to an {unsigned long long} using base base, which is 10 by default ...
short toShort(bool *ok=nullptr, int base=10) const
Returns the string view converted to a short using base base, which is 10 by default and must be betw...
constexpr QStringView right(qsizetype n) const noexcept
const_reverse_iterator crbegin() const noexcept
Same as rbegin().
constexpr QChar at(qsizetype n) const noexcept
Returns the character at position n in this string view.
char16_t storage_type
Alias for {char16_t}.
constexpr int compare(QChar c) const noexcept
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
qsizetype indexOf(QStringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QStringView sliced(qsizetype pos) const noexcept
friend bool operator==(QChar lhs, QStringView rhs) noexcept
friend bool operator==(QStringView lhs, QChar rhs) noexcept
static constexpr QStringView fromArray(const Char(&string)[Size]) noexcept
Constructs a string view on the full character string literal string, including any trailing {Char(0)...
value_type * const_pointer
Alias for {value_type *}.
QStringView trimmed() const noexcept
Strips leading and trailing whitespace and returns the result.
constexpr QChar front() const
friend bool operator>=(QStringView lhs, QStringView rhs) noexcept
Operators for comparing lhs to rhs.
const_iterator constBegin() const noexcept
friend bool operator!=(QStringView lhs, QChar rhs) noexcept
constexpr QStringView sliced(qsizetype pos, qsizetype n) const noexcept
const_iterator end() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary character after...
friend bool operator<=(QStringView lhs, QStringView rhs) noexcept
const_pointer constData() const noexcept
friend bool operator>=(QChar lhs, QStringView rhs) noexcept
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QStringView(std::nullptr_t) noexcept
Constructs a null string view.
uint toUInt(bool *ok=nullptr, int base=10) const
Returns the string view converted to an {unsigned int} using base base, which is 10 by default and mu...
constexpr QStringView(const Char *f, const Char *l)
Constructs a string view on first with length (last - first).
qsizetype lastIndexOf(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QStringView(const Char *str, qsizetype len)
Constructs a string view on str with length len.
qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
long toLong(bool *ok=nullptr, int base=10) const
Returns the string view converted to a long using base base, which is 10 by default and must be betwe...
std::reverse_iterator< iterator > reverse_iterator
This typedef provides an STL-style const reverse iterator for QStringView.
qsizetype toWCharArray(wchar_t *array) const
constexpr QStringView(const Pointer &str) noexcept
qsizetype size_type
Alias for qsizetype.
constexpr QChar first() const
Returns the first character in the string view.
QStringView(const String &str) noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isNull() const
Returns true if this string is null; otherwise returns false.
Combined button and popup list for selecting options.
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QByteArrayView haystack, QByteArrayView needle) noexcept
constexpr Q_ALWAYS_INLINE std::enable_if_t< sizeof(Char)==sizeof(char16_t), qsizetype > lengthHelperContainer(const Char(&str)[N])
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype qustrlen(const char16_t *str) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isValidUtf16(QStringView s) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QByteArrayView trimmed(QByteArrayView s) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QByteArrayView haystack, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QByteArrayView haystack, qsizetype from, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QByteArrayView haystack, QByteArrayView needle) noexcept
Q_CORE_EXPORT QByteArray convertToLocal8Bit(QStringView str)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool equalStrings(QStringView lhs, QStringView rhs) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findString(QStringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isRightToLeft(QStringView string) noexcept
Q_CORE_EXPORT QByteArray convertToLatin1(QStringView str)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
qsizetype indexOf(const QList< V > &list, const U &u, qsizetype from) noexcept
Q_CORE_EXPORT QByteArray convertToUtf8(QStringView str)
#define Q_DECL_NS_RETURNS_AUTORELEASED
#define Q_DECL_CF_RETURNS_RETAINED
#define Q_FORWARD_DECLARE_CF_TYPE(type)
#define Q_FORWARD_DECLARE_OBJC_CLASS(classname)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static constexpr QChar sep
constexpr auto qTokenize(Haystack &&h, Needle &&n, Flags...flags) noexcept(QtPrivate::Tok::is_nothrow_constructible_from< Haystack, Needle >::value) -> decltype(QtPrivate::Tok::TokenizerResult< Haystack, Needle >{std::forward< Haystack >(h), std::forward< Needle >(n), flags...})
QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)