7#include <QtCore/qchar.h>
8#include <QtCore/qcompare.h>
9#include <QtCore/qbytearray.h>
10#include <QtCore/qstringliteral.h>
11#include <QtCore/qstringalgorithms.h>
15#include <QtCore/q20type_traits.h>
17#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
33template <
typename Char>
35 : std::integral_constant<bool,
36 std::is_same<Char, QChar>::value ||
37 std::is_same<Char, ushort>::value ||
38 std::is_same<Char, char16_t>::value ||
39 (std::is_same<Char, wchar_t>::value && sizeof(wchar_t) == sizeof(QChar))> {};
40template <
typename Char>
44template <
typename Po
inter>
46template <
typename Char>
48 : IsCompatibleCharType<Char> {};
49template <
typename Po
inter>
53template <
typename T,
typename Enable =
void>
59 IsCompatiblePointer<decltype( std::data(std::declval<const T &>()) )>,
61 std::is_convertible<decltype( std::size(std::declval<const T &>()) ), qsizetype>,
63 IsCompatibleCharType<typename std::iterator_traits<decltype( std::begin(std::declval<const T &>()) )>::value_type>,
65 decltype( std::begin(std::declval<const T &>()) != std::end(std::declval<const T &>()) ),
69 std::negation<std::is_same<std::decay_t<T>, QString>>,
72 std::negation<std::is_same<std::decay_t<T>, QStringView>>
73 >>> : std::true_type {};
95 template <
typename Char>
96 using if_compatible_char =
typename std::enable_if<QtPrivate::IsCompatibleCharType<Char>::value,
bool>
::type;
98 template <
typename Po
inter>
99 using if_compatible_pointer =
typename std::enable_if<QtPrivate::IsCompatiblePointer<Pointer>::value,
bool>
::type;
101 template <
typename T>
102 using if_compatible_qstring_like =
typename std::enable_if<std::is_same<T, QString>::value,
bool>
::type;
104 template <
typename T>
105 using if_compatible_container =
typename std::enable_if<QtPrivate::IsContainerCompatibleWithQStringView<T>::value,
bool>
::type;
107 template <
typename Char>
111 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)
187 { verify(
n, 1);
return QChar(m_data[
n]); }
193 template <
typename...Args>
199 [[nodiscard]]
inline QList<uint>
toUcs4()
const;
211 if (
size_t(
n) >=
size_t(
size()))
217 if (
size_t(
n) >=
size_t(
size()))
223 { verify(0,
n);
return sliced(0,
n); }
231 { verify(0,
n);
return sliced(0, m_size -
n); }
234 { verify(0,
n); ; m_size =
n; }
236 { verify(0,
n); m_size -=
n; }
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);
341 [[nodiscard]]
inline short toShort(
bool *
ok =
nullptr,
int base = 10)
const;
343 [[nodiscard]]
inline int toInt(
bool *
ok =
nullptr,
int base = 10)
const;
345 [[nodiscard]]
inline long toLong(
bool *
ok =
nullptr,
int base = 10)
const;
349 [[nodiscard]] Q_CORE_EXPORT
float toFloat(
bool *
ok =
nullptr)
const;
350 [[nodiscard]] Q_CORE_EXPORT
double toDouble(
bool *
ok =
nullptr)
const;
355 [[nodiscard]] Q_CORE_EXPORT
359 [[nodiscard]] Q_CORE_EXPORT
363#if QT_CONFIG(regularexpression)
364 [[nodiscard]] Q_CORE_EXPORT
382 {
return lhs.size() == 1 && lhs[0] == rhs; }
399 [[nodiscard]]
constexpr bool empty() const noexcept {
return size() == 0; }
403 [[nodiscard]]
Q_IMPLICIT operator std::u16string_view() const noexcept
404 {
return std::u16string_view(m_data,
size_t(m_size)); }
411 [[nodiscard]]
constexpr bool isNull() const noexcept {
return !m_data; }
412 [[nodiscard]]
constexpr bool isEmpty() const noexcept {
return empty(); }
418#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED)
435 constexpr int compare_single_char_helper(
int diff)
const noexcept
436 {
return diff ? diff :
size() > 1 ? 1 : 0; }
441#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
443 {
return equal_helper(lhs, rhs.data(), rhs.size()); }
447 const int res = compare_helper(lhs, rhs.data(), rhs.size());
457template <
typename QStringLike,
typename std::enable_if<
458 std::is_same<QStringLike, QString>::value,
465[[nodiscard]]
constexpr auto QChar::fromUcs4(
char32_t c)
noexcept
470 [[nodiscard]]
constexpr qsizetype size() const noexcept {
return chars[1] ? 2 : 1; }
471 [[nodiscard]]
constexpr const char16_t *
begin() const noexcept {
return chars; }
472 [[nodiscard]]
constexpr const char16_t *
end() const noexcept {
return begin() +
size(); }
474 return requiresSurrogates(
c) ?
R{{QChar::highSurrogate(
c),
475 QChar::lowSurrogate(
c)}} :
476 R{{char16_t(
c), u
'\0'}} ;
487 char16_t c =
ch.unicode();
488 const char16_t *
n =
s + from;
\inmodule QtCore \reentrant
\inmodule QtCore \reentrant
const_iterator cend() const noexcept
Same as end().
bool isLower() const 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 &}.
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.
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 QStringView(const Char *f, const Char *l)
Constructs a string view on first with length (last - first).
constexpr bool isEmpty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
friend bool comparesEqual(const QStringView &lhs, const QStringView &rhs) noexcept
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 ...
friend Qt::strong_ordering compareThreeWay(const QStringView &lhs, QChar rhs) noexcept
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...
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>.
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
constexpr QStringView sliced(qsizetype pos, qsizetype n) 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
friend Qt::strong_ordering compareThreeWay(const QStringView &lhs, const QByteArrayView &rhs) 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.
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
bool isUpper() const noexcept
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
constexpr QStringView(const Char *str, qsizetype len)
Constructs a string view on str with length len.
const_iterator constBegin() const noexcept
const_iterator end() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary character after...
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)...
const_pointer constData() const noexcept
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
friend bool comparesEqual(const QStringView &lhs, const QByteArrayView &rhs) 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...
qsizetype lastIndexOf(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QStringView sliced(qsizetype pos) 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
friend Qt::strong_ordering compareThreeWay(const QStringView &lhs, const QStringView &rhs) noexcept
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
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
bool isNull() const
Returns true if this string is null; otherwise returns false.
qsizetype size() const noexcept
Returns the number of characters in this string.
\inmodule QtCore \title Classes and helpers for defining comparison operators \keyword qtcompare
Combined button and popup list for selecting options.
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QByteArrayView haystack, qsizetype from, char needle) noexcept
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 bool isLower(QStringView s) 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 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
qsizetype findString(QStringView str, qsizetype from, QChar 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)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype qustrlen(const char16_t *str) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION const char16_t * qustrcasechr(QStringView str, char16_t ch) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isUpper(QStringView s) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION const char16_t * qustrchr(QStringView str, char16_t ch) noexcept
constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcept
constexpr bool is_constant_evaluated() noexcept
#define Q_DECLARE_STRONGLY_ORDERED(...)
#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)
constexpr const T & qMax(const T &a, const T &b)
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 QT_ASCII_CAST_WARN
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)