IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QStringRef Class

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QStringRef Class

  • Header: QStringRef

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core5Compat)

    target_link_libraries(mytarget PRIVATE Qt6::Core5Compat)

  • qmake: QT += core5compat

  • Group: QStringRef is part of tools, string-processing

Detailed Description

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.

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

Member Type Documentation

 

[since 5.4] QStringRef::const_iterator

This typedef was introduced in Qt 5.4.

See Also

[since 5.7] QStringRef::const_reverse_iterator

This typedef was introduced in Qt 5.7.

See Also

Member Function Documentation

 

[constexpr] 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.

[default] QStringRef::QStringRef(const QStringRef &other)

Constructs a copy of the other string reference.

[default] 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

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()).

[since 5.10] QChar QStringRef::back() const

Returns the last character in the string. Same as at(size() - 1).

This function is provided for STL compatibility.

Calling this function on an empty string constitutes undefined behavior.

This function was introduced in Qt 5.10.

See Also

See also front(), at(), operator[]()

[since 5.4] QStringRef::const_iterator QStringRef::begin() const

Returns a const STL-style iterator pointing to the first character in the string.

This function was introduced in Qt 5.4.

See Also

See also cbegin(), constBegin(), end(), constEnd(), rbegin(), rend()

[since 5.4] QStringRef::const_iterator QStringRef::cbegin() const

Same as begin().

This function was introduced in Qt 5.4.

See Also

See also begin(), constBegin(), cend(), constEnd(), rbegin(), rend()

[since 5.4] QStringRef::const_iterator QStringRef::cend() const

Same as end().

This function was introduced in Qt 5.4.

See Also

See also end(), constEnd(), cbegin(), constBegin(), rbegin(), rend()

[since 5.8] void QStringRef::chop(int n)

Removes n characters from the end of the string.

If n is greater than or equal to size(), the result is an empty string; if n is negative, it is equivalent to passing zero.

This function was introduced in Qt 5.8.

See Also

See also QString::chop(), truncate()

[since 5.10] QStringRef QStringRef::chopped(int len) const

Returns a substring reference to the size() - len leftmost characters of this string.

The behavior is undefined if len is negative or greater than size().

This function was introduced in Qt 5.10.

See Also

See also endsWith(), left(), right(), mid(), chop(), truncate()

void QStringRef::clear()

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

See Also

See also isEmpty(), isNull()

[static] int QStringRef::compare(const QStringRef &s1, const QString &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.

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

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

This is an overloaded function.

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

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

This is an overloaded function.

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

[since 5.14] int QStringRef::compare(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

This is an overloaded function.

Compares this string with ch and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than ch, interpreted as a string of length one.

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

This function was introduced in Qt 5.14.

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

This is an overloaded function.

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

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

This is an overloaded function.

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.

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

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

This function was introduced in Qt 5.8.

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

This is an overloaded function.

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.

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

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

This is an overloaded function.

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.

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

[since 5.9] QStringRef::const_iterator QStringRef::constBegin() const

Same as begin().

This function was introduced in Qt 5.9.

See Also

See also begin(), cend(), constEnd(), rbegin(), rend()

const QChar *QStringRef::constData() const

Same as unicode().

[since 5.9] QStringRef::const_iterator QStringRef::constEnd() const

Same as end().

This function was introduced in Qt 5.9.

See Also

See also end(), cend(), cbegin(), constBegin(), rbegin(), rend()

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

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

See Also

See also indexOf(), count()

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

This function overloads contains().

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

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

See Also

See also indexOf(), count()

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

This function overloads contains().

Returns true if this string contains an occurrence of the character ch; otherwise returns false.

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

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

This function overloads contains().

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

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

See Also

See also indexOf(), count()

[since 5.14] bool QStringRef::contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

This function overloads contains().

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

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

This function was introduced in Qt 5.14.

See Also

See also indexOf(), count()

int QStringRef::count() const

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

See Also

See also position(), string()

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.

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

See Also

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

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

This function overloads count().

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

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

See Also

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

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

This function overloads count().

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

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

See Also

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

[since 5.7] QStringRef::const_reverse_iterator QStringRef::crbegin() const

Same as rbegin().

This function was introduced in Qt 5.7.

See Also

See also begin(), rbegin(), rend()

[since 5.7] QStringRef::const_reverse_iterator QStringRef::crend() const

Same as rend().

This function was introduced in Qt 5.7.

See Also

See also end(), rend(), rbegin()

const QChar *QStringRef::data() const

Same as unicode().

[since 5.4] QStringRef::const_iterator QStringRef::end() const

Returns a const STL-style iterator pointing to the imaginary character after the last character in the list.

This function was introduced in Qt 5.4.

See Also

See also cbegin(), constBegin(), end(), constEnd(), rbegin(), rend()

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

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

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

See Also

[since 5.10] bool QStringRef::endsWith(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

This function overloads endsWith().

This function was introduced in Qt 5.10.

See Also

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

This function overloads endsWith().

See Also

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

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

This function overloads endsWith().

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

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

See Also

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

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

This function overloads endsWith().

See Also

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

[since 5.10] QChar QStringRef::front() const

Returns the first character in the string. Same as at(0).

This function is provided for STL compatibility.

Calling this function on an empty string constitutes undefined behavior.

This function was introduced in Qt 5.10.

See Also

See also back(), at(), operator[]()

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

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

This function overloads 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 is not found.

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

See Also

[since 5.14] int QStringRef::indexOf(QStringView str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

This function overloads indexOf().

Returns the index position of the first occurrence of the string view str in this string reference, searching forward from index position from. 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.

This function was introduced in Qt 5.14.

See Also

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

This function overloads 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.

See Also

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

bool QStringRef::isEmpty() const

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

A string reference is empty if its size is zero.

See Also

See also size()

bool QStringRef::isNull() const

Returns true if this string reference does not reference a string or if the string it references is null (i.e. QString::isNull() is true).

See Also

See also size()

[since 5.9] bool QStringRef::isRightToLeft() const

Returns true if the string is read right to left.

This function was introduced in Qt 5.9.

See Also

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

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

This function overloads lastIndexOf().

Returns the index position of the last occurrence of the string reference str in this string reference, searching backward from index position from. 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

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

This function overloads lastIndexOf().

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

See Also

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

This function overloads lastIndexOf().

Returns the index position of the last occurrence of the string str in this string reference, searching backward from index position from. 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

[since 5.14] int QStringRef::lastIndexOf(QStringView str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

This function overloads lastIndexOf().

Returns the index position of the last occurrence of the string view str in this string, searching backward from index position from. 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.

This function was introduced in Qt 5.14.

See Also

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

[since 5.2] QStringRef QStringRef::left(int n) const

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

If n is greater than or equal to size(), or less than zero, a reference to the entire string is returned.

This function was introduced in Qt 5.2.

See Also

See also right(), mid(), startsWith(), chopped(), chop(), truncate()

int QStringRef::length() const

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

See Also

See also position(), string()

[static] int QStringRef::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.

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

See Also

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

This is an overloaded function.

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.

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

See Also

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

This is an overloaded function.

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.

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

See Also

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

This is an overloaded function.

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.

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

See Also

[since 5.2] QStringRef QStringRef::mid(int position, int n = -1) const

Returns a substring reference to n characters of this string, starting at the specified position.

If the 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, or if n is -1 (default), the function returns all characters from the specified position onwards.

This function was introduced in Qt 5.2.

See Also

See also left(), right(), chopped(), chop(), truncate()

int QStringRef::position() const

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

See Also

See also size(), string()

[since 5.7] QStringRef::const_reverse_iterator QStringRef::rbegin() const

Returns a const STL-style reverse iterator pointing to the first character in the string, in reverse order.

This function was introduced in Qt 5.7.

See Also

See also begin(), crbegin(), rend()

[since 5.7] QStringRef::const_reverse_iterator QStringRef::rend() const

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

This function was introduced in Qt 5.7.

See Also

See also end(), crend(), rbegin()

[since 5.2] QStringRef QStringRef::right(int n) const

If n is greater than or equal to size(), or less than zero, a reference to the entire string is returned.

This function was introduced in Qt 5.2.

See Also

See also left(), mid(), endsWith(), chopped(), chop(), truncate()

int QStringRef::size() const

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

See Also

See also position(), string()

[since 5.14] QList<QStringRef> QStringRef::split(const QString &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

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

See 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 to be dangling pointers.

This function was introduced in Qt 5.14.

[since 5.14] QList<QStringRef> QStringRef::split(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

This is an overloaded function.

This function was introduced in Qt 5.14.

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

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

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

See Also

[since 5.10] bool QStringRef::startsWith(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

This function overloads startsWith().

This function was introduced in Qt 5.10.

See Also

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

This function overloads startsWith().

See Also

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

This function overloads startsWith().

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

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

See Also

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

This function overloads startsWith().

See Also

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.

See Also

See also unicode()

[since 5.1] double QStringRef::toDouble(bool *ok = nullptr) const

Returns the string converted to a double value.

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

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

For historic reasons, this function does not handle thousands group separators. If you need to convert such numbers, use QLocale::toDouble().

This function was introduced in Qt 5.1.

See Also

See also QString::toDouble()

[since 5.1] float QStringRef::toFloat(bool *ok = nullptr) const

Returns the string converted to a float value.

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

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

This function was introduced in Qt 5.1.

See Also

See also QString::toFloat()

[since 5.1] int QStringRef::toInt(bool *ok = nullptr, int base = 10) const

Returns the string converted to an int using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

If 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()

This function was introduced in Qt 5.1.

See Also

See also 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.

See Also

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.

On Unix systems this is equivalent to toUtf8(), on Windows the systems current code page is being used.

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

See also toLatin1(), toUtf8(), QStringEncoder

[since 5.1] long QStringRef::toLong(bool *ok = nullptr, int base = 10) const

Returns the string converted to a long using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

If 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()

This function was introduced in Qt 5.1.

See Also

See also QString::toLong()

[since 5.1] qlonglong QStringRef::toLongLong(bool *ok = nullptr, int base = 10) const

Returns the string converted to a long long using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

If 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()

This function was introduced in Qt 5.1.

See Also

See also QString::toLongLong()

[since 5.1] short QStringRef::toShort(bool *ok = nullptr, int base = 10) const

Returns the string converted to a short using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

If 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()

This function was introduced in Qt 5.1.

See Also

See also QString::toShort()

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

See also string()

[since 5.1] uint QStringRef::toUInt(bool *ok = nullptr, int base = 10) const

Returns the string converted to an unsigned int using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

If 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()

This function was introduced in Qt 5.1.

See Also

See also QString::toUInt()

[since 5.1] ulong QStringRef::toULong(bool *ok = nullptr, int base = 10) const

Returns the string converted to an unsigned long using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

If 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()

This function was introduced in Qt 5.1.

See Also

See also QString::toULong()

[since 5.1] qulonglong QStringRef::toULongLong(bool *ok = nullptr, int base = 10) const

Returns the string converted to an unsigned long long using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

If 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()

This function was introduced in Qt 5.1.

See Also

[since 5.1] ushort QStringRef::toUShort(bool *ok = nullptr, int base = 10) const

Returns the string converted to an unsigned short using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

If ok is not nullptr, failure is reported by setting *ok to false, and success by setting *ok to true.

If 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()

This function was introduced in Qt 5.1.

See Also

See also QString::toUShort()

QList<uint> QStringRef::toUcs4() const

Returns a UCS-4/UTF-32 representation of the string as a QList<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 list is not \0'-terminated.

See Also

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.

See Also

[since 5.1] QStringRef QStringRef::trimmed() const

Returns a string that has whitespace removed from the start and the end.

Whitespace means any character for which QChar::isSpace() returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.

Unlike QString::simplified(), trimmed() leaves internal whitespace alone.

This function was introduced in Qt 5.1.

See Also

See also QString::trimmed()

[since 5.6] void QStringRef::truncate(int position)

Truncates the string at the given position index.

If the specified position index is beyond the end of the string, nothing happens.

If position is negative, it is equivalent to passing zero.

This function was introduced in Qt 5.6.

See Also

See also 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 \0'-terminated unless the string reference includes the string's null terminator.

See Also

See also 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.

You can disable this operator by defining 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.

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

See Also

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.

You can disable this operator by defining 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.

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

See Also

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.

You can disable this operator by defining 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.

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

See Also

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

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

[default] QStringRef &QStringRef::operator=(const QStringRef &other)

Assigns the other string reference to this string reference, and returns 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.

You can disable this operator by defining 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.

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

See Also

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.

You can disable this operator by defining 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.

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

See Also

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.

You can disable this operator by defining 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.

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

See Also

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

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

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

This function was introduced in Qt 5.7.

See Also

See also at()

Related Non-Members

 

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

Returns true if string reference s1 is lexically less than string reference s2; otherwise returns false.

See Also

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

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

See Also

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

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

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

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

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

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

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

Returns true if string reference s1 is lexically greater than string reference s2; otherwise returns false.

See Also

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

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

See Also

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+