The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal. 更多...
头: | #include <QLatin1String> |
qmake: | QT += core |
注意: 此类的所有函数 可重入 .
typedef | const_iterator |
typedef | const_reference |
typedef | const_reverse_iterator |
typedef | difference_type |
typedef | iterator |
typedef | reference |
typedef | reverse_iterator |
typedef | size_type |
typedef | value_type |
QLatin1String () | |
QLatin1String (const char * str ) | |
QLatin1String (const char * first , const char * last ) | |
QLatin1String (const char * str , int size ) | |
QLatin1String (const QByteArray & str ) | |
QLatin1Char | at (int pos ) const |
QLatin1Char | back () const |
QLatin1String::const_iterator | begin () const |
QLatin1String::const_iterator | cbegin () const |
QLatin1String::const_iterator | cend () const |
void | chop (int length ) |
QLatin1String | chopped (int length ) const |
QLatin1String::const_reverse_iterator | crbegin () const |
QLatin1String::const_reverse_iterator | crend () const |
const char * | data () const |
QLatin1String::const_iterator | end () const |
bool | endsWith (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
bool | endsWith (QLatin1String l1 , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
bool | endsWith (QChar ch ) const |
bool | endsWith (QChar ch , Qt::CaseSensitivity cs ) const |
QLatin1Char | front () const |
bool | isEmpty () const |
bool | isNull () const |
const char * | latin1 () const |
QLatin1String | left (int length ) const |
QLatin1String | mid (int start ) const |
QLatin1String | mid (int start , int length ) const |
QLatin1String::const_reverse_iterator | rbegin () const |
QLatin1String::const_reverse_iterator | rend () const |
QLatin1String | right (int length ) const |
int | size () const |
bool | startsWith (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
bool | startsWith (QLatin1String l1 , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
bool | startsWith (QChar ch ) const |
bool | startsWith (QChar ch , Qt::CaseSensitivity cs ) const |
QLatin1String | trimmed () const |
void | truncate (int length ) |
bool | operator!= (const QString & other ) const |
bool | operator!= (const char * other ) const |
bool | operator!= (const QByteArray & other ) const |
bool | operator< (const QString & other ) const |
bool | operator< (const char * other ) const |
bool | operator< (const QByteArray & other ) const |
bool | operator<= (const QString & other ) const |
bool | operator<= (const char * other ) const |
bool | operator<= (const QByteArray & other ) const |
bool | operator== (const QString & other ) const |
bool | operator== (const char * other ) const |
bool | operator== (const QByteArray & other ) const |
bool | operator> (const QString & other ) const |
bool | operator> (const char * other ) const |
bool | operator> (const QByteArray & other ) const |
bool | operator>= (const QString & other ) const |
bool | operator>= (const char * other ) const |
bool | operator>= (const QByteArray & other ) const |
QLatin1Char | operator[] (int pos ) const |
bool | operator!= (QLatin1String s1 , QLatin1String s2 ) |
bool | operator< (QLatin1String s1 , QLatin1String s2 ) |
bool | operator<= (QLatin1String s1 , QLatin1String s2 ) |
bool | operator== (QLatin1String s1 , QLatin1String s2 ) |
bool | operator> (QLatin1String s1 , QLatin1String s2 ) |
bool | operator>= (QLatin1String s1 , QLatin1String s2 ) |
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
很多
QString
's member functions are overloaded to accept
const char *
而不是
QString
. This includes the copy constructor, the assignment operator, the comparison operators, and various other functions such as
insert()
,
replace()
,和
indexOf()
. These functions are usually optimized to avoid constructing a
QString
对象为
const char *
data. For example, assuming
str
是
QString
,
if (str == "auto" || str == "extern" || str == "static" || str == "register") { ... }
is much faster than
if (str == QString("auto") || str == QString("extern") || str == QString("static") || str == QString("register")) { ... }
because it doesn't construct four temporary QString objects and make a deep copy of the character data.
Applications that define
QT_NO_CAST_FROM_ASCII
(as explained in the
QString
documentation) don't have access to
QString
's
const char *
API. To provide an efficient way of specifying constant Latin-1 strings, Qt provides the
QLatin1String
, which is just a very thin wrapper around a
const char *
。使用
QLatin1String
, the example code above becomes
if (str == QLatin1String("auto") || str == QLatin1String("extern") || str == QLatin1String("static") || str == QLatin1String("register") { ... }
This is a bit longer to type, but it provides exactly the same benefits as the first version of the code, and is faster than converting the Latin-1 strings using QString::fromLatin1 ().
Thanks to the QString ( QLatin1String ) constructor, QLatin1String can be used everywhere a QString is expected. For example:
QLabel *label = new QLabel(QLatin1String("MOD"), this);
注意: If the function you're calling with a QLatin1String argument isn't actually overloaded to take QLatin1String , the implicit conversion to QString will trigger a memory allocation, which is usually what you want to avoid by using QLatin1String in the first place. In those cases, using QStringLiteral may be the better option.
另请参阅 QString , QLatin1Char , QStringLiteral ,和 QT_NO_CAST_FROM_ASCII .
此 typedef 提供 STL 样式 const 迭代器为 QLatin1String .
该 typedef 在 Qt 5.10 引入。
另请参阅 iterator and const_reverse_iterator .
别名化的
reference
。为兼容 STL (标准模板库) 提供。
该 typedef 在 Qt 5.11 引入。
This typedef provides an STL-style const reverse iterator for QLatin1String .
该 typedef 在 Qt 5.10 引入。
另请参阅 reverse_iterator and const_iterator .
别名化的
int
。为兼容 STL (标准模板库) 提供。
该 typedef 在 Qt 5.10 引入。
此 typedef 提供 STL 样式 const 迭代器为 QLatin1String .
QLatin1String does not support mutable iterators, so this is the same as const_iterator .
该 typedef 在 Qt 5.10 引入。
另请参阅 const_iterator and reverse_iterator .
别名化的
value_type &
。为兼容 STL (标准模板库) 提供。
该 typedef 在 Qt 5.10 引入。
This typedef provides an STL-style const reverse iterator for QLatin1String .
QLatin1String does not support mutable reverse iterators, so this is the same as const_reverse_iterator .
该 typedef 在 Qt 5.10 引入。
另请参阅 const_reverse_iterator and iterator .
别名化的
int
。为兼容 STL (标准模板库) 提供。
该 typedef 在 Qt 5.10 引入。
别名化的
const char
。为兼容 STL (标准模板库) 提供。
该 typedef 在 Qt 5.10 引入。
返回
true
if this Latin-1 string ends with string-view
str
, Latin-1 string
l1
, or character
ch
, respectively; otherwise returns
false
.
若 cs is Qt::CaseSensitive (默认),搜索区分大小写;否则,搜索不区分大小写。
This documentation was introduced in Qt 5.10.
另请参阅 startsWith ().
返回
true
if this Latin-1 string starts with string-view
str
, Latin-1 string
l1
, or character
ch
, respectively; otherwise returns
false
.
若 cs is Qt::CaseSensitive (默认),搜索区分大小写;否则,搜索不区分大小写。
This documentation was introduced in Qt 5.10.
另请参阅 endsWith ().
构造 QLatin1String object that stores a nullptr.
该函数在 Qt 5.6 引入。
构造 QLatin1String object that stores str .
The string data is not copied. The caller must be able to guarantee that str will not be deleted or modified as long as the QLatin1String object exists.
另请参阅 latin1 ().
构造 QLatin1String object that stores first 按长度 ( last - first ).
范围
[first,last)
must remain valid for the lifetime of this Latin-1 string object.
传递
nullptr
as
first
是安全的若
last
is
nullptr
, too, and results in a null Latin-1 string.
行为未定义若
last
precedes
first
,
first
is
nullptr
and
last
is not, or if
last - first > INT_MAX
.
该函数在 Qt 5.10 引入。
构造 QLatin1String object that stores str with size .
The string data is not copied. The caller must be able to guarantee that str will not be deleted or modified as long as the QLatin1String object exists.
另请参阅 latin1 ().
构造 QLatin1String object that stores str .
The string data is not copied. The caller must be able to guarantee that str will not be deleted or modified as long as the QLatin1String object exists.
另请参阅 latin1 ().
返回字符位于位置 pos 在此对象。
注意: This function performs no error checking. The behavior is undefined when pos < 0 or pos >= size ().
该函数在 Qt 5.8 引入。
另请参阅 operator[] ().
返回字符串中的最后一个字符。如同
at(size() - 1)
.
此函数为兼容 STL (标准模板库) 提供。
警告: 在空字符串调用此函数,将构成未定义行为。
该函数在 Qt 5.10 引入。
另请参阅 front (), at (),和 operator[] ().
返回常量 STL 样式迭代器 指向字符串中的首个字符。
此函数为兼容 STL (标准模板库) 提供。
该函数在 Qt 5.10 引入。
另请参阅 end (), cbegin (), rbegin (),和 data ().
如同 begin ().
此函数为兼容 STL (标准模板库) 提供。
该函数在 Qt 5.10 引入。
另请参阅 cend (), begin (), crbegin (),和 data ().
如同 end ().
此函数为兼容 STL (标准模板库) 提供。
该函数在 Qt 5.10 引入。
另请参阅 cbegin (), end (),和 crend ().
Truncates this string by length 字符。
如同
*this = left(size() - length)
.
注意: 行为未定义当 length < 0 or length > size ().
该函数在 Qt 5.10 引入。
另请参阅 mid (), left (), right (), chopped (),和 truncate ().
返回子字符串长度 size () - length 起始于此对象的开头。
如同
left(size() - length)
.
注意: 行为未定义当 length < 0 or length > size ().
该函数在 Qt 5.10 引入。
另请参阅 mid (), left (), right (), chop (),和 truncate ().
如同 rbegin ().
此函数为兼容 STL (标准模板库) 提供。
该函数在 Qt 5.10 引入。
另请参阅 crend (), rbegin (),和 cbegin ().
如同 rend ().
此函数为兼容 STL (标准模板库) 提供。
该函数在 Qt 5.10 引入。
另请参阅 crbegin (), rend (),和 cend ().
Returns the Latin-1 string stored in this object.
返回常量 STL 样式迭代器 pointing to the imaginary character after the last character in the list.
此函数为兼容 STL (标准模板库) 提供。
该函数在 Qt 5.10 引入。
另请参阅 begin (), cend (),和 rend ().
Returns the first character in the string. Same as
at(0)
.
此函数为兼容 STL (标准模板库) 提供。
警告: 在空字符串调用此函数,将构成未定义行为。
该函数在 Qt 5.10 引入。
另请参阅 back (), at (),和 operator[] ().
Returns whether the Latin-1 string stored in this object is empty (
size() == 0
) or not.
该函数在 Qt 5.10 引入。
Returns whether the Latin-1 string stored in this object is null (
data() == nullptr
) or not.
该函数在 Qt 5.10 引入。
Returns the Latin-1 string stored in this object.
返回子字符串长度 length starting at position 0 in this object.
注意: This function performs no error checking. The behavior is undefined when length < 0 or length > size ().
该函数在 Qt 5.8 引入。
另请参阅 mid (), right (), chopped (), chop (),和 truncate ().
Returns the substring starting at position start in this object, and extending to the end of the string.
注意: This function performs no error checking. The behavior is undefined when start < 0 or start > size ().
该函数在 Qt 5.8 引入。
另请参阅 left (), right (), chopped (), chop (),和 truncate ().
这是重载函数。
返回子字符串长度 length 起始于位置 start 在此对象。
注意: This function performs no error checking. The behavior is undefined when start < 0, length < 0, or start + length > size ().
该函数在 Qt 5.8 引入。
另请参阅 left (), right (), chopped (), chop (),和 truncate ().
返回常量 STL-style reverse iterator pointing to the first character in the string, in reverse order.
此函数为兼容 STL (标准模板库) 提供。
该函数在 Qt 5.10 引入。
另请参阅 rend (), crbegin (),和 begin ().
返回 STL-style reverse iterator pointing to one past the last character in the string, in reverse order.
此函数为兼容 STL (标准模板库) 提供。
该函数在 Qt 5.10 引入。
另请参阅 rbegin (), crend (),和 end ().
返回子字符串长度 length 起始于位置 size () - length 在此对象。
注意: This function performs no error checking. The behavior is undefined when length < 0 or length > size ().
该函数在 Qt 5.8 引入。
另请参阅 mid (), left (), chopped (), chop (),和 truncate ().
Returns the size of the Latin-1 string stored in this object.
Strips leading and trailing whitespace and returns the result.
空白意味着任何字符其。
QChar::isSpace
() 返回
true
。这包括 ASCII 字符 \t、\n、\v、\f、\r、及 " "。
该函数在 Qt 5.10 引入。
Truncates this string to length length .
如同
*this = left(length)
.
注意: 行为未定义当 length < 0 or length > size ().
该函数在 Qt 5.10 引入。
另请参阅 mid (), left (), right (), chopped (),和 chop ().
返回
true
if this string is not equal to string
other
;否则返回
false
.
The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare ().
此函数重载 operator!= ().
The other const char pointer is converted to a QString 使用 QString::fromUtf8 () 函数。
可以禁用此运算符通过定义
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
该函数在 Qt 4.3 引入。
另请参阅 QT_NO_CAST_FROM_ASCII .
此函数重载 operator!= ().
The other byte array is converted to a QString 使用 QString::fromUtf8 () 函数。
可以禁用此运算符通过定义
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
该函数在 Qt 5.0 引入。
另请参阅 QT_NO_CAST_FROM_ASCII .
返回
true
if this string is lexically less than the
other
string; otherwise returns
false
.
The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings using the QString::localeAwareCompare () 函数。
这是重载函数。
The other const char pointer is converted to a QString 使用 QString::fromUtf8 () 函数。
可以禁用此运算符通过定义
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
该函数在 Qt 4.3 引入。
另请参阅 QT_NO_CAST_FROM_ASCII .
这是重载函数。
The other const char pointer is converted to a QString 使用 QString::fromUtf8 () 函数。
可以禁用此运算符通过定义
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
该函数在 Qt 5.0 引入。
另请参阅 QT_NO_CAST_FROM_ASCII .
返回
true
if this string is lexically less than or equal to string
other
;否则返回
false
.
The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare ().
这是重载函数。
The other const char pointer is converted to a QString 使用 QString::fromUtf8 () 函数。
可以禁用此运算符通过定义
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
该函数在 Qt 4.3 引入。
另请参阅 QT_NO_CAST_FROM_ASCII .
这是重载函数。
The other array is converted to a QString 使用 QString::fromUtf8 () 函数。
可以禁用此运算符通过定义
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
该函数在 Qt 5.0 引入。
另请参阅 QT_NO_CAST_FROM_ASCII .
返回
true
if this string is equal to string
other
;否则返回
false
.
The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare ().
这是重载函数。
The other const char pointer is converted to a QString 使用 QString::fromUtf8 () 函数。
可以禁用此运算符通过定义
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
该函数在 Qt 4.3 引入。
另请参阅 QT_NO_CAST_FROM_ASCII .
这是重载函数。
The other byte array is converted to a QString 使用 QString::fromUtf8 () 函数。
可以禁用此运算符通过定义
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
该函数在 Qt 5.0 引入。
另请参阅 QT_NO_CAST_FROM_ASCII .
返回
true
if this string is lexically greater than string
other
;否则返回
false
.
The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare ().
这是重载函数。
The other const char pointer is converted to a QString 使用 QString::fromUtf8 () 函数。
可以禁用此运算符通过定义
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
该函数在 Qt 4.3 引入。
另请参阅 QT_NO_CAST_FROM_ASCII .
这是重载函数。
The other const char pointer is converted to a QString 使用 QString::fromUtf8 () 函数。
可以禁用此运算符通过定义
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
该函数在 Qt 5.0 引入。
另请参阅 QT_NO_CAST_FROM_ASCII .
返回
true
if this string is lexically greater than or equal to string
other
;否则返回
false
.
The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare ().
这是重载函数。
The other const char pointer is converted to a QString 使用 QString::fromUtf8 () 函数。
可以禁用此运算符通过定义
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
该函数在 Qt 4.3 引入。
另请参阅 QT_NO_CAST_FROM_ASCII .
这是重载函数。
The other array is converted to a QString 使用 QString::fromUtf8 () 函数。
可以禁用此运算符通过定义
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
该函数在 Qt 5.0 引入。
另请参阅 QT_NO_CAST_FROM_ASCII .
返回字符位于位置 pos 在此对象。
注意: This function performs no error checking. The behavior is undefined when pos < 0 or pos >= size ().
该函数在 Qt 5.8 引入。
另请参阅 at ().
返回
true
若字符串
s1
is lexically unequal to string
s2
;否则返回
false
.
返回
true
若字符串
s1
is lexically smaller than string
s2
;否则返回
false
.
返回
true
若字符串
s1
is lexically smaller than or equal to string
s2
;否则返回
false
.
返回
true
若字符串
s1
is lexically equal to string
s2
;否则返回
false
.
返回
true
若字符串
s1
词法上大于字符串
s2
;否则返回
false
.
返回
true
若字符串
s1
词法上大于等于字符串
s2
;否则返回
false
.