Struct qt_core::QStringView
source · #[repr(C)]pub struct QStringView { /* private fields */ }
Expand description
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QString API.
C++ class: QStringView
.
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QString API.
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
(on compilers that support C++11 Unicode strings) 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, QStringRef, 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:
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
- QChar: this overload can delegate to the QStringView version:
void fun(QChar ch) { fun(QStringView(&ch, 1)); }
even though, for technical reasons, QStringView cannot provide a QChar constructor by itself.
- QString: if you store an unmodified copy of the string and thus would like to take advantage of QString's implicit sharing.
- QLatin1String: if you can implement the function without converting the QLatin1String to UTF-16 first; users expect a function overloaded on QLatin1String to perform strictly less memory allocations than the semantically equivalent call of the QStringView version, involving construction of a QString from the QLatin1String.
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.
Note: We strongly discourage the use of QList<QStringView>, because QList is a very inefficient container for QStringViews (it would heap-allocate every element). Use QVector (or std::vector) to hold QStringViews instead.
Implementations§
source§impl QStringView
impl QStringView
sourcepub unsafe fn at(&self, n: c_longlong) -> CppBox<QChar>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn at(&self, n: c_longlong) -> CppBox<QChar>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns the character at position n in this string view.
Calls C++ function: QChar QStringView::at(long long n) const
.
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(), and back().
sourcepub unsafe fn back(&self) -> CppBox<QChar>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn back(&self) -> CppBox<QChar>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns the last character in the string. Same as last().
Calls C++ function: QChar QStringView::back() const
.
sourcepub unsafe fn begin(&self) -> Ptr<QChar>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn begin(&self) -> Ptr<QChar>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns a const STL-style iterator pointing to the first character in the string.
Calls C++ function: const QChar* QStringView::begin() const
.
Returns a const STL-style iterator pointing to the first character in the string.
This function is provided for STL compatibility.
sourcepub unsafe fn cbegin(&self) -> Ptr<QChar>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn cbegin(&self) -> Ptr<QChar>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.sourcepub unsafe fn cend(&self) -> Ptr<QChar>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn cend(&self) -> Ptr<QChar>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.sourcepub unsafe fn chop(&self, n: c_longlong)
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn chop(&self, n: c_longlong)
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Truncates this string view by length characters.
Calls C++ function: void QStringView::chop(long long n)
.
sourcepub unsafe fn chopped(&self, n: c_longlong) -> CppBox<QStringView>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn chopped(&self, n: c_longlong) -> CppBox<QStringView>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns the substring of length size() - length starting at the beginning of this object.
Calls C++ function: QStringView QStringView::chopped(long long n) const
.
sourcepub unsafe fn compare_2a(
&self,
other: impl CastInto<Ref<QStringView>>,
cs: CaseSensitivity
) -> c_int
Available on cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn compare_2a( &self, other: impl CastInto<Ref<QStringView>>, cs: CaseSensitivity ) -> c_int
cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.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.
Calls C++ function: int QStringView::compare(QStringView other, Qt::CaseSensitivity cs = …) const
.
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.
If cs is Qt::CaseSensitive, the comparison is case sensitive; otherwise the comparison is case insensitive.
This function was introduced in Qt 5.12.
See also operator==(), operator<(), and operator>().
sourcepub unsafe fn compare_1a(&self, other: impl CastInto<Ref<QStringView>>) -> c_int
Available on cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn compare_1a(&self, other: impl CastInto<Ref<QStringView>>) -> c_int
cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.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.
Calls C++ function: int QStringView::compare(QStringView other) const
.
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.
If cs is Qt::CaseSensitive, the comparison is case sensitive; otherwise the comparison is case insensitive.
This function was introduced in Qt 5.12.
See also operator==(), operator<(), and operator>().
sourcepub unsafe fn contains_q_char_case_sensitivity(
&self,
c: impl CastInto<Ref<QChar>>,
cs: CaseSensitivity
) -> bool
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn contains_q_char_case_sensitivity( &self, c: impl CastInto<Ref<QChar>>, cs: CaseSensitivity ) -> bool
cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::contains(QChar c, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn contains_q_string_view_case_sensitivity(
&self,
s: impl CastInto<Ref<QStringView>>,
cs: CaseSensitivity
) -> bool
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn contains_q_string_view_case_sensitivity( &self, s: impl CastInto<Ref<QStringView>>, cs: CaseSensitivity ) -> bool
cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::contains(QStringView s, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn contains_q_latin1_string_case_sensitivity(
&self,
s: impl CastInto<Ref<QLatin1String>>,
cs: CaseSensitivity
) -> bool
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn contains_q_latin1_string_case_sensitivity( &self, s: impl CastInto<Ref<QLatin1String>>, cs: CaseSensitivity ) -> bool
cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::contains(QLatin1String s, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn contains_q_char(&self, c: impl CastInto<Ref<QChar>>) -> bool
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn contains_q_char(&self, c: impl CastInto<Ref<QChar>>) -> bool
cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::contains(QChar c) const
.
sourcepub unsafe fn contains_q_string_view(
&self,
s: impl CastInto<Ref<QStringView>>
) -> bool
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn contains_q_string_view( &self, s: impl CastInto<Ref<QStringView>> ) -> bool
cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::contains(QStringView s) const
.
sourcepub unsafe fn contains_q_latin1_string(
&self,
s: impl CastInto<Ref<QLatin1String>>
) -> bool
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn contains_q_latin1_string( &self, s: impl CastInto<Ref<QLatin1String>> ) -> bool
cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::contains(QLatin1String s) const
.
sourcepub unsafe fn copy_from(
&self,
other: impl CastInto<Ref<QStringView>>
) -> Ref<QStringView>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn copy_from( &self, other: impl CastInto<Ref<QStringView>> ) -> Ref<QStringView>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QString API.
Calls C++ function: QStringView& QStringView::operator=(const QStringView& other)
.
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QString API.
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
(on compilers that support C++11 Unicode strings) 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, QStringRef, 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:
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
- QChar: this overload can delegate to the QStringView version:
void fun(QChar ch) { fun(QStringView(&ch, 1)); }
even though, for technical reasons, QStringView cannot provide a QChar constructor by itself.
- QString: if you store an unmodified copy of the string and thus would like to take advantage of QString's implicit sharing.
- QLatin1String: if you can implement the function without converting the QLatin1String to UTF-16 first; users expect a function overloaded on QLatin1String to perform strictly less memory allocations than the semantically equivalent call of the QStringView version, involving construction of a QString from the QLatin1String.
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.
Note: We strongly discourage the use of QList<QStringView>, because QList is a very inefficient container for QStringViews (it would heap-allocate every element). Use QVector (or std::vector) to hold QStringViews instead.
sourcepub unsafe fn data(&self) -> Ptr<QChar>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn data(&self) -> Ptr<QChar>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns a const pointer to the first character in the string.
Calls C++ function: const QChar* QStringView::data() const
.
sourcepub unsafe fn empty(&self) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn empty(&self) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns whether this string view is empty - that is, whether size() == 0
.
Calls C++ function: bool QStringView::empty() const
.
sourcepub unsafe fn end(&self) -> Ptr<QChar>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn end(&self) -> Ptr<QChar>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns a const STL-style iterator pointing to the imaginary character after the last character in the list.
Calls C++ function: const QChar* QStringView::end() const
.
Returns a const STL-style iterator pointing to the imaginary character after the last character in the list.
This function is provided for STL compatibility.
sourcepub unsafe fn ends_with_q_string_view_case_sensitivity(
&self,
s: impl CastInto<Ref<QStringView>>,
cs: CaseSensitivity
) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn ends_with_q_string_view_case_sensitivity( &self, s: impl CastInto<Ref<QStringView>>, cs: CaseSensitivity ) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::endsWith(QStringView s, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn ends_with_q_latin1_string_case_sensitivity(
&self,
s: impl CastInto<Ref<QLatin1String>>,
cs: CaseSensitivity
) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn ends_with_q_latin1_string_case_sensitivity( &self, s: impl CastInto<Ref<QLatin1String>>, cs: CaseSensitivity ) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::endsWith(QLatin1String s, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn ends_with_q_char(&self, c: impl CastInto<Ref<QChar>>) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn ends_with_q_char(&self, c: impl CastInto<Ref<QChar>>) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::endsWith(QChar c) const
.
sourcepub unsafe fn ends_with_q_char_case_sensitivity(
&self,
c: impl CastInto<Ref<QChar>>,
cs: CaseSensitivity
) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn ends_with_q_char_case_sensitivity( &self, c: impl CastInto<Ref<QChar>>, cs: CaseSensitivity ) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::endsWith(QChar c, Qt::CaseSensitivity cs) const
.
sourcepub unsafe fn ends_with_q_string_view(
&self,
s: impl CastInto<Ref<QStringView>>
) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn ends_with_q_string_view( &self, s: impl CastInto<Ref<QStringView>> ) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::endsWith(QStringView s) const
.
sourcepub unsafe fn ends_with_q_latin1_string(
&self,
s: impl CastInto<Ref<QLatin1String>>
) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn ends_with_q_latin1_string( &self, s: impl CastInto<Ref<QLatin1String>> ) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::endsWith(QLatin1String s) const
.
sourcepub unsafe fn first(&self) -> CppBox<QChar>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn first(&self) -> CppBox<QChar>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns the first character in the string. Same as front().
Calls C++ function: QChar QStringView::first() const
.
sourcepub unsafe fn front(&self) -> CppBox<QChar>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn front(&self) -> CppBox<QChar>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns the first character in the string. Same as first().
Calls C++ function: QChar QStringView::front() const
.
sourcepub unsafe fn index(&self, n: c_longlong) -> CppBox<QChar>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn index(&self, n: c_longlong) -> CppBox<QChar>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns the character at position n in this string view.
Calls C++ function: QChar QStringView::operator[](long long n) const
.
sourcepub unsafe fn index_of_q_char_longlong_case_sensitivity(
&self,
c: impl CastInto<Ref<QChar>>,
from: c_longlong,
cs: CaseSensitivity
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn index_of_q_char_longlong_case_sensitivity( &self, c: impl CastInto<Ref<QChar>>, from: c_longlong, cs: CaseSensitivity ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::indexOf(QChar c, long long from = …, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn index_of_q_string_view_longlong_case_sensitivity(
&self,
s: impl CastInto<Ref<QStringView>>,
from: c_longlong,
cs: CaseSensitivity
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn index_of_q_string_view_longlong_case_sensitivity( &self, s: impl CastInto<Ref<QStringView>>, from: c_longlong, cs: CaseSensitivity ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::indexOf(QStringView s, long long from = …, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn index_of_q_latin1_string_longlong_case_sensitivity(
&self,
s: impl CastInto<Ref<QLatin1String>>,
from: c_longlong,
cs: CaseSensitivity
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn index_of_q_latin1_string_longlong_case_sensitivity( &self, s: impl CastInto<Ref<QLatin1String>>, from: c_longlong, cs: CaseSensitivity ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::indexOf(QLatin1String s, long long from = …, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn index_of_q_char_longlong(
&self,
c: impl CastInto<Ref<QChar>>,
from: c_longlong
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn index_of_q_char_longlong( &self, c: impl CastInto<Ref<QChar>>, from: c_longlong ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::indexOf(QChar c, long long from = …) const
.
sourcepub unsafe fn index_of_q_char(&self, c: impl CastInto<Ref<QChar>>) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn index_of_q_char(&self, c: impl CastInto<Ref<QChar>>) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::indexOf(QChar c) const
.
sourcepub unsafe fn index_of_q_string_view_longlong(
&self,
s: impl CastInto<Ref<QStringView>>,
from: c_longlong
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn index_of_q_string_view_longlong( &self, s: impl CastInto<Ref<QStringView>>, from: c_longlong ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::indexOf(QStringView s, long long from = …) const
.
sourcepub unsafe fn index_of_q_string_view(
&self,
s: impl CastInto<Ref<QStringView>>
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn index_of_q_string_view( &self, s: impl CastInto<Ref<QStringView>> ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::indexOf(QStringView s) const
.
sourcepub unsafe fn index_of_q_latin1_string_longlong(
&self,
s: impl CastInto<Ref<QLatin1String>>,
from: c_longlong
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn index_of_q_latin1_string_longlong( &self, s: impl CastInto<Ref<QLatin1String>>, from: c_longlong ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::indexOf(QLatin1String s, long long from = …) const
.
sourcepub unsafe fn index_of_q_latin1_string(
&self,
s: impl CastInto<Ref<QLatin1String>>
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn index_of_q_latin1_string( &self, s: impl CastInto<Ref<QLatin1String>> ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::indexOf(QLatin1String s) const
.
sourcepub unsafe fn is_empty(&self) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn is_empty(&self) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns whether this string view is empty - that is, whether size() == 0
.
Calls C++ function: bool QStringView::isEmpty() const
.
sourcepub unsafe fn is_null(&self) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn is_null(&self) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns whether this string view is null - that is, whether data() == nullptr
.
Calls C++ function: bool QStringView::isNull() const
.
sourcepub unsafe fn is_right_to_left(&self) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn is_right_to_left(&self) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns true
if the string is read right to left.
Calls C++ function: bool QStringView::isRightToLeft() const
.
Returns true
if the string is read right to left.
This function was introduced in Qt 5.11.
See also QString::isRightToLeft().
sourcepub unsafe fn last(&self) -> CppBox<QChar>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn last(&self) -> CppBox<QChar>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns the last character in the string. Same as back().
Calls C++ function: QChar QStringView::last() const
.
sourcepub unsafe fn last_index_of_q_char_longlong_case_sensitivity(
&self,
c: impl CastInto<Ref<QChar>>,
from: c_longlong,
cs: CaseSensitivity
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn last_index_of_q_char_longlong_case_sensitivity( &self, c: impl CastInto<Ref<QChar>>, from: c_longlong, cs: CaseSensitivity ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::lastIndexOf(QChar c, long long from = …, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn last_index_of_q_string_view_longlong_case_sensitivity(
&self,
s: impl CastInto<Ref<QStringView>>,
from: c_longlong,
cs: CaseSensitivity
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn last_index_of_q_string_view_longlong_case_sensitivity( &self, s: impl CastInto<Ref<QStringView>>, from: c_longlong, cs: CaseSensitivity ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::lastIndexOf(QStringView s, long long from = …, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn last_index_of_q_latin1_string_longlong_case_sensitivity(
&self,
s: impl CastInto<Ref<QLatin1String>>,
from: c_longlong,
cs: CaseSensitivity
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn last_index_of_q_latin1_string_longlong_case_sensitivity( &self, s: impl CastInto<Ref<QLatin1String>>, from: c_longlong, cs: CaseSensitivity ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::lastIndexOf(QLatin1String s, long long from = …, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn last_index_of_q_char_longlong(
&self,
c: impl CastInto<Ref<QChar>>,
from: c_longlong
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn last_index_of_q_char_longlong( &self, c: impl CastInto<Ref<QChar>>, from: c_longlong ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::lastIndexOf(QChar c, long long from = …) const
.
sourcepub unsafe fn last_index_of_q_char(
&self,
c: impl CastInto<Ref<QChar>>
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn last_index_of_q_char( &self, c: impl CastInto<Ref<QChar>> ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::lastIndexOf(QChar c) const
.
sourcepub unsafe fn last_index_of_q_string_view_longlong(
&self,
s: impl CastInto<Ref<QStringView>>,
from: c_longlong
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn last_index_of_q_string_view_longlong( &self, s: impl CastInto<Ref<QStringView>>, from: c_longlong ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::lastIndexOf(QStringView s, long long from = …) const
.
sourcepub unsafe fn last_index_of_q_string_view(
&self,
s: impl CastInto<Ref<QStringView>>
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn last_index_of_q_string_view( &self, s: impl CastInto<Ref<QStringView>> ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::lastIndexOf(QStringView s) const
.
sourcepub unsafe fn last_index_of_q_latin1_string_longlong(
&self,
s: impl CastInto<Ref<QLatin1String>>,
from: c_longlong
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn last_index_of_q_latin1_string_longlong( &self, s: impl CastInto<Ref<QLatin1String>>, from: c_longlong ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::lastIndexOf(QLatin1String s, long long from = …) const
.
sourcepub unsafe fn last_index_of_q_latin1_string(
&self,
s: impl CastInto<Ref<QLatin1String>>
) -> c_longlong
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn last_index_of_q_latin1_string( &self, s: impl CastInto<Ref<QLatin1String>> ) -> c_longlong
cpp_lib_version="5.14.0"
only.Calls C++ function: long long QStringView::lastIndexOf(QLatin1String s) const
.
sourcepub unsafe fn left(&self, n: c_longlong) -> CppBox<QStringView>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn left(&self, n: c_longlong) -> CppBox<QStringView>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns the substring of length length starting at position 0 in this object.
Calls C++ function: QStringView QStringView::left(long long n) const
.
sourcepub unsafe fn length(&self) -> c_int
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn length(&self) -> c_int
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Same as size(), except returns the result as an int
.
Calls C++ function: int QStringView::length() const
.
Same as size(), except returns the result as an int
.
This function is provided for compatibility with other Qt containers.
Warning: QStringView can represent strings with more than 231 characters. Calling this function on a string view for which size() returns a value greater than INT_MAX
constitutes undefined behavior.
sourcepub unsafe fn mid_1a(&self, pos: c_longlong) -> CppBox<QStringView>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn mid_1a(&self, pos: c_longlong) -> CppBox<QStringView>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns the substring starting at position start in this object, and extending to the end of the string.
Calls C++ function: QStringView QStringView::mid(long long pos) const
.
sourcepub unsafe fn mid_2a(
&self,
pos: c_longlong,
n: c_longlong
) -> CppBox<QStringView>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn mid_2a( &self, pos: c_longlong, n: c_longlong ) -> CppBox<QStringView>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.This is an overloaded function.
Calls C++ function: QStringView QStringView::mid(long long pos, long long n) const
.
sourcepub unsafe fn new() -> CppBox<QStringView>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn new() -> CppBox<QStringView>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Constructs a null string view.
Calls C++ function: [constructor] void QStringView::QStringView()
.
Constructs a null string view.
See also isNull().
sourcepub unsafe fn new_copy(
other: impl CastInto<Ref<QStringView>>
) -> CppBox<QStringView>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn new_copy( other: impl CastInto<Ref<QStringView>> ) -> CppBox<QStringView>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QString API.
Calls C++ function: [constructor] void QStringView::QStringView(const QStringView& other)
.
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QString API.
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
(on compilers that support C++11 Unicode strings) 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, QStringRef, 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:
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
- QChar: this overload can delegate to the QStringView version:
void fun(QChar ch) { fun(QStringView(&ch, 1)); }
even though, for technical reasons, QStringView cannot provide a QChar constructor by itself.
- QString: if you store an unmodified copy of the string and thus would like to take advantage of QString's implicit sharing.
- QLatin1String: if you can implement the function without converting the QLatin1String to UTF-16 first; users expect a function overloaded on QLatin1String to perform strictly less memory allocations than the semantically equivalent call of the QStringView version, involving construction of a QString from the QLatin1String.
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.
Note: We strongly discourage the use of QList<QStringView>, because QList is a very inefficient container for QStringViews (it would heap-allocate every element). Use QVector (or std::vector) to hold QStringViews instead.
sourcepub unsafe fn right(&self, n: c_longlong) -> CppBox<QStringView>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn right(&self, n: c_longlong) -> CppBox<QStringView>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns the substring of length length starting at position size() - length in this object.
Calls C++ function: QStringView QStringView::right(long long n) const
.
sourcepub unsafe fn size(&self) -> c_longlong
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn size(&self) -> c_longlong
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.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 and QStringRef).
Calls C++ function: long long QStringView::size() const
.
sourcepub unsafe fn starts_with_q_string_view_case_sensitivity(
&self,
s: impl CastInto<Ref<QStringView>>,
cs: CaseSensitivity
) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn starts_with_q_string_view_case_sensitivity( &self, s: impl CastInto<Ref<QStringView>>, cs: CaseSensitivity ) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::startsWith(QStringView s, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn starts_with_q_latin1_string_case_sensitivity(
&self,
s: impl CastInto<Ref<QLatin1String>>,
cs: CaseSensitivity
) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn starts_with_q_latin1_string_case_sensitivity( &self, s: impl CastInto<Ref<QLatin1String>>, cs: CaseSensitivity ) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::startsWith(QLatin1String s, Qt::CaseSensitivity cs = …) const
.
sourcepub unsafe fn starts_with_q_char(&self, c: impl CastInto<Ref<QChar>>) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn starts_with_q_char(&self, c: impl CastInto<Ref<QChar>>) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::startsWith(QChar c) const
.
sourcepub unsafe fn starts_with_q_char_case_sensitivity(
&self,
c: impl CastInto<Ref<QChar>>,
cs: CaseSensitivity
) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn starts_with_q_char_case_sensitivity( &self, c: impl CastInto<Ref<QChar>>, cs: CaseSensitivity ) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::startsWith(QChar c, Qt::CaseSensitivity cs) const
.
sourcepub unsafe fn starts_with_q_string_view(
&self,
s: impl CastInto<Ref<QStringView>>
) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn starts_with_q_string_view( &self, s: impl CastInto<Ref<QStringView>> ) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::startsWith(QStringView s) const
.
sourcepub unsafe fn starts_with_q_latin1_string(
&self,
s: impl CastInto<Ref<QLatin1String>>
) -> bool
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn starts_with_q_latin1_string( &self, s: impl CastInto<Ref<QLatin1String>> ) -> bool
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Calls C++ function: bool QStringView::startsWith(QLatin1String s) const
.
sourcepub unsafe fn to_latin1(&self) -> CppBox<QByteArray>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn to_latin1(&self) -> CppBox<QByteArray>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns a Latin-1 representation of the string as a QByteArray.
Calls C++ function: QByteArray QStringView::toLatin1() const
.
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(), and QTextCodec.
sourcepub unsafe fn to_local8_bit(&self) -> CppBox<QByteArray>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn to_local8_bit(&self) -> CppBox<QByteArray>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns a local 8-bit representation of the string as a QByteArray.
Calls C++ function: QByteArray QStringView::toLocal8Bit() const
.
Returns a local 8-bit representation of the string as a QByteArray.
QTextCodec::codecForLocale() is used to perform the conversion from Unicode. If the locale's encoding could not be determined, this function does the same as toLatin1().
The behavior is undefined if the string contains characters not supported by the locale's 8-bit encoding.
See also toLatin1(), toUtf8(), and QTextCodec.
sourcepub unsafe fn to_string(&self) -> CppBox<QString>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn to_string(&self) -> CppBox<QString>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns a deep copy of this string view's data as a QString.
Calls C++ function: QString QStringView::toString() const
.
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.
Warning: QStringView can store strings with more than 230 characters while QString cannot. Calling this function on a string view for which size() returns a value greater than INT_MAX / 2
constitutes undefined behavior.
sourcepub unsafe fn to_ucs4(&self) -> CppBox<QVectorOfUint>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn to_ucs4(&self) -> CppBox<QVectorOfUint>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns a UCS-4/UTF-32 representation of the string as a QVector<uint>.
Calls C++ function: QVector<unsigned int> QStringView::toUcs4() const
.
Returns a UCS-4/UTF-32 representation of the string as a QVector<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 replacement character (QChar::ReplacementCharacter, which corresponds to U+FFFD
).
The returned vector is not 0-terminated.
See also toUtf8(), toLatin1(), toLocal8Bit(), and QTextCodec.
sourcepub unsafe fn to_utf8(&self) -> CppBox<QByteArray>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn to_utf8(&self) -> CppBox<QByteArray>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns a UTF-8 representation of the string as a QByteArray.
Calls C++ function: QByteArray QStringView::toUtf8() const
.
Returns a UTF-8 representation of the string as a QByteArray.
UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QString.
See also toLatin1(), toLocal8Bit(), and QTextCodec.
sourcepub unsafe fn to_w_char_array(&self, array: *mut wchar_t) -> c_int
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn to_w_char_array(&self, array: *mut wchar_t) -> c_int
cpp_lib_version="5.14.0"
only.Transcribes this string into the given array.
Calls C++ function: int QStringView::toWCharArray(wchar_t* array) const
.
Transcribes this string into the given array.
The caller is responsible for ensuring array is large enough to hold the wchar_t
encoding of this string (allocating the array with the same length as the string 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.
This function was introduced in Qt 5.14.
See also QString::toWCharArray().
sourcepub unsafe fn trimmed(&self) -> CppBox<QStringView>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn trimmed(&self) -> CppBox<QStringView>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Strips leading and trailing whitespace and returns the result.
Calls C++ function: QStringView QStringView::trimmed() const
.
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 ' '.
sourcepub unsafe fn truncate(&self, n: c_longlong)
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn truncate(&self, n: c_longlong)
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Truncates this string view to length length.
Calls C++ function: void QStringView::truncate(long long n)
.
sourcepub unsafe fn utf16(&self) -> *const char16_t
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn utf16(&self) -> *const char16_t
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns a const pointer to the first character in the string.
Calls C++ function: const char16_t* QStringView::utf16() const
.
Trait Implementations§
source§impl Begin for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Begin for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§unsafe fn begin(&self) -> Ptr<QChar>
unsafe fn begin(&self) -> Ptr<QChar>
Returns a const STL-style iterator pointing to the first character in the string.
Calls C++ function: const QChar* QStringView::begin() const
.
Returns a const STL-style iterator pointing to the first character in the string.
This function is provided for STL compatibility.
source§impl CppDeletable for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl CppDeletable for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§unsafe fn delete(&self)
unsafe fn delete(&self)
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QString API.
Calls C++ function: [destructor] void QStringView::~QStringView()
.
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QString API.
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
(on compilers that support C++11 Unicode strings) 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, QStringRef, 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:
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
- QChar: this overload can delegate to the QStringView version:
void fun(QChar ch) { fun(QStringView(&ch, 1)); }
even though, for technical reasons, QStringView cannot provide a QChar constructor by itself.
- QString: if you store an unmodified copy of the string and thus would like to take advantage of QString's implicit sharing.
- QLatin1String: if you can implement the function without converting the QLatin1String to UTF-16 first; users expect a function overloaded on QLatin1String to perform strictly less memory allocations than the semantically equivalent call of the QStringView version, involving construction of a QString from the QLatin1String.
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.
Note: We strongly discourage the use of QList<QStringView>, because QList is a very inefficient container for QStringViews (it would heap-allocate every element). Use QVector (or std::vector) to hold QStringViews instead.
source§impl Data for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Data for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§impl End for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl End for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§unsafe fn end(&self) -> Ptr<QChar>
unsafe fn end(&self) -> Ptr<QChar>
Returns a const STL-style iterator pointing to the imaginary character after the last character in the list.
Calls C++ function: const QChar* QStringView::end() const
.
Returns a const STL-style iterator pointing to the imaginary character after the last character in the list.
This function is provided for STL compatibility.
source§impl Ge<Ref<QChar>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Ge<Ref<QChar>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§unsafe fn ge(&self, rhs: &Ref<QChar>) -> bool
unsafe fn ge(&self, rhs: &Ref<QChar>) -> bool
Returns true
if the numeric Unicode value of c1 is greater than or equal to that of c2; otherwise returns false
.
Calls C++ function: bool operator>=(QStringView lhs, QChar rhs)
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for bool operator>=(QChar c1, QChar c2)
:
Returns true
if the numeric Unicode value of c1 is greater than or equal to that of c2; otherwise returns false
.
source§impl Ge<Ref<QLatin1String>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Ge<Ref<QLatin1String>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§unsafe fn ge(&self, rhs: &Ref<QLatin1String>) -> bool
unsafe fn ge(&self, rhs: &Ref<QLatin1String>) -> bool
Returns true
if the numeric Unicode value of c1 is greater than or equal to that of c2; otherwise returns false
.
Calls C++ function: bool operator>=(QStringView lhs, QLatin1String rhs)
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for bool operator>=(QChar c1, QChar c2)
:
Returns true
if the numeric Unicode value of c1 is greater than or equal to that of c2; otherwise returns false
.
source§impl Ge<Ref<QStringView>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Ge<Ref<QStringView>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§unsafe fn ge(&self, rhs: &Ref<QStringView>) -> bool
unsafe fn ge(&self, rhs: &Ref<QStringView>) -> bool
Returns true
if the numeric Unicode value of c1 is greater than or equal to that of c2; otherwise returns false
.
Calls C++ function: bool operator>=(QStringView lhs, QStringView rhs)
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for bool operator>=(QChar c1, QChar c2)
:
Returns true
if the numeric Unicode value of c1 is greater than or equal to that of c2; otherwise returns false
.
source§impl Gt<Ref<QChar>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Gt<Ref<QChar>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§impl Gt<Ref<QLatin1String>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Gt<Ref<QLatin1String>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§impl Gt<Ref<QStringView>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Gt<Ref<QStringView>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§impl Le<Ref<QChar>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Le<Ref<QChar>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§unsafe fn le(&self, rhs: &Ref<QChar>) -> bool
unsafe fn le(&self, rhs: &Ref<QChar>) -> bool
Returns true
if the numeric Unicode value of c1 is less than or equal to that of c2; otherwise returns false
.
Calls C++ function: bool operator<=(QStringView lhs, QChar rhs)
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for bool operator<=(QChar c1, QChar c2)
:
Returns true
if the numeric Unicode value of c1 is less than or equal to that of c2; otherwise returns false
.
source§impl Le<Ref<QLatin1String>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Le<Ref<QLatin1String>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§unsafe fn le(&self, rhs: &Ref<QLatin1String>) -> bool
unsafe fn le(&self, rhs: &Ref<QLatin1String>) -> bool
Returns true
if the numeric Unicode value of c1 is less than or equal to that of c2; otherwise returns false
.
Calls C++ function: bool operator<=(QStringView lhs, QLatin1String rhs)
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for bool operator<=(QChar c1, QChar c2)
:
Returns true
if the numeric Unicode value of c1 is less than or equal to that of c2; otherwise returns false
.
source§impl Le<Ref<QStringView>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Le<Ref<QStringView>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§unsafe fn le(&self, rhs: &Ref<QStringView>) -> bool
unsafe fn le(&self, rhs: &Ref<QStringView>) -> bool
Returns true
if the numeric Unicode value of c1 is less than or equal to that of c2; otherwise returns false
.
Calls C++ function: bool operator<=(QStringView lhs, QStringView rhs)
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for bool operator<=(QChar c1, QChar c2)
:
Returns true
if the numeric Unicode value of c1 is less than or equal to that of c2; otherwise returns false
.
source§impl Lt<Ref<QChar>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Lt<Ref<QChar>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§impl Lt<Ref<QLatin1String>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Lt<Ref<QLatin1String>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§impl Lt<Ref<QStringView>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Lt<Ref<QStringView>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§impl PartialEq<Ref<QChar>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl PartialEq<Ref<QChar>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§fn eq(&self, rhs: &Ref<QChar>) -> bool
fn eq(&self, rhs: &Ref<QChar>) -> bool
Returns true
if c1 and c2 are the same Unicode character; otherwise returns false
.
Calls C++ function: bool operator==(QStringView lhs, QChar rhs)
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for bool operator==(QChar c1, QChar c2)
:
Returns true
if c1 and c2 are the same Unicode character; otherwise returns false
.
source§impl PartialEq<Ref<QLatin1String>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl PartialEq<Ref<QLatin1String>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§fn eq(&self, rhs: &Ref<QLatin1String>) -> bool
fn eq(&self, rhs: &Ref<QLatin1String>) -> bool
Returns true
if c1 and c2 are the same Unicode character; otherwise returns false
.
Calls C++ function: bool operator==(QStringView lhs, QLatin1String rhs)
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for bool operator==(QChar c1, QChar c2)
:
Returns true
if c1 and c2 are the same Unicode character; otherwise returns false
.
source§impl PartialEq<Ref<QStringView>> for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl PartialEq<Ref<QStringView>> for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.source§fn eq(&self, rhs: &Ref<QStringView>) -> bool
fn eq(&self, rhs: &Ref<QStringView>) -> bool
Returns true
if c1 and c2 are the same Unicode character; otherwise returns false
.
Calls C++ function: bool operator==(QStringView lhs, QStringView rhs)
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for bool operator==(QChar c1, QChar c2)
:
Returns true
if c1 and c2 are the same Unicode character; otherwise returns false
.
source§impl Size for QStringView
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
impl Size for QStringView
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.