Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QStringView Class Reference

\inmodule QtCore More...

#include <qstringview.h>

+ Collaboration diagram for QStringView:

Public Types

typedef char16_t storage_type
 Alias for {char16_t}.
 
typedef const QChar value_type
 Alias for {const QChar}.
 
typedef std::ptrdiff_t difference_type
 Alias for {std::ptrdiff_t}.
 
typedef qsizetype size_type
 Alias for qsizetype.
 
typedef value_typereference
 Alias for {value_type &}.
 
typedef value_typeconst_reference
 Alias for {value_type &}.
 
typedef value_typepointer
 Alias for {value_type *}.
 
typedef value_typeconst_pointer
 Alias for {value_type *}.
 
typedef pointer iterator
 This typedef provides an STL-style const iterator for QStringView.
 
typedef const_pointer const_iterator
 This typedef provides an STL-style const iterator for QStringView.
 
typedef std::reverse_iterator< iteratorreverse_iterator
 This typedef provides an STL-style const reverse iterator for QStringView.
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 This typedef provides an STL-style const reverse iterator for QStringView.
 

Public Member Functions

constexpr QStringView () noexcept
 Constructs a null string view.
 
constexpr QStringView (std::nullptr_t) noexcept
 Constructs a null string view.
 
template<typename Char , if_compatible_char< Char > = true>
constexpr QStringView (const Char *str, qsizetype len)
 
template<typename Char , if_compatible_char< Char > = true>
constexpr QStringView (const Char *f, const Char *l)
 Constructs a string view on first with length (last - first).
 
template<typename Pointer , if_compatible_pointer< Pointer > = true>
constexpr QStringView (const Pointer &str) noexcept
 
template<typename String , if_compatible_qstring_like< String > = true>
 QStringView (const String &str) noexcept
 
template<typename Container , if_compatible_container< Container > = true>
constexpr Q_ALWAYS_INLINE QStringView (const Container &c) noexcept
 
QString toString () const
 Returns a deep copy of this string view's data as a QString.
 
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 the purposes of this function, the same as in QString).
 
const_pointer data () const noexcept
 
const_pointer constData () const noexcept
 
constexpr const storage_typeutf16 () const noexcept
 
constexpr QChar operator[] (qsizetype n) const
 Returns the character at position n in this string view.
 
template<typename... Args>
QString arg (Args &&...args) const
 
QByteArray toLatin1 () const
 Returns a Latin-1 representation of the string as a QByteArray.
 
QByteArray toUtf8 () const
 Returns a UTF-8 representation of the string view as a QByteArray.
 
QByteArray toLocal8Bit () const
 Returns a local 8-bit representation of the string as a QByteArray.
 
QList< uinttoUcs4 () const
 Returns a UCS-4/UTF-32 representation of the string view as a QList<uint>.
 
constexpr QChar at (qsizetype n) const noexcept
 Returns the character at position n in this string view.
 
constexpr QStringView mid (qsizetype pos, qsizetype n=-1) const noexcept
 Returns the substring of length length starting at position start in this object.
 
constexpr QStringView left (qsizetype n) const noexcept
 
constexpr QStringView right (qsizetype n) const noexcept
 
constexpr QStringView first (qsizetype n) const noexcept
 
constexpr QStringView last (qsizetype n) const noexcept
 
constexpr QStringView sliced (qsizetype pos) const noexcept
 
constexpr QStringView sliced (qsizetype pos, 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.
 
constexpr void truncate (qsizetype n) noexcept
 Truncates this string view to length length.
 
constexpr void chop (qsizetype n) noexcept
 Truncates this string view by length characters.
 
QStringView trimmed () const noexcept
 Strips leading and trailing whitespace and returns the result.
 
constexpr QStringViewslice (qsizetype pos)
 
constexpr QStringViewslice (qsizetype pos, qsizetype n)
 
template<typename Needle , typename... Flags>
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...))
 
int compare (QStringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
int compare (QLatin1StringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
int compare (QUtf8StringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
constexpr int compare (QChar c) const noexcept
 
int compare (QChar c, Qt::CaseSensitivity cs) const noexcept
 
int localeAwareCompare (QStringView other) const
 
bool startsWith (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool startsWith (QLatin1StringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool startsWith (QChar c) const noexcept
 
bool startsWith (QChar c, Qt::CaseSensitivity cs) const noexcept
 Returns true if this string view starts with.
 
bool endsWith (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool endsWith (QLatin1StringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool endsWith (QChar c) const noexcept
 
bool endsWith (QChar c, Qt::CaseSensitivity cs) const noexcept
 Returns true if this string view ends with.
 
qsizetype indexOf (QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
qsizetype indexOf (QStringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
qsizetype indexOf (QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool contains (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool contains (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool contains (QLatin1StringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
qsizetype count (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
qsizetype count (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
qsizetype count (QLatin1StringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
qsizetype lastIndexOf (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
qsizetype lastIndexOf (QChar c, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
qsizetype lastIndexOf (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
qsizetype lastIndexOf (QStringView s, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
qsizetype lastIndexOf (QLatin1StringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
qsizetype lastIndexOf (QLatin1StringView s, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool isRightToLeft () const noexcept
 
bool isValidUtf16 () const noexcept
 
bool isUpper () const noexcept
 
bool isLower () const noexcept
 
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 between 2 and 36, or 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 must be between 2 and 36, or 0.
 
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 between 2 and 36, or 0.
 
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 must be between 2 and 36, or 0.
 
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 between 2 and 36, or 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 must be between 2 and 36, or 0.
 
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 be between 2 and 36, or 0.
 
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 and must be between 2 and 36, or 0.
 
Q_CORE_EXPORT float toFloat (bool *ok=nullptr) const
 Returns the string view converted to a float value.
 
Q_CORE_EXPORT double toDouble (bool *ok=nullptr) const
 Returns the string view converted to a double value.
 
qsizetype toWCharArray (wchar_t *array) const
 
Q_CORE_EXPORT QList< QStringViewsplit (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.
 
Q_CORE_EXPORT QList< QStringViewsplit (QChar sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const_iterator begin () const noexcept
 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the string view.
 
const_iterator end () const noexcept
 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary character after the last character in the list.
 
const_iterator cbegin () const noexcept
 Same as begin().
 
const_iterator cend () const noexcept
 Same as end().
 
const_reverse_iterator rbegin () const noexcept
 Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first character in the string view, in reverse order.
 
const_reverse_iterator rend () const noexcept
 Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past the last character in the string view, in reverse order.
 
const_reverse_iterator crbegin () const noexcept
 Same as rbegin().
 
const_reverse_iterator crend () const noexcept
 Same as rend().
 
constexpr bool empty () const noexcept
 Returns whether this string view is empty - that is, whether {size() == 0}.
 
constexpr QChar front () const
 
constexpr QChar back () const
 Returns the last character in the string view.
 
Q_IMPLICIT operator std::u16string_view () const noexcept
 
constexpr qsizetype max_size () const noexcept
 
const_iterator constBegin () const noexcept
 
const_iterator constEnd () const noexcept
 
constexpr bool isNull () const noexcept
 Returns whether this string view is null - that is, whether {data() == nullptr}.
 
constexpr bool isEmpty () const noexcept
 Returns whether this string view is empty - that is, whether {size() == 0}.
 
constexpr qsizetype length () const noexcept
 Same as size().
 
constexpr QChar first () const
 Returns the first character in the string view.
 
constexpr QChar last () const
 Returns the last character in the string view.
 
template<typename... Args>
Q_ALWAYS_INLINE QString arg (Args &&...args) const
 

Static Public Member Functions

template<typename Char , size_t Size, if_compatible_char< Char > = true>
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)}.
 
static constexpr qsizetype maxSize () noexcept
 

Friends

bool comparesEqual (const QStringView &lhs, const QStringView &rhs) noexcept
 
Qt::strong_ordering compareThreeWay (const QStringView &lhs, const QStringView &rhs) noexcept
 
bool comparesEqual (const QStringView &lhs, QChar rhs) noexcept
 
Qt::strong_ordering compareThreeWay (const QStringView &lhs, QChar rhs) noexcept
 
bool comparesEqual (const QStringView &lhs, const QByteArrayView &rhs) noexcept
 
Qt::strong_ordering compareThreeWay (const QStringView &lhs, const QByteArrayView &rhs) noexcept
 

Related Symbols

(Note that these are not member symbols.)

int compareStrings (QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QStringView lhs, QLatin1StringView rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QStringView lhs, QBasicUtf8StringView< false > rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QLatin1StringView lhs, QStringView rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QLatin1StringView lhs, QLatin1StringView rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QLatin1StringView lhs, QBasicUtf8StringView< false > rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QBasicUtf8StringView< false > lhs, QStringView rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QBasicUtf8StringView< false > lhs, QLatin1StringView rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QBasicUtf8StringView< false > lhs, QBasicUtf8StringView< false > rhs, Qt::CaseSensitivity cs) noexcept
 
QByteArray convertToLatin1 (QStringView string)
 
QByteArray convertToLocal8Bit (QStringView string)
 
QByteArray convertToUtf8 (QStringView string)
 
QList< uintconvertToUcs4 (QStringView string)
 
QLatin1StringView trimmed (QLatin1StringView s)
 
bool isRightToLeft (QStringView string) noexcept
 
bool startsWith (QLatin1StringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
 
bool endsWith (QLatin1StringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
 
size_t qHash (QStringView key, size_t seed=0)
 

Detailed Description

\inmodule QtCore

Since
5.10

The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QString API. \reentrant

A QStringView references a contiguous portion of a UTF-16 string it does not own. It acts as an interface type to all kinds of UTF-16 string, without the need to construct a QString first.

The UTF-16 string may be represented as an array (or an array-compatible data-structure such as QString, std::basic_string, etc.) of QChar, ushort, char16_t or (on platforms, such as Windows, where it is a 16-bit type) wchar_t.

QStringView is designed as an interface type; its main use-case is as a function parameter type. When QStringViews are used as automatic variables or data members, care must be taken to ensure that the referenced string data (for example, owned by a QString) outlives the QStringView on all code paths, lest the string view ends up referencing deleted data.

When used as an interface type, QStringView allows a single function to accept a wide variety of UTF-16 string data sources. One function accepting QStringView thus replaces three function overloads (taking QString and {(const QChar*, qsizetype)}), while at the same time enabling even more string data sources to be passed to the function, such as {u"Hello World"}, a char16_t string literal.

QStringViews should be passed by value, not by reference-to-const:

void myfun1(QStringView sv); // preferred
void myfun2(const QStringView &sv); // compiles and works, but slower

If you want to give your users maximum freedom in what strings they can pass to your function, accompany the QStringView overload with overloads for

\list

QStringView can also be used as the return value of a function. If you call a function returning QStringView, take extra care to not keep the QStringView around longer than the function promises to keep the referenced string data alive. If in doubt, obtain a strong reference to the data by calling toString() to convert the QStringView into a QString.

QStringView is a {Literal Type}, but since it stores data as {char16_t}, iteration is not constexpr (casts from {const char16_t*} to {const QChar*}, which is not allowed in constexpr functions). You can use an indexed loop and/or utf16() in constexpr contexts instead.

See also
QString

Definition at line 78 of file qstringview.h.

Member Typedef Documentation

◆ const_iterator

This typedef provides an STL-style const iterator for QStringView.

See also
iterator, const_reverse_iterator

Definition at line 91 of file qstringview.h.

◆ const_pointer

Alias for {value_type *}.

Provided for compatibility with the STL.

Definition at line 88 of file qstringview.h.

◆ const_reference

Alias for {value_type &}.

Provided for compatibility with the STL.

Definition at line 86 of file qstringview.h.

◆ const_reverse_iterator

This typedef provides an STL-style const reverse iterator for QStringView.

See also
reverse_iterator, const_iterator

Definition at line 93 of file qstringview.h.

◆ difference_type

Alias for {std::ptrdiff_t}.

Provided for compatibility with the STL.

Definition at line 83 of file qstringview.h.

◆ iterator

This typedef provides an STL-style const iterator for QStringView.

QStringView does not support mutable iterators, so this is the same as const_iterator.

See also
const_iterator, reverse_iterator

Definition at line 90 of file qstringview.h.

◆ pointer

Alias for {value_type *}.

Provided for compatibility with the STL.

QStringView does not support mutable pointers, so this is the same as const_pointer.

Definition at line 87 of file qstringview.h.

◆ reference

Alias for {value_type &}.

Provided for compatibility with the STL.

QStringView does not support mutable references, so this is the same as const_reference.

Definition at line 85 of file qstringview.h.

◆ reverse_iterator

std::reverse_iterator<iterator> QStringView::reverse_iterator

This typedef provides an STL-style const reverse iterator for QStringView.

QStringView does not support mutable reverse iterators, so this is the same as const_reverse_iterator.

See also
const_reverse_iterator, iterator

Definition at line 92 of file qstringview.h.

◆ size_type

Alias for qsizetype.

Provided for compatibility with the STL.

Definition at line 84 of file qstringview.h.

◆ storage_type

Alias for {char16_t}.

Definition at line 81 of file qstringview.h.

◆ value_type

Alias for {const QChar}.

Provided for compatibility with the STL.

Definition at line 82 of file qstringview.h.

Constructor & Destructor Documentation

◆ QStringView() [1/7]

QStringView::QStringView ( )
inlineconstexprnoexcept

Constructs a null string view.

See also
isNull()

Definition at line 127 of file qstringview.h.

Referenced by QStringView().

+ Here is the caller graph for this function:

◆ QStringView() [2/7]

QStringView::QStringView ( std::nullptr_t )
inlineconstexprnoexcept

Constructs a null string view.

See also
isNull()

Definition at line 128 of file qstringview.h.

References QStringView().

+ Here is the call graph for this function:

◆ QStringView() [3/7]

template<typename Char , if_compatible_char< Char > = true>
QStringView::QStringView ( const Char * str,
qsizetype len )
inlineconstexpr

Definition at line 132 of file qstringview.h.

References QStringView().

Referenced by QStringView().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ QStringView() [4/7]

template<typename Char , if_compatible_char< Char > = true>
QStringView::QStringView ( const Char * first,
const Char * last )
inlineconstexpr

Constructs a string view on first with length (last - first).

\fn template <typename Char, QStringView::if_compatible_char<Char> = true> QStringView::QStringView(const Char *str, qsizetype len)

Constructs a string view on \a str with length \a len.

The range \c{[str,len)} must remain valid for the lifetime of this string view object.

Passing \nullptr as \a str is safe if \a len is 0, too, and results in a null string view.

The behavior is undefined if \a len is negative or, when positive, if \a str is \nullptr.

! [compatible-char-types] This constructor only participates in overload resolution if Char is a compatible character type. The compatible character types are: QChar, ushort, char16_t and (on platforms, such as Windows, where it is a 16-bit type) wchar_t. ! [compatible-char-types]

The range {[first,last)} must remain valid for the lifetime of this string view object.

Passing \nullptr as first is safe if last is \nullptr, too, and results in a null string view.

The behavior is undefined if last precedes first, or first is \nullptr and last is not.

compatible-char-types

Definition at line 143 of file qstringview.h.

◆ QStringView() [5/7]

template<typename Pointer , if_compatible_pointer< Pointer > = true>
QStringView::QStringView ( const Pointer & str)
inlineconstexprnoexcept

Definition at line 155 of file qstringview.h.

◆ QStringView() [6/7]

template<typename String , if_compatible_qstring_like< String > = true>
QStringView::QStringView ( const String & str)
inlinenoexcept

Definition at line 163 of file qstringview.h.

◆ QStringView() [7/7]

template<typename Container , if_compatible_container< Container > = true>
Q_ALWAYS_INLINE QStringView::QStringView ( const Container & c)
inlineconstexprnoexcept

Definition at line 168 of file qstringview.h.

Member Function Documentation

◆ arg() [1/2]

template<typename... Args>
Q_ALWAYS_INLINE QString QStringView::arg ( Args &&... args) const

Definition at line 1612 of file qstring.h.

◆ arg() [2/2]

template<typename... Args>
QString QStringView::arg ( Args &&... args) const
inlinenodiscard

◆ at()

QChar QStringView::at ( qsizetype n) const
inlinenodiscardconstexprnoexcept

Returns the character at position n in this string view.

The behavior is undefined if n is negative or not less than size().

See also
operator[](), front(), back()

Definition at line 202 of file qstringview.h.

◆ back()

QChar QStringView::back ( ) const
inlinenodiscardconstexpr

Returns the last character in the string view.

\fn template <typename...Args> QString QStringView::arg(Args &&...args) const
\fn template <typename...Args> QString QLatin1StringView::arg(Args &&...args) const
\fn template <typename...Args> QString QString::arg(Args &&...args) const
\since 5.14

![qstring-multi-arg] Replaces occurrences of {N} in this string with the corresponding argument from args. The arguments are not positional: the first of the args replaces the {N} with the lowest {N} (all of them), the second of the args the {N} with the next-lowest {N} etc.

Args can consist of anything that implicitly converts to QString, QStringView or QLatin1StringView.

In addition, the following types are also supported: QChar, QLatin1Char. ![qstring-multi-arg]

\sa QString::arg()
\fn QChar QStringView::front() const

Returns the first character in the string view. Same as first().

This function is provided for STL compatibility.

! [calling-on-empty-is-UB]

Warning
Calling this function on an empty string view constitutes undefined behavior. ! [calling-on-empty-is-UB]
\sa back(), first(), last()

Same as last().

This function is provided for STL compatibility.

calling-on-empty-is-UB

See also
front(), first(), last()

Definition at line 407 of file qstringview.h.

◆ begin()

const_iterator QStringView::begin ( ) const
inlinenodiscardnoexcept

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the string view.

This function is provided for STL compatibility.

See also
end(), constBegin(), cbegin(), rbegin(), data()

Definition at line 396 of file qstringview.h.

◆ cbegin()

const_iterator QStringView::cbegin ( ) const
inlinenodiscardnoexcept

Same as begin().

This function is provided for STL compatibility.

See also
cend(), begin(), constBegin(), crbegin(), data()

Definition at line 398 of file qstringview.h.

◆ cend()

const_iterator QStringView::cend ( ) const
inlinenodiscardnoexcept

Same as end().

This function is provided for STL compatibility.

See also
cbegin(), end(), constEnd(), crend()

Definition at line 399 of file qstringview.h.

◆ chop()

void QStringView::chop ( qsizetype length)
inlineconstexprnoexcept

Truncates this string view by length characters.

Same as {*this = left(size() - length)}.

Note
The behavior is undefined when length < 0 or length > size().
See also
mid(), left(), right(), chopped(), truncate(), slice()

Definition at line 236 of file qstringview.h.

◆ chopped()

QStringView QStringView::chopped ( qsizetype length) const
inlinenodiscardconstexprnoexcept

Returns the substring of length size() - length starting at the beginning of this object.

Same as {left(size() - length)}.

Note
The behavior is undefined when length < 0 or length > size().
See also
mid(), left(), right(), chop(), truncate(), slice()

Definition at line 231 of file qstringview.h.

◆ compare() [1/5]

int QStringView::compare ( QChar c) const
inlinenodiscardconstexprnoexcept

Definition at line 256 of file qstringview.h.

◆ compare() [2/5]

int QStringView::compare ( QChar ch,
Qt::CaseSensitivity cs ) const
inlinenodiscardnoexcept
Since
5.15

Compares this string view to the Latin-1 string view l1, or the character ch. Returns a negative integer if this string view is less than l1 or ch, a positive integer if it is greater than l1 or ch, and zero if they are equal.

{search-comparison-case-sensitivity} {comparison}

See also
operator==(), operator<(), operator>()

Definition at line 258 of file qstringview.h.

◆ compare() [3/5]

int QStringView::compare ( QLatin1StringView other,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 72 of file qstring.h.

◆ compare() [4/5]

int QStringView::compare ( QStringView str,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept
Since
5.12

Compares this string view with string view str and returns a negative integer if this string view is less than str, a positive integer if it is greater than str, and zero if they are equal.

{search-comparison-case-sensitivity} {comparison}

See also
operator==(), operator<(), operator>()

Definition at line 252 of file qstringview.h.

◆ compare() [5/5]

int QStringView::compare ( QUtf8StringView str,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept
Since
6.5

Compares this string view with QUtf8StringView str and returns a negative integer if this string view is less than str, a positive integer if it is greater than str, and zero if they are equal.

{search-comparison-case-sensitivity} {comparison}

See also
operator==(), operator<(), operator>()

Definition at line 1123 of file qstring.h.

◆ constBegin()

const_iterator QStringView::constBegin ( ) const
inlinenodiscardnoexcept
Since
6.1

Same as begin().

See also
constEnd(), begin(), cbegin(), crbegin(), data()

Definition at line 417 of file qstringview.h.

◆ constData()

const_pointer QStringView::constData ( ) const
inlinenodiscardnoexcept
\fn const QChar *QStringView::data() const

! [const-pointer-to-first-ch] Returns a const pointer to the first character in the string view.

Note
The character array represented by the return value is not null-terminated. ! [const-pointer-to-first-ch]
\sa begin(), end(), utf16()
Since
6.0

const-pointer-to-first-ch

See also
data(), begin(), end(), utf16()

Definition at line 184 of file qstringview.h.

References data().

+ Here is the call graph for this function:

◆ constEnd()

const_iterator QStringView::constEnd ( ) const
inlinenodiscardnoexcept
Since
6.1

Same as end().

See also
constBegin(), end(), cend(), crend()

Definition at line 418 of file qstringview.h.

◆ contains() [1/3]

bool QStringView::contains ( QChar c,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept
Since
5.14

Returns true if this string view contains an occurrence of

utf16-or-latin1-or-ch respectively; otherwise returns false.

{search-comparison-case-sensitivity} {search}

See also
indexOf()

Definition at line 285 of file qstringview.h.

◆ contains() [2/3]

bool QStringView::contains ( QLatin1StringView s,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 80 of file qstring.h.

◆ contains() [3/3]

bool QStringView::contains ( QStringView s,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 287 of file qstringview.h.

◆ count() [1/3]

qsizetype QStringView::count ( QChar c,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 291 of file qstringview.h.

◆ count() [2/3]

qsizetype QStringView::count ( QLatin1StringView s,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscard

Definition at line 86 of file qstring.h.

◆ count() [3/3]

qsizetype QStringView::count ( QStringView s,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 293 of file qstringview.h.

◆ crbegin()

const_reverse_iterator QStringView::crbegin ( ) const
inlinenodiscardnoexcept

Same as rbegin().

This function is provided for STL compatibility.

See also
crend(), rbegin(), cbegin()

Definition at line 402 of file qstringview.h.

◆ crend()

const_reverse_iterator QStringView::crend ( ) const
inlinenodiscardnoexcept

Same as rend().

This function is provided for STL compatibility.

See also
crbegin(), rend(), cend()

Definition at line 403 of file qstringview.h.

◆ data()

const_pointer QStringView::data ( ) const
inlinenodiscardnoexcept

Definition at line 183 of file qstringview.h.

Referenced by constData().

+ Here is the caller graph for this function:

◆ empty()

bool QStringView::empty ( ) const
inlinenodiscardconstexprnoexcept

Returns whether this string view is empty - that is, whether {size() == 0}.

This function is provided for STL compatibility.

See also
isEmpty(), isNull(), size(), length()

Definition at line 405 of file qstringview.h.

◆ end()

const_iterator QStringView::end ( ) const
inlinenodiscardnoexcept

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary character after the last character in the list.

This function is provided for STL compatibility.

See also
begin(), constEnd(), cend(), rend()

Definition at line 397 of file qstringview.h.

◆ endsWith() [1/4]

bool QStringView::endsWith ( QChar c) const
inlinenodiscardnoexcept

Definition at line 274 of file qstringview.h.

◆ endsWith() [2/4]

bool QStringView::endsWith ( QChar ch,
Qt::CaseSensitivity cs ) const
inlinenodiscardnoexcept

Returns true if this string view ends with.

utf16-or-latin1-or-ch respectively; otherwise returns false.

{search-comparison-case-sensitivity} {search}

See also
startsWith()

Definition at line 276 of file qstringview.h.

◆ endsWith() [3/4]

bool QStringView::endsWith ( QLatin1StringView s,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 76 of file qstring.h.

◆ endsWith() [4/4]

bool QStringView::endsWith ( QStringView s,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 271 of file qstringview.h.

◆ first() [1/2]

QChar QStringView::first ( ) const
inlinenodiscardconstexpr

Returns the first character in the string view.

Same as front().

This function is provided for compatibility with other Qt containers.

calling-on-empty-is-UB

See also
front(), back(), last()

Definition at line 423 of file qstringview.h.

◆ first() [2/2]

QStringView QStringView::first ( qsizetype n) const
inlinenodiscardconstexprnoexcept
Since
6.0

Returns a string view that points to the first n characters of this string view.

Note
The behavior is undefined when n < 0 or n > size().
See also
last(), sliced(), startsWith(), chopped(), chop(), truncate(), slice()

Definition at line 223 of file qstringview.h.

◆ fromArray()

template<typename Char , size_t Size, if_compatible_char< Char > = true>
static constexpr QStringView QStringView::fromArray ( const Char(&) string[Size])
inlinestaticnodiscardconstexprnoexcept

Constructs a string view on the full character string literal string, including any trailing {Char(0)}.

If you don't want the null-terminator included in the view then you can chop() it off when you are certain it is at the end. Alternatively you can use the constructor overload taking an array literal which will create a view up to, but not including, the first null-terminator in the data.

string must remain valid for the lifetime of this string view object.

This function will work with any array literal if Char is a compatible character type. The compatible character types are: QChar, ushort, char16_t and (on platforms, such as Windows, where it is a 16-bit type) wchar_t.

Definition at line 172 of file qstringview.h.

◆ front()

QChar QStringView::front ( ) const
inlinenodiscardconstexpr

Definition at line 406 of file qstringview.h.

◆ indexOf() [1/3]

qsizetype QStringView::indexOf ( QChar c,
qsizetype from = 0,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept
Since
5.14

Returns the index position of the first occurrence of

utf16-or-latin1-or-ch respectively, in this string view, searching forward from index position from. Returns -1 if str, l1 or ch is not found, respectively.

{search-comparison-case-sensitivity} {search}

negative-index-start-search-from-end

See also
QString::indexOf()

Definition at line 279 of file qstringview.h.

◆ indexOf() [2/3]

qsizetype QStringView::indexOf ( QLatin1StringView s,
qsizetype from = 0,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 78 of file qstring.h.

◆ indexOf() [3/3]

qsizetype QStringView::indexOf ( QStringView s,
qsizetype from = 0,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 281 of file qstringview.h.

◆ isEmpty()

bool QStringView::isEmpty ( ) const
inlinenodiscardconstexprnoexcept

Returns whether this string view is empty - that is, whether {size() == 0}.

This function is provided for compatibility with other Qt containers.

See also
empty(), isNull(), size(), length()

Definition at line 420 of file qstringview.h.

◆ isLower()

bool QStringView::isLower ( ) const
inlinenodiscardnoexcept
Since
6.7 Returns true if this view is identical to its lowercase folding.

Note that this does not mean that the string view does not contain uppercase letters (some uppercase letters do not have a lowercase folding; they are left unchanged by toString().toLower()). For more information, refer to the Unicode standard, section 3.13.

See also
QChar::toLower(), isUpper()

Definition at line 344 of file qstringview.h.

◆ isNull()

bool QStringView::isNull ( ) const
inlinenodiscardconstexprnoexcept

Returns whether this string view is null - that is, whether {data() == nullptr}.

This functions is provided for compatibility with other Qt containers.

See also
empty(), isEmpty(), size(), length()

Definition at line 419 of file qstringview.h.

◆ isRightToLeft()

bool QStringView::isRightToLeft ( ) const
inlinenodiscardnoexcept
Since
5.11

Returns true if the string view is read right to left.

See also
QString::isRightToLeft()

Definition at line 337 of file qstringview.h.

◆ isUpper()

bool QStringView::isUpper ( ) const
inlinenodiscardnoexcept
Since
6.7 Returns true if this view is identical to its uppercase folding.

Note that this does not mean that the the string view does not contain lowercase letters (some lowercase letters do not have a uppercase folding; they are left unchanged by toString().toUpper()). For more information, refer to the Unicode standard, section 3.13.

See also
QChar::toUpper(), isLower()

Definition at line 342 of file qstringview.h.

◆ isValidUtf16()

bool QStringView::isValidUtf16 ( ) const
inlinenodiscardnoexcept
Since
5.15

Returns true if the string view contains valid UTF-16 encoded data, or false otherwise.

Note that this function does not perform any special validation of the data; it merely checks if it can be successfully decoded from UTF-16. The data is assumed to be in host byte order; the presence of a BOM is meaningless.

See also
QString::isValidUtf16()

Definition at line 339 of file qstringview.h.

◆ last() [1/2]

QChar QStringView::last ( ) const
inlinenodiscardconstexpr

Returns the last character in the string view.

Same as back().

This function is provided for compatibility with other Qt containers.

calling-on-empty-is-UB

See also
back(), front(), first()

Definition at line 424 of file qstringview.h.

◆ last() [2/2]

QStringView QStringView::last ( qsizetype n) const
inlinenodiscardconstexprnoexcept
Since
6.0

Returns a string view that points to the last n characters of this string view.

Note
The behavior is undefined when n < 0 or n > size().
See also
first(), sliced(), endsWith(), chopped(), chop(), truncate(), slice()

Definition at line 225 of file qstringview.h.

◆ lastIndexOf() [1/6]

qsizetype QStringView::lastIndexOf ( QChar c,
qsizetype from,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept
Since
5.14

Returns the index position of the last occurrence of

utf16-or-latin1-or-ch respectively, in this string view, searching backward from index position from.

negative-index-start-search-from-end

Returns -1 if str, l1 or c is not found, respectively.

{search-comparison-case-sensitivity} {search}

Note
When searching for a 0-length str or l1, the match at the end of the data is excluded from the search by a negative from, even though {-1} is normally thought of as searching from the end of the string view: the match at the end is after the last character, so it is excluded. To include such a final empty match, either give a positive value for from or omit the from parameter entirely.
See also
QString::lastIndexOf()

Definition at line 299 of file qstringview.h.

◆ lastIndexOf() [2/6]

qsizetype QStringView::lastIndexOf ( QChar c,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 297 of file qstringview.h.

◆ lastIndexOf() [3/6]

qsizetype QStringView::lastIndexOf ( QLatin1StringView s,
qsizetype from,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 84 of file qstring.h.

◆ lastIndexOf() [4/6]

qsizetype QStringView::lastIndexOf ( QLatin1StringView s,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 82 of file qstring.h.

◆ lastIndexOf() [5/6]

qsizetype QStringView::lastIndexOf ( QStringView s,
qsizetype from,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 303 of file qstringview.h.

◆ lastIndexOf() [6/6]

qsizetype QStringView::lastIndexOf ( QStringView s,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 301 of file qstringview.h.

◆ left()

QStringView QStringView::left ( qsizetype length) const
inlinenodiscardconstexprnoexcept
Deprecated
Use first() instead in new code.

Returns the substring of length length starting at position 0 in this object.

The entire string view is returned if length is greater than or equal to size(), or less than zero.

See also
first(), last(), sliced(), startsWith(), chopped(), chop(), truncate(), slice()
Deprecated
Use first() instead in new code.

Returns the substring of length length starting at position 0 in this object.

The entire string view is returned if length is greater than or equal to size(), or less than zero.

See also
first(), last(), sliced(), startsWith(), chopped(), chop(), truncate(), slice()

Definition at line 210 of file qstringview.h.

Referenced by testing.tools.safetynet_image.ImageLocations::Left().

+ Here is the caller graph for this function:

◆ length()

qsizetype QStringView::length ( ) const
inlinenodiscardconstexprnoexcept

Same as size().

This function is provided for compatibility with other Qt containers.

See also
empty(), isEmpty(), isNull(), size()

Definition at line 421 of file qstringview.h.

Referenced by testing.tools.encode_pdf_filter._PngIdatPdfStream::write().

+ Here is the caller graph for this function:

◆ localeAwareCompare()

int QStringView::localeAwareCompare ( QStringView other) const
inlinenodiscard
Since
6.4

Compares this string view with the other string view and returns an integer less than, equal to, or greater than zero if this string view is less than, equal to, or greater than the other string view.

The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.

See also
{Comparing Strings}

Definition at line 1520 of file qstring.h.

◆ max_size()

qsizetype QStringView::max_size ( ) const
inlinenodiscardconstexprnoexcept
Since
6.8

This function is provided for STL compatibility.

Returns maxSize().

Definition at line 412 of file qstringview.h.

◆ maxSize()

static constexpr qsizetype QStringView::maxSize ( )
inlinestaticnodiscardconstexprnoexcept
Since
6.8

It returns the maximum number of elements that the view can theoretically represent. In practice, the number can be much smaller, limited by the amount of memory available to the system.

Definition at line 426 of file qstringview.h.

◆ mid()

QStringView QStringView::mid ( qsizetype start,
qsizetype length = -1 ) const
inlinenodiscardconstexprnoexcept

Returns the substring of length length starting at position start in this object.

Deprecated
Use sliced() instead in new code.

Returns an empty string view if start exceeds the length of the string view. If there are less than length characters available in the string view starting at start, or if length is negative (default), the function returns all characters that are available from start.

See also
first(), last(), sliced(), chopped(), chop(), truncate(), slice()
Deprecated
Use sliced() instead in new code.

Returns an empty string view if start exceeds the length of the string view. If there are less than length characters available in the string view starting at start, or if length is negative (default), the function returns all characters that are available from start.

See also
first(), last(), sliced(), chopped(), chop(), truncate(), slice()

Definition at line 204 of file qstringview.h.

◆ operator std::u16string_view()

Q_IMPLICIT QStringView::operator std::u16string_view ( ) const
inlinenodiscardnoexcept
Since
6.7

Converts this QStringView object to a {std::u16string_view} object. The returned view will have the same data pointer and length of this view.

Definition at line 409 of file qstringview.h.

◆ operator[]()

QChar QStringView::operator[] ( qsizetype n) const
inlinenodiscardconstexpr

Returns the character at position n in this string view.

The behavior is undefined if n is negative or not less than size().

See also
at(), front(), back()

Definition at line 187 of file qstringview.h.

◆ rbegin()

const_reverse_iterator QStringView::rbegin ( ) const
inlinenodiscardnoexcept

Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first character in the string view, in reverse order.

This function is provided for STL compatibility.

See also
rend(), crbegin(), begin()

Definition at line 400 of file qstringview.h.

◆ rend()

const_reverse_iterator QStringView::rend ( ) const
inlinenodiscardnoexcept

Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past the last character in the string view, in reverse order.

This function is provided for STL compatibility.

See also
rbegin(), crend(), end()

Definition at line 401 of file qstringview.h.

◆ right()

QStringView QStringView::right ( qsizetype length) const
inlinenodiscardconstexprnoexcept
Deprecated
Use last() instead in new code.

Returns the substring of length length starting at position size() - length in this object.

The entire string view is returned if length is greater than or equal to size(), or less than zero.

See also
first(), last(), sliced(), endsWith(), chopped(), chop(), truncate(), slice()
Deprecated
Use last() instead in new code.

Returns the substring of length length starting at position size() - length in this object.

The entire string view is returned if length is greater than or equal to size(), or less than zero.

See also
first(), last(), sliced(), endsWith(), chopped(), chop(), truncate(), slice()

Definition at line 216 of file qstringview.h.

Referenced by testing.tools.safetynet_image.ImageLocations::Right().

+ Here is the caller graph for this function:

◆ size()

qsizetype QStringView::size ( ) const
inlinenodiscardconstexprnoexcept

Returns the size of this string view, in UTF-16 code units (that is, surrogate pairs count as two for the purposes of this function, the same as in QString).

See also
empty(), isEmpty(), isNull(), length()

Definition at line 182 of file qstringview.h.

◆ slice() [1/2]

QStringView & QStringView::slice ( qsizetype pos)
inlineconstexpr
Since
6.8 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Modifies this string view to start from position pos, extending to its end.

UB-sliced-index-only

See also
sliced(), first(), last(), chopped(), chop(), truncate()

Definition at line 241 of file qstringview.h.

◆ slice() [2/2]

QStringView & QStringView::slice ( qsizetype pos,
qsizetype n )
inlineconstexpr
\fn QStringView QStringView::sliced(qsizetype pos, qsizetype n) const
\since 6.0

Returns a string view that points to \a n characters of this string view,
starting at position \a pos.

! [UB-sliced-index-length]

Note
The behavior is undefined when pos < 0, n < 0, or pos + n > size(). ! [UB-sliced-index-length]
\sa first(), last(), chopped(), chop(), truncate(), slice()
\fn QStringView QStringView::sliced(qsizetype pos) const
\since 6.0
\overload

Returns a string view starting at position \a pos in this object,
and extending to its end.

! [UB-sliced-index-only]

Note
The behavior is undefined when pos < 0 or pos > size(). ! [UB-sliced-index-only]
\sa first(), last(), chopped(), chop(), truncate(), slice()
Since
6.8

Modifies this string view to start from position pos, extending for n code points.

UB-sliced-index-length

See also
sliced(), first(), last(), chopped(), chop(), truncate()

Definition at line 243 of file qstringview.h.

◆ sliced() [1/2]

QStringView QStringView::sliced ( qsizetype pos) const
inlinenodiscardconstexprnoexcept

Definition at line 227 of file qstringview.h.

◆ sliced() [2/2]

QStringView QStringView::sliced ( qsizetype pos,
qsizetype n ) const
inlinenodiscardconstexprnoexcept

Definition at line 229 of file qstringview.h.

◆ split() [1/2]

QList< QStringView > QStringView::split ( QChar sep,
Qt::SplitBehavior behavior = Qt::KeepEmptyParts,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
nodiscard

Definition at line 8303 of file qstring.cpp.

◆ split() [2/2]

QList< QStringView > QStringView::split ( QStringView sep,
Qt::SplitBehavior behavior = Qt::KeepEmptyParts,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
nodiscard

Splits the view into substring views wherever sep occurs, and returns the list of those string views.

See QString::split() for how sep, behavior and cs interact to form the result.

Note
All the returned views are valid as long as the data referenced by this string view is valid. Destroying the data will cause all views to become dangling.
Since
6.0

Definition at line 8298 of file qstring.cpp.

◆ startsWith() [1/4]

bool QStringView::startsWith ( QChar c) const
inlinenodiscardnoexcept

Definition at line 266 of file qstringview.h.

◆ startsWith() [2/4]

bool QStringView::startsWith ( QChar ch,
Qt::CaseSensitivity cs ) const
inlinenodiscardnoexcept

Returns true if this string view starts with.

utf16-or-latin1-or-ch respectively; otherwise returns false.

{search-comparison-case-sensitivity} {search}

See also
endsWith()

Definition at line 268 of file qstringview.h.

◆ startsWith() [3/4]

bool QStringView::startsWith ( QLatin1StringView s,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 74 of file qstring.h.

◆ startsWith() [4/4]

bool QStringView::startsWith ( QStringView s,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inlinenodiscardnoexcept

Definition at line 263 of file qstringview.h.

◆ toDouble()

double QStringView::toDouble ( bool * ok = nullptr) const
nodiscard

Returns the string view converted to a double value.

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).

If ok is not \nullptr, failure is reported by setting *{ok} to false, and success by setting *{ok} to true.

The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toDouble()

For historic reasons, this function does not handle thousands group separators. If you need to convert such numbers, use QLocale::toDouble().

See also
QString::toDouble()
Since
6.0

Definition at line 7958 of file qstring.cpp.

◆ toFloat()

float QStringView::toFloat ( bool * ok = nullptr) const
nodiscard

Returns the string view converted to a float value.

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).

If ok is not \nullptr, failure is reported by setting *{ok} to false, and success by setting *{ok} to true.

The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toFloat()

See also
QString::toFloat()
Since
6.0

Definition at line 8004 of file qstring.cpp.

◆ toInt()

int QStringView::toInt ( bool * ok = nullptr,
int base = 10 ) const
inlinenodiscard

Returns the string view converted to an int using base base, which is 10 by default and must be between 2 and 36, or 0.

Returns 0 if the conversion fails.

If ok is not \nullptr, failure is reported by setting *{ok} to false, and success by setting *{ok} to true.

If base is 0, the C language convention is used: if the string view begins with "0x", base 16 is used; otherwise, if the string view begins with "0", base 8 is used; otherwise, base 10 is used.

The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toInt()

See also
QString::toInt()
Since
6.0

Definition at line 1141 of file qstring.h.

◆ tokenize()

template<typename Needle , typename... Flags>
auto QStringView::tokenize ( Needle && needle,
Flags... flags ) const -> decltype(qTokenize(*this, std::forward<Needle>(needle), flags...))
inlinenodiscardconstexprnoexcept

Definition at line 247 of file qstringview.h.

◆ toLatin1()

QByteArray QStringView::toLatin1 ( ) const
inlinenodiscard

Returns a Latin-1 representation of the string as a QByteArray.

The behavior is undefined if the string contains non-Latin1 characters.

See also
toUtf8(), toLocal8Bit(), QStringEncoder

Definition at line 197 of file qstringview.h.

◆ toLocal8Bit()

QByteArray QStringView::toLocal8Bit ( ) const
inlinenodiscard

Returns a local 8-bit representation of the string as a QByteArray.

On Unix systems this is equivalen to toUtf8(), on Windows the systems current code page is being used.

The behavior is undefined if the string contains characters not supported by the locale's 8-bit encoding.

See also
toLatin1(), toUtf8(), QStringEncoder

Definition at line 199 of file qstringview.h.

◆ toLong()

long QStringView::toLong ( bool * ok = nullptr,
int base = 10 ) const
inlinenodiscard

Returns the string view converted to a long using base base, which is 10 by default and must be between 2 and 36, or 0.

Returns 0 if the conversion fails.

If ok is not \nullptr, failure is reported by setting *{ok} to false, and success by setting *{ok} to true.

If base is 0, the C language convention is used: if the string view begins with "0x", base 16 is used; otherwise, if the string view begins with "0", base 8 is used; otherwise, base 10 is used.

The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toLong()

See also
QString::toLong()
Since
6.0

Definition at line 1137 of file qstring.h.

◆ toLongLong()

qint64 QStringView::toLongLong ( bool * ok = nullptr,
int base = 10 ) const
inlinenodiscard

Returns the string view converted to a {long long} using base base, which is 10 by default and must be between 2 and 36, or 0.

Returns 0 if the conversion fails.

If ok is not \nullptr, failure is reported by setting *{ok} to false, and success by setting *{ok} to true.

If base is 0, the C language convention is used: if the string view begins with "0x", base 16 is used; otherwise, if the string view begins with "0", base 8 is used; otherwise, base 10 is used.

The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toLongLong()

See also
QString::toLongLong()
Since
6.0

Definition at line 1133 of file qstring.h.

◆ toShort()

short QStringView::toShort ( bool * ok = nullptr,
int base = 10 ) const
inlinenodiscard

Returns the string view converted to a short using base base, which is 10 by default and must be between 2 and 36, or 0.

Returns 0 if the conversion fails.

If ok is not \nullptr, failure is reported by setting *{ok} to false, and success by setting *{ok} to true.

If base is 0, the C language convention is used: if the string view begins with "0x", base 16 is used; otherwise, if the string view begins with "0", base 8 is used; otherwise, base 10 is used.

The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toShort()

See also
QString::toShort()
Since
6.0

Definition at line 1145 of file qstring.h.

◆ toString()

QString QStringView::toString ( ) const
inlinenodiscard

Returns a deep copy of this string view's data as a QString.

The return value will be the null QString if and only if this string view is null.

Definition at line 1130 of file qstring.h.

◆ toUcs4()

QList< uint > QStringView::toUcs4 ( ) const
inlinenodiscard

Returns a UCS-4/UTF-32 representation of the string view as a QList<uint>.

UCS-4 is a Unicode codec and therefore it is lossless. All characters from this string view will be encoded in UCS-4. Any invalid sequence of code units in this string view is replaced by the Unicode replacement character (QChar::ReplacementCharacter, which corresponds to {U+FFFD}).

The returned list is not 0-terminated.

See also
toUtf8(), toLatin1(), toLocal8Bit(), QStringEncoder

Definition at line 1021 of file qlist.h.

◆ toUInt()

uint QStringView::toUInt ( bool * ok = nullptr,
int base = 10 ) const
inlinenodiscard

Returns the string view converted to an {unsigned int} using base base, which is 10 by default and must be between 2 and 36, or 0.

Returns 0 if the conversion fails.

If ok is not \nullptr, failure is reported by setting *{ok} to false, and success by setting *{ok} to true.

If base is 0, the C language convention is used: if the string view begins with "0x", base 16 is used; otherwise, if the string view begins with "0", base 8 is used; otherwise, base 10 is used.

The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toUInt()

See also
QString::toUInt()
Since
6.0

Definition at line 1143 of file qstring.h.

◆ toULong()

ulong QStringView::toULong ( bool * ok = nullptr,
int base = 10 ) const
inlinenodiscard

Returns the string view converted to an {unsigned long} using base base, which is 10 by default and must be between 2 and 36, or 0.

Returns 0 if the conversion fails.

If ok is not \nullptr, failure is reported by setting *{ok} to false, and success by setting *{ok} to true.

If base is 0, the C language convention is used: if the string view begins with "0x", base 16 is used; otherwise, if the string view begins with "0", base 8 is used; otherwise, base 10 is used.

The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toULongLong()

See also
QString::toULong()
Since
6.0

Definition at line 1139 of file qstring.h.

◆ toULongLong()

quint64 QStringView::toULongLong ( bool * ok = nullptr,
int base = 10 ) const
inlinenodiscard

Returns the string view converted to an {unsigned long long} using base base, which is 10 by default and must be between 2 and 36, or 0.

Returns 0 if the conversion fails.

If ok is not \nullptr, failure is reported by setting *{ok} to false, and success by setting *{ok} to true.

If base is 0, the C language convention is used: if the string view begins with "0x", base 16 is used; otherwise, if the string view begins with "0", base 8 is used; otherwise, base 10 is used.

The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toULongLong()

See also
QString::toULongLong()
Since
6.0

Definition at line 1135 of file qstring.h.

◆ toUShort()

ushort QStringView::toUShort ( bool * ok = nullptr,
int base = 10 ) const
inlinenodiscard

Returns the string view converted to an {unsigned short} using base base, which is 10 by default and must be between 2 and 36, or 0.

Returns 0 if the conversion fails.

If ok is not \nullptr, failure is reported by setting *{ok} to false, and success by setting *{ok} to true.

If base is 0, the C language convention is used: if the string view begins with "0x", base 16 is used; otherwise, if the string view begins with "0", base 8 is used; otherwise, base 10 is used.

The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toUShort()

See also
QString::toUShort()
Since
6.0

Definition at line 1147 of file qstring.h.

◆ toUtf8()

QByteArray QStringView::toUtf8 ( ) const
inlinenodiscard

Returns a UTF-8 representation of the string view as a QByteArray.

UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QString.

See also
toLatin1(), toLocal8Bit(), QStringEncoder

Definition at line 198 of file qstringview.h.

◆ toWCharArray()

qsizetype QStringView::toWCharArray ( wchar_t * array) const
inlinenodiscard
Since
5.14

Transcribes this string view into the given array.

The caller is responsible for ensuring array is large enough to hold the wchar_t encoding of this string view (allocating the array with the same length as the string view is always sufficient). The array is encoded in UTF-16 on platforms where wchar_t is 2 bytes wide (e.g. Windows); otherwise (Unix systems), wchar_t is assumed to be 4 bytes wide and the data is written in UCS-4.

Note
This function writes no null terminator to the end of array.

Returns the number of wchar_t entries written to array.

See also
QString::toWCharArray()

Definition at line 1305 of file qstring.h.

◆ trimmed()

QStringView QStringView::trimmed ( ) const
inlinenodiscardnoexcept

Strips leading and trailing whitespace and returns the result.

Whitespace means any character for which QChar::isSpace() returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.

Definition at line 239 of file qstringview.h.

◆ truncate()

void QStringView::truncate ( qsizetype length)
inlineconstexprnoexcept

Truncates this string view to length length.

Same as {*this = left(length)}.

Note
The behavior is undefined when length < 0 or length > size().
See also
mid(), left(), right(), chopped(), chop()

Definition at line 234 of file qstringview.h.

◆ utf16()

const storage_type * QStringView::utf16 ( ) const
inlinenodiscardconstexprnoexcept

const-pointer-to-first-ch

{storage_type} is {char16_t}.

See also
begin(), end(), data()

Definition at line 185 of file qstringview.h.

Referenced by QtPrivate::findString().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ comparesEqual [1/3]

bool comparesEqual ( const QStringView & lhs,
const QByteArrayView & rhs )
friend

Definition at line 456 of file qstringview.h.

◆ comparesEqual [2/3]

bool comparesEqual ( const QStringView & lhs,
const QStringView & rhs )
friend

Definition at line 376 of file qstringview.h.

◆ comparesEqual [3/3]

bool comparesEqual ( const QStringView & lhs,
QChar rhs )
friend

Definition at line 387 of file qstringview.h.

◆ compareStrings() [1/9]

int compareStrings ( QBasicUtf8StringView< false > lhs,
QBasicUtf8StringView< false > rhs,
Qt::CaseSensitivity cs )
related
Since
6.0 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1588 of file qstring.cpp.

◆ compareStrings() [2/9]

int compareStrings ( QBasicUtf8StringView< false > lhs,
QLatin1StringView rhs,
Qt::CaseSensitivity cs )
related
Since
6.0 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1577 of file qstring.cpp.

◆ compareStrings() [3/9]

int compareStrings ( QBasicUtf8StringView< false > lhs,
QStringView rhs,
Qt::CaseSensitivity cs )
related
Since
6.0 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1564 of file qstring.cpp.

◆ compareStrings() [4/9]

int compareStrings ( QLatin1StringView lhs,
QBasicUtf8StringView< false > rhs,
Qt::CaseSensitivity cs )
related
Since
6.0 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1553 of file qstring.cpp.

◆ compareStrings() [5/9]

int compareStrings ( QLatin1StringView lhs,
QLatin1StringView rhs,
Qt::CaseSensitivity cs )
related
Since
5.10 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns an integer that compares to 0 as lhs compares to rhs.

{search-comparison-case-sensitivity} {comparison}

Case-sensitive comparison is based exclusively on the numeric Latin-1 values of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with QString::localeAwareCompare().

See also
{Comparing Strings}

Definition at line 1534 of file qstring.cpp.

◆ compareStrings() [6/9]

int compareStrings ( QLatin1StringView lhs,
QStringView rhs,
Qt::CaseSensitivity cs )
related
Since
5.10 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1513 of file qstring.cpp.

◆ compareStrings() [7/9]

int compareStrings ( QStringView lhs,
QBasicUtf8StringView< false > rhs,
Qt::CaseSensitivity cs )
related
Since
6.0 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1502 of file qstring.cpp.

◆ compareStrings() [8/9]

int compareStrings ( QStringView lhs,
QLatin1StringView rhs,
Qt::CaseSensitivity cs )
related
Since
5.10 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns an integer that compares to 0 as lhs compares to rhs.

{search-comparison-case-sensitivity} {comparison}

Case-sensitive comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with QString::localeAwareCompare().

See also
{Comparing Strings}

Definition at line 1489 of file qstring.cpp.

◆ compareStrings() [9/9]

int compareStrings ( QStringView lhs,
QStringView rhs,
Qt::CaseSensitivity cs )
related
Since
5.10

Returns an integer that compares to 0 as lhs compares to rhs.

{search-comparison-case-sensitivity} {comparison}

Case-sensitive comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with QString::localeAwareCompare().

See also
{Comparing Strings}

Definition at line 1466 of file qstring.cpp.

◆ compareThreeWay [1/3]

Qt::strong_ordering compareThreeWay ( const QStringView & lhs,
const QByteArrayView & rhs )
friend

Definition at line 459 of file qstringview.h.

◆ compareThreeWay [2/3]

Qt::strong_ordering compareThreeWay ( const QStringView & lhs,
const QStringView & rhs )
friend

Definition at line 379 of file qstringview.h.

◆ compareThreeWay [3/3]

Qt::strong_ordering compareThreeWay ( const QStringView & lhs,
QChar rhs )
friend

Definition at line 389 of file qstringview.h.

◆ convertToLatin1()

QByteArray convertToLatin1 ( QStringView string)
related
Since
5.10

Returns a Latin-1 representation of string as a QByteArray.

The behavior is undefined if string contains non-Latin1 characters.

See also
QString::toLatin1(), QStringView::toLatin1(), QtPrivate::convertToUtf8(), QtPrivate::convertToLocal8Bit(), QtPrivate::convertToUcs4()

Definition at line 5652 of file qstring.cpp.

◆ convertToLocal8Bit()

QByteArray convertToLocal8Bit ( QStringView string)
related
Since
5.10

Returns a local 8-bit representation of string as a QByteArray.

On Unix systems this is equivalent to toUtf8(), on Windows the systems current code page is being used.

The behavior is undefined if string contains characters not supported by the locale's 8-bit encoding.

See also
QString::toLocal8Bit(), QStringView::toLocal8Bit()

Definition at line 5793 of file qstring.cpp.

◆ convertToUcs4()

QList< uint > convertToUcs4 ( QStringView string)
related
Since
5.10

Returns a UCS-4/UTF-32 representation of string as a QList<uint>.

UCS-4 is a Unicode codec and therefore it is lossless. All characters from this string will be encoded in UCS-4. Any invalid sequence of code units in this string is replaced by the Unicode's replacement character (QChar::ReplacementCharacter, which corresponds to {U+FFFD}).

The returned list is not \0'-terminated.

See also
QString::toUcs4(), QStringView::toUcs4(), QtPrivate::convertToLatin1(), QtPrivate::convertToLocal8Bit(), QtPrivate::convertToUtf8()

Definition at line 5891 of file qstring.cpp.

◆ convertToUtf8()

QByteArray convertToUtf8 ( QStringView string)
related
Since
5.10

Returns a UTF-8 representation of string as a QByteArray.

UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QStringView.

See also
QString::toUtf8(), QStringView::toUtf8()

Definition at line 5836 of file qstring.cpp.

◆ endsWith()

bool endsWith ( QLatin1StringView haystack,
QLatin1StringView needle,
Qt::CaseSensitivity cs )
related
Since
5.10

Returns true if haystack ends with needle, otherwise returns false.

{search-comparison-case-sensitivity} {search}

See also
QtPrivate::startsWith(), QString::endsWith(), QStringView::endsWith(), QLatin1StringView::endsWith()

◆ isRightToLeft()

bool isRightToLeft ( QStringView string)
related
Since
5.11

Returns true if the string is read right to left.

See also
QString::isRightToLeft()

Definition at line 9709 of file qstring.cpp.

References QStringIterator::hasNext(), and QStringIterator::next().

+ Here is the call graph for this function:

◆ qHash()

size_t qHash ( QStringView key,
size_t seed = 0 )
related
Since
5.10

Returns the hash value for the key, using seed to seed the calculation.

◆ startsWith()

bool startsWith ( QLatin1StringView haystack,
QLatin1StringView needle,
Qt::CaseSensitivity cs )
related
Since
5.10

Returns true if haystack starts with needle, otherwise returns false.

{search-comparison-case-sensitivity} {search}

See also
QtPrivate::endsWith(), QString::endsWith(), QStringView::endsWith(), QLatin1StringView::endsWith()

◆ trimmed()

QLatin1StringView trimmed ( QLatin1StringView s)
related
Since
5.10

Returns s with whitespace removed from the start and the end.

Whitespace means any character for which QChar::isSpace() returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.

See also
QString::trimmed(), QStringView::trimmed(), QLatin1StringView::trimmed()

The documentation for this class was generated from the following files: