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

QByteArrayView Class

The QByteArrayView class provides a view on an array of bytes with a read-only subset of the QByteArray API.

This class was introduced in Qt 6.0.

All functions in this class are reentrant.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QByteArrayView Class

  • Header: QByteArrayView

  • Since: Qt 6.0

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

  • Group: QByteArrayView is part of tools, Implicitly Shared Classes, string-processing

Detailed Description

A QByteArrayView references a contiguous portion of raw bytes it does not own. It acts as an interface type to all kinds of byte-array-like data, without the need to construct a QByteArray first.

The byte array data may be represented as an array (or an array-compatible data-structure such as QByteArray, std::basic_string, etc.) of char, signed char, unsigned char or std::byte.

QByteArrayView is designed as an interface type; its main use-case is as a function parameter type. When QByteArrayViews are used as automatic variables or data members, care must be taken to ensure that the referenced data (for example, owned by a QByteArray) outlives the QByteArrayView on all code paths, lest the byte array view ends up referencing deleted data.

When used as an interface type, QByteArrayView allows a single function to accept a wide variety of byte-array-like data sources. One function accepting QByteArrayView thus replaces several function overloads (taking, for example, QByteArray, const char *, etc.) while at the same time enabling even more byte array data sources to be passed to the function.

QByteArrayView should be passed by value, not by reference-to-const:

 
Sélectionnez
    void myfun1(QByteArrayView bv);        // preferred
    void myfun2(const QByteArrayView &bv); // compiles and works, but slower

If you want to give your users maximum freedom in what type of data they can pass to your function, accompany the QByteArrayView overload with overloads for

  • char: this overload can delegate to the QByteArrayView version:

     
    Sélectionnez
        void fun(QByteArrayView bv);
        void fun(char ch) { fun(QByteArrayView(&ch, 1)); }

    even though, for technical reasons, QByteArrayView cannot provide a char constructor by itself.

  • QByteArray: if you store an unmodified copy of the byte array and thus would like to take advantage of QByteArray's implicit sharing.

QByteArrayView can also be used as the return value of a function. If you call a function returning QByteArrayView, take extra care to not keep the QByteArrayView around longer than the function promises to keep the referenced data alive. If in doubt, obtain a strong reference to the data by calling toByteArray() to convert the QByteArrayView into a QByteArray.

The methods supported by QByteArrayView reflect those of QByteArray. In particular, to the limited degree that it ascribes semantics (such as character case, spacing, digits of numbers) to the character data viewed, it uses the C locale and ASCII encoding. See C locale and ASCII functions for details and the limitations on these methods.

Compatible Byte Types

QByteArrayView can be constructed on any container of bytes, where the byte type is one of:

  • char (both signed and unsigned)

  • std::byte

See Also

Member Type Documentation

 

QByteArrayView::const_iterator

This typedef provides an STL-style const iterator for QByteArrayView.

See Also

QByteArrayView::const_pointer

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

QByteArrayView::const_reference

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

QByteArrayView::const_reverse_iterator

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

See Also

QByteArrayView::difference_type

Alias for std::ptrdiff_t. Provided for compatibility with the STL.

QByteArrayView::iterator

This typedef provides an STL-style const iterator for QByteArrayView.

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

See Also

QByteArrayView::pointer

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

QByteArrayView does not support mutable pointers, so this is the same as const_pointer.

QByteArrayView::reference

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

QByteArrayView does not support mutable references, so this is the same as const_reference.

QByteArrayView::reverse_iterator

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

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

See Also

QByteArrayView::size_type

Alias for qsizetype. Provided for compatibility with the STL.

QByteArrayView::storage_type

Alias for char.

QByteArrayView::value_type

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

Member Function Documentation

 

bool QByteArrayView::startsWith(QByteArrayView bv) const

bool QByteArrayView::startsWith(char ch) const

Returns true if this byte array view starts with byte array view bv or character ch, respectively; otherwise returns false.

See Also

See also endsWith()

bool QByteArrayView::endsWith(QByteArrayView bv) const

bool QByteArrayView::endsWith(char ch) const

Returns true if this byte array view ends with byte array view bv or character ch, respectively; otherwise returns false.

See Also

See also startsWith()

qsizetype QByteArrayView::indexOf(QByteArrayView bv, qsizetype from = 0) const

qsizetype QByteArrayView::indexOf(char ch, qsizetype from = 0) const

Returns the index position of either the start of the first occurrence of the sequence of bytes viewed by bv or the first occurrence of byte ch, respectively, in this byte array view, searching forward from index position from.Returns -1 if no match is found.

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

See also lastIndexOf(), contains()

bool QByteArrayView::contains(QByteArrayView bv) const

bool QByteArrayView::contains(char ch) const

Returns true if this byte array view contains an occurrence of the sequence of bytes viewed by bv or character ch, respectively; otherwise returns false.

See Also

See also indexOf(), lastIndexOf()

qsizetype QByteArrayView::lastIndexOf(QByteArrayView bv, qsizetype from) const

qsizetype QByteArrayView::lastIndexOf(char ch, qsizetype from = -1) const

Returns the index position of either the start of the last occurrence of the sequence of bytes viewed by bv or the last occurrence of byte ch, respectively, in this byte array view, searching backward from index position from. If from is -1, the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if no match is found.

When searching for a 0-length bv, 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 view: 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.

See Also

See also indexOf(), contains()

[constexpr] QByteArrayView::QByteArrayView()

Constructs a null byte array view.

See Also

See also isNull()

[constexpr] QByteArrayView::QByteArrayView(std::nullptr_t)

Constructs a null byte array view.

See Also

See also isNull()

[constexpr] QByteArrayView::QByteArrayView(const Byte *data, qsizetype len)

Constructs a byte array view on data with length len.

The range [data,len) must remain valid for the lifetime of this QByteArrayView.

Passing nullptr as data is safe if len is 0, too, and results in a null byte array view.

The behavior is undefined if len is negative or, when positive, if data is nullptr.

This constructor only participates in overload resolution if Byte is a compatible byte type.

See Also

[constexpr] QByteArrayView::QByteArrayView(const Byte *first, const Byte *last)

Constructs a byte array view on first with length (last - first).

The range [first,last) must remain valid for the lifetime of this QByteArrayView.

Passing \nullptr as first is safe if last is nullptr, too, and results in a null byte array view.

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

This constructor only participates in overload resolution if Byte is a compatible byte type.

See Also

[constexpr] QByteArrayView::QByteArrayView(const Byte *data)

Constructs a byte array view on data. The length is determined by scanning for the first Byte(0).

data must remain valid for the lifetime of this byte array view object.

Passing nullptr as data is safe and results in a null byte array view.

This constructor only participates in overload resolution if data is not an array and if Byte is a compatible byte type.

See Also

QByteArrayView::QByteArrayView(const QByteArray &byteArray)

Constructs a byte array view on byteArray.

byteArray.data() must remain valid for the lifetime of this byte array view object.

The byte array view will be null if and only if byteArray.isNull().

[constexpr] QByteArrayView::QByteArrayView(const Container &c)

Constructs a byte array view on the array-like container c. The length and data are set via std::size(c) and std::data(c) respectively.

The container's data must remain valid for the lifetime of this byte array view object.

This constructor participates in overload resolution if c is any contiguous container container with elements of a compatible byte type.

See Also

[constexpr] QByteArrayView::QByteArrayView(const char (&)[Size] data = Size)

Constructs a byte array view on the char array data. The view covers the array until the first '\0' is encountered, or Size, whichever comes first. If you need the full array, use fromArray() instead.

data must remain valid for the lifetime of this byte array view object.

This constructor is only available for char array literals. The reasoning behind that is for compatibility with C-libraries which predefine "large-enough" arrays, but only use some of the preallocated space. To support this in an intuitive way in an implicit constructor overload, we need to stop at the first char(0). This is logical for a char array, but not for a std::byte array.

See Also

See also fromArray

[constexpr] char QByteArrayView::at(qsizetype n) const

Returns the character at position n in this byte array view.

The behavior is undefined if n is negative or not less than size().

See Also

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

[constexpr] char QByteArrayView::back() const

Returns the last byte in the byte array view.

This function is provided for STL compatibility.

Calling this function on an empty byte array view constitutes undefined behavior.

See Also

See also front()

[constexpr] QByteArrayView::const_iterator QByteArrayView::begin() const

Returns a const STL-style iterator pointing to the first byte in the byte array view.

This function is provided for STL compatibility.

See Also

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

[constexpr] QByteArrayView::const_iterator QByteArrayView::cbegin() const

Same as begin().

This function is provided for STL compatibility.

See Also

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

[constexpr] QByteArrayView::const_iterator QByteArrayView::cend() const

Same as end().

This function is provided for STL compatibility.

See Also

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

[constexpr] void QByteArrayView::chop(qsizetype length)

Truncates this byte array view by length characters.

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

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

See Also

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

[constexpr] QByteArrayView QByteArrayView::chopped(qsizetype length) const

Returns a copy of this byte array view that omits its last length bytes. In other words, returns a byte array view of length size() - length starting at the beginning of this object.

Same as first(size() - length).

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

See Also

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

[since 6.2] int QByteArrayView::compare(QByteArrayView bv, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

Returns an integer less than, equal to, or greater than zero depending on whether this QByteArrayView sorts before, at the same position as, or after the QByteArrayView bv. The comparison is performed according to case sensitivity cs.

This function was introduced in Qt 6.2.

See Also

See also operator==()

[constexpr] QByteArrayView::const_pointer QByteArrayView::constData() const

Returns a const char pointer to the first byte in the byte array view.

The character array represented by the return value is not guaranteed to be null-terminated. The returned pointer is only safe to use for accessing bytes at indices that are less than this byte array view's size().

See Also

See also data(), begin(), end()

qsizetype QByteArrayView::count(QByteArrayView bv) const

Returns the number of (potentially overlapping) occurrences of the sequence of bytes viewed by bv in this byte array view.

See Also

See also contains(), indexOf()

qsizetype QByteArrayView::count(char ch) const

This is an overloaded function.

Returns the number of occurrences of byte ch in this byte array view.

See Also

See also contains(), indexOf()

[constexpr] QByteArrayView::const_reverse_iterator QByteArrayView::crbegin() const

Same as rbegin().

This function is provided for STL compatibility.

See Also

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

[constexpr] QByteArrayView::const_reverse_iterator QByteArrayView::crend() const

Same as rend().

This function is provided for STL compatibility.

See Also

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

[constexpr] QByteArrayView::const_pointer QByteArrayView::data() const

Returns a const char pointer to the first byte in the byte array view.

The character array represented by the return value is not guaranteed to be null-terminated. The returned pointer is only safe to use for accessing bytes at indices that are less than this byte array view's size().

See Also

See also begin(), end()

[constexpr] bool QByteArrayView::empty() const

Returns true if this byte array view is empty - that is, size() == 0.

This function is provided for STL compatibility.

See Also

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

[constexpr] QByteArrayView::const_iterator QByteArrayView::end() const

Returns a const STL-style iterator pointing just after the last byte in the byte array view.

This function is provided for STL compatibility.

See Also

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

[constexpr] QByteArrayView QByteArrayView::first(qsizetype n) const

Returns a byte array view that points to the first n bytes of this byte array view. Equivalent to sliced(0, n).

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

See Also

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

[static constexpr] QByteArrayView QByteArrayView::fromArray(const Byte (&)[Size] data = Size)

Constructs a byte array view on the array literal data. The view covers the full array. That includes the trailing null-terminator of char array literals. If you don't want the null-terminator included in the view, you can chop() it off when you are certain it is at the end. Alternatively you can use the constructor overload taking a char array literal which will create a view up to, but not including, the first null-terminator in the data.

This function will work with any array literal of a compatible byte type.

See Also

[constexpr] char QByteArrayView::front() const

Returns the first byte in the byte array view.

This function is provided for STL compatibility.

Calling this function on an empty byte array view constitutes undefined behavior.

See Also

See also back()

[constexpr] bool QByteArrayView::isEmpty() const

Returns true if this byte array view is empty - that is, size() == 0.

See Also

See also empty(), isNull(), size()

[constexpr] bool QByteArrayView::isNull() const

Returns true if this byte array view is null - that is, data() == nullptr.

See Also

See also empty(), isEmpty(), size()

[since 6.3] bool QByteArrayView::isValidUtf8() const

Returns true if this byte array view contains valid UTF-8 encoded data, or false otherwise.

This function was introduced in Qt 6.3.

[constexpr] QByteArrayView QByteArrayView::last(qsizetype n) const

Returns a byte array view that points to the last n bytes of this byte array view.

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

See Also

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

[since 6.2] qsizetype QByteArrayView::lastIndexOf(QByteArrayView bv) const

This is an overloaded function.

Returns the index position of the start of the last occurrence of the sequence of bytes viewed by bv in this byte array view, searching backward from the end of this byte array view. Returns -1 if no match is found.

This function was introduced in Qt 6.2.

See Also

See also indexOf(), contains()

[constexpr] qsizetype QByteArrayView::length() const

Same as size().

See Also

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

[constexpr] QByteArrayView::const_reverse_iterator QByteArrayView::rbegin() const

Returns a const STL-style reverse iterator pointing to the first byte in the byte array view, in reverse order.

This function is provided for STL compatibility.

See Also

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

[constexpr] QByteArrayView::const_reverse_iterator QByteArrayView::rend() const

Returns a STL-style reverse iterator pointing to one past the last byte in the byte array view, in reverse order.

This function is provided for STL compatibility.

See Also

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

[constexpr] qsizetype QByteArrayView::size() const

Returns the number of bytes in this byte array view.

See Also

See also empty(), isEmpty(), isNull()

[constexpr] QByteArrayView QByteArrayView::sliced(qsizetype pos) const

Returns a byte array view starting at position pos in this object, and extending to its end.

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

See Also

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

[constexpr] QByteArrayView QByteArrayView::sliced(qsizetype pos, qsizetype n) const

Returns a byte array view that points to n bytes of this byte array view, starting at position pos.

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

See Also

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

QByteArray QByteArrayView::toByteArray() const

Returns a deep copy of this byte array view's data as a QByteArray.

The return value will be a null QByteArray if and only if this byte array view is null.

[since 6.3] double QByteArrayView::toDouble(bool *ok = nullptr) const

Returns this byte array view 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 QByteArrayView 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.3.

[since 6.3] float QByteArrayView::toFloat(bool *ok = nullptr) const

Returns this byte array view 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.

 
Sélectionnez
QByteArrayView string("1234.56 Volt");
bool ok;
float a = str.toFloat(&amp;ok);       // a == 0, ok == false
a = string.first(7).toFloat(&amp;ok); // a == 1234.56, ok == true

The QByteArrayView 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 whitespace.

This function was introduced in Qt 6.3.

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

Returns this byte array view converted to an int 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 byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); 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.

 
Sélectionnez
QByteArrayView str("FF");
bool ok;
int hex = str.toInt(&amp;ok, 16);     // hex == 255, ok == true
int dec = str.toInt(&amp;ok, 10);     // dec == 0, ok == false

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 was introduced in Qt 6.3.

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

Returns this byte array view converted to a long int 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 byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); 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.

 
Sélectionnez
QByteArrayView str("FF");
bool ok;
long hex = str.toLong(&amp;ok, 16);   // hex == 255, ok == true
long dec = str.toLong(&amp;ok, 10);   // dec == 0, ok == false

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 was introduced in Qt 6.3.

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

Returns this byte array view converted to a long long 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 byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); 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 was introduced in Qt 6.3.

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

Returns this byte array view converted to a short 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 byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); 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 was introduced in Qt 6.3.

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

Returns this byte array view converted to an unsigned int 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 byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); 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 was introduced in Qt 6.3.

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

Returns this byte array view converted to an unsigned long int 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 byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); 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 was introduced in Qt 6.3.

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

Returns this byte array view converted to an unsigned long long 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 byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); 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 was introduced in Qt 6.3.

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

Returns this byte array view converted to an unsigned short 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 byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); 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 was introduced in Qt 6.3.

[since 6.3] QByteArrayView QByteArrayView::trimmed() const

Returns a copy of this byte array view with spacing characters removed from the start and end.

The spacing characters are those for which the standard C++ isspace() function returns true in the C locale; these are the ASCII characters tabulation '\t', line feed '\n', carriage return '\r', vertical tabulation '\v', form feed '\f', and space ' '.

This function was introduced in Qt 6.3.

See Also

[constexpr] void QByteArrayView::truncate(qsizetype length)

Truncates this byte array view to length length.

Same as *this = first(length).

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

See Also

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

[constexpr] char QByteArrayView::operator[](qsizetype n) const

Returns the character at position n in this byte array view.

The behavior is undefined if n is negative or not less than size().

See Also

See also at(), front(), back()

Related Non-Members

 

bool operator!=(QByteArrayView lhs, QByteArrayView rhs)

bool operator<(QByteArrayView lhs, QByteArrayView rhs)

bool operator<=(QByteArrayView lhs, QByteArrayView rhs)

bool operator==(QByteArrayView lhs, QByteArrayView rhs)

bool operator>(QByteArrayView lhs, QByteArrayView rhs)

bool operator>=(QByteArrayView lhs, QByteArrayView rhs)

Comparison operators for QByteArrayView.

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