Qt 4.8
Public Functions | Static Public Functions | Properties | Related Functions | List of all members
QStringRef Class Reference

The QStringRef class provides a thin wrapper around QString substrings. More...

#include <qstring.h>

Public Functions

QStringRef appendTo (QString *string) const
 Appends the string reference to string, and returns a new reference to the combined string data. More...
 
const QChar at (int i) const
 Returns the character at the given index position in the string reference. More...
 
void clear ()
 Clears the contents of the string reference by making it null and empty. More...
 
int compare (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
int compare (const QStringRef &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
int compare (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
const QCharconstData () const
 Same as unicode(). More...
 
QBool contains (const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 Returns true if this string reference contains an occurrence of the string str; otherwise returns false. More...
 
QBool contains (QChar ch, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
QBool contains (QLatin1String str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
QBool contains (const QStringRef &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
int count () const
 Returns the number of characters referred to by the string reference. More...
 
int count (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 Returns the number of (potentially overlapping) occurrences of the string str in this string reference. More...
 
int count (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
int count (const QStringRef &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const QChardata () const
 Same as unicode(). More...
 
bool endsWith (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 Returns true if the string reference ends with str; otherwise returns false. More...
 
bool endsWith (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool endsWith (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool endsWith (const QStringRef &c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
int 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. More...
 
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
 Returns the index position of the first occurrence of the string str in this string reference, searching forward from index position from. More...
 
int indexOf (const QStringRef &str, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool isEmpty () const
 Returns true if the string reference has no characters; otherwise returns false. More...
 
bool isNull () const
 Returns true if string() returns a null pointer or a pointer to a null string; otherwise returns true. More...
 
int 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. More...
 
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
 
int length () const
 Returns the number of characters referred to by the string reference. More...
 
int localeAwareCompare (const QString &s) 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 string. More...
 
int localeAwareCompare (const QStringRef &s) 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 string. More...
 
QStringRefoperator= (const QStringRef &other)
 Assigns the other string reference to this string reference, and returns the result. More...
 
QStringRefoperator= (const QString *string)
 Constructs a string reference to the given string and assigns it to this string reference, returning the result. More...
 
int position () const
 Returns the starting position in the referenced string that is referred to by the string reference. More...
 
 QStringRef ()
 Constructs an empty string reference. More...
 
 QStringRef (const QString *string, int position, int size)
 Constructs a string reference to the range of characters in the given string specified by the starting position and length in characters. More...
 
 QStringRef (const QString *string)
 Constructs a string reference to the given string. More...
 
 QStringRef (const QStringRef &other)
 Constructs a copy of the other string reference. More...
 
int size () const
 Returns the number of characters referred to by the string reference. More...
 
bool startsWith (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 Returns true if the string reference starts with str; otherwise returns false. More...
 
bool startsWith (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool startsWith (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool startsWith (const QStringRef &c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
const QStringstring () const
 Returns a pointer to the string referred to by the string reference, or 0 if it does not reference a string. More...
 
QByteArray toAscii () const Q_REQUIRED_RESULT
 Returns an 8-bit representation of the string as a QByteArray. More...
 
QByteArray toLatin1 () const Q_REQUIRED_RESULT
 Returns a Latin-1 representation of the string as a QByteArray. More...
 
QByteArray toLocal8Bit () const Q_REQUIRED_RESULT
 Returns the local 8-bit representation of the string as a QByteArray. More...
 
QString toString () const
 Returns a copy of the string reference as a QString object. More...
 
QVector< uinttoUcs4 () const Q_REQUIRED_RESULT
 Returns a UCS-4/UTF-32 representation of the string as a QVector<uint>. More...
 
QByteArray toUtf8 () const Q_REQUIRED_RESULT
 Returns a UTF-8 representation of the string as a QByteArray. More...
 
const QCharunicode () const
 Returns a Unicode representation of the string reference. More...
 
 ~QStringRef ()
 Destroys the string reference. More...
 

Static Public Functions

static int compare (const QStringRef &s1, const QString &s2, Qt::CaseSensitivity=Qt::CaseSensitive)
 Compares the string s1 with the string s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2. More...
 
static int compare (const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity=Qt::CaseSensitive)
 Compares the string s1 with the string s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2. More...
 
static int compare (const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 Compares the string s1 with the string s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2. More...
 
static int localeAwareCompare (const QStringRef &s1, const QString &s2)
 Compares 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. More...
 
static int localeAwareCompare (const QStringRef &s1, const QStringRef &s2)
 Compares 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. More...
 

Properties

int m_position
 
int m_size
 
const QStringm_string
 

Related Functions

(Note that these are not member functions.)

bool operator< (const QStringRef &s1, const QStringRef &s2)
 Returns true if string reference s1 is lexically less than string reference s2; otherwise returns false. More...
 
bool operator<= (const QStringRef &s1, const QStringRef &s2)
 
bool operator== (const QStringRef &s1, const QStringRef &s2)
 Returns true if string reference s1 is lexically equal to string reference s2; otherwise returns false. More...
 
bool operator== (const QString &s1, const QStringRef &s2)
 Returns true if string s1 is lexically equal to string reference s2; otherwise returns false. More...
 
bool operator== (const QLatin1String &s1, const QStringRef &s2)
 Returns true if string s1 is lexically equal to string reference s2; otherwise returns false. More...
 
bool operator> (const QStringRef &s1, const QStringRef &s2)
 
bool operator>= (const QStringRef &s1, const QStringRef &s2)
 

Detailed Description

The QStringRef class provides a thin wrapper around QString substrings.

Since
4.3
Note
This class or function is reentrant.

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(). Calling toString() returns a copy of the data as a real QString instance.

This class is designed to improve the performance of substring handling when manipulating substrings obtained from existing QString instances. 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 instead of QString since QStringRef requires attention to be paid to memory management issues, potentially making code more complex to write and maintain.

Warning
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.

See also
{Implicitly Shared Classes}

Definition at line 1099 of file qstring.h.

Constructors and Destructors

◆ QStringRef() [1/4]

QStringRef::QStringRef ( )
inline

Constructs an empty string reference.

Definition at line 1104 of file qstring.h.

1104 :m_string(0), m_position(0), m_size(0){}
int m_position
Definition: qstring.h:1101
int m_size
Definition: qstring.h:1102
const QString * m_string
Definition: qstring.h:1100

◆ QStringRef() [2/4]

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

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

Warning
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.

Definition at line 1196 of file qstring.h.

1197  :m_string(aString), m_position(aPosition), m_size(aSize){}
int m_position
Definition: qstring.h:1101
int m_size
Definition: qstring.h:1102
const QString * m_string
Definition: qstring.h:1100

◆ QStringRef() [3/4]

QStringRef::QStringRef ( const QString string)
inline

Constructs a string reference to the given string.

Definition at line 1199 of file qstring.h.

1200  :m_string(aString), m_position(0), m_size(aString?aString->size() : 0){}
int m_position
Definition: qstring.h:1101
int m_size
Definition: qstring.h:1102
const QString * m_string
Definition: qstring.h:1100

◆ QStringRef() [4/4]

QStringRef::QStringRef ( const QStringRef other)
inline

Constructs a copy of the other string reference.

Definition at line 1107 of file qstring.h.

1108  :m_string(other.m_string), m_position(other.m_position), m_size(other.m_size)
1109  {}
int m_position
Definition: qstring.h:1101
int m_size
Definition: qstring.h:1102
const QString * m_string
Definition: qstring.h:1100

◆ ~QStringRef()

QStringRef::~QStringRef ( )
inline

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.

Definition at line 1111 of file qstring.h.

1111 {}

Functions

◆ appendTo()

QStringRef QStringRef::appendTo ( QString string) const

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

Definition at line 8828 of file qstring.cpp.

Referenced by QString::append(), and QXmlStreamWriterPrivate::write().

8829 {
8830  if (!string)
8831  return QStringRef();
8832  int pos = string->size();
8833  string->insert(pos, unicode(), size());
8834  return QStringRef(string, pos, size());
8835 }
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
QStringRef()
Constructs an empty string reference.
Definition: qstring.h:1104

◆ at()

const QChar QStringRef::at ( int  position) const
inline

Returns the character at the given index position in the string reference.

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

Definition at line 1174 of file qstring.h.

Referenced by QPatternist::CompressedWhitespace::compress(), createSvgGlyph(), QXmlUtils::isNCName(), QString::lastIndexOf(), lastIndexOf(), QDateTimeParser::parse(), QDeclarativeStyledTextPrivate::parseCloseTag(), parseCoreNode(), parseFont(), QDeclarativeStyledTextPrivate::parseFontAttributes(), QDeclarativeStyledTextPrivate::parseTag(), QSvgAttributes::QSvgAttributes(), and resolveColor().

1175  { Q_ASSERT(uint(i) < uint(size())); return m_string->at(i + m_position); }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int m_position
Definition: qstring.h:1101
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
unsigned int uint
Definition: qglobal.h:996
const QString * m_string
Definition: qstring.h:1100

◆ clear()

void QStringRef::clear ( )
inline

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

See also
isEmpty(), isNull()

Definition at line 1167 of file qstring.h.

Referenced by QXmlStreamReaderPrivate::EntityDeclaration::clear(), QXmlStreamWriterPrivate::findNamespace(), QXmlStreamReaderPrivate::parse(), QXmlStreamReaderPrivate::resolveTag(), and QXmlStreamWriter::writeDefaultNamespace().

1167 { m_string = 0; m_position = m_size = 0; }
int m_position
Definition: qstring.h:1101
int m_size
Definition: qstring.h:1102
const QString * m_string
Definition: qstring.h:1100

◆ compare() [1/6]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.5

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

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

Equivalent to {compare(*this, other, cs)}.

See also
QString::compare()

Definition at line 1249 of file qstring.h.

1250 { return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159
static int compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, Qt::CaseSensitivity cs=Qt::CaseSensitive)
Definition: qstring.cpp:5059

◆ compare() [2/6]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.5

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

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

Equivalent to {compare(*this, other, cs)}.

See also
QString::compare()

Definition at line 1251 of file qstring.h.

1252 { return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159
static int compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, Qt::CaseSensitivity cs=Qt::CaseSensitive)
Definition: qstring.cpp:5059

◆ compare() [3/6]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.5

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

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

Equivalent to {compare(*this, other, cs)}.

See also
QString::compare()

Definition at line 1253 of file qstring.h.

1254 { return QString::compare_helper(constData(), length(), s, cs); }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159
static int compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, Qt::CaseSensitivity cs=Qt::CaseSensitive)
Definition: qstring.cpp:5059

◆ compare() [4/6]

int QStringRef::compare ( const QStringRef s1,
const QString s2,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
inlinestatic

Compares the string s1 with the string s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.

Since
4.5

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

Definition at line 1255 of file qstring.h.

1256 { return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159
static int compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, Qt::CaseSensitivity cs=Qt::CaseSensitive)
Definition: qstring.cpp:5059
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ compare() [5/6]

int QStringRef::compare ( const QStringRef s1,
const QStringRef s2,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
inlinestatic

Compares the string s1 with the string s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.

Since
4.5 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Definition at line 1257 of file qstring.h.

1258 { return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159
static int compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, Qt::CaseSensitivity cs=Qt::CaseSensitive)
Definition: qstring.cpp:5059

◆ compare() [6/6]

int QStringRef::compare ( const QStringRef s1,
QLatin1String  s2,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
inlinestatic

Compares the string s1 with the string s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.

Since
4.5 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Definition at line 1259 of file qstring.h.

1260 { return QString::compare_helper(s1.constData(), s1.length(), s2, cs); }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159
static int compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, Qt::CaseSensitivity cs=Qt::CaseSensitive)
Definition: qstring.cpp:5059

◆ constData()

const QChar * QStringRef::constData ( ) const
inline

◆ contains() [1/4]

QBool QStringRef::contains ( const QString str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns true if this string reference contains an occurrence of the string str; otherwise returns false.

Since
4.8

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

See also
indexOf(), count()

Definition at line 1275 of file qstring.h.

1276 { return QBool(indexOf(s, 0, cs) != -1); }
int 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...
Definition: qstring.cpp:9132

◆ contains() [2/4]

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

Definition at line 1279 of file qstring.h.

1280 { return QBool(indexOf(c, 0, cs) != -1); }
unsigned char c[8]
Definition: qnumeric_p.h:62
int 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...
Definition: qstring.cpp:9132

◆ contains() [3/4]

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

Definition at line 1277 of file qstring.h.

1278 { return QBool(indexOf(s, 0, cs) != -1); }
int 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...
Definition: qstring.cpp:9132

◆ contains() [4/4]

QBool QStringRef::contains ( const QStringRef str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Definition at line 1281 of file qstring.h.

1282 { return QBool(indexOf(s, 0, cs) != -1); }
int 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...
Definition: qstring.cpp:9132

◆ count() [1/4]

int QStringRef::count ( ) const
inline

Returns the number of characters referred to by the string reference.

Equivalent to size() and length().

See also
position(), string()

Definition at line 1115 of file qstring.h.

1115 { return m_size; }
int m_size
Definition: qstring.h:1102

◆ count() [2/4]

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

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

Since
4.8

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

See also
QString::count(), contains(), indexOf()

Definition at line 9350 of file qstring.cpp.

9351 {
9352  return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs);
9353 }
static int qt_string_count(const QChar *haystack, int haystackLen, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:9622
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153

◆ count() [3/4]

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

Definition at line 9370 of file qstring.cpp.

9371 {
9372  return qt_string_count(unicode(), size(), ch, cs);
9373 }
static int qt_string_count(const QChar *haystack, int haystackLen, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:9622
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153

◆ count() [4/4]

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

Definition at line 9390 of file qstring.cpp.

9391 {
9392  return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs);
9393 }
static int qt_string_count(const QChar *haystack, int haystackLen, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:9622
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153

◆ data()

const QChar * QStringRef::data ( ) const
inline

Same as unicode().

Definition at line 1158 of file qstring.h.

1158 { return unicode(); }
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153

◆ endsWith() [1/4]

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

Returns true if the string reference ends with str; otherwise returns false.

Since
4.8

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

See also
QString::endsWith(), startsWith()

Definition at line 9476 of file qstring.cpp.

9477 {
9478  return qt_ends_with(isNull() ? 0 : unicode(), size(),
9479  str.isNull() ? 0 : str.unicode(), str.size(), cs);
9480 }
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
bool isNull() const
Returns true if string() returns a null pointer or a pointer to a null string; otherwise returns true...
Definition: qstring.h:1170
static bool qt_ends_with(const QChar *haystack, int haystackLen, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:9722

◆ endsWith() [2/4]

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

Definition at line 9515 of file qstring.cpp.

9516 {
9517  return qt_ends_with(isNull() ? 0 : unicode(), size(), str, cs);
9518 }
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
bool isNull() const
Returns true if string() returns a null pointer or a pointer to a null string; otherwise returns true...
Definition: qstring.h:1170
static bool qt_ends_with(const QChar *haystack, int haystackLen, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:9722

◆ endsWith() [3/4]

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

Definition at line 9497 of file qstring.cpp.

9498 {
9499  if (!isEmpty()) {
9500  const ushort *data = reinterpret_cast<const ushort*>(unicode());
9501  const int size = length();
9502  return (cs == Qt::CaseSensitive
9503  ? data[size - 1] == ch
9504  : foldCase(data[size - 1]) == foldCase(ch.unicode()));
9505  } else {
9506  return false;
9507  }
9508 }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
const QChar * data() const
Same as unicode().
Definition: qstring.h:1158
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
bool isEmpty() const
Returns true if the string reference has no characters; otherwise returns false.
Definition: qstring.h:1169
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
unsigned short ushort
Definition: qglobal.h:995

◆ endsWith() [4/4]

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

Definition at line 9525 of file qstring.cpp.

9526 {
9527  return qt_ends_with(isNull() ? 0 : unicode(), size(),
9528  str.isNull() ? 0 : str.unicode(), str.size(), cs);
9529 }
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
bool isNull() const
Returns true if string() returns a null pointer or a pointer to a null string; otherwise returns true...
Definition: qstring.h:1170
static bool qt_ends_with(const QChar *haystack, int haystackLen, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:9722

◆ indexOf() [1/4]

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.

Since
4.8

Returns -1 if str is not found.

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

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

See also
QString::indexOf(), lastIndexOf(), contains(), count()

Definition at line 9132 of file qstring.cpp.

Referenced by contains().

9133 {
9134  return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs);
9135 }
int qFindString(const QChar *haystack, int haystackLen, int from, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:2753
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153

◆ indexOf() [2/4]

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

Definition at line 9150 of file qstring.cpp.

9151 {
9152  return findChar(unicode(), length(), ch, from, cs);
9153 }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
static int findChar(const QChar *str, int len, QChar ch, int from, Qt::CaseSensitivity cs)
Returns the index position of the first occurrence of the character ch in the string given by str and...
Definition: qstring.cpp:333

◆ indexOf() [3/4]

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.

Since
4.8

Returns -1 if str is not found.

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

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

See also
QString::indexOf(), lastIndexOf(), contains(), count()

Definition at line 9173 of file qstring.cpp.

9174 {
9175  return qt_find_latin1_string(unicode(), size(), str, from, cs);
9176 }
static int qt_find_latin1_string(const QChar *hay, int size, const QLatin1String &needle, int from, Qt::CaseSensitivity cs)
Definition: qstring.cpp:9659
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153

◆ indexOf() [4/4]

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

Definition at line 9195 of file qstring.cpp.

9196 {
9197  return qFindString(unicode(), size(), from, str.unicode(), str.size(), cs);
9198 }
int qFindString(const QChar *haystack, int haystackLen, int from, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:2753
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153

◆ isEmpty()

bool QStringRef::isEmpty ( ) const
inline

◆ isNull()

bool QStringRef::isNull ( ) const
inline

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

See also
size()

Definition at line 1170 of file qstring.h.

Referenced by QString::endsWith(), endsWith(), QPatternist::XSLTTokenizer::handleValidationAttributes(), QXmlStreamReaderPrivate::parse(), QXmlStreamReaderPrivate::resolveTag(), QString::startsWith(), and startsWith().

1170 { return m_string == 0 || m_string->isNull(); }
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
const QString * m_string
Definition: qstring.h:1100

◆ lastIndexOf() [1/4]

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.

Since
4.8

If 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 is not found.

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

See also
QString::lastIndexOf(), indexOf(), contains(), count()

Definition at line 9217 of file qstring.cpp.

9218 {
9219  const int sl = str.size();
9220  if (sl == 1)
9221  return lastIndexOf(str.at(0), from, cs);
9222 
9223  const int l = size();;
9224  if (from < 0)
9225  from += l;
9226  int delta = l - sl;
9227  if (from == l && sl == 0)
9228  return from;
9229  if (from < 0 || from >= l || delta < 0)
9230  return -1;
9231  if (from > delta)
9232  from = delta;
9233 
9234  return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from,
9235  reinterpret_cast<const ushort*>(str.unicode()), str.size(), cs);
9236 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
int 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...
Definition: qstring.cpp:9217
static int lastIndexOfHelper(const ushort *haystack, int from, const ushort *needle, int sl, Qt::CaseSensitivity cs)
Definition: qstring.cpp:2863
QFactoryLoader * l

◆ lastIndexOf() [2/4]

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

Definition at line 9250 of file qstring.cpp.

9251 {
9252  return qt_last_index_of(unicode(), size(), ch, from, cs);
9253 }
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
static int qt_last_index_of(const QChar *haystack, int haystackLen, const QChar &needle, int from, Qt::CaseSensitivity cs)
Definition: qstring.cpp:9595
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153

◆ lastIndexOf() [3/4]

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

Definition at line 9273 of file qstring.cpp.

9274 {
9275  const int sl = qstrlen(str.latin1());
9276  if (sl == 1)
9277  return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs);
9278 
9279  const int l = size();
9280  if (from < 0)
9281  from += l;
9282  int delta = l - sl;
9283  if (from == l && sl == 0)
9284  return from;
9285  if (from < 0 || from >= l || delta < 0)
9286  return -1;
9287  if (from > delta)
9288  from = delta;
9289 
9291  for (int i = 0; i < sl; ++i)
9292  s[i] = str.latin1()[i];
9293 
9294  return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, s.data(), sl, cs);
9295 }
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const char * latin1() const
Returns the Latin-1 string stored in this object.
Definition: qstring.h:661
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
int 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...
Definition: qstring.cpp:9217
uint qstrlen(const char *str)
Definition: qbytearray.h:79
static int lastIndexOfHelper(const ushort *haystack, int from, const ushort *needle, int sl, Qt::CaseSensitivity cs)
Definition: qstring.cpp:2863
QFactoryLoader * l
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ lastIndexOf() [4/4]

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

Definition at line 9315 of file qstring.cpp.

9316 {
9317  const int sl = str.size();
9318  if (sl == 1)
9319  return lastIndexOf(str.at(0), from, cs);
9320 
9321  const int l = size();
9322  if (from < 0)
9323  from += l;
9324  int delta = l - sl;
9325  if (from == l && sl == 0)
9326  return from;
9327  if (from < 0 || from >= l || delta < 0)
9328  return -1;
9329  if (from > delta)
9330  from = delta;
9331 
9332  return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from,
9333  reinterpret_cast<const ushort*>(str.unicode()),
9334  str.size(), cs);
9335 }
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
int 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...
Definition: qstring.cpp:9217
static int lastIndexOfHelper(const ushort *haystack, int from, const ushort *needle, int sl, Qt::CaseSensitivity cs)
Definition: qstring.cpp:2863
QFactoryLoader * l
const QChar at(int i) const
Returns the character at the given index position in the string reference.
Definition: qstring.h:1174

◆ length()

int QStringRef::length ( ) const
inline

◆ localeAwareCompare() [1/4]

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

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

Since
4.5 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Definition at line 1266 of file qstring.h.

1267 { return QString::localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); }
static int localeAwareCompare_helper(const QChar *data1, int length1, const QChar *data2, int length2)
Definition: qstring.cpp:5212
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159

◆ localeAwareCompare() [2/4]

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

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

Since
4.5 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Definition at line 1268 of file qstring.h.

1269 { return QString::localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); }
static int localeAwareCompare_helper(const QChar *data1, int length1, const QChar *data2, int length2)
Definition: qstring.cpp:5212
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159

◆ localeAwareCompare() [3/4]

int QStringRef::localeAwareCompare ( const QStringRef s1,
const QString s2 
)
inlinestatic

Compares 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.

Since
4.5

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 Mac OS X, this function compares according the "Order for sorted lists" setting in the International prefereces panel.

See also
compare(), QTextCodec::locale()

Definition at line 1270 of file qstring.h.

1271 { return QString::localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); }
static int localeAwareCompare_helper(const QChar *data1, int length1, const QChar *data2, int length2)
Definition: qstring.cpp:5212
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ localeAwareCompare() [4/4]

int QStringRef::localeAwareCompare ( const QStringRef s1,
const QStringRef s2 
)
inlinestatic

Compares 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.

Since
4.5 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Definition at line 1272 of file qstring.h.

1273 { return QString::localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); }
static int localeAwareCompare_helper(const QChar *data1, int length1, const QChar *data2, int length2)
Definition: qstring.cpp:5212
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159

◆ operator=() [1/2]

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

Assigns the other string reference to this string reference, and returns the result.

Definition at line 1118 of file qstring.h.

1118  {
1119  m_string = other.m_string; m_position = other.m_position;
1120  m_size = other.m_size; return *this;
1121  }
int m_position
Definition: qstring.h:1101
int m_size
Definition: qstring.h:1102
const QString * m_string
Definition: qstring.h:1100

◆ operator=() [2/2]

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

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

Definition at line 1193 of file qstring.h.

1194 { m_string = aString; m_position = 0; m_size = aString?aString->size():0; return *this; }
int m_position
Definition: qstring.h:1101
int m_size
Definition: qstring.h:1102
const QString * m_string
Definition: qstring.h:1100

◆ position()

int QStringRef::position ( ) const
inline

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

See also
size(), string()

Definition at line 1113 of file qstring.h.

Referenced by parseBrush(), parsePen(), QSvgAttributes::QSvgAttributes(), resolveColor(), and trimRef().

1113 { return m_position; }
int m_position
Definition: qstring.h:1101

◆ size()

int QStringRef::size ( ) const
inline

◆ startsWith() [1/4]

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

Returns true if the string reference starts with str; otherwise returns false.

Since
4.8

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

See also
QString::startsWith(), endsWith()

Definition at line 9409 of file qstring.cpp.

9410 {
9411  return qt_starts_with(isNull() ? 0 : unicode(), size(),
9412  str.isNull() ? 0 : str.unicode(), str.size(), cs);
9413 }
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
static bool qt_starts_with(const QChar *haystack, int haystackLen, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:9673
bool isNull() const
Returns true if string() returns a null pointer or a pointer to a null string; otherwise returns true...
Definition: qstring.h:1170

◆ startsWith() [2/4]

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

Definition at line 9420 of file qstring.cpp.

9421 {
9422  return qt_starts_with(isNull() ? 0 : unicode(), size(), str, cs);
9423 }
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
static bool qt_starts_with(const QChar *haystack, int haystackLen, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:9673
bool isNull() const
Returns true if string() returns a null pointer or a pointer to a null string; otherwise returns true...
Definition: qstring.h:1170

◆ startsWith() [3/4]

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

Definition at line 9451 of file qstring.cpp.

9452 {
9453  if (!isEmpty()) {
9454  const ushort *data = reinterpret_cast<const ushort*>(unicode());
9455  return (cs == Qt::CaseSensitive
9456  ? data[0] == ch
9457  : foldCase(data[0]) == foldCase(ch.unicode()));
9458  } else {
9459  return false;
9460  }
9461 }
const QChar * data() const
Same as unicode().
Definition: qstring.h:1158
bool isEmpty() const
Returns true if the string reference has no characters; otherwise returns false.
Definition: qstring.h:1169
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
static uint foldCase(const ushort *ch, const ushort *start)
Definition: qchar.cpp:1380
unsigned short ushort
Definition: qglobal.h:995

◆ startsWith() [4/4]

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

Definition at line 9430 of file qstring.cpp.

9431 {
9432  return qt_starts_with(isNull() ? 0 : unicode(), size(),
9433  str.isNull() ? 0 : str.unicode(), str.size(), cs);
9434 }
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
static bool qt_starts_with(const QChar *haystack, int haystackLen, const QChar *needle, int needleLen, Qt::CaseSensitivity cs)
Definition: qstring.cpp:9673
bool isNull() const
Returns true if string() returns a null pointer or a pointer to a null string; otherwise returns true...
Definition: qstring.h:1170

◆ string()

const QString * QStringRef::string ( ) const
inline

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

See also
unicode()

Definition at line 1112 of file qstring.h.

Referenced by QString::append(), parseBrush(), parsePen(), QSvgAttributes::QSvgAttributes(), resolveColor(), and trimRef().

1112 { return m_string; }
const QString * m_string
Definition: qstring.h:1100

◆ toAscii()

QByteArray QStringRef::toAscii ( ) const

Returns an 8-bit representation of the string as a QByteArray.

Since
4.8

If a codec has been set using QTextCodec::setCodecForCStrings(), it is used to convert Unicode to 8-bit char; otherwise this function does the same as toLatin1().

Note that, despite the name, this function does not necessarily return an US-ASCII (ANSI X3.4-1986) string and its result may not be US-ASCII compatible.

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

Definition at line 9810 of file qstring.cpp.

9811 {
9812 #ifndef QT_NO_TEXTCODEC
9815 #endif // QT_NO_TEXTCODEC
9816  return toLatin1();
9817 }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
QByteArray fromUnicode(const QString &uc) const
Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray...
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
static QTextCodec * codecForCStrings
Definition: qstring.h:621
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:9788

◆ toLatin1()

QByteArray QStringRef::toLatin1 ( ) const

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

Since
4.8

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

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

Definition at line 9788 of file qstring.cpp.

Referenced by QXmlStreamReaderPrivate::startDocument(), and QXmlStreamWriterPrivate::write().

9789 {
9790  return toLatin1_helper(unicode(), length());
9791 }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
static QByteArray toLatin1_helper(const QChar *data, int length)
Definition: qstring.cpp:3924
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153

◆ toLocal8Bit()

QByteArray QStringRef::toLocal8Bit ( ) const

Returns the local 8-bit representation of the string as a QByteArray.

Since
4.8

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.

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

Definition at line 9839 of file qstring.cpp.

9840 {
9841 #ifndef QT_NO_TEXTCODEC
9844 #endif // QT_NO_TEXTCODEC
9845  return toLatin1();
9846 }
static QTextCodec * codecForLocale()
Returns a pointer to the codec most suitable for this locale.
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
QByteArray fromUnicode(const QString &uc) const
Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray...
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:9788

◆ toString()

QString QStringRef::toString ( ) const

Returns a copy of the string reference as a QString object.

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

See also
string()

Definition at line 8653 of file qstring.cpp.

Referenced by QXmlSerializer::attribute(), QPatternist::AccelTreeBuilder< true >::attribute(), QXmlFormatter::characters(), QXmlSerializer::characters(), QSvgHandler::characters(), QPatternist::ColoringMessageHandler::colorifyDescription(), createCircleNode(), createEllipseNode(), createFontNode(), createImageNode(), createLinearGradientNode(), createLineNode(), createPolygonNode(), createPolylineNode(), createRadialGradientNode(), createRectNode(), createSvgNode(), createTextAreaNode(), createTextNode(), createUseNode(), QDeclarativeXMLHttpRequest::findTextCodec(), QPatternist::formatKeyword(), QPatternist::XSLTTokenizer::handleXSLTVersion(), QPatternist::XSLTTokenizer::insideSequenceConstructor(), QPatternist::XSLTTokenizer::insideTemplate(), Document::load(), QXmlStreamReaderPrivate::namespaceForPrefix(), QDeclarativeInfo::operator<<(), QDebug::operator<<(), QScriptXmlParser::parse(), QSvgHandler::parse(), QXmlStreamReaderPrivate::parse(), parseAnimateColorNode(), parseAnimateTransformNode(), parseBaseGradient(), parseCompOp(), parseCoreNode(), parseFont(), QDeclarativeStyledTextPrivate::parseFontAttributes(), parseFontFaceNameNode(), parseFontFaceNode(), parseOpacity(), parseOthers(), parsePen(), parseServerList(), parseStopNode(), parseStyleNode(), QSvgAttributes::QSvgAttributes(), QPatternist::XSLTTokenizer::queueNamespaceDeclarations(), QPatternist::XSLTTokenizer::queueSelectOrSequenceConstructor(), QPatternist::XSLTTokenizer::queueSimpleContentConstructor(), QPatternist::XSLTTokenizer::queueSorting(), QPatternist::XSLTTokenizer::queueVariableDeclaration(), QPatternist::XSLTTokenizer::readAlternativeAttribute(), QPatternist::XSLTTokenizer::readElementText(), QPatternist::XSLTTokenizer::readToggleAttribute(), QXmlStreamReaderPrivate::resolveCharRef(), resolveColor(), QPatternist::NamespaceSupport::setPrefixes(), someId(), QXmlStreamReaderPrivate::startDocument(), QPatternist::AccelTreeResourceLoader::streamToReceiver(), tokenUntil(), QPatternist::TagValidationHandler::validate(), QPatternist::MaintainingReader< XSLTTokenLookup >::validateElement(), QAbstractXmlReceiver::whitespaceOnly(), QPatternist::AccelTreeBuilder< true >::whitespaceOnly(), QPatternist::QAbstractXmlReceiver::whitespaceOnly(), QXmlStreamWriter::writeAttribute(), and QXmlStreamWriter::writeCurrentToken().

8653  {
8654  if (!m_string)
8655  return QString();
8656  if (m_size && m_position == 0 && m_size == m_string->size())
8657  return *m_string;
8658  return QString(m_string->unicode() + m_position, m_size);
8659 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
int m_position
Definition: qstring.h:1101
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
int m_size
Definition: qstring.h:1102
const QString * m_string
Definition: qstring.h:1100

◆ toUcs4()

QVector< uint > QStringRef::toUcs4 ( ) const

Returns a UCS-4/UTF-32 representation of the string as a QVector<uint>.

Since
4.8

UCS-4 is a Unicode codec and is lossless. All characters from this string can be encoded in UCS-4.

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

Definition at line 9890 of file qstring.cpp.

9891 {
9892  QVector<uint> v(length());
9893  uint *a = v.data();
9894  int len = toUcs4_helper<uint>(reinterpret_cast<const unsigned short *>(unicode()), length(), a);
9895  v.resize(len);
9896  return v;
9897 }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
long ASN1_INTEGER_get ASN1_INTEGER * a
unsigned int uint
Definition: qglobal.h:996
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153

◆ toUtf8()

QByteArray QStringRef::toUtf8 ( ) const

Returns a UTF-8 representation of the string as a QByteArray.

Since
4.8

UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QString.

However, in the Unicode range, there are certain codepoints that are not considered characters. The Unicode standard reserves the last two codepoints in each Unicode Plane (U+FFFE, U+FFFF, U+1FFFE, U+1FFFF, U+2FFFE, etc.), as well as 16 codepoints in the range U+FDD0..U+FDDF, inclusive, as non-characters. If any of those appear in the string, they may be discarded and will not appear in the UTF-8 representation, or they may be replaced by one or more replacement characters.

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

Definition at line 9869 of file qstring.cpp.

9870 {
9871  if (isNull())
9872  return QByteArray();
9873 
9874  return QUtf8::convertFromUnicode(constData(), length(), 0);
9875 }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QByteArray convertFromUnicode(const QChar *, int, QTextCodec::ConverterState *)
Definition: qutfcodec.cpp:64
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159
bool isNull() const
Returns true if string() returns a null pointer or a pointer to a null string; otherwise returns true...
Definition: qstring.h:1170

◆ unicode()

const QChar * QStringRef::unicode ( ) const
inline

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.

See also
string()

Definition at line 1153 of file qstring.h.

Referenced by QXmlStreamPrivateTagStack::addToStringStorage(), QString::append(), QString::count(), count(), QString::endsWith(), endsWith(), QString::indexOf(), indexOf(), QString::lastIndexOf(), lastIndexOf(), operator==(), qHash(), resolveColor(), QString::startsWith(), and startsWith().

1153  {
1154  if (!m_string)
1155  return reinterpret_cast<const QChar *>(QString::shared_null.data);
1156  return m_string->unicode() + m_position;
1157  }
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int m_position
Definition: qstring.h:1101
static Data shared_null
Definition: qstring.h:616
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
ushort * data
Definition: qstring.h:606
const QString * m_string
Definition: qstring.h:1100

Friends and Related Functions

◆ operator<()

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

Returns true if string reference s1 is lexically less than string reference s2; 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() function.

Definition at line 8727 of file qstring.cpp.

Referenced by operator!=().

8728 {
8729  return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0;
8730 }
int length() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1116
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159
static int ucstrcmp(const QChar *a, int alen, const QChar *b, int blen)
Definition: qstring.cpp:211

◆ operator<=()

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

Returns true if string reference s1 is lexically less than or equal to string reference s2; 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() function.

Definition at line 1223 of file qstring.h.

1224 { return !(s1 > s2); }

◆ operator==() [1/3]

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

Returns true if string reference s1 is lexically equal to string reference s2; otherwise returns false.

Definition at line 8670 of file qstring.cpp.

Referenced by operator!=(), and QStringRef().

8671 { return (s1.size() == s2.size() &&
8672  qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));
8673 }
static bool qMemEquals(const quint16 *a, const quint16 *b, int length)
Definition: qstring.cpp:273
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
unsigned short ushort
Definition: qglobal.h:995

◆ operator==() [2/3]

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

Returns true if string s1 is lexically equal to string reference s2; otherwise returns false.

Definition at line 8683 of file qstring.cpp.

8684 { return (s1.size() == s2.size() &&
8685  qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));
8686 }
static bool qMemEquals(const quint16 *a, const quint16 *b, int length)
Definition: qstring.cpp:273
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
unsigned short ushort
Definition: qglobal.h:995

◆ operator==() [3/3]

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

Returns true if string s1 is lexically equal to string reference s2; otherwise returns false.

Definition at line 8696 of file qstring.cpp.

8697 {
8698  const ushort *uc = reinterpret_cast<const ushort *>(s2.unicode());
8699  const ushort *e = uc + s2.size();
8700  const uchar *c = reinterpret_cast<const uchar *>(s1.latin1());
8701  if (!c)
8702  return s2.isEmpty();
8703 
8704  while (*c) {
8705  if (uc == e || *uc != *c)
8706  return false;
8707  ++uc;
8708  ++c;
8709  }
8710  return (uc == e);
8711 }
unsigned char c[8]
Definition: qnumeric_p.h:62
unsigned char uchar
Definition: qglobal.h:994
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const char * latin1() const
Returns the Latin-1 string stored in this object.
Definition: qstring.h:661
bool isEmpty() const
Returns true if the string reference has no characters; otherwise returns false.
Definition: qstring.h:1169
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153
unsigned short ushort
Definition: qglobal.h:995

◆ operator>()

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

Returns true if string reference s1 is lexically greater than string reference s2; 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() function.

Definition at line 1221 of file qstring.h.

1222 { return s2 < s1; }

◆ operator>=()

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

Returns true if string reference s1 is lexically greater than or equal to string reference s2; 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() function.

Definition at line 1225 of file qstring.h.

1226 { return !(s1 < s2); }

Properties

◆ m_position

int QStringRef::m_position
private

Definition at line 1101 of file qstring.h.

Referenced by operator=().

◆ m_size

int QStringRef::m_size
private

Definition at line 1102 of file qstring.h.

Referenced by operator=().

◆ m_string

const QString* QStringRef::m_string
private

Definition at line 1100 of file qstring.h.

Referenced by operator=().


The documentation for this class was generated from the following files: