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
QAnyStringView Class Reference

\inmodule QtCore More...

#include <qanystringview.h>

+ Collaboration diagram for QAnyStringView:

Public Types

typedef qptrdiff difference_type
 Alias for {std::ptrdiff_t}.
 
typedef qsizetype size_type
 Alias for qsizetype.
 

Public Member Functions

constexpr QAnyStringView () noexcept
 Constructs a null string view.
 
constexpr QAnyStringView (std::nullptr_t) noexcept
 Constructs a null string view.
 
template<typename Char , if_compatible_char< Char > = true>
constexpr QAnyStringView (const Char *str, qsizetype len)
 Constructs a string view on str with length len.
 
template<typename Char , if_compatible_char< Char > = true>
constexpr QAnyStringView (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 QAnyStringView (const Pointer &str) noexcept
 
 QAnyStringView (const QByteArray &str) noexcept
 Constructs a string view on str.
 
 QAnyStringView (const QString &str) noexcept
 Constructs a string view on str.
 
constexpr QAnyStringView (QLatin1StringView str) noexcept
 
template<typename Container , if_compatible_container< Container > = true>
constexpr Q_ALWAYS_INLINE QAnyStringView (const Container &c) noexcept
 
template<typename Container , if_convertible_to< QString, Container > = true>
constexpr QAnyStringView (Container &&c, QtPrivate::wrapped_t< Container, QString > &&capacity={})
 
template<typename Container , if_convertible_to< QByteArray, Container > = true>
constexpr QAnyStringView (Container &&c, QtPrivate::wrapped_t< Container, QByteArray > &&capacity={})
 
template<typename Char , if_compatible_char< Char > = true>
constexpr QAnyStringView (const Char &c) noexcept
 
template<typename Char , if_convertible_to< QChar, Char > = true>
constexpr QAnyStringView (Char ch, QCharContainer &&capacity=QCharContainer()) noexcept
 
template<typename Char , typename Container = decltype(QChar::fromUcs4(U'x')), std::enable_if_t< std::is_same_v< Char, char32_t >, bool > = true>
constexpr QAnyStringView (Char c, Container &&capacity={}) noexcept
 
constexpr QAnyStringView (QStringView v) noexcept
 
template<bool UseChar8T>
constexpr QAnyStringView (QBasicUtf8StringView< UseChar8T > v) noexcept
 
template<typename Visitor >
constexpr decltype(auto) visit (Visitor &&v) const
 
constexpr QAnyStringView mid (qsizetype pos, qsizetype n=-1) const
 
constexpr QAnyStringView left (qsizetype n) const
 
constexpr QAnyStringView right (qsizetype n) const
 
constexpr QAnyStringView sliced (qsizetype pos) const
 
constexpr QAnyStringView sliced (qsizetype pos, qsizetype n) const
 
constexpr QAnyStringView first (qsizetype n) const
 
constexpr QAnyStringView last (qsizetype n) const
 
constexpr QAnyStringView chopped (qsizetype n) const
 
constexpr QAnyStringViewslice (qsizetype pos)
 
constexpr QAnyStringViewslice (qsizetype pos, qsizetype n)
 
constexpr void truncate (qsizetype n)
 
constexpr void chop (qsizetype n)
 
template<typename... Args>
QString arg (Args &&...args) const
 
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 the encoding's code points.
 
constexpr const voiddata () const noexcept
 Returns a const pointer to the first character in the string view.
 
constexpr QChar front () const
 Returns the first character in the string view.
 
constexpr QChar back () const
 Returns the last character in the string view.
 
constexpr bool empty () const noexcept
 Returns whether this string view is empty - that is, whether {size() == 0}.
 
constexpr qsizetype size_bytes () const noexcept
 Returns the size of this string view, but in bytes, not code-points.
 
constexpr qsizetype max_size () 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().
 
template<typename Visitor >
constexpr decltype(auto) visit (Visitor &&v) const
 

Static Public Member Functions

template<typename Char , size_t Size, if_compatible_char< Char > = true>
static constexpr QAnyStringView fromArray (const Char(&string)[Size]) noexcept
 
static Q_CORE_EXPORT int compare (QAnyStringView lhs, QAnyStringView rhs, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
 Compares the string view lhs with the string view rhs and returns a negative integer if lhs is less than rhs, a positive integer if it is greater than rhs, and zero if they are equal.
 
static Q_CORE_EXPORT bool equal (QAnyStringView lhs, QAnyStringView rhs) noexcept
 

Static Public Attributes

static constexpr bool detects_US_ASCII_at_compile_time
 

Friends

class ::tst_QAnyStringView
 
bool comparesEqual (const QAnyStringView &lhs, const QAnyStringView &rhs) noexcept
 
Qt::strong_ordering compareThreeWay (const QAnyStringView &lhs, const QAnyStringView &rhs) noexcept
 
Q_CORE_EXPORT friend QDebug operator<< (QDebug d, QAnyStringView s)
 

Related Symbols

(Note that these are not member symbols.)

QString convertToQString (QAnyStringView string)
 

Detailed Description

\inmodule QtCore

Since
6.0

The QAnyStringView class provides a unified view on Latin-1, UTF-8, or UTF-16 strings with a read-only subset of the QString API. \reentrant

\compares strong \compareswith strong char16_t QChar {const char16_t *} {const char *} \ QByteArray QByteArrayView QString QStringView QUtf8StringView \ QLatin1StringView \endcompareswith

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

Unlike QStringView and QUtf8StringView, QAnyStringView can hold strings of any of the following encodings: UTF-8, UTF-16, and Latin-1. The latter is supported because Latin-1, unlike UTF-8, can be efficiently compared to UTF-16 data: a length mismatch already means the strings cannot be equal. This is not true for UTF-8/UTF-16 comparisons, because UTF-8 is a variable-length encoding.

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

QAnyStringView is designed as an interface type; its main use-case is as a function parameter type. When QAnyStringViews 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 QAnyStringView on all code paths, lest the string view ends up referencing deleted data.

When used as an interface type, QAnyStringView allows a single function to accept a wide variety of string data sources. One function accepting QAnyStringView thus replaces five function overloads (taking QString, {(const QChar*, qsizetype)}, QUtf8StringView, QLatin1StringView (but see above), and QChar), while at the same time enabling even more string data sources to be passed to the function, such as {u8"Hello World"}, a char8_t string literal.

Like elsewhere in Qt, QAnyStringView assumes char data is encoded in UTF-8, unless it is presented as a QLatin1StringView.

Since Qt 6.4, however, UTF-8 string literals that are pure US-ASCII are automatically stored as Latin-1. This is a compile-time check with no runtime overhead. The feature requires compiling in C++20, or with a recent GCC.

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

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

QAnyStringView can also be used as the return value of a function, but this is not recommended. QUtf8StringView or QStringView are better suited as function return values. If you call a function returning QAnyStringView, take extra care to not keep the QAnyStringView 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 QAnyStringView into a QString.

QAnyStringView is a {Literal Type}.

Definition at line 30 of file qanystringview.h.

Member Typedef Documentation

◆ difference_type

Alias for {std::ptrdiff_t}.

Provided for compatibility with the STL.

Definition at line 33 of file qanystringview.h.

◆ size_type

Alias for qsizetype.

Provided for compatibility with the STL.

Definition at line 34 of file qanystringview.h.

Constructor & Destructor Documentation

◆ QAnyStringView() [1/16]

QAnyStringView::QAnyStringView ( )
inlineconstexprnoexcept

Constructs a null string view.

See also
isNull()

Definition at line 166 of file qanystringview.h.

References m_data.

Referenced by QAnyStringView().

+ Here is the caller graph for this function:

◆ QAnyStringView() [2/16]

QAnyStringView::QAnyStringView ( std::nullptr_t )
inlineconstexprnoexcept

Constructs a null string view.

See also
isNull()

Definition at line 168 of file qanystringview.h.

References QAnyStringView().

+ Here is the call graph for this function:

◆ QAnyStringView() [3/16]

template<typename Char , if_compatible_char< Char > = true>
QAnyStringView::QAnyStringView ( 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.

See also
isNull(), {Compatible Character Types}

Definition at line 172 of file qanystringview.h.

References m_data.

◆ QAnyStringView() [4/16]

template<typename Char , if_compatible_char< Char > = true>
QAnyStringView::QAnyStringView ( 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.

See also
isNull(), {Compatible Character Types}

Definition at line 178 of file qanystringview.h.

◆ QAnyStringView() [5/16]

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

Definition at line 190 of file qanystringview.h.

◆ QAnyStringView() [6/16]

QAnyStringView::QAnyStringView ( const QByteArray & str)
inlinenoexcept

Constructs a string view on str.

The data in str is interpreted as UTF-8.

{str.data()} must remain valid for the lifetime of this string view object.

The string view will be null if and only if {str.isNull()}.

Definition at line 1222 of file qstring.h.

◆ QAnyStringView() [7/16]

QAnyStringView::QAnyStringView ( const QString & str)
inlinenoexcept

Constructs a string view on str.

{str.data()} must remain valid for the lifetime of this string view object.

The string view will be null if and only if {str.isNull()}.

Definition at line 1224 of file qstring.h.

◆ QAnyStringView() [8/16]

QAnyStringView::QAnyStringView ( QLatin1StringView str)
inlineconstexprnoexcept

Definition at line 93 of file qstring.h.

◆ QAnyStringView() [9/16]

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

Definition at line 200 of file qanystringview.h.

◆ QAnyStringView() [10/16]

template<typename Container , if_convertible_to< QString, Container > = true>
QAnyStringView::QAnyStringView ( Container && c,
QtPrivate::wrapped_t< Container, QString > && capacity = {} )
inlineconstexpr

Definition at line 204 of file qanystringview.h.

◆ QAnyStringView() [11/16]

template<typename Container , if_convertible_to< QByteArray, Container > = true>
QAnyStringView::QAnyStringView ( Container && c,
QtPrivate::wrapped_t< Container, QByteArray > && capacity = {} )
inlineconstexpr

Definition at line 209 of file qanystringview.h.

◆ QAnyStringView() [12/16]

template<typename Char , if_compatible_char< Char > = true>
QAnyStringView::QAnyStringView ( const Char & c)
inlineconstexprnoexcept

Definition at line 214 of file qanystringview.h.

◆ QAnyStringView() [13/16]

template<typename Char , if_convertible_to< QChar, Char > = true>
QAnyStringView::QAnyStringView ( Char ch,
QCharContainer && capacity = QCharContainer() )
inlineconstexprnoexcept

Definition at line 217 of file qanystringview.h.

◆ QAnyStringView() [14/16]

template<typename Char , typename Container = decltype(QChar::fromUcs4(U'x')), std::enable_if_t< std::is_same_v< Char, char32_t >, bool > = true>
QAnyStringView::QAnyStringView ( Char c,
Container && capacity = {} )
inlineconstexprnoexcept

Definition at line 221 of file qanystringview.h.

◆ QAnyStringView() [15/16]

QAnyStringView::QAnyStringView ( QStringView v)
inlineconstexprnoexcept

Definition at line 224 of file qanystringview.h.

◆ QAnyStringView() [16/16]

template<bool UseChar8T>
QAnyStringView::QAnyStringView ( QBasicUtf8StringView< UseChar8T > v)
inlineconstexprnoexcept

Definition at line 228 of file qanystringview.h.

Member Function Documentation

◆ arg()

template<typename... Args>
QString QAnyStringView::arg ( Args &&... args) const
inlinenodiscard
Since
6.9

qstring-multi-arg

See also
QString::arg(Args&&...)

Definition at line 1632 of file qstring.h.

◆ back()

QChar QAnyStringView::back ( ) const
nodiscardconstexpr

Returns the last character in the string view.

This function is provided for STL compatibility.

Warning
Calling this function on an empty string view constitutes undefined behavior.
See also
front(), {Sizes and Sub-Strings}

Definition at line 122 of file qstring.h.

◆ chop()

void QAnyStringView::chop ( qsizetype n)
inlineconstexpr
Since
6.5

Truncates this string view by n code points.

Same as {*this = first(size() - n)}.

Note
The behavior is undefined when n < 0 or n > size().
See also
sliced(), first(), last(), chopped(), truncate(), slice(), {Sizes and Sub-Strings}

Definition at line 279 of file qanystringview.h.

◆ chopped()

QAnyStringView QAnyStringView::chopped ( qsizetype n) const
inlinenodiscardconstexpr
Since
6.5

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

Same as {first(size() - n)}.

Note
The behavior is undefined when n < 0 or n > size().
See also
sliced(), first(), last(), chop(), truncate(), slice(), {Sizes and Sub-Strings}

Definition at line 269 of file qanystringview.h.

◆ compare()

int QAnyStringView::compare ( QAnyStringView lhs,
QAnyStringView rhs,
Qt::CaseSensitivity cs = Qt::CaseSensitive )
staticnodiscardnoexcept

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

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

◆ data()

const void * QAnyStringView::data ( ) const
inlinenodiscardconstexprnoexcept

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

Definition at line 289 of file qanystringview.h.

◆ empty()

bool QAnyStringView::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()

Definition at line 307 of file qanystringview.h.

◆ equal()

bool QAnyStringView::equal ( QAnyStringView lhs,
QAnyStringView rhs )
staticnodiscardnoexcept

Definition at line 1440 of file qstring.cpp.

◆ first()

QAnyStringView QAnyStringView::first ( qsizetype n) const
inlinenodiscardconstexpr
Since
6.5

Returns a string view that contains the first n code points of this string view.

Note
The behavior is undefined when n < 0 or n > size().
See also
last(), sliced(), chopped(), chop(), truncate(), slice(), {Sizes and Sub-Strings}

Definition at line 265 of file qanystringview.h.

◆ fromArray()

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

Definition at line 232 of file qanystringview.h.

◆ front()

QChar QAnyStringView::front ( ) const
nodiscardconstexpr

Returns the first character in the string view.

This function is provided for STL compatibility.

Warning
Calling this function on an empty string view constitutes undefined behavior.
See also
back(), {Sizes and Sub-Strings}

Definition at line 118 of file qstring.h.

◆ isEmpty()

bool QAnyStringView::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()

Definition at line 321 of file qanystringview.h.

◆ isNull()

bool QAnyStringView::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()

Definition at line 320 of file qanystringview.h.

◆ last()

QAnyStringView QAnyStringView::last ( qsizetype n) const
inlinenodiscardconstexpr
Since
6.5

Returns a string view that contains the last n code points of this string view.

Note
The behavior is undefined when n < 0 or n > size().
See also
first(), sliced(), chopped(), chop(), truncate(), slice(), {Sizes and Sub-Strings}

Definition at line 267 of file qanystringview.h.

◆ left()

QAnyStringView QAnyStringView::left ( qsizetype n) const
inlinenodiscardconstexpr
Since
6.5
Deprecated
Use first() instead in new code.

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

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

See also
first(), last(), sliced(), chopped(), chop(), truncate(), slice(), {Sizes and Sub-Strings}
Since
6.5
Deprecated
Use first() instead in new code.

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

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

See also
first(), last(), sliced(), chopped(), chop(), truncate(), slice(), {Sizes and Sub-Strings}

Definition at line 247 of file qanystringview.h.

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

+ Here is the caller graph for this function:

◆ length()

qsizetype QAnyStringView::length ( ) const
inlinenodiscardconstexprnoexcept

Same as size().

This function is provided for compatibility with other Qt containers.

See also
size()

Definition at line 322 of file qanystringview.h.

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

+ Here is the caller graph for this function:

◆ max_size()

qsizetype QAnyStringView::max_size ( ) const
inlinenodiscardconstexprnoexcept
Since
6.8

This function is provided for STL compatibility.

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

Note
The returned value is calculated based on the currently used character type, so calling this function on two different views may return different results.

Definition at line 311 of file qanystringview.h.

◆ mid()

QAnyStringView QAnyStringView::mid ( qsizetype pos,
qsizetype n = -1 ) const
inlinenodiscardconstexpr
Since
6.5

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

Deprecated
Use sliced() instead in new code.

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

See also
first(), last(), sliced(), chopped(), chop(), truncate(), slice(), {Sizes and Sub-Strings}
Since
6.5

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

Deprecated
Use sliced() instead in new code.

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

See also
first(), last(), sliced(), chopped(), chop(), truncate(), slice(), {Sizes and Sub-Strings}

Definition at line 240 of file qanystringview.h.

◆ right()

QAnyStringView QAnyStringView::right ( qsizetype n) const
inlinenodiscardconstexpr
Since
6.5
Deprecated
Use last() instead in new code.

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

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

See also
first(), last(), sliced(), chopped(), chop(), truncate(), slice(), {Sizes and Sub-Strings}
Since
6.5
Deprecated
Use last() instead in new code.

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

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

See also
first(), last(), sliced(), chopped(), chop(), truncate(), slice(), {Sizes and Sub-Strings}

Definition at line 254 of file qanystringview.h.

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

+ Here is the caller graph for this function:

◆ size()

qsizetype QAnyStringView::size ( ) const
inlinenodiscardconstexprnoexcept

Returns the size of this string view, in the encoding's code points.

See also
empty(), isEmpty(), isNull(), size_bytes(), {Sizes and Sub-Strings}

Definition at line 287 of file qanystringview.h.

◆ size_bytes()

qsizetype QAnyStringView::size_bytes ( ) const
inlinenodiscardconstexprnoexcept

Returns the size of this string view, but in bytes, not code-points.

You can use this function together with data() for hashing or serialization.

This function is provided for STL compatibility.

See also
size(), data()

Definition at line 308 of file qanystringview.h.

◆ slice() [1/2]

QAnyStringView & QAnyStringView::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 at position pos, extending to its end.

UB-sliced-index-only

See also
sliced(), first(), last(), chopped(), chop(), truncate(), {Sizes and Sub-Strings}

Definition at line 272 of file qanystringview.h.

◆ slice() [2/2]

QAnyStringView & QAnyStringView::slice ( qsizetype pos,
qsizetype n )
inlineconstexpr
\fn QAnyStringView::sliced(qsizetype pos, qsizetype n) const
\since 6.5

Returns a string view containing \a n code points 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(), {Sizes and Sub-Strings}
\fn QAnyStringView::sliced(qsizetype pos) const
\since 6.5

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(), {Sizes and Sub-Strings}
Since
6.8

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

UB-sliced-index-length

See also
sliced(), first(), last(), chopped(), chop(), truncate(), {Sizes and Sub-Strings}

Definition at line 274 of file qanystringview.h.

◆ sliced() [1/2]

QAnyStringView QAnyStringView::sliced ( qsizetype pos) const
inlinenodiscardconstexpr

Definition at line 261 of file qanystringview.h.

◆ sliced() [2/2]

QAnyStringView QAnyStringView::sliced ( qsizetype pos,
qsizetype n ) const
inlinenodiscardconstexpr

Definition at line 263 of file qanystringview.h.

◆ toString()

QString QAnyStringView::toString ( ) const
inlinenodiscard

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

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

Definition at line 1227 of file qstring.h.

◆ truncate()

void QAnyStringView::truncate ( qsizetype n)
inlineconstexpr
Since
6.5

Truncates this string view to n code points.

Same as {*this = first(n)}.

Note
The behavior is undefined when n < 0 or n > size().
See also
sliced(), first(), last(), chopped(), chop(), {Sizes and Sub-Strings}

Definition at line 277 of file qanystringview.h.

◆ visit() [1/2]

template<typename Visitor >
decltype(auto) QAnyStringView::visit ( Visitor && v) const
inlineconstexpr

◆ visit() [2/2]

template<typename Visitor >
decltype(auto) QAnyStringView::visit ( Visitor && v) const
constexpr

Definition at line 104 of file qstring.h.

Friends And Related Symbol Documentation

◆ ::tst_QAnyStringView

friend class ::tst_QAnyStringView
friend

Definition at line 367 of file qanystringview.h.

◆ comparesEqual

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

Definition at line 326 of file qanystringview.h.

◆ compareThreeWay

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

Definition at line 329 of file qanystringview.h.

◆ convertToQString()

QString convertToQString ( QAnyStringView string)
related
Since
6.0

Returns a UTF-16 representation of string as a QString.

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

Definition at line 5635 of file qstring.cpp.

◆ operator<<

Q_CORE_EXPORT friend QDebug operator<< ( QDebug d,
QAnyStringView s )
friend

Definition at line 674 of file qanystringview.cpp.

Member Data Documentation

◆ detects_US_ASCII_at_compile_time

bool QAnyStringView::detects_US_ASCII_at_compile_time
inlinestaticconstexpr
Initial value:
=
false

Definition at line 294 of file qanystringview.h.

◆ m_data

const void* QAnyStringView::m_data

Definition at line 362 of file qanystringview.h.

Referenced by QAnyStringView(), and QAnyStringView().

◆ m_data_utf16

const char16_t* QAnyStringView::m_data_utf16

Definition at line 364 of file qanystringview.h.

◆ m_data_utf8

const char* QAnyStringView::m_data_utf8

Definition at line 363 of file qanystringview.h.


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