QStringView 類提供 UTF-16 字符串統一視圖,采用隻讀子集的 QString API. 更多...
| 頭: |
#include <QStringView>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
|
| qmake: |
QT += core
|
注意: 此類的所有函數 可重入 .
| const_iterator | |
| const_pointer | |
| const_reference | |
| const_reverse_iterator | |
| difference_type | |
| iterator | |
| pointer | |
| reference | |
| reverse_iterator | |
| size_type | |
| storage_type | |
| value_type |
| QStringView () | |
| QStringView (const Char (&)[N] string ) | |
| QStringView (const Char * str ) | |
| QStringView (const Container & str ) | |
| QStringView (const QString & str ) | |
| QStringView (std::nullptr_t) | |
| QStringView (const Char * first , const Char * last ) | |
| QStringView (const Char * str , qsizetype len ) | |
| QString | arg (Args &&... args ) const |
| QChar | at (qsizetype n ) const |
| QChar | back () const |
| QStringView::const_iterator | begin () const |
| QStringView::const_iterator | cbegin () const |
| QStringView::const_iterator | cend () const |
| void | chop (qsizetype length ) |
| QStringView | chopped (qsizetype length ) const |
| int | compare (QChar ch ) const |
| int | compare (QChar ch , Qt::CaseSensitivity cs ) const |
| int | compare (QLatin1StringView l1 , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | compare (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
(從 6.5 起)
int
|
compare (QUtf8StringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
(從 6.1 起)
QStringView::const_iterator
|
constBegin () const |
(從 6.0 起)
QStringView::const_pointer
|
constData () const |
(從 6.1 起)
QStringView::const_iterator
|
constEnd () const |
| bool | contains (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | contains (QLatin1StringView l1 , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | contains (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
(從 6.1 起)
bool
|
contains (const QRegularExpression & re , QRegularExpressionMatch * rmatch = nullptr) const |
(從 6.1 起)
qsizetype
|
count (const QRegularExpression & re ) const |
(從 6.0 起)
qsizetype
|
count (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
(從 6.4 起)
qsizetype
|
count (QLatin1StringView l1 , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
(從 6.0 起)
qsizetype
|
count (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QStringView::const_reverse_iterator | crbegin () const |
| QStringView::const_reverse_iterator | crend () const |
| QStringView::const_pointer | data () const |
| bool | empty () const |
| QStringView::const_iterator | end () const |
| bool | endsWith (QChar ch ) const |
| bool | endsWith (QChar ch , Qt::CaseSensitivity cs ) const |
| bool | endsWith (QLatin1StringView l1 , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | endsWith (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QChar | first () const |
(從 6.0 起)
QStringView
|
first (qsizetype n ) const |
| QChar | front () const |
| qsizetype | indexOf (QChar ch , qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | indexOf (QLatin1StringView l1 , qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | indexOf (QStringView str , qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
(從 6.1 起)
qsizetype
|
indexOf (const QRegularExpression & re , qsizetype from = 0, QRegularExpressionMatch * rmatch = nullptr) const |
| bool | isEmpty () const |
(從 6.7 起)
bool
|
isLower () const |
| bool | isNull () const |
| bool | isRightToLeft () const |
(從 6.7 起)
bool
|
isUpper () const |
| bool | isValidUtf16 () const |
| QChar | last () const |
(從 6.0 起)
QStringView
|
last (qsizetype n ) const |
(從 6.2 起)
qsizetype
|
lastIndexOf (const QRegularExpression & re , QRegularExpressionMatch * rmatch = nullptr) const |
| qsizetype | lastIndexOf (QChar ch , qsizetype from , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | lastIndexOf (QLatin1StringView l1 , qsizetype from , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | lastIndexOf (QStringView str , qsizetype from , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
(從 6.1 起)
qsizetype
|
lastIndexOf (const QRegularExpression & re , qsizetype from , QRegularExpressionMatch * rmatch = nullptr) const |
(從 6.3 起)
qsizetype
|
lastIndexOf (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
(從 6.2 起)
qsizetype
|
lastIndexOf (QLatin1StringView l1 , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
(從 6.2 起)
qsizetype
|
lastIndexOf (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | length () const |
(從 6.4 起)
int
|
localeAwareCompare (QStringView other ) const |
(從 6.8 起)
qsizetype
|
max_size () const |
| QStringView::const_reverse_iterator | rbegin () const |
| QStringView::const_reverse_iterator | rend () const |
| qsizetype | size () const |
(從 6.8 起)
QStringView &
|
slice (qsizetype pos , qsizetype n ) |
(從 6.8 起)
QStringView &
|
slice (qsizetype pos ) |
(從 6.0 起)
QStringView
|
sliced (qsizetype pos , qsizetype n ) const |
(從 6.0 起)
QStringView
|
sliced (qsizetype pos ) const |
(從 6.0 起)
QList<QStringView>
|
split (QChar sep , Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
(從 6.0 起)
QList<QStringView>
|
split (QStringView sep , Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
(從 6.0 起)
QList<QStringView>
|
split (const QRegularExpression & re , Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const |
| bool | startsWith (QChar ch ) const |
| bool | startsWith (QChar ch , Qt::CaseSensitivity cs ) const |
| bool | startsWith (QLatin1StringView l1 , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | startsWith (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
(從 6.0 起)
CFStringRef
|
toCFString () const |
(從 6.0 起)
double
|
toDouble (bool * ok = nullptr) const |
(從 6.0 起)
float
|
toFloat (bool * ok = nullptr) const |
(從 6.0 起)
int
|
toInt (bool * ok = nullptr, int base = 10) const |
| QByteArray | toLatin1 () const |
| QByteArray | toLocal8Bit () const |
(從 6.0 起)
long
|
toLong (bool * ok = nullptr, int base = 10) const |
(從 6.0 起)
qlonglong
|
toLongLong (bool * ok = nullptr, int base = 10) const |
(從 6.0 起)
NSString *
|
toNSString () const |
(從 6.0 起)
short
|
toShort (bool * ok = nullptr, int base = 10) const |
| QString | toString () const |
(從 6.0 起)
uint
|
toUInt (bool * ok = nullptr, int base = 10) const |
(從 6.0 起)
ulong
|
toULong (bool * ok = nullptr, int base = 10) const |
(從 6.0 起)
qulonglong
|
toULongLong (bool * ok = nullptr, int base = 10) const |
(從 6.0 起)
ushort
|
toUShort (bool * ok = nullptr, int base = 10) const |
| QList<uint> | toUcs4 () const |
| QByteArray | toUtf8 () const |
| qsizetype | toWCharArray (wchar_t * array ) const |
(從 6.0 起)
auto
|
tokenize (Needle && sep , Flags... flags ) const |
| QStringView | trimmed () const |
| void | truncate (qsizetype length ) |
| const QStringView::storage_type * | utf16 () const |
(從 6.7 起)
std::u16string_view
|
operator std::u16string_view () const |
| QChar | operator[] (qsizetype n ) const |
| QStringView | fromArray (const Char (&)[Size] string ) |
(從 6.8 起)
qsizetype
|
maxSize () |
| size_t | qHash (QStringView key , size_t seed = 0) |
| bool | operator!= (const QStringView & lhs , const QStringView & rhs ) |
| bool | operator< (const QStringView & lhs , const QStringView & rhs ) |
| bool | operator<= (const QStringView & lhs , const QStringView & rhs ) |
| bool | operator== (const QStringView & lhs , const QStringView & rhs ) |
| bool | operator> (const QStringView & lhs , const QStringView & rhs ) |
| bool | operator>= (const QStringView & lhs , const QStringView & rhs ) |
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 首先。
The UTF-16 string may be represented as an array (or an array-compatible data-structure such as
QString
, std::basic_string, etc.) of
QChar
,
ushort
,
char16_t
or (on platforms, such as Windows, where it is a 16-bit type)
wchar_t
.
QStringView is designed as an interface type; its main use-case is as a function parameter type. When QStringViews are used as automatic variables or data members, care must be taken to ensure that the referenced string data (for example, owned by a QString ) outlives the QStringView on all code paths, lest the string view ends up referencing deleted data.
When used as an interface type, QStringView allows a single function to accept a wide variety of UTF-16 string data sources. One function accepting QStringView thus replaces three function overloads (taking
QString
and
(const QChar*, qsizetype)
), while at the same time enabling even more string data sources to be passed to the function, such as
u"Hello World"
,
char16_t
字符串文字。
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
void fun(QChar ch) { fun(QStringView(&ch, 1)); }
even though, for technical reasons, QStringView cannot provide a QChar constructor by itself.
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
文字類型
, 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
() 在
constexpr
contexts instead.
此 typedef 提供 STL 樣式 const 迭代器為 QStringView .
另請參閱 iterator and const_reverse_iterator .
彆名化的
value_type *
。為兼容 STL (標準模闆庫) 提供。
彆名化的
value_type &
。為兼容 STL (標準模闆庫) 提供。
This typedef provides an STL-style const reverse iterator for QStringView .
另請參閱 reverse_iterator and const_iterator .
彆名化的
std::ptrdiff_t
。為兼容 STL (標準模闆庫) 提供。
此 typedef 提供 STL 樣式 const 迭代器為 QStringView .
QStringView does not support mutable iterators, so this is the same as const_iterator .
另請參閱 const_iterator and reverse_iterator .
彆名化的
value_type *
。為兼容 STL (標準模闆庫) 提供。
QStringView does not support mutable pointers, so this is the same as const_pointer .
彆名化的
value_type &
。為兼容 STL (標準模闆庫) 提供。
QStringView does not support mutable references, so this is the same as const_reference .
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 .
另請參閱 const_reverse_iterator and iterator .
彆名化的 qsizetype。為兼容 STL (標準模闆庫) 提供。
彆名化的
char16_t
.
彆名化的
const QChar
。為兼容 STL (標準模闆庫) 提供。
[since 6.0]
QList
<
QStringView
> QStringView::
split
(
QChar
sep
,
Qt::SplitBehavior
behavior
= Qt::KeepEmptyParts,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
[since 6.0]
QList
<
QStringView
> QStringView::
split
(
QStringView
sep
,
Qt::SplitBehavior
behavior
= Qt::KeepEmptyParts,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
Splits the view into substring views wherever sep occurs, and returns the list of those string views.
見 QString::split () for how sep , behavior and cs interact to form the result.
注意: All the returned views are valid as long as the data referenced by this string view is valid. Destroying the data will cause all views to become dangling.
這些函數在 Qt 6.0 引入。
Replaces occurrences of
%N
in this string with the corresponding argument from
args
. The arguments are not positional: the first of the
args
替換
%N
with the lowest
N
(all of them), the second of the
args
the
%N
with the next-lowest
N
etc.
Args
can consist of anything that implicitly converts to
QAnyStringView
.
注意:
In Qt versions prior to 6.9,
QAnyStringView
and UTF-8 strings (
QUtf8StringView
,
QByteArray
,
QByteArrayView
,
const char8_t*
, etc) were not supported as
args
.
另請參閱 QString::arg ().
[constexpr noexcept]
int
QStringView::
compare
(
QChar
ch
) const
[noexcept]
int
QStringView::
compare
(
QChar
ch
,
Qt::CaseSensitivity
cs
) const
[noexcept]
int
QStringView::
compare
(
QLatin1StringView
l1
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
Compares this string view to the Latin-1 string view l1 , or the character ch . Returns a negative integer if this string view is less than l1 or ch ,正整數若大於 l1 or ch ,和 0 若它們相等。
若 cs is Qt::CaseSensitive (默認),比較區分大小寫;否則,比較不區分大小寫。
另請參閱 operator== (), operator< (),和 operator> ().
[noexcept]
bool
QStringView::
startsWith
(
QChar
ch
) const
[noexcept]
bool
QStringView::
startsWith
(
QChar
ch
,
Qt::CaseSensitivity
cs
) const
[noexcept]
bool
QStringView::
startsWith
(
QLatin1StringView
l1
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
[noexcept]
bool
QStringView::
startsWith
(
QStringView
str
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
返迴
true
if this string view starts with the UTF-16 string viewed by
str
, the Latin-1 string viewed by
l1
, or the character
ch
respectively; otherwise returns
false
.
若 cs is Qt::CaseSensitive (默認),搜索區分大小寫;否則,搜索不區分大小寫。
另請參閱 endsWith ().
[noexcept]
bool
QStringView::
endsWith
(
QChar
ch
) const
[noexcept]
bool
QStringView::
endsWith
(
QChar
ch
,
Qt::CaseSensitivity
cs
) const
[noexcept]
bool
QStringView::
endsWith
(
QLatin1StringView
l1
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
[noexcept]
bool
QStringView::
endsWith
(
QStringView
str
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
返迴
true
if this string view ends with the UTF-16 string viewed by
str
, the Latin-1 string viewed by
l1
, or the character
ch
respectively; otherwise returns
false
.
若 cs is Qt::CaseSensitive (默認),搜索區分大小寫;否則,搜索不區分大小寫。
另請參閱 startsWith ().
[noexcept]
qsizetype
QStringView::
indexOf
(
QChar
ch
,
qsizetype
from
= 0,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
[noexcept]
qsizetype
QStringView::
indexOf
(
QLatin1StringView
l1
,
qsizetype
from
= 0,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
[noexcept]
qsizetype
QStringView::
indexOf
(
QStringView
str
,
qsizetype
from
= 0,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
Returns the index position of the first occurrence of the UTF-16 string viewed by str , the Latin-1 string viewed by l1 , or the character ch respectively, in this string view, searching forward from index position from . Returns -1 if str , l1 or ch is not found, respectively.
若 cs is Qt::CaseSensitive (默認),搜索區分大小寫;否則,搜索不區分大小寫。
若 from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.
另請參閱 QString::indexOf ().
[noexcept]
bool
QStringView::
contains
(
QChar
ch
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
[noexcept]
bool
QStringView::
contains
(
QLatin1StringView
l1
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
[noexcept]
bool
QStringView::
contains
(
QStringView
str
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
返迴
true
if this string view contains an occurrence of the UTF-16 string viewed by
str
, the Latin-1 string viewed by
l1
, or the character
ch
respectively; otherwise returns
false
.
若 cs is Qt::CaseSensitive (默認),搜索區分大小寫;否則,搜索不區分大小寫。
另請參閱 indexOf ().
[noexcept]
qsizetype
QStringView::
lastIndexOf
(
QChar
ch
,
qsizetype
from
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
[noexcept]
qsizetype
QStringView::
lastIndexOf
(
QLatin1StringView
l1
,
qsizetype
from
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
[noexcept]
qsizetype
QStringView::
lastIndexOf
(
QStringView
str
,
qsizetype
from
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
Returns the index position of the last occurrence of the UTF-16 string viewed by str , the Latin-1 string viewed by l1 , or the character ch respectively, in this string view, searching backward from index position from .
若 from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.
返迴 -1,若 str , l1 or ch is not found, respectively.
若 cs is Qt::CaseSensitive (默認),搜索區分大小寫;否則,搜索不區分大小寫。
注意:
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.
另請參閱 QString::lastIndexOf ().
[noexcept, since 6.2]
qsizetype
QStringView::
lastIndexOf
(
QLatin1StringView
l1
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
[noexcept, since 6.2]
qsizetype
QStringView::
lastIndexOf
(
QStringView
str
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
Returns the index position of the last occurrence of the UTF-16 string viewed by str or the Latin-1 string viewed by l1 respectively, in this string view searching backward from the last character of this string view. Returns -1 if str or l1 is not found, respectively.
若 cs is Qt::CaseSensitive (默認),搜索區分大小寫;否則,搜索不區分大小寫。
These functions were introduced in Qt 6.2.
另請參閱 QString::lastIndexOf ().
[constexpr noexcept(...), since 6.0]
template <typename Needle, typename... Flags>
auto
QStringView::
tokenize
(
Needle
&&
sep
,
Flags
...
flags
) const
Splits the string into substring views wherever sep occurs, and returns a lazy sequence of those strings.
相當於
return QStringTokenizer{std::forward<Needle>(sep), flags...};
except it works without C++17 Class Template Argument Deduction (CTAD) enabled in the compiler.
見 QStringTokenizer for how sep and flags interact to form the result.
注意: While this function returns QStringTokenizer , you should never, ever, name its template arguments explicitly. If you can use C++17 Class Template Argument Deduction (CTAD), you may write
QStringTokenizer result = sv.tokenize(sep);
(without template arguments). If you can't use C++17 CTAD, you must store the return value only in
auto
變量:
auto result = sv.tokenize(sep);
This is because the template arguments of QStringTokenizer have a very subtle dependency on the specific tokenize () overload from which they are returned, and they don't usually correspond to the type used for the separator.
These function were introduced in Qt 6.0.
注意:
This function is noexcept when
noexcept(qTokenize(std::declval<const QStringView&>(), std::forward<Needle>(needle), flags...))
is
true
.
另請參閱 QStringTokenizer and qTokenize ().
[constexpr noexcept]
QStringView::
QStringView
()
構造 null 字符串視圖。
另請參閱 isNull ().
[constexpr noexcept]
template <typename Char, size_t N> QStringView::
QStringView
(const
Char
(&)[
N
]
string
)
構造字符串視圖按字符串文字
string
。視圖覆蓋數組,直到第 1 個
Char(0)
被遇到,或
N
,以先到的為準。若需要完整數組,使用
fromArray
() 代替。
string 必須在此字符串視圖對象的壽命內保持有效。
Participates in overload resolution only 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
.
另請參閱 fromArray .
[constexpr noexcept]
template <typename Char> QStringView::
QStringView
(const
Char
*
str
)
構造字符串視圖對
str
. The length is determined by scanning for the first
Char(0)
.
str 必須在此字符串視圖對象的壽命內保持有效。
傳遞
nullptr
as
str
是安全的且結果在 null 字符串視圖中。
Participates in overload resolution only 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
.
[constexpr noexcept]
template <typename Container, QStringView::if_compatible_container<Container> = true> QStringView::
QStringView
(const
容器
&
str
)
構造字符串視圖對
str
。長度取自
std::size(str)
.
std::data(str)
必須在此字符串視圖對象的壽命內保持有效。
The string view will be empty if and only if
std::size(str) == 0
. It is unspecified whether this constructor can result in a null string view (
std::data(str)
would have to return
nullptr
for this).
Participates in overload resolution only if
Container
is a container with a compatible character type as
value_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
.
[noexcept]
QStringView::
QStringView
(const
QString
&
str
)
構造字符串視圖對 str .
str.data()
必須在此字符串視圖對象的壽命內保持有效。
字符串視圖將為 null 當且僅當
str.isNull()
.
[constexpr noexcept]
QStringView::
QStringView
(
std::nullptr_t
)
構造 null 字符串視圖。
另請參閱 isNull ().
[constexpr]
template <typename Char, QStringView::if_compatible_char<Char> = true> QStringView::
QStringView
(const
Char
*
first
, const
Char
*
last
)
構造字符串視圖對 first 按長度 ( last - first ).
範圍
[first,last)
必須在此字符串視圖對象的壽命內保持有效。
傳遞
\nullptr
as
first
是安全的若
last
is
nullptr
, too, and results in a null string view.
行為未定義若
last
precedes
first
,或
first
is
nullptr
and
last
is not.
Participates in overload resolution only 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
.
[constexpr]
template <typename Char, QStringView::if_compatible_char<Char> = true> QStringView::
QStringView
(const
Char
*
str
,
qsizetype
len
)
構造字符串視圖對 str 按長度 len .
範圍
[str,len)
必須在此字符串視圖對象的壽命內保持有效。
傳遞
nullptr
as
str
是安全的若
len
is 0, too, and results in a null string view.
行為未定義若
len
is negative or, when positive, if
str
is
nullptr
.
Participates in overload resolution only 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
.
[constexpr noexcept]
QChar
QStringView::
at
(
qsizetype
n
) const
返迴字符位於位置 n 在此字符串視圖。
行為未定義若 n is negative or not less than size ().
另請參閱 operator[] (), front (),和 back ().
[constexpr]
QChar
QStringView::
back
() const
Returns the last character in the string view. Same as last ().
此函數為兼容 STL (標準模闆庫) 提供。
警告: 在空字符串視圖調用此函數,將構成未定義行為。
另請參閱 front (), first (),和 last ().
[noexcept]
QStringView::const_iterator
QStringView::
begin
() const
返迴常量 STL 樣式迭代器 pointing to the first character in the string view.
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 end (), constBegin (), cbegin (), rbegin (),和 data ().
[noexcept]
QStringView::const_iterator
QStringView::
cbegin
() const
如同 begin ().
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 cend (), begin (), constBegin (), crbegin (),和 data ().
[noexcept]
QStringView::const_iterator
QStringView::
cend
() const
如同 end ().
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 cbegin (), end (), constEnd (),和 crend ().
[constexpr noexcept]
void
QStringView::
chop
(
qsizetype
length
)
截取此字符串視圖按 length 字符。
如同
*this = left(size() - length)
.
注意: 行為未定義當 length < 0 or length > size ().
另請參閱 sliced (), left (), right (), chopped (), truncate (),和 slice ().
[constexpr noexcept]
QStringView
QStringView::
chopped
(
qsizetype
length
) const
返迴子字符串長度 size () - length 起始於此對象的開頭。
如同
left(size() - length)
.
注意: 行為未定義當 length < 0 or length > size ().
另請參閱 sliced (), left (), right (), chop (), truncate (),和 slice ().
[noexcept]
int
QStringView::
compare
(
QStringView
str
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
Compares this string view with string view str and returns a negative integer if this string view is less than str ,正整數若大於 str ,和 0 若它們相等。
若 cs is Qt::CaseSensitive (默認),比較區分大小寫;否則,比較不區分大小寫。
另請參閱 operator== (), operator< (),和 operator> ().
[noexcept, since 6.5]
int
QStringView::
compare
(
QUtf8StringView
str
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
Compares this string view with QUtf8StringView str and returns a negative integer if this string view is less than str ,正整數若大於 str ,和 0 若它們相等。
若 cs is Qt::CaseSensitive (默認),比較區分大小寫;否則,比較不區分大小寫。
該函數在 Qt 6.5 引入。
另請參閱 operator== (), operator< (),和 operator> ().
[noexcept, since 6.1]
QStringView::const_iterator
QStringView::
constBegin
() const
如同 begin ().
該函數在 Qt 6.1 引入。
另請參閱 constEnd (), begin (), cbegin (), crbegin (),和 data ().
[noexcept, since 6.0]
QStringView::const_pointer
QStringView::
constData
() const
Returns a const pointer to the first character in the string view.
注意: The character array represented by the return value is not null-terminated.
該函數在 Qt 6.0 引入。
另請參閱 data (), begin (), end (),和 utf16 ().
[noexcept, since 6.1]
QStringView::const_iterator
QStringView::
constEnd
() const
如同 end ().
該函數在 Qt 6.1 引入。
另請參閱 constBegin (), end (), cend (),和 crend ().
[since 6.1]
bool
QStringView::
contains
(const
QRegularExpression
&
re
,
QRegularExpressionMatch
*
rmatch
= nullptr) const
返迴
true
若正則錶達式
re
matches somewhere in this string view; otherwise returns
false
.
若匹配成功且
rmatch
不是
nullptr
,它還把匹配結果寫入
QRegularExpressionMatch
對象指嚮的
rmatch
.
該函數在 Qt 6.1 引入。
另請參閱 QRegularExpression::match ().
[since 6.1]
qsizetype
QStringView::
count
(const
QRegularExpression
&
re
) const
返迴次數對於正則錶達式 re matches in the string view.
For historical reasons, this function counts overlapping matches. This behavior is different from simply iterating over the matches in the string view using QRegularExpressionMatchIterator .
該函數在 Qt 6.1 引入。
另請參閱 QRegularExpression::globalMatch ().
[noexcept, since 6.0]
qsizetype
QStringView::
count
(
QChar
ch
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
Returns the number of occurrences of the character ch in the string view.
若 cs is Qt::CaseSensitive (默認),搜索區分大小寫;否則,搜索不區分大小寫。
此函數重載 QStringView::count ().
該函數在 Qt 6.0 引入。
另請參閱 QString::count (), contains (),和 indexOf ().
[since 6.4]
qsizetype
QStringView::
count
(
QLatin1StringView
l1
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
Returns the number of (potentially overlapping) occurrences of the Latin-1 string viewed by l1 在此字符串視圖。
若 cs is Qt::CaseSensitive (默認),搜索區分大小寫;否則,搜索不區分大小寫。
此函數重載 QStringView::count ().
該函數在 Qt 6.4 引入。
另請參閱 QString::count (), contains (),和 indexOf ().
[noexcept, since 6.0]
qsizetype
QStringView::
count
(
QStringView
str
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
返迴 (潛在重疊) 齣現數對於字符串視圖 str 在此字符串視圖。
若 cs is Qt::CaseSensitive (默認),搜索區分大小寫;否則,搜索不區分大小寫。
此函數重載 QStringView::count ().
該函數在 Qt 6.0 引入。
另請參閱 QString::count (), contains (),和 indexOf ().
[noexcept]
QStringView::const_reverse_iterator
QStringView::
crbegin
() const
如同 rbegin ().
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 crend (), rbegin (),和 cbegin ().
[noexcept]
QStringView::const_reverse_iterator
QStringView::
crend
() const
如同 rend ().
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 crbegin (), rend (),和 cend ().
[noexcept]
QStringView::const_pointer
QStringView::
data
() const
Returns a const pointer to the first character in the string view.
注意: The character array represented by the return value is not null-terminated.
另請參閱 begin (), end (),和 utf16 ().
[constexpr noexcept]
bool
QStringView::
empty
() const
Returns whether this string view is empty - that is, whether
size() == 0
.
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 isEmpty (), isNull (), size (),和 length ().
[noexcept]
QStringView::const_iterator
QStringView::
end
() const
返迴常量 STL 樣式迭代器 pointing to the imaginary character after the last character in the list.
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 begin (), constEnd (), cend (),和 rend ().
[constexpr]
QChar
QStringView::
第一
() const
Returns the first character in the string view. Same as front ().
This function is provided for compatibility with other Qt containers.
警告: 在空字符串視圖調用此函數,將構成未定義行為。
另請參閱 front (), back (),和 last ().
[constexpr noexcept, since 6.0]
QStringView
QStringView::
第一
(
qsizetype
n
) const
Returns a string view that points to the first n characters of this string view.
注意: 行為未定義當 n < 0 or n > size ().
該函數在 Qt 6.0 引入。
另請參閱 last (), sliced (), startsWith (), chopped (), chop (), truncate (),和 slice ().
[static constexpr noexcept]
template <typename Char, size_t Size, QStringView::if_compatible_char<Char> = true>
QStringView
QStringView::
fromArray
(const
Char
(&)[
Size
]
string
)
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 必須在此字符串視圖對象的壽命內保持有效。
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
.
[constexpr]
QChar
QStringView::
front
() const
Returns the first character in the string view. Same as first ().
此函數為兼容 STL (標準模闆庫) 提供。
警告: 在空字符串視圖調用此函數,將構成未定義行為。
另請參閱 back (), first (),和 last ().
[since 6.1]
qsizetype
QStringView::
indexOf
(const
QRegularExpression
&
re
,
qsizetype
from
= 0,
QRegularExpressionMatch
*
rmatch
= nullptr) const
Returns the index position of the first match of the regular expression re in the string view, searching forward from index position from . Returns -1 if re didn't match anywhere.
若匹配成功且
rmatch
不是
nullptr
,它還把匹配結果寫入
QRegularExpressionMatch
對象指嚮的
rmatch
.
注意: Due to how the regular expression matching algorithm works, this function will actually match repeatedly from the beginning of the string view until the position from is reached.
該函數在 Qt 6.1 引入。
[constexpr noexcept]
bool
QStringView::
isEmpty
() const
Returns whether this string view is empty - that is, whether
size() == 0
.
This function is provided for compatibility with other Qt containers.
另請參閱 empty (), isNull (), size (),和 length ().
[noexcept, since 6.7]
bool
QStringView::
isLower
() const
返迴
true
if this view is identical to its lowercase folding.
Note that this does not mean that the string view does not contain uppercase letters (some uppercase letters do not have a lowercase folding; they are left unchanged by toString ().toLower()). For more information, refer to the Unicode standard, section 3.13.
該函數在 Qt 6.7 引入。
另請參閱 QChar::toLower () 和 isUpper ().
[constexpr noexcept]
bool
QStringView::
isNull
() const
Returns whether this string view is null - that is, whether
data() == nullptr
.
This functions is provided for compatibility with other Qt containers.
另請參閱 empty (), isEmpty (), size (),和 length ().
[noexcept]
bool
QStringView::
isRightToLeft
() const
返迴
true
if the string view is read right to left.
另請參閱 QString::isRightToLeft ().
[noexcept, since 6.7]
bool
QStringView::
isUpper
() const
返迴
true
if this view is identical to its uppercase folding.
Note that this does not mean that the the string view does not contain lowercase letters (some lowercase letters do not have a uppercase folding; they are left unchanged by toString ().toUpper()). For more information, refer to the Unicode standard, section 3.13.
該函數在 Qt 6.7 引入。
另請參閱 QChar::toUpper () 和 isLower ().
[noexcept]
bool
QStringView::
isValidUtf16
() const
返迴
true
if the string view contains valid UTF-16 encoded data, or
false
否則。
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.
另請參閱 QString::isValidUtf16 ().
[constexpr]
QChar
QStringView::
last
() const
Returns the last character in the string view. Same as back ().
This function is provided for compatibility with other Qt containers.
警告: 在空字符串視圖調用此函數,將構成未定義行為。
另請參閱 back (), front (),和 first ().
[constexpr noexcept, since 6.0]
QStringView
QStringView::
last
(
qsizetype
n
) const
Returns a string view that points to the last n characters of this string view.
注意: 行為未定義當 n < 0 or n > size ().
該函數在 Qt 6.0 引入。
另請參閱 first (), sliced (), endsWith (), chopped (), chop (), truncate (),和 slice ().
[since 6.2]
qsizetype
QStringView::
lastIndexOf
(const
QRegularExpression
&
re
,
QRegularExpressionMatch
*
rmatch
= nullptr) const
Returns the index position of the last match of the regular expression re in the string view. Returns -1 if re didn't match anywhere.
若匹配成功且
rmatch
不是
nullptr
,它還把匹配結果寫入
QRegularExpressionMatch
對象指嚮的
rmatch
.
注意: Due to how the regular expression matching algorithm works, this function will actually match repeatedly from the beginning of the string view until the end of the string view is reached.
該函數在 Qt 6.2 引入。
[since 6.1]
qsizetype
QStringView::
lastIndexOf
(const
QRegularExpression
&
re
,
qsizetype
from
,
QRegularExpressionMatch
*
rmatch
= nullptr) const
Returns the index position of the last match of the regular expression re in the string view, which starts before the index position from .
若 from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.
返迴 -1,若 re didn't match anywhere.
若匹配成功且
rmatch
不是
nullptr
,它還把匹配結果寫入
QRegularExpressionMatch
對象指嚮的
rmatch
.
注意: Due to how the regular expression matching algorithm works, this function will actually match repeatedly from the beginning of the string view until the position from is reached.
注意:
When searching for a regular expression
re
that may match 0 characters, 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.
該函數在 Qt 6.1 引入。
[noexcept, since 6.3]
qsizetype
QStringView::
lastIndexOf
(
QChar
ch
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
此函數重載 QStringView::lastIndexOf ().
該函數在 Qt 6.3 引入。
[constexpr noexcept]
qsizetype
QStringView::
length
() const
如同 size ().
This function is provided for compatibility with other Qt containers.
另請參閱 empty (), isEmpty (), isNull (),和 size ().
[since 6.4]
int
QStringView::
localeAwareCompare
(
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.
The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.
該函數在 Qt 6.4 引入。
另請參閱 Comparing Strings .
[static constexpr noexcept, since 6.8]
qsizetype
QStringView::
maxSize
()
It returns the maximum number of elements that the view can theoretically represent. In practice, the number can be much smaller, limited by the amount of memory available to the system.
該函數在 Qt 6.8 引入。
[constexpr noexcept, since 6.8]
qsizetype
QStringView::
max_size
() const
此函數為兼容 STL (標準模闆庫) 提供。
返迴 maxSize ().
該函數在 Qt 6.8 引入。
[noexcept]
QStringView::const_reverse_iterator
QStringView::
rbegin
() const
返迴常量 STL-style reverse iterator pointing to the first character in the string view, in reverse order.
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 rend (), crbegin (),和 begin ().
[noexcept]
QStringView::const_reverse_iterator
QStringView::
rend
() const
返迴 STL-style reverse iterator pointing to one past the last character in the string view, in reverse order.
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 rbegin (), crend (),和 end ().
[constexpr noexcept]
qsizetype
QStringView::
size
() const
Returns the size of this string view, in UTF-16 code units (that is, surrogate pairs count as two for the purposes of this function, the same as in QString ).
另請參閱 empty (), isEmpty (), isNull (),和 length ().
[constexpr, since 6.8]
QStringView
&QStringView::
slice
(
qsizetype
pos
,
qsizetype
n
)
Modifies this string view to start from position pos , extending for n 代碼點。
注意: 行為未定義當 pos < 0, n < 0, or pos + n > size ().
該函數在 Qt 6.8 引入。
另請參閱 sliced (), first (), last (), chopped (), chop (),和 truncate ().
[constexpr, since 6.8]
QStringView
&QStringView::
slice
(
qsizetype
pos
)
Modifies this string view to start from position pos , extending to its end.
注意: 行為未定義當 pos < 0 or pos > size ().
這是重載函數。
該函數在 Qt 6.8 引入。
另請參閱 sliced (), first (), last (), chopped (), chop (),和 truncate ().
[constexpr noexcept, since 6.0]
QStringView
QStringView::
sliced
(
qsizetype
pos
,
qsizetype
n
) const
Returns a string view that points to n characters of this string view, starting at position pos .
注意: 行為未定義當 pos < 0, n < 0, or pos + n > size ().
該函數在 Qt 6.0 引入。
另請參閱 first (), last (), chopped (), chop (), truncate (),和 slice ().
[constexpr noexcept, since 6.0]
QStringView
QStringView::
sliced
(
qsizetype
pos
) const
Returns a string view starting at position pos in this object, and extending to its end.
注意: 行為未定義當 pos < 0 or pos > size ().
這是重載函數。
該函數在 Qt 6.0 引入。
另請參閱 first (), last (), chopped (), chop (), truncate (),和 slice ().
[since 6.0]
QList
<
QStringView
> QStringView::
split
(const
QRegularExpression
&
re
,
Qt::SplitBehavior
behavior
= Qt::KeepEmptyParts) const
Splits the string into substring views wherever the regular expression re matches, and returns the list of those strings. If re does not match anywhere in the string, split() returns a single-element list containing this string as view.
注意: The views in the returned list are sub-views of this view; as such, they reference the same data as it and only remain valid for as long as that data remains live.
這是重載函數。
該函數在 Qt 6.0 引入。
[since 6.0]
CFStringRef
QStringView::
toCFString
() const
Creates a CFString from this QStringView .
The caller owns the CFString and is responsible for releasing it.
注意: 此函數隻可用於 macOS 和 iOS。
該函數在 Qt 6.0 引入。
[since 6.0]
double
QStringView::
toDouble
(
bool
*
ok
= nullptr) const
Returns the string view converted to a
double
值。
Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).
若
ok
不是
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 ().
該函數在 Qt 6.0 引入。
另請參閱 QString::toDouble ().
[since 6.0]
float
QStringView::
toFloat
(
bool
*
ok
= nullptr) const
Returns the string view converted to a
float
值。
Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).
若
ok
不是
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 ()
該函數在 Qt 6.0 引入。
另請參閱 QString::toFloat ().
[since 6.0]
int
QStringView::
toInt
(
bool
*
ok
= nullptr,
int
base
= 10) const
Returns the string view converted to an
int
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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 ()
該函數在 Qt 6.0 引入。
另請參閱 QString::toInt ().
Returns a Latin-1 representation of the string as a QByteArray .
The behavior is undefined if the string contains non-Latin1 characters.
另請參閱 toUtf8 (), toLocal8Bit (),和 QStringEncoder .
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.
另請參閱 toLatin1 (), toUtf8 (),和 QStringEncoder .
[since 6.0]
long
QStringView::
toLong
(
bool
*
ok
= nullptr,
int
base
= 10) const
Returns the string view converted to a
long
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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 ()
該函數在 Qt 6.0 引入。
另請參閱 QString::toLong ().
[since 6.0]
qlonglong
QStringView::
toLongLong
(
bool
*
ok
= nullptr,
int
base
= 10) const
Returns the string view converted to a
long long
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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 ()
該函數在 Qt 6.0 引入。
另請參閱 QString::toLongLong ().
[since 6.0]
NSString
*QStringView::
toNSString
() const
Creates an NSString from this QStringView .
The NSString is autoreleased.
注意: 此函數隻可用於 macOS 和 iOS。
該函數在 Qt 6.0 引入。
[since 6.0]
short
QStringView::
toShort
(
bool
*
ok
= nullptr,
int
base
= 10) const
Returns the string view converted to a
short
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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 ()
該函數在 Qt 6.0 引入。
另請參閱 QString::toShort ().
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.
[since 6.0]
uint
QStringView::
toUInt
(
bool
*
ok
= nullptr,
int
base
= 10) const
Returns the string view converted to an
unsigned int
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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 ()
該函數在 Qt 6.0 引入。
另請參閱 QString::toUInt ().
[since 6.0]
ulong
QStringView::
toULong
(
bool
*
ok
= nullptr,
int
base
= 10) const
Returns the string view converted to an
unsigned long
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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 ()
該函數在 Qt 6.0 引入。
另請參閱 QString::toULong ().
[since 6.0]
qulonglong
QStringView::
toULongLong
(
bool
*
ok
= nullptr,
int
base
= 10) const
Returns the string view converted to an
unsigned long long
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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 ()
該函數在 Qt 6.0 引入。
另請參閱 QString::toULongLong ().
[since 6.0]
ushort
QStringView::
toUShort
(
bool
*
ok
= nullptr,
int
base
= 10) const
Returns the string view converted to an
unsigned short
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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 ()
該函數在 Qt 6.0 引入。
另請參閱 QString::toUShort ().
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.
另請參閱 toUtf8 (), toLatin1 (), toLocal8Bit (),和 QStringEncoder .
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 .
另請參閱 toLatin1 (), toLocal8Bit (),和 QStringEncoder .
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.
注意: This function writes no null terminator to the end of array .
Returns the number of
wchar_t
entries written to
array
.
另請參閱 QString::toWCharArray ().
[noexcept]
QStringView
QStringView::
trimmed
() const
Strips leading and trailing whitespace and returns the result.
空白意味著任何字符其。
QChar::isSpace
() 返迴
true
。這包括 ASCII 字符 \t、\n、\v、\f、\r、及 " "。
[constexpr noexcept]
void
QStringView::
truncate
(
qsizetype
length
)
Truncates this string view to length length .
如同
*this = left(length)
.
注意: 行為未定義當 length < 0 or length > size ().
另請參閱 sliced (), left (), right (), chopped (),和 chop ().
[constexpr noexcept]
const
QStringView::storage_type
*QStringView::
utf16
() const
Returns a const pointer to the first character in the string view.
注意: The character array represented by the return value is not null-terminated.
storage_type
is
char16_t
.
另請參閱 begin (), end (),和 data ().
[noexcept, since 6.7]
std::u16string_view
QStringView::
operator std::u16string_view
() const
轉換此
QStringView
object to a
std::u16string_view
object. The returned view will have the same data pointer and length of this view.
該函數在 Qt 6.7 引入。
[constexpr]
QChar
QStringView::
operator[]
(
qsizetype
n
) const
返迴字符位於位置 n 在此字符串視圖。
行為未定義若 n is negative or not less than size ().
另請參閱 at (), front (),和 back ().
[noexcept]
bool
operator!=
(const
QStringView
&
lhs
, const
QStringView
&
rhs
)
[noexcept]
bool
operator<
(const
QStringView
&
lhs
, const
QStringView
&
rhs
)
[noexcept]
bool
operator<=
(const
QStringView
&
lhs
, const
QStringView
&
rhs
)
[noexcept]
bool
operator==
(const
QStringView
&
lhs
, const
QStringView
&
rhs
)
[noexcept]
bool
operator>
(const
QStringView
&
lhs
, const
QStringView
&
rhs
)
[noexcept]
bool
operator>=
(const
QStringView
&
lhs
, const
QStringView
&
rhs
)
Operators for comparing lhs to rhs .
另請參閱 compare ().
[noexcept]
size_t
qHash
(
QStringView
key
,
size_t
seed
= 0)
返迴哈希值為 key ,使用 seed 做計算種子。