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

QLatin1StringView Class

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QLatin1StringView Class

  • Header: QLatin1StringView

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

  • Group: QLatin1StringView is part of string-processing

Detailed Description

Many of QString's member functions are overloaded to accept const char * instead of QString. This includes the copy constructor, the assignment operator, the comparison operators, and various other functions such as insert(), append(), and prepend(). Some of these functions are optimized to avoid constructing a QString object for the const char * data. For example, assuming str is a QString,

 
Sélectionnez
if (str == "auto" || str == "extern"
        || str == "static" || str == "register") {
    ...
}

is much faster than

 
Sélectionnez
if (str == QString("auto") || str == QString("extern")
        || str == QString("static") || str == QString("register")) {
    ...
}

because it doesn't construct four temporary QString objects and make a deep copy of the character data.

However, that is not true for all QString member functions that take const char * and therefore applications should assume a temporary will be created, such as in

 
Sélectionnez
str.append("Hello ").append("World");

Applications that define QT_NO_CAST_FROM_ASCII (as explained in the QString documentation) don't have access to QString's const char * API. To provide an efficient way of specifying constant Latin-1 strings, Qt provides the QLatin1StringView, which is just a very thin wrapper around a const char *. Using QLatin1StringView, the example code above becomes

 
Sélectionnez
if (str == "auto"_L1
        || str == "extern"_L1
        || str == "static"_L1
        || str == "register"_L1 {
    ...
}

This is a bit longer to type, but it provides exactly the same benefits as the first version of the code, and is faster than converting the Latin-1 strings using QString::fromLatin1().

Thanks to the QString(QLatin1StringView) constructor, QLatin1StringView can be used everywhere a QString is expected. For example:

 
Sélectionnez
QLabel *label = new QLabel("MOD"_L1, this);

If the function you're calling with a QLatin1StringView argument isn't actually overloaded to take QLatin1StringView, the implicit conversion to QString will trigger a memory allocation, which is usually what you want to avoid by using QLatin1StringView in the first place. In those cases, using QStringLiteral may be the better option.

See Also

Member Type Documentation

 

[alias, since 5.10] QLatin1StringView::const_iterator

This typedef was introduced in Qt 5.10.

See Also

[alias, since 5.11] QLatin1StringView::const_reference

Alias for reference. Provided for compatibility with the STL.

This typedef was introduced in Qt 5.11.

[alias, since 5.10] QLatin1StringView::const_reverse_iterator

This typedef was introduced in Qt 5.10.

See Also

[alias, since 5.10] QLatin1StringView::difference_type

Alias for qsizetype. Provided for compatibility with the STL.

This typedef was introduced in Qt 5.10.

[alias, since 5.10] QLatin1StringView::iterator

QLatin1StringView does not support mutable iterators, so this is the same as const_iterator.

This typedef was introduced in Qt 5.10.

See Also

[alias, since 5.10] QLatin1StringView::reference

Alias for value_type &. Provided for compatibility with the STL.

This typedef was introduced in Qt 5.10.

[alias, since 5.10] QLatin1StringView::reverse_iterator

QLatin1StringView does not support mutable reverse iterators, so this is the same as const_reverse_iterator.

This typedef was introduced in Qt 5.10.

See Also

[alias, since 5.10] QLatin1StringView::size_type

Alias for qsizetype. Provided for compatibility with the STL.

In version prior to Qt 6, this was an alias for int, restricting the amount of data that could be held in a QLatin1StringView on 64-bit architectures.

This typedef was introduced in Qt 5.10.

[alias, since 5.10] QLatin1StringView::value_type

Alias for const char. Provided for compatibility with the STL.

This typedef was introduced in Qt 5.10.

Member Function Documentation

 

[constexpr, since 5.14] int QLatin1StringView::compare(QChar ch) const

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

[since 5.14] int QLatin1StringView::compare(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[since 5.14] int QLatin1StringView::compare(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

Returns an integer that compares to zero as this Latin-1 string compares to the string-view str, Latin-1 string l1, or character ch, respectively.

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

This function was introduced in Qt 5.14.

See Also

See also operator==(), operator<(), operator>()

[constexpr, since 5.10] bool QLatin1StringView::startsWith(QChar ch) const

[since 5.10] bool QLatin1StringView::startsWith(QChar ch, Qt::CaseSensitivity cs) const

[since 5.10] bool QLatin1StringView::startsWith(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

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

Returns true if this Latin-1 string starts with string-view str, Latin-1 string l1, or character ch, respectively; otherwise returns false.

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

This function was introduced in Qt 5.10.

See Also

See also endsWith()

[constexpr, since 5.10] bool QLatin1StringView::endsWith(QChar ch) const

[since 5.10] bool QLatin1StringView::endsWith(QChar ch, Qt::CaseSensitivity cs) const

[since 5.10] bool QLatin1StringView::endsWith(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

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

Returns true if this Latin-1 string ends with string-view str, Latin-1 string l1, or character ch, respectively; otherwise returns false.

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

This function was introduced in Qt 5.10.

See Also

See also startsWith()

[since 5.14] qsizetype QLatin1StringView::indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[since 5.14] qsizetype QLatin1StringView::indexOf(QLatin1StringView l1, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

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

Returns the index position of the first occurrence of the string-view str, Latin-1 string l1, or character ch, respectively, in this Latin-1 string, 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

See also QString::indexOf()

[since 5.14] bool QLatin1StringView::contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[since 5.14] bool QLatin1StringView::contains(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

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

Returns true if this Latin-1 string contains an occurrence of the string-view str, Latin-1 string l1, or character ch; otherwise returns false.

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

This function was introduced in Qt 5.14.

See Also

[since 5.14] qsizetype QLatin1StringView::lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[since 5.14] qsizetype QLatin1StringView::lastIndexOf(QLatin1StringView l1, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[since 5.14] qsizetype QLatin1StringView::lastIndexOf(QStringView str, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

Returns the index position of the last occurrence of the string-view str, Latin-1 string l1, or character ch, respectively, in this Latin-1 string, searching backward from index position from. Returns -1 if str is not found.

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

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

When searching for a 0-length str or l1, the match at the end of the data is excluded from the search by a negative from, even though -1 is normally thought of as searching from the end of the string: the match at the end is after the last character, so it is excluded. To include such a final empty match, either give a positive value for from or omit the from parameter entirely.

This function was introduced in Qt 5.14.

See Also

[since 6.2] qsizetype QLatin1StringView::lastIndexOf(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[since 6.2] qsizetype QLatin1StringView::lastIndexOf(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

This function overloads lastIndexOf().

Returns the index position of the last occurrence of the string-view str or Latin-1 string l1, respectively, in this Latin-1 string. 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 6.2.

[since 6.4] qsizetype QLatin1StringView::count(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[since 6.4] qsizetype QLatin1StringView::count(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[since 6.4] qsizetype QLatin1StringView::count(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

Returns the number of (potentially overlapping) occurrences of the string-view str, Latin-1 string l1, or character ch, respectively, in this Latin-1 string.

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

This function was introduced in Qt 6.4.

See Also

See also contains(), indexOf()

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

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

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

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

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

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

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

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

Returns this QLatin1StringView converted to a corresponding numeric value using base base, which is ten by default. Bases 0 and 2 through 36 are supported, using letters for digits beyond 9; A is ten, B is eleven and so on.

If base is 0, the base is determined automatically using the following rules: if the Latin-1 string begins with "0x", the rest of it is read as hexadecimal (base 16); otherwise, if it begins with "0b", the rest of it is read as binary (base 2); otherwise, if it begins with "0", the rest of it is read as octal (base 8); otherwise it is read as decimal.

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.

The conversion of the number is performed in the default C locale, regardless of the user's locale. Use QLocale to perform locale-aware conversions between numbers and strings.

This function ignores leading and trailing spacing characters.

Support for the "0b" prefix was added in Qt 6.4.

This function was introduced in Qt 6.4.

[since 6.4] double QLatin1StringView::toDouble(bool *ok = nullptr) const

[since 6.4] float QLatin1StringView::toFloat(bool *ok = nullptr) const

Returns this QLatin1StringView converted to a corresponding floating-point 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 QLatin1StringView content may only contain valid numerical characters which includes the plus/minus sign, the character e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.

The conversion of the number is performed in the default C locale, regardless of the user's locale. Use QLocale to perform locale-aware conversions between numbers and strings.

This function ignores leading and trailing spacing characters.

This function was introduced in Qt 6.4.

[since 5.14] QString QLatin1StringView::arg(Args &&... args) const

Replaces occurrences of %N in this string with the corresponding argument from args. The arguments are not positional: the first of the args replaces the %N with the lowest N (all of them), the second of the args the %N with the next-lowest N etc.

Args can consist of anything that implicitly converts to QString, QStringView or QLatin1StringView.

In addition, the following types are also supported: QChar, QLatin1Char.

This function was introduced in Qt 5.14.

See Also

See also QString::arg()

[constexpr, since 6.0] decltype(qTokenize(*this, std::forward<Needle>(needle), flags...)) QLatin1StringView::tokenize(Needle &&sep, Flags... flags) const

Splits the string into substring views wherever sep occurs, and returns a lazy sequence of those strings.

Equivalent to

 
Sélectionnez
return QStringTokenizer{std::forward&lt;Needle&gt;(sep), flags...};

except it works without C++17 Class Template Argument Deduction (CTAD) enabled in the compiler.

See QStringTokenizer for how sep and flags interact to form the result.

While this function returns QStringTokenizer, you should never, ever, name its template arguments explicitly. If you can use C++17 Class Template Argument Deduction (CTAD), you may write

 
Sélectionnez
QStringTokenizer result = sv.tokenize(sep);

(without template arguments). If you can't use C++17 CTAD, you must store the return value only in auto variables:

 
Sélectionnez
auto result = sv.tokenize(sep);

This is because the template arguments of QStringTokenizer have a very subtle dependency on the specific tokenize() overload from which they are returned, and they don't usually correspond to the type used for the separator.

This function was introduced in Qt 6.0.

See Also

[constexpr, since 5.6] QLatin1StringView::QLatin1StringView()

Constructs a QLatin1StringView object that stores a nullptr.

This function was introduced in Qt 5.6.

See Also

[constexpr, since 6.4] QLatin1StringView::QLatin1StringView(std::nullptr_t)

Constructs a QLatin1StringView object that stores a nullptr.

This function was introduced in Qt 6.4.

See Also

[explicit constexpr] QLatin1StringView::QLatin1StringView(const char *str)

Constructs a QLatin1StringView object that stores str.

The string data is not copied. The caller must be able to guarantee that str will not be deleted or modified as long as the QLatin1StringView object exists.

See Also

See also latin1()

[constexpr, since 5.10] QLatin1StringView::QLatin1StringView(const char *first, const char *last)

Constructs a QLatin1StringView object that stores first with length (last - first).

The range [first,last) must remain valid for the lifetime of this Latin-1 string object.

Passing nullptr as first is safe if last is nullptr, too, and results in a null Latin-1 string.

The behavior is undefined if last precedes first, first is nullptr and last is not, or if last - first > INT_MAX.

This function was introduced in Qt 5.10.

[constexpr] QLatin1StringView::QLatin1StringView(const char *str, qsizetype size)

Constructs a QLatin1StringView object that stores str with size.

The string data is not copied. The caller must be able to guarantee that str will not be deleted or modified as long as the QLatin1StringView object exists.

: any null ('\0') bytes in the byte array will be included in this string, which will be converted to Unicode null characters (U+0000) if this string is used by QString. This behavior is different from Qt 5.x.

See Also

See also latin1()

[explicit] QLatin1StringView::QLatin1StringView(const QByteArray &str)

Constructs a QLatin1StringView object that stores str.

The string data is not copied. The caller must be able to guarantee that str will not be deleted or modified as long as the QLatin1StringView object exists.

See Also

See also latin1()

[explicit constexpr, since 6.3] QLatin1StringView::QLatin1StringView(QByteArrayView str)

Constructs a QLatin1StringView object that stores str.

The string data is not copied. The caller must be able to guarantee that the data which str is pointing to will not be deleted or modified as long as the QLatin1StringView object exists. The size is obtained from str as-is, without checking for a null-terminator.

: any null ('\0') bytes in the byte array will be included in this string, which will be converted to Unicode null characters (U+0000) if this string is used by QString.

This function was introduced in Qt 6.3.

See Also

See also latin1()

[constexpr, since 5.8] QLatin1Char QLatin1StringView::at(qsizetype pos) const

Returns the character at position pos in this object.

This function performs no error checking. The behavior is undefined when pos < 0 or pos >= size().

This function was introduced in Qt 5.8.

See Also

See also operator[]()

[constexpr, since 5.10] QLatin1Char QLatin1StringView::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[]()

[constexpr, since 5.10] QLatin1StringView::const_iterator QLatin1StringView::begin() const

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

This function is provided for STL compatibility.

This function was introduced in Qt 5.10.

See Also

See also end(), cbegin(), rbegin(), data()

[constexpr, since 5.10] QLatin1StringView::const_iterator QLatin1StringView::cbegin() const

Same as begin().

This function is provided for STL compatibility.

This function was introduced in Qt 5.10.

See Also

See also cend(), begin(), crbegin(), data()

[constexpr, since 5.10] QLatin1StringView::const_iterator QLatin1StringView::cend() const

Same as end().

This function is provided for STL compatibility.

This function was introduced in Qt 5.10.

See Also

See also cbegin(), end(), crend()

[constexpr, since 5.10] void QLatin1StringView::chop(qsizetype length)

Truncates this string by length characters.

Same as *this = left(size() - length).

The behavior is undefined when length < 0 or length > size().

This function was introduced in Qt 5.10.

See Also

See also sliced(), first(), last(), chopped(), truncate()

[constexpr, since 5.10] QLatin1StringView QLatin1StringView::chopped(qsizetype length) const

Returns the substring of length size() - length starting at the beginning of this object.

Same as left(size() - length).

The behavior is undefined when length < 0 or length > size().

This function was introduced in Qt 5.10.

See Also

See also sliced(), first(), last(), chop(), truncate()

[constexpr, since 6.4] const char *QLatin1StringView::constBegin() const

Same as begin().

This function is provided for compatibility with other Qt containers.

This function was introduced in Qt 6.4.

See Also

See also constEnd(), begin(), cbegin(), data()

[constexpr, since 6.4] const char *QLatin1StringView::constData() const

Returns the start of the Latin-1 string referenced by this object.

This function is provided for compatibility with other Qt containers.

This function was introduced in Qt 6.4.

See Also

See also data()

[constexpr, since 6.4] const char *QLatin1StringView::constEnd() const

Same as end().

This function is provided for compatibility with other Qt containers.

This function was introduced in Qt 6.4.

See Also

See also constBegin(), end(), cend(), crend()

[since 5.10] QLatin1StringView::const_reverse_iterator QLatin1StringView::crbegin() const

Same as rbegin().

This function is provided for STL compatibility.

This function was introduced in Qt 5.10.

See Also

See also crend(), rbegin(), cbegin()

[since 5.10] QLatin1StringView::const_reverse_iterator QLatin1StringView::crend() const

Same as rend().

This function is provided for STL compatibility.

This function was introduced in Qt 5.10.

See Also

See also crbegin(), rend(), cend()

[constexpr] const char *QLatin1StringView::data() const

Returns the start of the Latin-1 string referenced by this object.

[constexpr, since 6.4] bool QLatin1StringView::empty() const

Returns whether the Latin-1 string referenced by this object is empty (size() == 0) or not.

This function is provided for STL compatibility.

This function was introduced in Qt 6.4.

See Also

See also isEmpty(), isNull(), size()

[constexpr, since 5.10] QLatin1StringView::const_iterator QLatin1StringView::end() const

Returns a const STL-style iterator pointing just after the last character in the string.

This function is provided for STL compatibility.

This function was introduced in Qt 5.10.

See Also

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

[constexpr, since 6.4] QLatin1Char QLatin1StringView::first() const

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

This function is provided for compatibility with other Qt containers.

Calling this function on an empty string constitutes undefined behavior.

This function was introduced in Qt 6.4.

See Also

See also last(), front(), back()

[constexpr, since 6.0] QLatin1StringView QLatin1StringView::first(qsizetype n) const

Returns a Latin-1 string that contains the first n characters of this Latin-1 string.

The behavior is undefined when n < 0 or n > size().

This function was introduced in Qt 6.0.

See Also

See also last(), startsWith(), chopped(), chop(), truncate()

[constexpr, since 5.10] QLatin1Char QLatin1StringView::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[]()

[constexpr, since 5.10] bool QLatin1StringView::isEmpty() const

Returns whether the Latin-1 string referenced by this object is empty (size() == 0) or not.

This function was introduced in Qt 5.10.

See Also

See also isNull(), size()

[constexpr, since 5.10] bool QLatin1StringView::isNull() const

Returns whether the Latin-1 string referenced by this object is null (data() == nullptr) or not.

This function was introduced in Qt 5.10.

See Also

See also isEmpty(), data()

[constexpr, since 6.4] QLatin1Char QLatin1StringView::last() const

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

This function is provided for compatibility with other Qt containers.

Calling this function on an empty string constitutes undefined behavior.

This function was introduced in Qt 6.4.

See Also

See also first(), back(), front()

[constexpr, since 6.0] QLatin1StringView QLatin1StringView::last(qsizetype n) const

Returns a Latin-1 string that contains the last n characters of this Latin-1 string.

The behavior is undefined when n < 0 or n > size().

This function was introduced in Qt 6.0.

See Also

See also first(), endsWith(), chopped(), chop(), truncate()

[since 6.3] qsizetype QLatin1StringView::lastIndexOf(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

This is an overloaded function.

This function was introduced in Qt 6.3.

[constexpr] const char *QLatin1StringView::latin1() const

Returns the start of the Latin-1 string referenced by this object.

[constexpr, since 5.8] QLatin1StringView QLatin1StringView::left(qsizetype length) const

If you know that length cannot be out of bounds, use first() instead in new code, because it is faster.

Returns the substring of length length starting at position 0 in this Latin-1 string.

The entire Latin-1 string is returned if length is greater than or equal to size(), or less than zero.

This function was introduced in Qt 5.8.

See Also

See also first(), last(), sliced(), startsWith(), chopped(), chop(), truncate()

[constexpr, since 6.4] qsizetype QLatin1StringView::length() const

Same as size().

This function is provided for compatibility with other Qt containers.

This function was introduced in Qt 6.4.

[constexpr, since 5.8] QLatin1StringView QLatin1StringView::mid(qsizetype start, qsizetype length = -1) const

Returns the substring of length length starting at position start in this Latin-1 string.

If you know that start and length cannot be out of bounds, use sliced() instead in new code, because it is faster.

Returns an empty Latin-1 string if start exceeds the length of this Latin-1 string. If there are less than length characters available in this Latin-1 string starting at start, or if length is negative (default), the function returns all characters that are available from start.

This function was introduced in Qt 5.8.

See Also

See also first(), last(), sliced(), chopped(), chop(), truncate()

[since 5.10] QLatin1StringView::const_reverse_iterator QLatin1StringView::rbegin() const

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

This function is provided for STL compatibility.

This function was introduced in Qt 5.10.

See Also

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

[since 5.10] QLatin1StringView::const_reverse_iterator QLatin1StringView::rend() const

Returns a STL-style reverse iterator pointing just after the last character in the string, in reverse order.

This function is provided for STL compatibility.

This function was introduced in Qt 5.10.

See Also

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

[constexpr, since 5.8] QLatin1StringView QLatin1StringView::right(qsizetype length) const

Returns the substring of length length starting at position size() - length in this Latin-1 string.

The entire Latin-1 string is returned if length is greater than or equal to size(), or less than zero.

This function was introduced in Qt 5.8.

See Also

See also first(), last(), sliced(), endsWith(), chopped(), chop(), truncate()

[constexpr] qsizetype QLatin1StringView::size() const

Returns the size of the Latin-1 string referenced by this object.

In version prior to Qt 6, this function returned int, restricting the amount of data that could be held in a QLatin1StringView on 64-bit architectures.

[constexpr, since 6.0] QLatin1StringView QLatin1StringView::sliced(qsizetype pos) const

Returns a Latin-1 string starting at position pos in this Latin-1 string, and extending to its end.

The behavior is undefined when pos < 0 or pos > size().

This function was introduced in Qt 6.0.

See Also

See also first(), last(), chopped(), chop(), truncate()

[constexpr, since 6.0] QLatin1StringView QLatin1StringView::sliced(qsizetype pos, qsizetype n) const

Returns a Latin-1 string that points to n characters of this Latin-1 string, starting at position pos.

The behavior is undefined when pos < 0, n < 0, or pos + n > size().

This function was introduced in Qt 6.0.

See Also

See also first(), last(), chopped(), chop(), truncate()

[since 6.0] QString QLatin1StringView::toString() const

Converts this Latin-1 string into a QString. Equivalent to

 
Sélectionnez
return QString(*this);

This function was introduced in Qt 6.0.

[since 5.10] QLatin1StringView QLatin1StringView::trimmed() const

Strips leading and trailing whitespace and returns the result.

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

This function was introduced in Qt 5.10.

[constexpr, since 5.10] void QLatin1StringView::truncate(qsizetype length)

Truncates this string to length length.

Same as *this = left(length).

The behavior is undefined when length < 0 or length > size().

This function was introduced in Qt 5.10.

See Also

See also sliced(), first(), last(), chopped(), chop()

bool QLatin1StringView::operator!=(const char *other) const

Returns true if this string is not equal to const char pointer other; otherwise returns false.

The other const char pointer is converted to a QString using the QString::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.

See Also

[since 5.0] bool QLatin1StringView::operator!=(const QByteArray &other) const

This function overloads operator!=().

The other byte array is converted to a QString using the QString::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.

This function was introduced in Qt 5.0.

bool QLatin1StringView::operator<(const char *other) const

Returns true if this string is lexically less than const char pointer other; otherwise returns false.

The other const char pointer is converted to a QString using the QString::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.

See Also

[since 5.0] bool QLatin1StringView::operator<(const QByteArray &other) const

This is an overloaded function.

The other byte array is converted to a QString using the QString::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.

This function was introduced in Qt 5.0.

bool QLatin1StringView::operator<=(const char *other) const

Returns true if this string is lexically less than or equal to const char pointer other; otherwise returns false.

The other const char pointer is converted to a QString using the QString::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.

See Also

[since 5.0] bool QLatin1StringView::operator<=(const QByteArray &other) const

This is an overloaded function.

The other byte array is converted to a QString using the QString::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.

This function was introduced in Qt 5.0.

bool QLatin1StringView::operator==(const char *other) const

Returns true if the string is equal to const char pointer other; otherwise returns false.

The other const char pointer is converted to a QString using the QString::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.

See Also

[since 5.0] bool QLatin1StringView::operator==(const QByteArray &other) const

This is an overloaded function.

The other byte array is converted to a QString using the QString::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.

This function was introduced in Qt 5.0.

bool QLatin1StringView::operator>(const char *other) const

Returns true if this string is lexically greater than const char pointer other; otherwise returns false.

The other const char pointer is converted to a QString using the QString::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.

See Also

[since 5.0] bool QLatin1StringView::operator>(const QByteArray &other) const

This is an overloaded function.

The other byte array is converted to a QString using the QString::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.

This function was introduced in Qt 5.0.

bool QLatin1StringView::operator>=(const char *other) const

Returns true if this string is lexically greater than or equal to const char pointer other; otherwise returns false.

The other const char pointer is converted to a QString using the QString::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.

See Also

[since 5.0] bool QLatin1StringView::operator>=(const QByteArray &other) const

This is an overloaded function.

The other byte array is converted to a QString using the QString::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.

This function was introduced in Qt 5.0.

[constexpr, since 5.8] QLatin1Char QLatin1StringView::operator[](qsizetype pos) const

Returns the character at position pos in this object.

This function performs no error checking. The behavior is undefined when pos < 0 or pos >= size().

This function was introduced in Qt 5.8.

See Also

See also at()

Related Non-Members

 

bool operator!=(QLatin1StringView s1, QLatin1StringView s2)

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

bool operator!=(QChar ch, QLatin1StringView s)

Returns true if char ch is lexically not equal to string s; otherwise returns false.

bool operator!=(QLatin1StringView s, QChar ch)

Returns true if string s is lexically not equal to char ch; otherwise returns false.

bool operator!=(QStringView s1, QLatin1StringView s2)

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

bool operator!=(QLatin1StringView s1, QStringView s2)

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

bool operator!=(const char *s1, QLatin1StringView s2)

Returns true if const char pointer s1 is lexically not equal to string s2; otherwise returns false.

[constexpr, since 6.4] QLatin1StringView operator""_L1(const char *str, size_t size)

Literal operator that creates a QLatin1StringView out of the first size characters in the char string literal str.

The following code creates a QLatin1StringView:

 
Sélectionnez
using namespace Qt::Literals::StringLiterals;

auto str = "hello"_L1;

This function was introduced in Qt 6.4.

See Also

bool operator<(QLatin1StringView s1, QLatin1StringView s2)

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

bool operator<(QChar ch, QLatin1StringView s)

Returns true if char ch is lexically less than string s; otherwise returns false.

bool operator<(QLatin1StringView s, QChar ch)

Returns true if string s is lexically less than char ch; otherwise returns false.

bool operator<(QStringView s1, QLatin1StringView s2)

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

bool operator<(QLatin1StringView s1, QStringView s2)

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

bool operator<(const char *s1, QLatin1StringView s2)

Returns true if const char pointer s1 is lexically less than string s2; otherwise returns false.

bool operator<=(QLatin1StringView s1, QLatin1StringView s2)

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

bool operator<=(QChar ch, QLatin1StringView s)

Returns true if char ch is lexically less than or equal to string s; otherwise returns false.

bool operator<=(QLatin1StringView s, QChar ch)

Returns true if string s is lexically less than or equal to char ch; otherwise returns false.

bool operator<=(QStringView s1, QLatin1StringView s2)

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

bool operator<=(QLatin1StringView s1, QStringView s2)

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

bool operator<=(const char *s1, QLatin1StringView s2)

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

bool operator==(QLatin1StringView s1, QLatin1StringView s2)

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

bool operator==(QChar ch, QLatin1StringView s)

Returns true if char ch is lexically equal to string s; otherwise returns false.

bool operator==(QLatin1StringView s, QChar ch)

Returns true if string s is lexically equal to char ch; otherwise returns false.

bool operator==(QStringView s1, QLatin1StringView s2)

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

bool operator==(QLatin1StringView s1, QStringView s2)

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

bool operator==(const char *s1, QLatin1StringView s2)

Returns true if const char pointer s1 is lexically equal to string s2; otherwise returns false.

bool operator>(QLatin1StringView s1, QLatin1StringView s2)

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

bool operator>(QChar ch, QLatin1StringView s)

Returns true if char ch is lexically greater than string s; otherwise returns false.

bool operator>(QLatin1StringView s, QChar ch)

Returns true if string s is lexically greater than char ch; otherwise returns false.

bool operator>(QStringView s1, QLatin1StringView s2)

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

bool operator>(QLatin1StringView s1, QStringView s2)

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

bool operator>(const char *s1, QLatin1StringView s2)

Returns true if const char pointer s1 is lexically greater than string s2; otherwise returns false.

bool operator>=(QLatin1StringView s1, QLatin1StringView s2)

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

bool operator>=(QChar ch, QLatin1StringView s)

Returns true if char ch is lexically greater than or equal to string s; otherwise returns false.

bool operator>=(QLatin1StringView s, QChar ch)

Returns true if string s is lexically greater than or equal to char ch; otherwise returns false.

bool operator>=(QStringView s1, QLatin1StringView s2)

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

bool operator>=(QLatin1StringView s1, QStringView s2)

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

bool operator>=(const char *s1, QLatin1StringView s2)

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

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