QStringRef 类

The QStringRef class provides a thin wrapper around QString 子字符串。 更多...

头: #include <QStringRef>
qmake: QT += core
Since: Qt 4.3

注意: 此类的所有函数 可重入 .

公共类型

typedef const_iterator
typedef const_reverse_iterator

公共函数

QStringRef ()
QStringRef (const QString * string , int position , int length )
QStringRef (const QString * string )
QStringRef (const QStringRef & other )
QStringRef (QStringRef && other )
~QStringRef ()
QStringRef appendTo (QString * string ) const
const QChar at (int position ) const
const_iterator begin () const
const_iterator cbegin () const
const_iterator cend () const
void chop (int n )
void clear ()
int compare (const QStringRef & other , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int compare (QLatin1String other , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int compare (const QByteArray & other , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int compare (const QString & other , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
const_iterator constBegin () const
const QChar * constData () const
const_iterator constEnd () const
bool contains (const QString & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool contains (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool contains (QLatin1String str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool contains (const QStringRef & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int count () const
int count (const QString & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int count (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int count (const QStringRef & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
const_reverse_iterator crbegin () const
const_reverse_iterator crend () const
const QChar * data () const
const_iterator end () const
bool endsWith (const QString & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool endsWith (QLatin1String str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool endsWith (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool endsWith (const QStringRef & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int indexOf (const QString & str , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int indexOf (QChar ch , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int indexOf (QLatin1String str , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int indexOf (const QStringRef & str , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool isEmpty () const
bool isNull () const
bool isRightToLeft () const
int lastIndexOf (const QString & str , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int lastIndexOf (QChar ch , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int lastIndexOf (QLatin1String str , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int lastIndexOf (const QStringRef & str , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
QStringRef left (int n ) const
int length () const
int localeAwareCompare (const QStringRef & other ) const
int localeAwareCompare (const QString & other ) const
QStringRef mid (int position , int n = -1) const
int position () const
const_reverse_iterator rbegin () const
const_reverse_iterator rend () const
QStringRef right (int n ) const
int size () const
QVector<QStringRef> split (const QString & sep , QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
QVector<QStringRef> split (QChar sep , QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool startsWith (const QString & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool startsWith (QLatin1String str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool startsWith (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool startsWith (const QStringRef & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
const QString * string () const
double toDouble (bool * ok = Q_NULLPTR) const
float toFloat (bool * ok = Q_NULLPTR) const
int toInt (bool * ok = Q_NULLPTR, int base = 10) const
QByteArray toLatin1 () const
QByteArray toLocal8Bit () const
long toLong (bool * ok = Q_NULLPTR, int base = 10) const
qlonglong toLongLong (bool * ok = Q_NULLPTR, int base = 10) const
short toShort (bool * ok = Q_NULLPTR, int base = 10) const
QString toString () const
uint toUInt (bool * ok = Q_NULLPTR, int base = 10) const
ulong toULong (bool * ok = Q_NULLPTR, int base = 10) const
qulonglong toULongLong (bool * ok = Q_NULLPTR, int base = 10) const
ushort toUShort (bool * ok = Q_NULLPTR, int base = 10) const
QVector<uint> toUcs4 () const
QByteArray toUtf8 () const
QStringRef trimmed () const
void truncate (int position )
const QChar * unicode () const
bool operator!= (const char * s ) const
bool operator< (const char * s ) const
bool operator<= (const char * s ) const
QStringRef & operator= (QStringRef && other )
QStringRef & operator= (const QStringRef & other )
QStringRef & operator= (const QString * string )
bool operator== (const char * s ) const
bool operator> (const char * s ) const
bool operator>= (const char * s ) const
QChar operator[] (int position ) const

静态公共成员

int compare (const QStringRef & s1 , const QString & s2 , Qt::CaseSensitivity cs = Qt::CaseSensitive)
int compare (const QStringRef & s1 , const QStringRef & s2 , Qt::CaseSensitivity cs = Qt::CaseSensitive)
int compare (const QStringRef & s1 , QLatin1String s2 , Qt::CaseSensitivity cs = Qt::CaseSensitive)
int localeAwareCompare (const QStringRef & s1 , const QString & s2 )
int localeAwareCompare (const QStringRef & s1 , const QStringRef & s2 )
bool operator< (const QStringRef & s1 , const QStringRef & s2 )
bool operator<= (const QStringRef & s1 , const QStringRef & s2 )
bool operator== (const QStringRef & s1 , const QStringRef & s2 )
bool operator== (const QString & s1 , const QStringRef & s2 )
bool operator== (QLatin1String s1 , const QStringRef & s2 )
bool operator> (const QStringRef & s1 , const QStringRef & s2 )
bool operator>= (const QStringRef & s1 , const QStringRef & s2 )

详细描述

The QStringRef class provides a thin wrapper around QString 子字符串。

QStringRef provides a read-only subset of the QString API.

A string reference explicitly references a portion of a string () with a given size (), starting at a specific position ()。调用 toString () returns a copy of the data as a real QString 实例。

This class is designed to improve the performance of substring handling when manipulating substrings obtained from existing QString 实例。 QStringRef avoids the memory allocation and reference counting overhead of a standard QString by simply referencing a part of the original string. This can prove to be advantageous in low level code, such as that used in a parser, at the expense of potentially more complex code.

For most users, there are no semantic benefits to using QStringRef 而不是 QString since QStringRef requires attention to be paid to memory management issues, potentially making code more complex to write and maintain.

警告: A QStringRef is only valid as long as the referenced string exists. If the original string is deleted, the string reference points to an invalid memory location.

We suggest that you only use this class in stable code where profiling has clearly identified that performance improvements can be made by replacing standard string operations with the optimized substring handling provided by this class.

另请参阅 隐式共享类 .

成员类型文档编制

typedef QStringRef:: const_iterator

此 typedef 提供 STL 样式 const 迭代器为 QStringRef .

该 typedef 在 Qt 5.4 引入。

另请参阅 QStringRef::const_reverse_iterator .

typedef QStringRef:: const_reverse_iterator

This typedef provides an STL-style const reverse iterator for QStringRef .

该 typedef 在 Qt 5.7 引入。

另请参阅 QStringRef::const_iterator .

成员函数文档编制

QStringRef:: QStringRef ()

Constructs an empty string reference.

QStringRef:: QStringRef (const QString * string , int position , int length )

Constructs a string reference to the range of characters in the given string specified by the starting position and length in characters.

警告: This function exists to improve performance as much as possible, and performs no bounds checking. For program correctness, position and length must describe a valid substring of string .

This means that the starting position must be positive or 0 and smaller than string 's length, and length must be positive or 0 but smaller than the string's length minus the starting position ; i.e, 0 <= position < string-> length () and 0 <= length <= string-> length () - position must both be satisfied.

QStringRef:: QStringRef (const QString * string )

Constructs a string reference to the given string .

QStringRef:: QStringRef (const QStringRef & other )

构造副本为 other string reference.

QStringRef:: QStringRef ( QStringRef && other )

移动拷贝构造函数。

QStringRef:: ~QStringRef ()

Destroys the string reference.

Since this class is only used to refer to string data, and does not take ownership of it, no memory is freed when instances are destroyed.

QStringRef QStringRef:: appendTo ( QString * string ) const

Appends the string reference to string , and returns a new reference to the combined string data.

const QChar QStringRef:: at ( int position ) const

返回字符按给定索引 position in the string reference.

The position must be a valid index position in the string (i.e., 0 <= position < size ()).

const_iterator QStringRef:: begin () const

返回常量 STL 样式迭代器 指向字符串中的首个字符。

该函数在 Qt 5.4 引入。

另请参阅 cbegin (), constBegin (), end (), constEnd (), rbegin (),和 rend ().

const_iterator QStringRef:: cbegin () const

如同 begin ().

该函数在 Qt 5.4 引入。

另请参阅 begin (), constBegin (), cend (), constEnd (), rbegin (),和 rend ().

const_iterator QStringRef:: cend () const

如同 end ().

该函数在 Qt 5.4 引入。

另请参阅 end (), constEnd (), cbegin (), constBegin (), rbegin (),和 rend ().

void QStringRef:: chop ( int n )

移除 n 个字符从字符串末尾起。

n >= size (),结果为空字符串;若 n 为负,相当于传递 0。

该函数在 Qt 5.8 引入。

另请参阅 QString::chop () 和 truncate ().

void QStringRef:: clear ()

Clears the contents of the string reference by making it null and empty.

另请参阅 isEmpty () 和 isNull ().

[static] int QStringRef:: compare (const QStringRef & s1 , const QString & s2 , Qt::CaseSensitivity cs = Qt::CaseSensitive)

比较字符串 s1 采用字符串 s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2 .

cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.

该函数在 Qt 4.5 引入。

int QStringRef:: compare (const QStringRef & other , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

这是重载函数。

Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other 字符串。

cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.

相当于 compare(*this, other, cs) .

该函数在 Qt 4.5 引入。

另请参阅 QString::compare ().

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

这是重载函数。

Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other 字符串。

cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.

相当于 compare(*this, other, cs) .

该函数在 Qt 4.5 引入。

另请参阅 QString::compare ().

int QStringRef:: compare (const QByteArray & other , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

这是重载函数。

Compares this string with other and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other byte array, interpreted as a UTF-8 sequence.

cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.

相当于 compare(*this, other, cs) .

该函数在 Qt 5.8 引入。

另请参阅 QString::compare ().

int QStringRef:: compare (const QString & other , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

这是重载函数。

Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other 字符串。

cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.

相当于 compare(*this, other, cs) .

该函数在 Qt 4.5 引入。

另请参阅 QString::compare ().

[static] int QStringRef:: compare (const QStringRef & s1 , const QStringRef & s2 , Qt::CaseSensitivity cs = Qt::CaseSensitive)

这是重载函数。

比较字符串 s1 采用字符串 s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2 .

cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.

该函数在 Qt 4.5 引入。

[static] int QStringRef:: compare (const QStringRef & s1 , QLatin1String s2 , Qt::CaseSensitivity cs = Qt::CaseSensitive)

这是重载函数。

比较字符串 s1 采用字符串 s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2 .

cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.

该函数在 Qt 4.5 引入。

const_iterator QStringRef:: constBegin () const

如同 begin ().

该函数在 Qt 5.9 引入。

另请参阅 begin (), cend (), constEnd (), rbegin (),和 rend ().

const QChar *QStringRef:: constData () const

如同 unicode ().

const_iterator QStringRef:: constEnd () const

如同 end ().

该函数在 Qt 5.9 引入。

另请参阅 end (), cend (), cbegin (), constBegin (), rbegin (),和 rend ().

bool QStringRef:: contains (const QString & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

返回 true if this string reference contains an occurrence of the string str ;否则返回 false .

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

该函数在 Qt 4.8 引入。

另请参阅 indexOf () 和 count ().

bool QStringRef:: contains ( QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 contains ().

返回 true 若此字符串包含出现字符 ch ;否则返回 false .

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

该函数在 Qt 4.8 引入。

bool QStringRef:: contains ( QLatin1String str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 contains ().

返回 true if this string reference contains an occurrence of the string str ;否则返回 false .

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

该函数在 Qt 4.8 引入。

另请参阅 indexOf () 和 count ().

bool QStringRef:: contains (const QStringRef & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 contains ().

返回 true if this string reference contains an occurrence of the string reference str ;否则返回 false .

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

该函数在 Qt 4.8 引入。

另请参阅 indexOf () 和 count ().

int QStringRef:: count () const

Returns the number of characters referred to by the string reference. Equivalent to size () 和 length ().

另请参阅 position () 和 string ().

int QStringRef:: count (const QString & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

返回 (潜在重叠) 出现数对于字符串 str in this string reference.

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

该函数在 Qt 4.8 引入。

另请参阅 QString::count (), contains (),和 indexOf ().

int QStringRef:: count ( QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 count ().

Returns the number of occurrences of the character ch in the string reference.

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

该函数在 Qt 4.8 引入。

另请参阅 QString::count (), contains (),和 indexOf ().

int QStringRef:: count (const QStringRef & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 count ().

Returns the number of (potentially overlapping) occurrences of the string reference str in this string reference.

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

该函数在 Qt 4.8 引入。

另请参阅 QString::count (), contains (),和 indexOf ().

const_reverse_iterator QStringRef:: crbegin () const

如同 rbegin ().

该函数在 Qt 5.7 引入。

另请参阅 begin (), rbegin (),和 rend ().

const_reverse_iterator QStringRef:: crend () const

如同 rend ().

该函数在 Qt 5.7 引入。

另请参阅 end (), rend (),和 rbegin ().

const QChar *QStringRef:: data () const

如同 unicode ().

const_iterator QStringRef:: end () const

返回常量 STL 样式迭代器 pointing to the imaginary character after the last character in the list.

该函数在 Qt 5.4 引入。

另请参阅 cbegin (), constBegin (), end(), constEnd (), rbegin (),和 rend ().

bool QStringRef:: endsWith (const QString & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

返回 true if the string reference ends with str ;否则返回 false .

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

该函数在 Qt 4.8 引入。

另请参阅 QString::endsWith () 和 startsWith ().

bool QStringRef:: endsWith ( QLatin1String str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 endsWith ().

该函数在 Qt 4.8 引入。

另请参阅 QString::endsWith () 和 endsWith ().

bool QStringRef:: endsWith ( QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 endsWith ().

返回 true if the string reference ends with ch ;否则返回 false .

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

该函数在 Qt 4.8 引入。

另请参阅 QString::endsWith () 和 endsWith ().

bool QStringRef:: endsWith (const QStringRef & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 endsWith ().

该函数在 Qt 4.8 引入。

另请参阅 QString::endsWith () 和 endsWith ().

int QStringRef:: indexOf (const QString & str , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

Returns the index position of the first occurrence of the string str in this string reference, searching forward from index position from . Returns -1 if str 找不到。

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

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

该函数在 Qt 4.8 引入。

另请参阅 QString::indexOf (), lastIndexOf (), contains (),和 count ().

int QStringRef:: indexOf ( QChar ch , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 indexOf ().

Returns the index position of the first occurrence of the character ch in the string reference, searching forward from index position from . Returns -1 if ch could not be found.

该函数在 Qt 4.8 引入。

另请参阅 QString::indexOf (), lastIndexOf (), contains (),和 count ().

int QStringRef:: indexOf ( QLatin1String str , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

Returns the index position of the first occurrence of the string str in this string reference, searching forward from index position from . Returns -1 if str 找不到。

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

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

该函数在 Qt 4.8 引入。

另请参阅 QString::indexOf (), lastIndexOf (), contains (),和 count ().

int QStringRef:: indexOf (const QStringRef & str , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 indexOf ().

Returns the index position of the first occurrence of the string reference str in this string reference, searching forward from index position from . Returns -1 if str 找不到。

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

该函数在 Qt 4.8 引入。

另请参阅 QString::indexOf (), lastIndexOf (), contains (),和 count ().

bool QStringRef:: isEmpty () const

返回 true if the string reference has no characters; otherwise returns false .

A string reference is empty if its size is zero.

另请参阅 size ().

bool QStringRef:: isNull () const

返回 true if string () returns a null pointer or a pointer to a null string; otherwise returns true .

另请参阅 size ().

bool QStringRef:: isRightToLeft () const

返回 true if the string is read right to left.

该函数在 Qt 5.9 引入。

另请参阅 QString::isRightToLeft ().

int QStringRef:: lastIndexOf (const QString & str , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

Returns the index position of the last occurrence of the string str in this string reference, searching backward from index position from 。若 from is -1 (default), the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if str 找不到。

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

该函数在 Qt 4.8 引入。

另请参阅 QString::lastIndexOf (), indexOf (), contains (),和 count ().

int QStringRef:: lastIndexOf ( QChar ch , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 lastIndexOf ().

Returns the index position of the last occurrence of the character ch , searching backward from position from .

该函数在 Qt 4.8 引入。

另请参阅 QString::lastIndexOf (), indexOf (), contains (),和 count ().

int QStringRef:: lastIndexOf ( QLatin1String str , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 lastIndexOf ().

Returns the index position of the last occurrence of the string str in this string reference, searching backward from index position from 。若 from is -1 (default), the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if str 找不到。

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

该函数在 Qt 4.8 引入。

另请参阅 QString::lastIndexOf (), indexOf (), contains (),和 count ().

int QStringRef:: lastIndexOf (const QStringRef & str , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 lastIndexOf ().

Returns the index position of the last occurrence of the string reference str in this string reference, searching backward from index position from 。若 from is -1 (default), the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if str 找不到。

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

该函数在 Qt 4.8 引入。

另请参阅 QString::lastIndexOf (), indexOf (), contains (),和 count ().

QStringRef QStringRef:: left ( int n ) const

Returns a substring reference to the n leftmost characters of the string.

n >= size (), or less than zero, a reference to the entire string is returned.

该函数在 Qt 5.2 引入。

另请参阅 right (), mid (),和 startsWith ().

int QStringRef:: length () const

Returns the number of characters referred to by the string reference. Equivalent to size () 和 count ().

另请参阅 position () 和 string ().

[static] int QStringRef:: localeAwareCompare (const QStringRef & s1 , const QString & s2 )

比较 s1 with s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2 .

The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.

On macOS and iOS, this function compares according the "Order for sorted lists" setting in the International prefereces panel.

该函数在 Qt 4.5 引入。

另请参阅 compare () 和 QLocale .

int QStringRef:: localeAwareCompare (const QStringRef & other ) const

这是重载函数。

Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other 字符串。

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 4.5 引入。

int QStringRef:: localeAwareCompare (const QString & other ) const

这是重载函数。

Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other 字符串。

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 4.5 引入。

[static] int QStringRef:: localeAwareCompare (const QStringRef & s1 , const QStringRef & s2 )

这是重载函数。

比较 s1 with s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2 .

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 4.5 引入。

QStringRef QStringRef:: mid ( int position , int n = -1) const

Returns a substring reference to n 个字符对于此字符串,起始于指定 position .

position exceeds the length of the string, a null reference is returned.

If there are less than n characters available in the string, starting at the given position ,或者若 n is -1 (default), the function returns all characters from the specified position onwards.

该函数在 Qt 5.2 引入。

另请参阅 left () 和 right ().

int QStringRef:: position () const

Returns the starting position in the referenced string that is referred to by the string reference.

另请参阅 size () 和 string ().

const_reverse_iterator QStringRef:: rbegin () const

返回常量 STL-style reverse iterator pointing to the first character in the string, in reverse order.

该函数在 Qt 5.7 引入。

另请参阅 begin (), crbegin (),和 rend ().

const_reverse_iterator QStringRef:: rend () const

返回 STL-style reverse iterator pointing to one past the last character in the string, in reverse order.

该函数在 Qt 5.7 引入。

另请参阅 end (), crend (),和 rbegin ().

Returns a substring reference to the n rightmost characters of the string.

n >= size (), or less than zero, a reference to the entire string is returned.

该函数在 Qt 5.2 引入。

另请参阅 left (), mid (),和 endsWith ().

int QStringRef:: size () const

Returns the number of characters referred to by the string reference. Equivalent to length () 和 count ().

另请参阅 position () 和 string ().

QVector < QStringRef > QStringRef:: split (const QString & sep , QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

Splits the string into substrings references wherever sep occurs, and returns the list of those strings.

QString::split () for how sep , behavior and cs interact to form the result.

注意: All references are valid as long this string is alive. Destroying this string will cause all references be dangling pointers.

该函数在 Qt 5.4 引入。

QVector < QStringRef > QStringRef:: split ( QChar sep , QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

这是重载函数。

该函数在 Qt 5.4 引入。

bool QStringRef:: startsWith (const QString & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

返回 true if the string reference starts with str ;否则返回 false .

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

该函数在 Qt 4.8 引入。

另请参阅 QString::startsWith () 和 endsWith ().

bool QStringRef:: startsWith ( QLatin1String str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 startsWith ().

该函数在 Qt 4.8 引入。

另请参阅 QString::startsWith () 和 endsWith ().

bool QStringRef:: startsWith ( QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 startsWith ().

返回 true if the string reference starts with ch ;否则返回 false .

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

该函数在 Qt 4.8 引入。

另请参阅 QString::startsWith () 和 endsWith ().

bool QStringRef:: startsWith (const QStringRef & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

此函数重载 startsWith ().

该函数在 Qt 4.8 引入。

另请参阅 QString::startsWith () 和 endsWith ().

const QString *QStringRef:: string () const

Returns a pointer to the string referred to by the string reference, or 0 if it does not reference a string.

另请参阅 unicode ().

double QStringRef:: toDouble ( bool * ok = Q_NULLPTR) const

Returns the string converted to a double 值。

Returns 0.0 if the conversion fails.

If a conversion error occurs, * ok 被设为 false ;否则 * ok 被设为 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 5.1 引入。

另请参阅 QString::toDouble ().

float QStringRef:: toFloat ( bool * ok = Q_NULLPTR) const

Returns the string converted to a float 值。

If a conversion error occurs, * ok 被设为 false ; otherwise * ok 被设为 true . Returns 0.0 if the conversion fails.

The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toFloat ()

该函数在 Qt 5.1 引入。

另请参阅 QString::toFloat ().

int QStringRef:: toInt ( bool * ok = Q_NULLPTR, int base = 10) const

Returns the string 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.

If a conversion error occurs, * ok 被设为 false ; otherwise * ok 被设为 true .

base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string 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 5.1 引入。

另请参阅 QString::toInt ().

QByteArray QStringRef:: toLatin1 () const

Returns a Latin-1 representation of the string as a QByteArray .

The returned byte array is undefined if the string contains non-Latin1 characters. Those characters may be suppressed or replaced with a question mark.

该函数在 Qt 4.8 引入。

另请参阅 toUtf8 (), toLocal8Bit (),和 QTextCodec .

QByteArray QStringRef:: toLocal8Bit () const

Returns the local 8-bit representation of the string as a QByteArray . The returned byte array is undefined if the string contains characters not supported by the local 8-bit encoding.

QTextCodec::codecForLocale () is used to perform the conversion from Unicode. If the locale encoding could not be determined, this function does the same as toLatin1 ().

If this string contains any characters that cannot be encoded in the locale, the returned byte array is undefined. Those characters may be suppressed or replaced by another.

该函数在 Qt 4.8 引入。

另请参阅 toLatin1 (), toUtf8 (),和 QTextCodec .

long QStringRef:: toLong ( bool * ok = Q_NULLPTR, int base = 10) const

Returns the string 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.

If a conversion error occurs, * ok 被设为 false ; otherwise * ok 被设为 true .

base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string 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 5.1 引入。

另请参阅 QString::toLong ().

qlonglong QStringRef:: toLongLong ( bool * ok = Q_NULLPTR, int base = 10) const

Returns the string 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.

If a conversion error occurs, * ok 被设为 false ; otherwise * ok 被设为 true .

base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string 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 5.1 引入。

另请参阅 QString::toLongLong ().

short QStringRef:: toShort ( bool * ok = Q_NULLPTR, int base = 10) const

Returns the string 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.

If a conversion error occurs, * ok 被设为 false ; otherwise * ok 被设为 true .

base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string 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 5.1 引入。

另请参阅 QString::toShort ().

QString QStringRef:: toString () const

Returns a copy of the string reference as a QString 对象。

If the string reference is not a complete reference of the string (meaning that position () is 0 and size () 等于 string ()-> size ()), this function will allocate a new string to return.

另请参阅 string ().

uint QStringRef:: toUInt ( bool * ok = Q_NULLPTR, int base = 10) const

Returns the string 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.

If a conversion error occurs, * ok 被设为 false ; otherwise * ok 被设为 true .

base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string 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 5.1 引入。

另请参阅 QString::toUInt ().

ulong QStringRef:: toULong ( bool * ok = Q_NULLPTR, int base = 10) const

Returns the string 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.

If a conversion error occurs, * ok 被设为 false ; otherwise * ok 被设为 true .

base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string 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 5.1 引入。

另请参阅 QString::toULong ().

qulonglong QStringRef:: toULongLong ( bool * ok = Q_NULLPTR, int base = 10) const

Returns the string 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.

If a conversion error occurs, * ok 被设为 false ; otherwise * ok 被设为 true .

base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string 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 5.1 引入。

另请参阅 QString::toULongLong ().

ushort QStringRef:: toUShort ( bool * ok = Q_NULLPTR, int base = 10) const

Returns the string 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.

If a conversion error occurs, * ok 被设为 false ; otherwise * ok 被设为 true .

base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string 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 5.1 引入。

另请参阅 QString::toUShort ().

QVector < uint > QStringRef:: 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's replacement character ( QChar::ReplacementCharacter , which corresponds to U+FFFD ).

The returned vector is not NUL terminated.

该函数在 Qt 4.8 引入。

另请参阅 toUtf8 (), toLatin1 (), toLocal8Bit (),和 QTextCodec .

QByteArray QStringRef:: 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 .

该函数在 Qt 4.8 引入。

另请参阅 toLatin1 (), toLocal8Bit (),和 QTextCodec .

QStringRef QStringRef:: trimmed () const

返回从开始到结束之间,已移除空白的字符串。

空白意味着任何字符其。 QChar::isSpace () 返回 true 。这包括 ASCII 字符 \t、\n、\v、\f、\r、及 " "。

不像 QString::simplified (),trimmed() 只留下内部空白。

该函数在 Qt 5.1 引入。

另请参阅 QString::trimmed ().

void QStringRef:: truncate ( int position )

截取字符串按给定 position 索引。

若指定 position 索引超出字符串末尾,什么都不发生。

position 为负,相当于传递 0。

该函数在 Qt 5.6 引入。

另请参阅 QString::truncate ().

const QChar *QStringRef:: unicode () const

Returns a Unicode representation of the string reference. Since the data stems directly from the referenced string, it is not null-terminated unless the string reference includes the string's null terminator.

另请参阅 string ().

bool QStringRef:: operator!= (const char * s ) const

This function overloads operator!=().

The s const char pointer is converted to a QStringRef using the fromUtf8() function.

可以禁用此运算符通过定义 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.

返回 true if this string is not lexically equal to the parameter string s . Otherwise returns false .

bool QStringRef:: operator< (const char * s ) const

This function overloads operator<().

The s const char pointer is converted to a QStringRef using the fromUtf8() function.

可以禁用此运算符通过定义 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.

返回 true if this string is lexically smaller than the parameter string s . Otherwise returns false .

bool QStringRef:: operator<= (const char * s ) const

This function overloads operator<=().

The s const char pointer is converted to a QStringRef using the fromUtf8() function.

可以禁用此运算符通过定义 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.

返回 true if this string is lexically smaller than or equal to the parameter string s . Otherwise returns false .

QStringRef &QStringRef:: operator= ( QStringRef && other )

移动赋值运算符。

QStringRef &QStringRef:: operator= (const QStringRef & other )

赋值 other string reference to this string reference, and returns the result.

QStringRef &QStringRef:: operator= (const QString * string )

Constructs a string reference to the given string and assigns it to this string reference, returning the result.

bool QStringRef:: operator== (const char * s ) const

This function overloads operator==().

The s byte array is converted to a QStringRef using the fromUtf8() function. This function stops conversion at the first NUL character found, or the end of the byte array.

可以禁用此运算符通过定义 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.

返回 true if this string is lexically equal to the parameter string s . Otherwise returns false .

bool QStringRef:: operator> (const char * s ) const

This function overloads operator>().

The s const char pointer is converted to a QStringRef using the fromUtf8() function.

可以禁用此运算符通过定义 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.

返回 true if this string is lexically greater than the parameter string s . Otherwise returns false .

bool QStringRef:: operator>= (const char * s ) const

此函数重载运算符 >=()。

The s const char pointer is converted to a QStringRef using the fromUtf8() function.

可以禁用此运算符通过定义 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.

返回 true if this string is lexically greater than or equal to the parameter string s . Otherwise returns false .

QChar QStringRef:: operator[] ( int position ) const

返回字符按给定索引 position in the string reference.

The position must be a valid index position in the string reference (i.e., 0 <= position < size ()).

该函数在 Qt 5.7 引入。

另请参阅 at ().

相关非成员

bool operator< (const QStringRef & s1 , const QStringRef & s2 )

返回 true if string reference s1 is lexically less than string reference s2 ;否则返回 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 () 函数。

bool operator<= (const QStringRef & s1 , const QStringRef & s2 )

返回 true if string reference s1 is lexically less than or equal to string reference s2 ;否则返回 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 () 函数。

bool operator== (const QStringRef & s1 , const QStringRef & s2 )

返回 true if string reference s1 is lexically equal to string reference s2 ;否则返回 false .

bool operator== (const QString & s1 , const QStringRef & s2 )

返回 true 若字符串 s1 is lexically equal to string reference s2 ;否则返回 false .

bool operator== ( QLatin1String s1 , const QStringRef & s2 )

返回 true 若字符串 s1 is lexically equal to string reference s2 ;否则返回 false .

bool operator> (const QStringRef & s1 , const QStringRef & s2 )

返回 true if string reference s1 is lexically greater than string reference s2 ;否则返回 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 () 函数。

bool operator>= (const QStringRef & s1 , const QStringRef & s2 )

返回 true if string reference s1 is lexically greater than or equal to string reference s2 ;否则返回 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 () 函数。