QStringRef Class Reference

[QtCore module]

该QStringRef类提供了简单包装的QString子。More…

Methods

  • __init__ (self)
  • __init__ (self, QString aString, int aPosition, int aSize)
  • __init__ (self, QString aString)
  • __init__ (self, QStringRef other)
  • QStringRef appendTo (self, QString string)
  • QChar at (self, int i)
  • clear (self)
  • int compare (self, QString other, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int compare (self, QStringRef other, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int compare (self, QLatin1String other, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • QChar constData (self)
  • bool contains (self, QString str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • bool contains (self, QLatin1String str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • bool contains (self, QStringRef str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int count (self)
  • int count (self, QString str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int count (self, QStringRef str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • QChar data (self)
  • bool endsWith (self, QString str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • bool endsWith (self, QLatin1String str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • bool endsWith (self, QStringRef str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int indexOf (self, QString str, int from = 0, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int indexOf (self, QLatin1String str, int from = 0, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int indexOf (self, QStringRef str, int from = 0, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • bool isEmpty (self)
  • bool isNull (self)
  • int lastIndexOf (self, QString str, int from = -1, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int lastIndexOf (self, QLatin1String str, int from = -1, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int lastIndexOf (self, QStringRef str, int from = -1, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int length (self)
  • int localeAwareCompare (self, QString s)
  • int localeAwareCompare (self, QStringRef s)
  • int position (self)
  • int size (self)
  • bool startsWith (self, QString str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • bool startsWith (self, QLatin1String str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • bool startsWith (self, QStringRef str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • QString string (self)
  • QByteArray toAscii (self)
  • QByteArray toLatin1 (self)
  • QByteArray toLocal8Bit (self)
  • QString toString (self)
  • list-of-int toUcs4 (self)
  • QByteArray toUtf8 (self)
  • QChar unicode (self)

Static Methods

  • int compare (QStringRef s1, QString s2, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int compare (QStringRef s1, QStringRef s2, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int compare (QStringRef s1, QLatin1String s2, Qt.CaseSensitivity cs = Qt.CaseSensitive)
  • int localeAwareCompare (QStringRef s1, QString s2)
  • int localeAwareCompare (QStringRef s1, QStringRef s2)

Special Methods

  • bool __eq__ (self, QStringRef s2)
  • bool __eq__ (self, QString s2)
  • bool __eq__ (self, QLatin1String s2)
  • bool __ge__ (self, QStringRef s2)
  • bool __gt__ (self, QStringRef s2)
  • bool __le__ (self, QStringRef s2)
  • __len__ (self)
  • bool __lt__ (self, QStringRef s2)
  • bool __ne__ (self, QStringRef s2)
  • bool __ne__ (self, QString s2)
  • bool __ne__ (self, QLatin1String s2)
  • str __str__ (self)
  • unicode __unicode__ (self)

Detailed Description

该QStringRef类提供了简单包装的QString子。

QStringRef提供的一个只读子集QStringAPI。

一个字符串引用明确引用的一部分string()与给定的size() ,起始于一个特定的position( ) 。调用toString()返回的数据的一个副本作为一个真正的QString实例。

本课程的目的是操纵现有获得字符串时,提高子处理性能QString实例。 QStringRef避免了一个标准的内存分配和引用计数的开销QString通过简单地引用原字符串的一部分。这可以证明是有利的,低级别的代码,例如,在一个解析器使用,在潜在的更复杂的代码的费用。

对于大多数用户来说,也有使用QStringRef ,而不是没有任何语义的好处QString因为QStringRef需要注意支付给内存管理问题,可能使代码更复杂的编写和维护。

Warning:一个QStringRef是唯一有效的,只要所引用的字符串存在。如果原始字符串将被删除,该字符串引用指向无效的内存位置。

我们建议您仅在稳定的代码,其中分析已经清楚地确定了性能的提升可以通过这个类提供了优化的子字符串处理来替代标准的字符串操作进行使用这个类。


Method Documentation

  1. QStringRef.__init__ (self)

构造一个空字符串引用。

  1. QStringRef.__init__ (self, QString aString, int aPosition, int aSize)

构造一个字符串引用的字符范围在给定的string由起始指定positionlength在字符。

Warning:此功能的存在是为了提高性能,尽可能地,并且不执行边界检查。对于程序的正确性,positionlength必须描述一个有效的子串string

这意味着它们的起始position必须为正或0和小于string的长度,length必须是正数或0 ,但比字符串的长度减去较小的起点position,即, 0 \u003c =位置\u003c字符串\u003elength( )且0 \u003c =长度\u003c =字符串\u003elength( ) - 位置必须同时满足。

  1. QStringRef.__init__ (self, QString aString)

构造一个字符串引用给定的string

  1. QStringRef.__init__ (self, QStringRef other)

构造的一个副本other字符串引用。

  1. QStringRef QStringRef.appendTo (self, QString string)

追加字符串引用string,并返回一个新的参考组合的字符串数据。

  1. QChar QStringRef.at (self, int i)

返回字符的给定索引处position在字符串引用。

position必须是在字符串中的有效索引位置(即0 \u003c =position\u003csize())。

  1. QStringRef.clear (self)

通过使空和空清除的字符串引用的内容。

See also isEmpty()和isNull( ) 。

  1. int QStringRef.compare (self, QString other, Qt.CaseSensitivity cs = Qt.CaseSensitive)

比较字符串s1与串s2并返回一个整数大于零小于,等于,或大于,如果s1小于,等于或大于s2

If cs is Qt.CaseSensitive,比较是区分大小写的,否则比较不区分大小写。

此功能被引入Qt的4.5 。

  1. int QStringRef.compare (self, QStringRef other, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这是一个重载函数。

比较字符串s1与串s2并返回一个整数大于零小于,等于,或大于,如果s1小于,等于或大于s2

If cs is Qt.CaseSensitive,比较是区分大小写的,否则比较不区分大小写。

此功能被引入Qt的4.5 。

  1. int QStringRef.compare (self, QLatin1String other, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这是一个重载函数。

比较字符串s1与串s2并返回一个整数大于零小于,等于,或大于,如果s1小于,等于或大于s2

If cs is Qt.CaseSensitive,比较是区分大小写的,否则比较不区分大小写。

此功能被引入Qt的4.5 。

  1. int QStringRef.compare (QStringRef s1, QString s2, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这是一个重载函数。

比较此字符串与other字符串并返回比,等于大于零的整数更少,或更大,如果该字符串比小于,等于,或大于other字符串。

If cs is Qt.CaseSensitive,比较是区分大小写的,否则比较不区分大小写。

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

此功能被引入Qt的4.5 。

See also QString.compare( ) 。

  1. int QStringRef.compare (QStringRef s1, QStringRef s2, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这是一个重载函数。

比较此字符串与other字符串并返回比,等于大于零的整数更少,或更大,如果该字符串比小于,等于,或大于other字符串。

If cs is Qt.CaseSensitive,比较是区分大小写的,否则比较不区分大小写。

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

此功能被引入Qt的4.5 。

See also QString.compare( ) 。

  1. int QStringRef.compare (QStringRef s1, QLatin1String s2, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这是一个重载函数。

比较此字符串与other字符串并返回比,等于大于零的整数更少,或更大,如果该字符串比小于,等于,或大于other字符串。

If cs is Qt.CaseSensitive,比较是区分大小写的,否则比较不区分大小写。

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

此功能被引入Qt的4.5 。

See also QString.compare( ) 。

  1. QChar QStringRef.constData (self)

unicode( ) 。

  1. bool QStringRef.contains (self, QString str, Qt.CaseSensitivity cs = Qt.CaseSensitive)

如果这个字符串引用包含字符串的出现,则返回Truestr否则返回False 。

If cs is Qt.CaseSensitive(默认) ,搜索是区分大小写的,否则搜索不区分大小写。

此功能被引入Qt的4.8 。

See also indexOf()和count( ) 。

  1. bool QStringRef.contains (self, QLatin1String str, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这个函数的重载contains( ) 。

如果这个字符串包含的字符的出现,则返回Truech否则返回False 。

If cs is Qt.CaseSensitive(默认) ,搜索是区分大小写的,否则搜索不区分大小写。

此功能被引入Qt的4.8 。

  1. bool QStringRef.contains (self, QStringRef str, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这个函数的重载contains( ) 。

如果此字符串包含引用的字符串引用的出现,则返回Truestr否则返回False 。

If cs is Qt.CaseSensitive(默认) ,搜索是区分大小写的,否则搜索不区分大小写。

此功能被引入Qt的4.8 。

See also indexOf()和count( ) 。

  1. int QStringRef.count (self)

返回由字符串引用所指的字符数。相当于size()和length( ) 。

See also position()和string( ) 。

  1. int QStringRef.count (self, QString str, Qt.CaseSensitivity cs = Qt.CaseSensitive)

返回(可能重叠)字符串的出现次数str在此字符串中引用。

If cs is Qt.CaseSensitive(默认) ,搜索是区分大小写的,否则搜索不区分大小写。

此功能被引入Qt的4.8 。

See also QString.count( )contains()和indexOf( ) 。

  1. int QStringRef.count (self, QStringRef str, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这个函数的重载count( ) 。

返回出现的字符数量ch在字符串引用。

If cs is Qt.CaseSensitive(默认) ,搜索是区分大小写的,否则搜索不区分大小写。

此功能被引入Qt的4.8 。

See also QString.count( )contains()和indexOf( ) 。

  1. QChar QStringRef.data (self)

unicode( ) 。

  1. bool QStringRef.endsWith (self, QString str, Qt.CaseSensitivity cs = Qt.CaseSensitive)

如果字符串参考结尾,则返回Truestr否则返回False 。

If cs is Qt.CaseSensitive(默认) ,搜索是区分大小写的,否则搜索不区分大小写。

此功能被引入Qt的4.8 。

See also QString.endsWith()和startsWith( ) 。

  1. bool QStringRef.endsWith (self, QLatin1String str, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这个函数的重载endsWith( ) 。

如果字符串参考结尾,则返回Truech否则返回False 。

If cs is Qt.CaseSensitive(默认) ,搜索是区分大小写的,否则搜索不区分大小写。

此功能被引入Qt的4.8 。

See also QString.endsWith()和endsWith( ) 。

  1. bool QStringRef.endsWith (self, QStringRef str, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这个函数的重载endsWith( ) 。

此功能被引入Qt的4.8 。

See also QString.endsWith()和endsWith( ) 。

  1. int QStringRef.indexOf (self, QString str, int from = 0, Qt.CaseSensitivity cs = Qt.CaseSensitive)

返回字符串中第一次出现的索引位置str在这个字符串引用,向前搜索的索引位置from。返回-1,如果str是没有找到。

If cs is Qt.CaseSensitive(默认) ,搜索是区分大小写的,否则搜索不区分大小写。

If from为-1,搜索从最后一个字符,如果是-2 ,在倒数第二个字符等等。

此功能被引入Qt的4.8 。

See also QString.indexOf( )lastIndexOf( )contains()和count( ) 。

  1. int QStringRef.indexOf (self, QLatin1String str, int from = 0, Qt.CaseSensitivity cs = Qt.CaseSensitive)

返回字符串中第一次出现的索引位置str在这个字符串引用,向前搜索的索引位置from。返回-1,如果str是没有找到。

If cs is Qt.CaseSensitive(默认) ,搜索是区分大小写的,否则搜索不区分大小写。

If from为-1,搜索从最后一个字符,如果是-2 ,在倒数第二个字符等等。

此功能被引入Qt的4.8 。

See also QString.indexOf( )lastIndexOf( )contains()和count( ) 。

  1. int QStringRef.indexOf (self, QStringRef str, int from = 0, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这个函数的重载indexOf( ) 。

返回字符的第一个匹配项的索引位置ch在字符串参考,向前搜索的索引位置from。返回-1,如果ch找不到。

此功能被引入Qt的4.8 。

See also QString.indexOf( )lastIndexOf( )contains()和count( ) 。

  1. bool QStringRef.isEmpty (self)

返回True如果字符串引用没有字符,否则返回False 。

一个字符串引用是空的,如果它的大小是零。

See also size( ) 。

  1. bool QStringRef.isNull (self)

返回True如果string( )返回一个空指针或指向一个空字符串,否则返回True。

See also size( ) 。

  1. int QStringRef.lastIndexOf (self, QString str, int from = -1, Qt.CaseSensitivity cs = Qt.CaseSensitive)

返回字符串中最后一次出现的索引位置str在这个字符串引用,从索引位置向后搜索from。如果from为-1 (默认),搜索从最后一个字符,如果from为-2 ,在倒数第二个字符等等。返回-1,如果str是没有找到。

If cs is Qt.CaseSensitive(默认) ,搜索是区分大小写的,否则搜索不区分大小写。

此功能被引入Qt的4.8 。

See also QString.lastIndexOf( )indexOf( )contains()和count( ) 。

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

这个函数的重载lastIndexOf( ) 。

返回字符的最后一个匹配项的索引位置ch从位置向后搜索from

此功能被引入Qt的4.8 。

See also QString.lastIndexOf( )indexOf( )contains()和count( ) 。

  1. int QStringRef.lastIndexOf (self, QStringRef str, int from = -1, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这个函数的重载lastIndexOf( ) 。

返回字符串中最后一次出现的索引位置str在这个字符串引用,从索引位置向后搜索from。如果from为-1 (默认),搜索从最后一个字符,如果from为-2 ,在倒数第二个字符等等。返回-1,如果str是没有找到。

If cs is Qt.CaseSensitive(默认) ,搜索是区分大小写的,否则搜索不区分大小写。

此功能被引入Qt的4.8 。

See also QString.lastIndexOf( )indexOf( )contains()和count( ) 。

  1. int QStringRef.length (self)

返回由字符串引用所指的字符数。相当于size()和count( ) 。

See also position()和string( ) 。

  1. int QStringRef.localeAwareCompare (self, QString s)

比较s1s2并返回一个整数大于零小于,等于,或大于,如果s1小于,等于或大于s2

比较是在一个语言环境,也依赖于平台的方式进行。使用此功能可呈现字符串排序的列表给用户。

在Mac OS X ,此功能根据“订单的排序列表”,在国际prefereces面板设置进行比较。

此功能被引入Qt的4.5 。

See also compare()和QTextCodec.locale( ) 。

  1. int QStringRef.localeAwareCompare (self, QStringRef s)

这是一个重载函数。

比较s1s2并返回一个整数大于零小于,等于,或大于,如果s1小于,等于或大于s2

比较是在一个语言环境,也依赖于平台的方式进行。使用此功能可呈现字符串排序的列表给用户。

此功能被引入Qt的4.5 。

  1. int QStringRef.localeAwareCompare (QStringRef s1, QString s2)

这是一个重载函数。

比较此字符串与other字符串并返回比,等于大于零的整数更少,或更大,如果该字符串比小于,等于,或大于other字符串。

比较是在一个语言环境,也依赖于平台的方式进行。使用此功能可呈现字符串排序的列表给用户。

此功能被引入Qt的4.5 。

  1. int QStringRef.localeAwareCompare (QStringRef s1, QStringRef s2)

这是一个重载函数。

比较此字符串与other字符串并返回比,等于大于零的整数更少,或更大,如果该字符串比小于,等于,或大于other字符串。

比较是在一个语言环境,也依赖于平台的方式进行。使用此功能可呈现字符串排序的列表给用户。

此功能被引入Qt的4.5 。

  1. int QStringRef.position (self)

返回由字符串引用所引用的参考的字符串的开始位置。

See also size()和string( ) 。

  1. int QStringRef.size (self)

返回由字符串引用所指的字符数。相当于length()和count( ) 。

See also position()和string( ) 。

  1. bool QStringRef.startsWith (self, QString str, Qt.CaseSensitivity cs = Qt.CaseSensitive)

如果字符串引用开头,则返回Truestr否则返回False 。

If cs is Qt.CaseSensitive(默认) ,搜索是区分大小写的,否则搜索不区分大小写。

此功能被引入Qt的4.8 。

See also QString.startsWith()和endsWith( ) 。

  1. bool QStringRef.startsWith (self, QLatin1String str, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这个函数的重载startsWith( ) 。

此功能被引入Qt的4.8 。

See also QString.startsWith()和endsWith( ) 。

  1. bool QStringRef.startsWith (self, QStringRef str, Qt.CaseSensitivity cs = Qt.CaseSensitive)

这个函数的重载startsWith( ) 。

此功能被引入Qt的4.8 。

See also QString.startsWith()和endsWith( ) 。

  1. QString QStringRef.string (self)

返回一个指向由字符串引用,或0称为如果它不引用的字符串的字符串。

See also unicode( ) 。

  1. QByteArray QStringRef.toAscii (self)

返回字符串的8位表示为QByteArray

如果一个编解码器已使用设置QTextCodec.setCodecForCStrings( ) ,它是用来为Unicode转换为8位字符,否则这个函数一样toLatin1( ) 。

需要注意的是,尽管这个名字,这个功能并不一定返回一个US-ASCII ( ANSI X3.4 - 1986)的字符串,其结果可能不是US-ASCII兼容。

此功能被引入Qt的4.8 。

See also toLatin1( )toUtf8( )toLocal8Bit()和QTextCodec

  1. QByteArray QStringRef.toLatin1 (self)

返回字符串的的Latin-1表示为QByteArray

返回的字节数组是不确定的,如果字符串包含非拉丁文字符。这些字符可以被抑制或问号代替。

此功能被引入Qt的4.8 。

See also toAscii( )toUtf8( )toLocal8Bit()和QTextCodec

  1. QByteArray QStringRef.toLocal8Bit (self)

返回字符串作为当地8位表示QByteArray。返回的字节数组是不确定的,如果该字符串包含不支持的本地8位编码的字符。

QTextCodec.codecForLocale( )是用来从Unicode执行转换。如果本地编码不能确定,这个函数一样toLatin1( ) 。

如果这个字符串包含不能在语言环境进行编码的任何字符,返回的字节数组是不确定的。这些字符可以由另一被抑制或更换。

此功能被引入Qt的4.8 。

See also toAscii( )toLatin1( )toUtf8()和QTextCodec

  1. QString QStringRef.toString (self)

返回的字符串引用的副本作为QString对象。

如果字符串引用不是字符串的一个完整的参考(即position()为0,并且size( )等于string() - \u003esize( ) ) ,这个函数会分配一个新的字符串返回。

See also string( ) 。

  1. list-of-int QStringRef.toUcs4 (self)

返回字符串的UCS-4/UTF-32表示为QVector\u003cuint\u003e 。

UCS-4是一个统一码的编解码器,并且是无损的。所有从这个字符串中的字符可以被编码在UCS- 4 。

此功能被引入Qt的4.8 。

See also toAscii( )toLatin1( )toLocal8Bit()和QTextCodec

  1. QByteArray QStringRef.toUtf8 (self)

返回字符串的UTF-8表示为QByteArray

UTF - 8是Unicode编码,可以表示所有字符的Unicode字符串像QString

然而,在Unicode的范围内,但是也有一些不被视为某些字符码点。 Unicode标准中保留每个Unicode平面( U + FFFE , U + FFFF , U +1 FFFE , U +1 FFFF , U +2 FFFE等) ,以及16码点在范围U + FDD0最后两个码点.. U + FDDF ,包容性的,非字符。如果任何这些出现在字符串中,它们可以被丢弃,而不会出现在UTF-8表示,或者它们可以由一个或多个字符替换被替换。

此功能被引入Qt的4.8 。

See also toAscii( )toLatin1( )toLocal8Bit()和QTextCodec

  1. QChar QStringRef.unicode (self)

返回的字符串引用一个Unicode表示。由于数据直接源于所引用的字符串,它是不是空终止,除非引用字符串包含字符串的空终止符。

See also string( ) 。

  1. bool QStringRef.__eq__ (self, QStringRef s2)
  1. bool QStringRef.__eq__ (self, QString s2)
  1. bool QStringRef.__eq__ (self, QLatin1String s2)
  1. bool QStringRef.__ge__ (self, QStringRef s2)
  1. bool QStringRef.__gt__ (self, QStringRef s2)
  1. bool QStringRef.__le__ (self, QStringRef s2)
  1. QStringRef.__len__ (self)
  1. bool QStringRef.__lt__ (self, QStringRef s2)
  1. bool QStringRef.__ne__ (self, QStringRef s2)
  1. bool QStringRef.__ne__ (self, QString s2)
  1. bool QStringRef.__ne__ (self, QLatin1String s2)
  1. str QStringRef.__str__ (self)
  1. unicode QStringRef.__unicode__ (self)