QtBase  v6.3.1
Public Types | Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
QStringView Class Reference

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

#include <qstringview.h>

Public Types

typedef char16_t storage_type
 
typedef const QChar value_type
 
typedef std::ptrdiff_t difference_type
 
typedef qsizetype size_type
 
typedef value_typereference
 
typedef value_typeconst_reference
 
typedef value_typepointer
 
typedef value_typeconst_pointer
 
typedef pointer iterator
 
typedef const_pointer const_iterator
 
typedef std::reverse_iterator< iteratorreverse_iterator
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 

Public Member Functions

constexpr QStringView () noexcept
 
constexpr QStringView (std::nullptr_t) noexcept
 
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)
 
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 QStringView (const Container &c) noexcept
 
QString toString () const
 
constexpr qsizetype size () const noexcept
 
const_pointer data () const noexcept
 
const_pointer constData () const noexcept
 
constexpr const storage_typeutf16 () const noexcept
 
constexpr QChar operator[] (qsizetype n) const
 
template<typename... Args>
QString arg (Args &&...args) const
 
QByteArray toLatin1 () const
 
QByteArray toUtf8 () const
 
QByteArray toLocal8Bit () const
 
QList< uinttoUcs4 () const
 
constexpr QChar at (qsizetype n) const noexcept
 
constexpr QStringView mid (qsizetype pos, qsizetype n=-1) const noexcept
 
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
 
constexpr void truncate (qsizetype n) noexcept
 
constexpr void chop (qsizetype n) noexcept
 
QStringView trimmed () const noexcept
 
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 (QLatin1String other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
constexpr int compare (QChar c) const noexcept
 
int compare (QChar c, Qt::CaseSensitivity cs) const noexcept
 
bool startsWith (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool startsWith (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool startsWith (QChar c) const noexcept
 
bool startsWith (QChar c, Qt::CaseSensitivity cs) const noexcept
 
bool endsWith (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool endsWith (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool endsWith (QChar c) const noexcept
 
bool endsWith (QChar c, Qt::CaseSensitivity cs) const noexcept
 
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 (QLatin1String 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 (QLatin1String 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 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 (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
qsizetype lastIndexOf (QLatin1String s, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool isRightToLeft () const noexcept
 
bool isValidUtf16 () const noexcept
 
short toShort (bool *ok=nullptr, int base=10) const
 
ushort toUShort (bool *ok=nullptr, int base=10) const
 
int toInt (bool *ok=nullptr, int base=10) const
 
uint toUInt (bool *ok=nullptr, int base=10) const
 
long toLong (bool *ok=nullptr, int base=10) const
 
ulong toULong (bool *ok=nullptr, int base=10) const
 
qlonglong toLongLong (bool *ok=nullptr, int base=10) const
 
qulonglong toULongLong (bool *ok=nullptr, int base=10) const
 
Q_CORE_EXPORT float toFloat (bool *ok=nullptr) const
 
Q_CORE_EXPORT double toDouble (bool *ok=nullptr) const
 
qsizetype toWCharArray (wchar_t *array) const
 
Q_CORE_EXPORT QList< QStringViewsplit (QStringView sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
Q_CORE_EXPORT QList< QStringViewsplit (QChar sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
const_reverse_iterator rbegin () const noexcept
 
const_reverse_iterator rend () const noexcept
 
const_reverse_iterator crbegin () const noexcept
 
const_reverse_iterator crend () const noexcept
 
constexpr bool empty () const noexcept
 
constexpr QChar front () const
 
constexpr QChar back () const
 
const_iterator constBegin () const noexcept
 
const_iterator constEnd () const noexcept
 
constexpr bool isNull () const noexcept
 
constexpr bool isEmpty () const noexcept
 
constexpr qsizetype length () const noexcept
 
constexpr QChar first () const
 
constexpr QChar last () const
 
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>
constexpr static QStringView fromArray (const Char(&string)[Size]) noexcept
 

Friends

bool operator== (QStringView lhs, QStringView rhs) noexcept
 
bool operator!= (QStringView lhs, QStringView rhs) noexcept
 
bool operator< (QStringView lhs, QStringView rhs) noexcept
 
bool operator<= (QStringView lhs, QStringView rhs) noexcept
 
bool operator> (QStringView lhs, QStringView rhs) noexcept
 
bool operator>= (QStringView lhs, QStringView rhs) noexcept
 
bool operator== (QStringView lhs, QChar rhs) noexcept
 
bool operator!= (QStringView lhs, QChar rhs) noexcept
 
bool operator< (QStringView lhs, QChar rhs) noexcept
 
bool operator<= (QStringView lhs, QChar rhs) noexcept
 
bool operator> (QStringView lhs, QChar rhs) noexcept
 
bool operator>= (QStringView lhs, QChar rhs) noexcept
 
bool operator== (QChar lhs, QStringView rhs) noexcept
 
bool operator!= (QChar lhs, QStringView rhs) noexcept
 
bool operator< (QChar lhs, QStringView rhs) noexcept
 
bool operator<= (QChar lhs, QStringView rhs) noexcept
 
bool operator> (QChar lhs, QStringView rhs) noexcept
 
bool operator>= (QChar lhs, QStringView rhs) noexcept
 

Related Functions

(Note that these are not member functions.)

int compareStrings (QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QStringView lhs, QBasicUtf8StringView< false > rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QLatin1String lhs, QBasicUtf8StringView< false > rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QBasicUtf8StringView< false > lhs, QStringView rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QBasicUtf8StringView< false > lhs, QLatin1String rhs, Qt::CaseSensitivity cs) noexcept
 
int compareStrings (QBasicUtf8StringView< false > lhs, QBasicUtf8StringView< false > rhs, Qt::CaseSensitivity cs) noexcept
 
size_t qHash (QStringView key, size_t seed=0)
 

Detailed Description

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

\inmodule QtCore

Since
5.10

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*, int)}), 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:

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 121 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 134 of file qstringview.h.

◆ const_pointer

Alias for {value_type *}. Provided for compatibility with the STL.

Definition at line 131 of file qstringview.h.

◆ const_reference

Alias for {value_type &}. Provided for compatibility with the STL.

Definition at line 129 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 136 of file qstringview.h.

◆ difference_type

Alias for {std::ptrdiff_t}. Provided for compatibility with the STL.

Definition at line 126 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 133 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 130 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 128 of file qstringview.h.

◆ 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 135 of file qstringview.h.

◆ size_type

Alias for qsizetype. Provided for compatibility with the STL.

Definition at line 127 of file qstringview.h.

◆ storage_type

Alias for {char16_t}.

Definition at line 124 of file qstringview.h.

◆ value_type

Alias for {const QChar}. Provided for compatibility with the STL.

Definition at line 125 of file qstringview.h.

Constructor & Destructor Documentation

◆ QStringView() [1/7]

QStringView::QStringView ( )
inlineconstexprnoexcept

Constructs a null string view.

See also
isNull()

Definition at line 189 of file qstringview.h.

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 191 of file qstringview.h.

◆ QStringView() [3/7]

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

Constructs a string view on str with length len.

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

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

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

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.

Definition at line 195 of file qstringview.h.

◆ QStringView() [4/7]

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

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

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.

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.

Definition at line 200 of file qstringview.h.

◆ QStringView() [5/7]

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

Definition at line 212 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 220 of file qstringview.h.

◆ QStringView() [7/7]

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

Definition at line 225 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 1547 of file qstring.h.

Here is the call graph for this function:

◆ arg() [2/2]

template<typename... Args>
template< typename...Args > QString QStringView::arg ( Args &&...  args) const
inline
Here is the caller graph for this function:

◆ at()

QChar QStringView::at ( qsizetype  n) const
inlineconstexprnoexcept

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 259 of file qstringview.h.

Here is the caller graph for this function:

◆ back()

QChar QStringView::back ( ) const
inlineconstexpr

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

This function is provided for STL compatibility.

Warning
Calling this function on an empty string view constitutes undefined behavior.
See also
front(), first(), last()

Definition at line 455 of file qstringview.h.

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

◆ begin()

QStringView::const_iterator QStringView::begin ( ) const
inlinenoexcept

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 444 of file qstringview.h.

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

◆ cbegin()

QStringView::const_iterator QStringView::cbegin ( ) const
inlinenoexcept

Same as begin().

This function is provided for STL compatibility.

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

Definition at line 446 of file qstringview.h.

Here is the call graph for this function:

◆ cend()

QStringView::const_iterator QStringView::cend ( ) const
inlinenoexcept

Same as end().

This function is provided for STL compatibility.

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

Definition at line 447 of file qstringview.h.

Here is the call graph for this function:

◆ 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()

Definition at line 293 of file qstringview.h.

Here is the call graph for this function:

◆ chopped()

QStringView QStringView::chopped ( qsizetype  length) const
inlineconstexprnoexcept

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()

Definition at line 288 of file qstringview.h.

Here is the call graph for this function:

◆ compare() [1/4]

int QStringView::compare ( QChar  c) const
inlineconstexprnoexcept

Definition at line 307 of file qstringview.h.

Here is the call graph for this function:

◆ compare() [2/4]

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

Returns an integer that compares to zero as this string view compares to the Latin-1 string l1, or character ch, respectively.

If cs is Qt::CaseSensitive (the default), the comparison is case sensitive; otherwise the comparison is case-insensitive.

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

Definition at line 309 of file qstringview.h.

Here is the call graph for this function:

◆ compare() [3/4]

int QStringView::compare ( QLatin1String  other,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inlinenoexcept

Definition at line 334 of file qstring.h.

Here is the call graph for this function:

◆ compare() [4/4]

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

Returns an integer that compares to zero as this string view compares to the string view str.

If cs is Qt::CaseSensitive (the default), the comparison is case sensitive; otherwise the comparison is case-insensitive.

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

Definition at line 304 of file qstringview.h.

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

◆ constBegin()

QStringView::const_iterator QStringView::constBegin ( ) const
inlinenoexcept
Since
6.1

Same as begin().

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

Definition at line 460 of file qstringview.h.

Here is the call graph for this function:

◆ constData()

const QChar * QStringView::constData ( ) const
inlinenoexcept
Since
6.0

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.
See also
data(), begin(), end(), utf16()

Definition at line 241 of file qstringview.h.

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

◆ constEnd()

QStringView::const_iterator QStringView::constEnd ( ) const
inlinenoexcept
Since
6.1

Same as end().

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

Definition at line 461 of file qstringview.h.

Here is the call graph for this function:

◆ contains() [1/3]

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

Returns true if this string view contains an occurrence of the string view str, Latin-1 string l1, or character ch; otherwise returns false.

If cs is Qt::CaseSensitive (the default), the search is case-sensitive; otherwise the search is case-insensitive.

See also
indexOf()

Definition at line 334 of file qstringview.h.

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

◆ contains() [2/3]

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

Definition at line 342 of file qstring.h.

Here is the call graph for this function:

◆ contains() [3/3]

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

Definition at line 336 of file qstringview.h.

Here is the call graph for this function:

◆ count() [1/2]

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

Definition at line 340 of file qstringview.h.

Here is the call graph for this function:

◆ count() [2/2]

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

Definition at line 342 of file qstringview.h.

Here is the call graph for this function:

◆ crbegin()

QStringView::const_reverse_iterator QStringView::crbegin ( ) const
inlinenoexcept

Same as rbegin().

This function is provided for STL compatibility.

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

Definition at line 450 of file qstringview.h.

Here is the call graph for this function:

◆ crend()

QStringView::const_reverse_iterator QStringView::crend ( ) const
inlinenoexcept

Same as rend().

This function is provided for STL compatibility.

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

Definition at line 451 of file qstringview.h.

Here is the call graph for this function:

◆ data()

const QChar * QStringView::data ( ) const
inlinenoexcept

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.
See also
begin(), end(), utf16()

Definition at line 240 of file qstringview.h.

Here is the caller graph for this function:

◆ empty()

bool QStringView::empty ( ) const
inlineconstexprnoexcept

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 453 of file qstringview.h.

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

◆ end()

QStringView::const_iterator QStringView::end ( ) const
inlinenoexcept

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 445 of file qstringview.h.

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

◆ endsWith() [1/4]

bool QStringView::endsWith ( QChar  c) const
inlinenoexcept

Definition at line 323 of file qstringview.h.

Here is the call graph for this function:

◆ endsWith() [2/4]

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

Returns true if this string view ends with string view str, Latin-1 string l1, or character ch, respectively; otherwise returns false.

If cs is Qt::CaseSensitive (the default), the search is case-sensitive; otherwise the search is case-insensitive.

See also
startsWith()

Definition at line 325 of file qstringview.h.

Here is the call graph for this function:

◆ endsWith() [3/4]

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

Definition at line 338 of file qstring.h.

Here is the call graph for this function:

◆ endsWith() [4/4]

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

Definition at line 320 of file qstringview.h.

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

◆ first() [1/2]

QChar QStringView::first ( ) const
inlineconstexpr

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

This function is provided for compatibility with other Qt containers.

Warning
Calling this function on an empty string view constitutes undefined behavior.
See also
front(), back(), last()

Definition at line 466 of file qstringview.h.

Here is the call graph for this function:

◆ first() [2/2]

QStringView QStringView::first ( qsizetype  n) const
inlineconstexprnoexcept
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()

Definition at line 280 of file qstringview.h.

Here is the call graph for this function:

◆ fromArray()

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

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 229 of file qstringview.h.

Here is the call graph for this function:

◆ front()

QChar QStringView::front ( ) const
inlineconstexpr

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

This function is provided for STL compatibility.

Warning
Calling this function on an empty string view constitutes undefined behavior.
See also
back(), first(), last()

Definition at line 454 of file qstringview.h.

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

◆ indexOf() [1/3]

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

Returns the index position of the first occurrence of the string view str, Latin-1 string l1, or character ch, respectively, in this string view, searching forward from index position from. Returns -1 if str is not found.

If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

If from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.

See also
QString::indexOf()

Definition at line 328 of file qstringview.h.

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

◆ indexOf() [2/3]

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

Definition at line 340 of file qstring.h.

Here is the call graph for this function:

◆ indexOf() [3/3]

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

Definition at line 330 of file qstringview.h.

Here is the call graph for this function:

◆ isEmpty()

bool QStringView::isEmpty ( ) const
inlineconstexprnoexcept

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 463 of file qstringview.h.

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

◆ isNull()

bool QStringView::isNull ( ) const
inlineconstexprnoexcept

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 462 of file qstringview.h.

Here is the caller graph for this function:

◆ isRightToLeft()

bool QStringView::isRightToLeft ( ) const
inlinenoexcept
Since
5.11

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

See also
QString::isRightToLeft()

Definition at line 385 of file qstringview.h.

Here is the call graph for this function:

◆ isValidUtf16()

bool QStringView::isValidUtf16 ( ) const
inlinenoexcept
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 387 of file qstringview.h.

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

◆ last() [1/2]

QChar QStringView::last ( ) const
inlineconstexpr

Returns the last character in the string view. Same as back().

This function is provided for compatibility with other Qt containers.

Warning
Calling this function on an empty string view constitutes undefined behavior.
See also
back(), front(), first()

Definition at line 467 of file qstringview.h.

Here is the call graph for this function:

◆ last() [2/2]

QStringView QStringView::last ( qsizetype  n) const
inlineconstexprnoexcept
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()

Definition at line 282 of file qstringview.h.

Here is the call graph for this function:

◆ lastIndexOf() [1/6]

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

Returns the index position of the last occurrence of the string view str, Latin-1 string l1, or character ch, respectively, in this string view, searching backward from index position from. If from is -1, the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if str is not found.

If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

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 347 of file qstringview.h.

Here is the call graph for this function:

◆ lastIndexOf() [2/6]

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

Definition at line 345 of file qstringview.h.

Here is the caller graph for this function:

◆ lastIndexOf() [3/6]

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

Definition at line 346 of file qstring.h.

Here is the call graph for this function:

◆ lastIndexOf() [4/6]

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

Definition at line 344 of file qstring.h.

Here is the call graph for this function:

◆ lastIndexOf() [5/6]

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

Definition at line 351 of file qstringview.h.

Here is the call graph for this function:

◆ lastIndexOf() [6/6]

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

Definition at line 349 of file qstringview.h.

Here is the call graph for this function:

◆ left()

QStringView QStringView::left ( qsizetype  length) const
inlineconstexprnoexcept
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()

Definition at line 267 of file qstringview.h.

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

◆ length()

int QStringView::length ( ) const
inlineconstexprnoexcept

Same as size().

This function is provided for compatibility with other Qt containers.

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

Definition at line 464 of file qstringview.h.

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

◆ mid()

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

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()

Definition at line 261 of file qstringview.h.

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

◆ operator[]()

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

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 244 of file qstringview.h.

Here is the call graph for this function:

◆ rbegin()

QStringView::const_reverse_iterator QStringView::rbegin ( ) const
inlinenoexcept

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 448 of file qstringview.h.

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

◆ rend()

QStringView::const_reverse_iterator QStringView::rend ( ) const
inlinenoexcept

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 449 of file qstringview.h.

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

◆ right()

QStringView QStringView::right ( qsizetype  length) const
inlineconstexprnoexcept
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()

Definition at line 273 of file qstringview.h.

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

◆ size()

qsizetype QStringView::size ( ) const
inlineconstexprnoexcept

Returns the size of this string view, in UTF-16 code points (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 239 of file qstringview.h.

Here is the caller graph for this function:

◆ sliced() [1/2]

QStringView QStringView::sliced ( qsizetype  pos) const
inlineconstexprnoexcept
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.

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

Note
The behavior is undefined when pos < 0 or pos > size().
See also
first(), last(), chopped(), chop(), truncate()

Definition at line 284 of file qstringview.h.

Here is the call graph for this function:

◆ sliced() [2/2]

QStringView QStringView::sliced ( qsizetype  pos,
qsizetype  n 
) const
inlineconstexprnoexcept
Since
6.0

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

Note
The behavior is undefined when pos < 0, n < 0, or pos + n > size().
See also
first(), last(), chopped(), chop(), truncate()

Definition at line 286 of file qstringview.h.

Here is the call graph for this function:

◆ split() [1/2]

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

Definition at line 7707 of file qstring.cpp.

Here is the call graph for this function:

◆ split() [2/2]

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

Splits the string 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 views are valid as long as this string is. Destroying this string will cause all views to be dangling pointers.
Since
6.0

Definition at line 7702 of file qstring.cpp.

Here is the caller graph for this function:

◆ startsWith() [1/4]

bool QStringView::startsWith ( QChar  c) const
inlinenoexcept

Definition at line 315 of file qstringview.h.

Here is the call graph for this function:

◆ startsWith() [2/4]

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

Returns true if this string view starts with string view str, Latin-1 string l1, or character ch, respectively; otherwise returns false.

If cs is Qt::CaseSensitive (the default), the search is case-sensitive; otherwise the search is case-insensitive.

See also
endsWith()

Definition at line 317 of file qstringview.h.

Here is the call graph for this function:

◆ startsWith() [3/4]

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

Definition at line 336 of file qstring.h.

Here is the call graph for this function:

◆ startsWith() [4/4]

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

Definition at line 312 of file qstringview.h.

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

◆ toDouble()

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

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 10801 of file qstring.cpp.

Here is the call graph for this function:

◆ toFloat()

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

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 10806 of file qstring.cpp.

Here is the call graph for this function:

◆ toInt()

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

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 1176 of file qstring.h.

Here is the caller graph for this function:

◆ tokenize()

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

Definition at line 299 of file qstringview.h.

Here is the call graph for this function:

◆ toLatin1()

QByteArray QStringView::toLatin1 ( ) const
inline

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 254 of file qstringview.h.

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

◆ toLocal8Bit()

QByteArray QStringView::toLocal8Bit ( ) const
inline

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 256 of file qstringview.h.

Here is the call graph for this function:

◆ toLong()

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

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 1172 of file qstring.h.

◆ toLongLong()

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

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 1168 of file qstring.h.

Here is the caller graph for this function:

◆ toShort()

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

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 1180 of file qstring.h.

Here is the caller graph for this function:

◆ toString()

QString QStringView::toString ( ) const
inline

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 1165 of file qstring.h.

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

◆ toUcs4()

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

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 1023 of file qlist.h.

Here is the call graph for this function:

◆ toUInt()

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

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 1178 of file qstring.h.

Here is the caller graph for this function:

◆ toULong()

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

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 1174 of file qstring.h.

◆ toULongLong()

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

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 1170 of file qstring.h.

◆ toUShort()

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

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 1182 of file qstring.h.

◆ toUtf8()

QByteArray QStringView::toUtf8 ( ) const
inline

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 255 of file qstringview.h.

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

◆ toWCharArray()

QStringView::toWCharArray ( wchar_t *  array) const
inline
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()
Here is the caller graph for this function:

◆ trimmed()

QStringView QStringView::trimmed ( ) const
inlinenoexcept

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 296 of file qstringview.h.

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

◆ 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 291 of file qstringview.h.

Here is the call graph for this function:

◆ utf16()

const storage_type * QStringView::utf16 ( ) const
inlineconstexprnoexcept

Returns a const pointer to the first character in the string view.

{storage_type} is {char16_t}.

Note
The character array represented by the return value is not null-terminated.
See also
begin(), end(), data()

Definition at line 242 of file qstringview.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ compareStrings() [1/9]

int compareStrings ( QBasicUtf8StringView< false lhs,
QBasicUtf8StringView< false rhs,
Qt::CaseSensitivity  cs 
)
related

Definition at line 1625 of file qstring.cpp.

Here is the call graph for this function:

◆ compareStrings() [2/9]

int compareStrings ( QBasicUtf8StringView< false lhs,
QLatin1String  rhs,
Qt::CaseSensitivity  cs 
)
related

Definition at line 1614 of file qstring.cpp.

Here is the call graph for this function:

◆ compareStrings() [3/9]

int compareStrings ( QBasicUtf8StringView< false lhs,
QStringView  rhs,
Qt::CaseSensitivity  cs 
)
related

Definition at line 1601 of file qstring.cpp.

Here is the call graph for this function:

◆ compareStrings() [4/9]

int compareStrings ( QLatin1String  lhs,
QBasicUtf8StringView< false rhs,
Qt::CaseSensitivity  cs 
)
related

Definition at line 1590 of file qstring.cpp.

Here is the call graph for this function:

◆ compareStrings() [5/9]

int compareStrings ( QLatin1String  lhs,
QLatin1String  rhs,
Qt::CaseSensitivity  cs 
)
related

Definition at line 1573 of file qstring.cpp.

Here is the call graph for this function:

◆ compareStrings() [6/9]

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

Definition at line 1551 of file qstring.cpp.

Here is the call graph for this function:

◆ compareStrings() [7/9]

int compareStrings ( QStringView  lhs,
QBasicUtf8StringView< false rhs,
Qt::CaseSensitivity  cs 
)
related

Definition at line 1540 of file qstring.cpp.

Here is the call graph for this function:

◆ compareStrings() [8/9]

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

Definition at line 1527 of file qstring.cpp.

◆ compareStrings() [9/9]

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

Definition at line 1503 of file qstring.cpp.

Here is the caller graph for this function:

◆ operator!= [1/3]

bool operator!= ( QChar  lhs,
QStringView  rhs 
)
friend

Definition at line 435 of file qstringview.h.

◆ operator!= [2/3]

bool operator!= ( QStringView  lhs,
QChar  rhs 
)
friend

Definition at line 428 of file qstringview.h.

◆ operator!= [3/3]

QStringView::operator!= ( QStringView  lhs,
QStringView  rhs 
)
friend

Definition at line 420 of file qstringview.h.

◆ operator< [1/3]

bool operator< ( QChar  lhs,
QStringView  rhs 
)
friend

Definition at line 436 of file qstringview.h.

◆ operator< [2/3]

bool operator< ( QStringView  lhs,
QChar  rhs 
)
friend

Definition at line 429 of file qstringview.h.

◆ operator< [3/3]

QStringView::operator< ( QStringView  lhs,
QStringView  rhs 
)
friend

Definition at line 421 of file qstringview.h.

◆ operator<= [1/3]

bool operator<= ( QChar  lhs,
QStringView  rhs 
)
friend

Definition at line 437 of file qstringview.h.

◆ operator<= [2/3]

bool operator<= ( QStringView  lhs,
QChar  rhs 
)
friend

Definition at line 430 of file qstringview.h.

◆ operator<= [3/3]

QStringView::operator<= ( QStringView  lhs,
QStringView  rhs 
)
friend

Definition at line 422 of file qstringview.h.

◆ operator== [1/3]

bool operator== ( QChar  lhs,
QStringView  rhs 
)
friend

Definition at line 434 of file qstringview.h.

◆ operator== [2/3]

bool operator== ( QStringView  lhs,
QChar  rhs 
)
friend

Definition at line 427 of file qstringview.h.

◆ operator== [3/3]

QStringView::operator== ( QStringView  lhs,
QStringView  rhs 
)
friend

Definition at line 419 of file qstringview.h.

◆ operator> [1/3]

bool operator> ( QChar  lhs,
QStringView  rhs 
)
friend

Definition at line 438 of file qstringview.h.

◆ operator> [2/3]

bool operator> ( QStringView  lhs,
QChar  rhs 
)
friend

Definition at line 431 of file qstringview.h.

◆ operator> [3/3]

QStringView::operator> ( QStringView  lhs,
QStringView  rhs 
)
friend

Definition at line 423 of file qstringview.h.

◆ operator>= [1/3]

bool operator>= ( QChar  lhs,
QStringView  rhs 
)
friend

Definition at line 439 of file qstringview.h.

◆ operator>= [2/3]

bool operator>= ( QStringView  lhs,
QChar  rhs 
)
friend

Definition at line 432 of file qstringview.h.

◆ operator>= [3/3]

QStringView::operator>= ( QStringView  lhs,
QStringView  rhs 
)
friend

Operators for comparing lhs to rhs.

See also
compare()

Definition at line 424 of file qstringview.h.

◆ 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.

Definition at line 812 of file qhash.cpp.


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