1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
7 \brief The QByteArrayView class provides a view on an array of bytes with a read-only
8 subset of the QByteArray API.
13 \ingroup string-processing
18 \compareswith strong QByteArray {const char *}
20 \compareswith strong QString QStringView QUtf8StringView QLatin1StringView \
22 When comparing with string and Unicode character types, the content is
26 A QByteArrayView references a contiguous portion of raw bytes it does
27 not own. It acts as an interface type to all kinds of byte-array-like data,
28 without the need to construct a QByteArray first.
30 The byte array data may be represented as an array (or an array-compatible
31 data-structure such as QByteArray, std::basic_string, etc.) of \c char,
32 \c{signed char}, \c{unsigned char} or \c std::byte.
34 QByteArrayView is designed as an interface type; its main use-case is
35 as a function parameter type. When QByteArrayViews are used as automatic
36 variables or data members, care must be taken to ensure that the referenced
37 data (for example, owned by a QByteArray) outlives the QByteArrayView on all
38 code paths, lest the byte array view ends up referencing deleted data.
40 When used as an interface type, QByteArrayView allows a single function to accept
41 a wide variety of byte-array-like data sources. One function accepting QByteArrayView
42 thus replaces several function overloads (taking, for example, QByteArray, const char *,
43 etc.) while at the same time enabling even more byte array data sources to be passed
46 QByteArrayView should be passed by value, not by reference-to-const:
47 \snippet code/src_corelib_text_qbytearrayview.cpp 0
49 If you want to give your users maximum freedom in what type of data they
50 can pass to your function, accompany the QByteArrayView overload with
54 \li \e char: this overload can delegate to the QByteArrayView version:
55 \snippet code/src_corelib_text_qbytearrayview.cpp 1
56 even though, for technical reasons, QByteArrayView cannot provide a
57 char constructor by itself.
58 \li \e QByteArray: if you store an unmodified copy of the byte array and
59 thus would like to take advantage of QByteArray's implicit sharing.
62 QByteArrayView can also be used as the return value of a function. If you call a
63 function returning QByteArrayView, take extra care to not keep the QByteArrayView
64 around longer than the function promises to keep the referenced data alive.
65 If in doubt, obtain a strong reference to the data by calling toByteArray() to convert
66 the QByteArrayView into a QByteArray.
68 The methods supported by QByteArrayView reflect those of \l QByteArray. In
69 particular, to the limited degree that it ascribes semantics (such as
70 character case, spacing, digits of numbers) to the character data viewed, it
71 uses the C locale and ASCII encoding. See \l {C locale and ASCII functions}
72 for details and the limitations on these methods.
74 \section1 Compatible Byte Types
76 QByteArrayView can be constructed on any container of bytes, where the byte type
80 \li \c char (both signed and unsigned)
84 \sa QByteArray, QStringView
88 \typedef QByteArrayView::storage_type
94 \typedef QByteArrayView::value_type
96 Alias for \c{const char}. Provided for compatibility with the STL.
100 \typedef QByteArrayView::difference_type
102 Alias for \c{std::ptrdiff_t}. Provided for compatibility with the STL.
106 \typedef QByteArrayView::size_type
108 Alias for qsizetype. Provided for compatibility with the STL.
112 \typedef QByteArrayView::reference
114 Alias for \c{value_type &}. Provided for compatibility with the STL.
116 QByteArrayView does not support mutable references, so this is the same
121 \typedef QByteArrayView::const_reference
123 Alias for \c{value_type &}. Provided for compatibility with the STL.
127 \typedef QByteArrayView::pointer
129 Alias for \c{value_type *}. Provided for compatibility with the STL.
131 QByteArrayView does not support mutable pointers, so this is the same
136 \typedef QByteArrayView::const_pointer
138 Alias for \c{value_type *}. Provided for compatibility with the STL.
142 \typedef QByteArrayView::iterator
144 This typedef provides an STL-style const iterator for QByteArrayView.
146 QByteArrayView does not support mutable iterators, so this is the same
149 \sa const_iterator, reverse_iterator
153 \typedef QByteArrayView::const_iterator
155 This typedef provides an STL-style const iterator for QByteArrayView.
157 \sa iterator, const_reverse_iterator
161 \typedef QByteArrayView::reverse_iterator
163 This typedef provides an STL-style const reverse iterator for QByteArrayView.
165 QByteArrayView does not support mutable reverse iterators, so this is the
166 same as const_reverse_iterator.
168 \sa const_reverse_iterator, iterator
172 \typedef QByteArrayView::const_reverse_iterator
174 This typedef provides an STL-style const reverse iterator for QByteArrayView.
176 \sa reverse_iterator, const_iterator
180 \fn QByteArrayView::QByteArrayView()
182 Constructs a null byte array view.
188 \fn QByteArrayView::QByteArrayView(std::nullptr_t)
190 Constructs a null byte array view.
196 \fn template <typename Byte, QByteArrayView::if_compatible_byte<Byte> = true> QByteArrayView::QByteArrayView(const Byte *data, qsizetype len)
198 Constructs a byte array view on \a data with length \a len.
200 The range \c{[data,len)} must remain valid for the lifetime of this QByteArrayView.
202 Passing \nullptr as \a data is safe if \a len is 0, too, and results in a null
205 The behavior is undefined if \a len is negative or, when positive, if \a data is \nullptr.
207 This constructor only participates in overload resolution if \c Byte is a compatible
210 \sa {Compatible Byte Types}
214 \fn template <typename Byte, QByteArrayView::if_compatible_byte<Byte> = true> QByteArrayView::QByteArrayView(const Byte *first, const Byte *last)
216 Constructs a byte array view on \a first with length (\a last - \a first).
218 The range \c{[first,last)} must remain valid for the lifetime of
221 Passing \c \nullptr as \a first is safe if \a last is \nullptr, too,
222 and results in a null byte array view.
224 The behavior is undefined if \a last precedes \a first, or \a first
225 is \nullptr and \a last is not.
227 This constructor only participates in overload resolution if \c Byte is
228 a compatible byte type.
230 \sa {Compatible Byte Types}
234 \fn template <typename Byte> QByteArrayView::QByteArrayView(const Byte *data)
236 Constructs a byte array view on \a data. The length is determined
237 by scanning for the first \c{Byte(0)}.
239 \a data must remain valid for the lifetime of this byte array view object.
241 Passing \nullptr as \a data is safe and results in a null byte array view.
243 This constructor only participates in overload resolution if \a data is not
244 an array and if \c Byte is a compatible byte type.
246 \sa {Compatible Byte Types}
250 \fn template <size_t Size> QByteArrayView::QByteArrayView(const char (&data)[Size])
252 Constructs a byte array view on the char array \a data.
253 The view covers the array until the first \c{'\0'} is encountered,
254 or \c Size, whichever comes first.
255 If you need the full array, use fromArray() instead.
257 \a data must remain valid for the lifetime of this byte array view
260 \note This constructor is only available for char array literals.
261 The reasoning behind that is for compatibility with C-libraries
262 which predefine "large-enough" arrays, but only use some of the
263 preallocated space. To support this in an intuitive way in an
264 implicit constructor overload, we need to stop at the first
265 \c{char(0)}. This is logical for a char array, but not
266 for a \c{std::byte} array.
272 \fn QByteArrayView::QByteArrayView(const QByteArray &byteArray)
274 Constructs a byte array view on \a byteArray.
276 \c{byteArray.data()} must remain valid for the lifetime of this byte array view object.
278 The byte array view will be null if and only if \c{byteArray.isNull()}.
282 \fn template <typename Container, QByteArrayView::if_compatible_container<Container> = true> QByteArrayView::QByteArrayView(const Container &c)
284 Constructs a byte array view on the array-like container \a c. The length and data
285 are set via \c{std::size(c)} and \c{std::data(c)} respectively.
287 The container's data must remain valid for the lifetime of this byte array view object.
289 This constructor participates in overload resolution if \a c is any contiguous
290 container with elements of a compatible byte type.
292 \sa {Compatible Byte Types}
296 \fn template <typename Byte, size_t Size> QByteArrayView QByteArrayView::fromArray(const Byte (&data)[Size])
298 Constructs a byte array view on the array literal \a data. The view covers the full
299 array. That includes the trailing null-terminator of \c{char} array literals.
300 If you don't want the null-terminator included in the view, you can chop() it off
301 when you are certain it is at the end. Alternatively you can use the constructor
302 overload taking a char array literal which will create a view up to, but not including,
303 the first null-terminator in the data.
305 This function will work with any array literal of a compatible byte type.
307 \sa {Compatible Byte Types}, QByteArrayView
311 \fn QByteArray QByteArrayView::toByteArray() const
313 Returns a deep copy of this byte array view's data as a QByteArray.
315 The return value will be a null QByteArray if and only if this byte array
320 \fn const char *QByteArrayView::data() const
322 Returns a const \c char pointer to the first byte in the byte array view.
324 \note The character array represented by the return value is \e not guaranteed
325 to be null-terminated. The returned pointer is only safe to use for accessing
326 bytes at indices that are less than this byte array view's size().
332 \fn const char *QByteArrayView::constData() const
334 Returns a const \c char pointer to the first byte in the byte array view.
336 \note The character array represented by the return value is \e not guaranteed
337 to be null-terminated. The returned pointer is only safe to use for accessing
338 bytes at indices that are less than this byte array view's size().
340 \sa data(), begin(), end()
344 \fn int QByteArrayView::operator==(const QByteArrayView &lhs, const QByteArrayView &rhs)
345 \fn int QByteArrayView::operator!=(const QByteArrayView &lhs, const QByteArrayView &rhs)
346 \fn int QByteArrayView::operator< (const QByteArrayView &lhs, const QByteArrayView &rhs)
347 \fn int QByteArrayView::operator<=(const QByteArrayView &lhs, const QByteArrayView &rhs)
348 \fn int QByteArrayView::operator> (const QByteArrayView &lhs, const QByteArrayView &rhs)
349 \fn int QByteArrayView::operator>=(const QByteArrayView &lhs, const QByteArrayView &rhs)
351 Comparison operators for QByteArrayView.
355 \fn int QByteArrayView::compare(QByteArrayView bv, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
358 Returns an integer less than, equal to, or greater than zero depending on
359 whether this QByteArrayView sorts before, at the same position as, or after
360 the QByteArrayView \a bv. The comparison is performed according to case
367 \fn QByteArrayView::isValidUtf8() const
369 Returns \c true if this byte array view contains valid UTF-8 encoded data,
370 or \c false otherwise.
376 \fn QByteArrayView::const_iterator QByteArrayView::begin() const
378 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the
379 first byte in the byte array view.
381 This function is provided for STL compatibility.
383 \sa end(), cbegin(), rbegin(), data()
387 \fn QByteArrayView::const_iterator QByteArrayView::cbegin() const
391 This function is provided for STL compatibility.
393 \sa cend(), begin(), crbegin(), data()
397 \fn QByteArrayView::const_iterator QByteArrayView::end() const
399 Returns a const \l{STL-style iterators}{STL-style iterator} pointing
400 just after the last byte in the byte array view.
402 This function is provided for STL compatibility.
404 \sa begin(), cend(), rend()
407/*! \fn QByteArrayView::const_iterator QByteArrayView::cend() const
411 This function is provided for STL compatibility.
413 \sa cbegin(), end(), crend()
417 \fn QByteArrayView::const_reverse_iterator QByteArrayView::rbegin() const
419 Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing
420 to the first byte in the byte array view, in reverse order.
422 This function is provided for STL compatibility.
424 \sa rend(), crbegin(), begin()
428 \fn QByteArrayView::const_reverse_iterator QByteArrayView::crbegin() const
432 This function is provided for STL compatibility.
434 \sa crend(), rbegin(), cbegin()
438 \fn QByteArrayView::const_reverse_iterator QByteArrayView::rend() const
440 Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
441 the last byte in the byte array view, in reverse order.
443 This function is provided for STL compatibility.
445 \sa rbegin(), crend(), end()
449 \fn QByteArrayView::const_reverse_iterator QByteArrayView::crend() const
453 This function is provided for STL compatibility.
455 \sa crbegin(), rend(), cend()
459 \fn bool QByteArrayView::empty() const
461 Returns \c true if this byte array view is empty - that is, \c{size() == 0}.
463 This function is provided for STL compatibility.
465 \sa isEmpty(), isNull(), size()
469 \fn bool QByteArrayView::isEmpty() const
471 Returns \c true if this byte array view is empty - that is, \c{size() == 0}.
473 \sa empty(), isNull(), size()
477 \fn bool QByteArrayView::isNull() const
479 Returns \c true if this byte array view is null - that is, \c{data() == nullptr}.
481 \sa empty(), isEmpty(), size()
485 \fn qsizetype QByteArrayView::size() const
487 Returns the number of bytes in this byte array view.
489 \sa empty(), isEmpty(), isNull()
493 \fn QByteArrayView::length() const
497 \sa empty(), isEmpty(), isNull(), size()
501 \fn char QByteArrayView::operator[](qsizetype n) const
503 Returns the character at position \a n in this byte array view.
505 The behavior is undefined if \a n is negative or not less than size().
507 \sa at(), front(), back()
511 \fn char QByteArrayView::at(qsizetype n) const
513 Returns the character at position \a n in this byte array view.
515 The behavior is undefined if \a n is negative or not less than size().
517 \sa operator[](), front(), back()
521 \fn char QByteArrayView::front() const
523 Returns the first byte in the byte array view.
525 This function is provided for STL compatibility.
527 \warning Calling this function on an empty byte array view constitutes
534 \fn char QByteArrayView::back() const
536 Returns the last byte in the byte array view.
538 This function is provided for STL compatibility.
540 \warning Calling this function on an empty byte array view constitutes
547 \fn QByteArrayView QByteArrayView::first(qsizetype n) const
549 Returns a byte array view that points to the first \a n bytes
550 of this byte array view. Equivalent to \c{sliced(0, n)}.
552 \note The behavior is undefined when \a n < 0 or \a n > size().
554 \sa last(), startsWith(), chopped(), chop(), truncate()
558 \fn QByteArrayView QByteArrayView::last(qsizetype n) const
560 Returns a byte array view that points to the last \a n bytes
561 of this byte array view.
563 \note The behavior is undefined when \a n < 0 or \a n > size().
565 \sa first(), endsWith(), chopped(), chop(), truncate()
569 \fn QByteArrayView QByteArrayView::sliced(qsizetype pos, qsizetype n) const
571 Returns a byte array view that points to \a n bytes of this byte array
572 view, starting at position \a pos.
574//! [UB-sliced-index-length]
575 \note The behavior is undefined when \a pos < 0, \a n < 0,
576 or \a pos + \a n > size().
577//! [UB-sliced-index-length]
579 \sa first(), last(), chopped(), chop(), truncate()
583 \fn QByteArrayView QByteArrayView::sliced(qsizetype pos) const
585 Returns a byte array view starting at position \a pos in this object,
586 and extending to its end.
588//! [UB-sliced-index-only]
589 \note The behavior is undefined when \a pos < 0 or \a pos > size().
590//! [UB-sliced-index-only]
592 \sa first(), last(), chopped(), chop(), truncate()
596 \fn QByteArrayView QByteArrayView::chopped(qsizetype length) const
598 Returns a copy of this byte array view that omits its last \a length bytes.
599 In other words, returns a byte array view of length size() - \a length starting
600 at the beginning of this object.
602 Same as \c{first(size() - length)}.
604 \note The behavior is undefined when \a length < 0 or \a length > size().
606 \sa first(), last(), sliced(), chop(), truncate()
610 \fn void QByteArrayView::truncate(qsizetype length)
612 Truncates this byte array view to length \a length.
614 Same as \c{*this = first(length)}.
616 \note The behavior is undefined when \a length < 0 or \a length > size().
618 \sa first(), last(), sliced(), chopped(), chop()
622 \fn void QByteArrayView::chop(qsizetype length)
624 Truncates this byte array view by \a length characters.
626 Same as \c{*this = first(size() - length)}.
628 \note The behavior is undefined when \a length < 0 or \a length > size().
630 \sa sliced(), first(), last(), chopped(), truncate()
634 \fn QByteArrayView QByteArrayView::mid(qsizetype start, qsizetype length) const
637 \deprecated Use sliced() instead in new code.
639 Returns the subarray of length \a length starting at position
640 \a start in this object.
642 Returns an empty byte array view if \a start exceeds the
643 length of the byte array view. If there are less than \a length characters
644 available in the byte array view starting at \a start, or if
645 \a length is negative (default), the function returns all characters that
646 are available from \a start.
648 \sa first(), last(), sliced(), chopped(), chop(), truncate()
652 \fn QByteArrayView QByteArrayView::left(qsizetype length) const
655 \deprecated Use first() instead in new code.
657 Returns the subarray of length \a length starting at position
660 The entire byte array view is returned if \a length is greater than or equal
661 to size(), or less than zero.
663 \sa first(), last(), sliced(), startsWith(), chopped(), chop(), truncate()
667 \fn QByteArrayView QByteArrayView::right(qsizetype length) const
670 \deprecated Use last() instead in new code.
672 Returns the subarray of length \a length starting at position
673 size() - \a length in this object.
675 The entire byte array view is returned if \a length is greater than or equal
676 to size(), or less than zero.
678 \sa first(), last(), sliced(), endsWith(), chopped(), chop(), truncate()
682 \fn QByteArrayView QByteArrayView::trimmed() const noexcept
685 Returns a copy of this byte array view with spacing characters
686 removed from the start and end.
688 The spacing characters are those for which the standard C++ \c isspace()
689 function returns \c true in the C locale; these are the ASCII characters
690 tabulation '\\t', line feed '\\n', carriage return '\\r', vertical
691 tabulation '\\v', form feed '\\f', and space ' '.
693 \sa QChar::SpecialCharacter, {QByteArray#Spacing Characters}{Spacing Characters}
697 \fn qlonglong QByteArrayView::toLongLong(bool *ok, int base) const
700 Returns this byte array view converted to a \c {long long} using base \a
701 base, which is ten by default. Bases 0 and 2 through 36 are supported, using
702 letters for digits beyond 9; A is ten, B is eleven and so on.
704 If \a base is 0, the base is determined automatically using the following
705 rules: if the byte array view begins with "0x", the rest of it is read as
706 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
707 read as octal (base 8); otherwise it is read as decimal.
709 Returns 0 if the conversion fails.
711 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
712 to \c false, and success by setting *\a{ok} to \c true.
714 \note The conversion of the number is performed in the default C locale,
715 regardless of the user's locale. Use QLocale to perform locale-aware
716 conversions between numbers and strings.
720 \fn qulonglong QByteArrayView::toULongLong(bool *ok, int base) const
723 Returns this byte array view converted to an \c {unsigned long long} using
724 base \a base, which is ten by default. Bases 0 and 2 through 36 are
725 supported, using letters for digits beyond 9; A is ten, B is eleven and so
728 If \a base is 0, the base is determined automatically using the following
729 rules: if the byte array view begins with "0x", the rest of it is read as
730 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
731 read as octal (base 8); otherwise it is read as decimal.
733 Returns 0 if the conversion fails.
735 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
736 to \c false, and success by setting *\a{ok} to \c true.
738 \note The conversion of the number is performed in the default C locale,
739 regardless of the user's locale. Use QLocale to perform locale-aware
740 conversions between numbers and strings.
744 \fn int QByteArrayView::toInt(bool *ok, int base) const
747 Returns this byte array view converted to an \c int using base \a base,
748 which is ten by default. Bases 0 and 2 through 36 are supported, using
749 letters for digits beyond 9; A is ten, B is eleven and so on.
751 If \a base is 0, the base is determined automatically using the following
752 rules: if the byte array view begins with "0x", the rest of it is read as
753 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
754 read as octal (base 8); otherwise it is read as decimal.
756 Returns 0 if the conversion fails.
758 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
759 to \c false, and success by setting *\a{ok} to \c true.
761 \snippet code/src_corelib_text_qbytearrayview.cpp 2
763 \note The conversion of the number is performed in the default C locale,
764 regardless of the user's locale. Use QLocale to perform locale-aware
765 conversions between numbers and strings.
769 \fn uint QByteArrayView::toUInt(bool *ok, int base) const
772 Returns this byte array view converted to an \c {unsigned int} using base \a
773 base, which is ten by default. Bases 0 and 2 through 36 are supported, using
774 letters for digits beyond 9; A is ten, B is eleven and so on.
776 If \a base is 0, the base is determined automatically using the following
777 rules: if the byte array view begins with "0x", the rest of it is read as
778 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
779 read as octal (base 8); otherwise it is read as decimal.
781 Returns 0 if the conversion fails.
783 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
784 to \c false, and success by setting *\a{ok} to \c true.
786 \note The conversion of the number is performed in the default C locale,
787 regardless of the user's locale. Use QLocale to perform locale-aware
788 conversions between numbers and strings.
792 \fn long QByteArrayView::toLong(bool *ok, int base) const
795 Returns this byte array view converted to a \c long int using base \a base,
796 which is ten by default. Bases 0 and 2 through 36 are supported, using
797 letters for digits beyond 9; A is ten, B is eleven and so on.
799 If \a base is 0, the base is determined automatically using the following
800 rules: if the byte array view begins with "0x", the rest of it is read as
801 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
802 read as octal (base 8); otherwise it is read as decimal.
804 Returns 0 if the conversion fails.
806 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
807 to \c false, and success by setting *\a{ok} to \c true.
809 \snippet code/src_corelib_text_qbytearrayview.cpp 3
811 \note The conversion of the number is performed in the default C locale,
812 regardless of the user's locale. Use QLocale to perform locale-aware
813 conversions between numbers and strings.
817 \fn ulong QByteArrayView::toULong(bool *ok, int base) const
820 Returns this byte array view converted to an \c {unsigned long int} using
821 base \a base, which is ten by default. Bases 0 and 2 through 36 are
822 supported, using letters for digits beyond 9; A is ten, B is eleven and so
825 If \a base is 0, the base is determined automatically using the following
826 rules: if the byte array view begins with "0x", the rest of it is read as
827 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
828 read as octal (base 8); otherwise it is read as decimal.
830 Returns 0 if the conversion fails.
832 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
833 to \c false, and success by setting *\a{ok} to \c true.
835 \note The conversion of the number is performed in the default C locale,
836 regardless of the user's locale. Use QLocale to perform locale-aware
837 conversions between numbers and strings.
841 \fn short QByteArrayView::toShort(bool *ok, int base) const
844 Returns this byte array view converted to a \c short using base \a base,
845 which is ten by default. Bases 0 and 2 through 36 are supported, using
846 letters for digits beyond 9; A is ten, B is eleven and so on.
848 If \a base is 0, the base is determined automatically using the following
849 rules: if the byte array view begins with "0x", the rest of it is read as
850 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
851 read as octal (base 8); otherwise it is read as decimal.
853 Returns 0 if the conversion fails.
855 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
856 to \c false, and success by setting *\a{ok} to \c true.
858 \note The conversion of the number is performed in the default C locale,
859 regardless of the user's locale. Use QLocale to perform locale-aware
860 conversions between numbers and strings.
864 \fn ushort QByteArrayView::toUShort(bool *ok, int base) const
867 Returns this byte array view converted to an \c {unsigned short} using base
868 \a base, which is ten by default. Bases 0 and 2 through 36 are supported,
869 using letters for digits beyond 9; A is ten, B is eleven and so on.
871 If \a base is 0, the base is determined automatically using the following
872 rules: if the byte array view begins with "0x", the rest of it is read as
873 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
874 read as octal (base 8); otherwise it is read as decimal.
876 Returns 0 if the conversion fails.
878 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
879 to \c false, and success by setting *\a{ok} to \c true.
881 \note The conversion of the number is performed in the default C locale,
882 regardless of the user's locale. Use QLocale to perform locale-aware
883 conversions between numbers and strings.
887 \fn double QByteArrayView::toDouble(bool *ok) const
890 Returns this byte array view converted to a \c double value.
892 Returns an infinity if the conversion overflows or 0.0 if the
893 conversion fails for other reasons (e.g. underflow).
895 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
896 to \c false, and success by setting *\a{ok} to \c true.
898 \warning The QByteArrayView content may only contain valid numerical
899 characters which includes the plus/minus sign, the character e used in
900 scientific notation, and the decimal point. Including the unit or additional
901 characters leads to a conversion error.
903 \note The conversion of the number is performed in the default C locale,
904 regardless of the user's locale. Use QLocale to perform locale-aware
905 conversions between numbers and strings.
907 This function ignores leading and trailing spacing characters.
911 \fn float QByteArrayView::toFloat(bool *ok) const
914 Returns this byte array view converted to a \c float value.
916 Returns an infinity if the conversion overflows or 0.0 if the
917 conversion fails for other reasons (e.g. underflow).
919 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
920 to \c false, and success by setting *\a{ok} to \c true.
922 \snippet code/src_corelib_text_qbytearrayview.cpp 4
924 \warning The QByteArrayView content may only contain valid numerical
925 characters which includes the plus/minus sign, the character e used in
926 scientific notation, and the decimal point. Including the unit or additional
927 characters leads to a conversion error.
929 \note The conversion of the number is performed in the default C locale,
930 regardless of the user's locale. Use QLocale to perform locale-aware
931 conversions between numbers and strings.
933 This function ignores leading and trailing whitespace.
937 \fn bool QByteArrayView::startsWith(QByteArrayView bv) const
938 \fn bool QByteArrayView::startsWith(char ch) const
940 Returns \c true if this byte array view starts with byte array view \a bv
941 or character \a ch, respectively; otherwise returns \c false.
947 \fn bool QByteArrayView::endsWith(QByteArrayView bv) const
948 \fn bool QByteArrayView::endsWith(char ch) const
950 Returns \c true if this byte array view ends with byte array view \a bv
951 or character \a ch, respectively; otherwise returns \c false.
957 \fn qsizetype QByteArrayView::indexOf(QByteArrayView bv, qsizetype from = 0) const
958 \fn qsizetype QByteArrayView::indexOf(char ch, qsizetype from = 0) const
960 Returns the index position of either the start of the first occurrence of
961 the sequence of bytes viewed by \a bv or the first occurrence of byte \a ch,
962 respectively, in this byte array view, searching forward from index position
963 \a from.Returns -1 if no match is found.
965 \include qstring.qdocinc negative-index-start-search-from-end
967 \sa lastIndexOf(), contains()
971 \fn bool QByteArrayView::contains(QByteArrayView bv) const
972 \fn bool QByteArrayView::contains(char ch) const
974 Returns \c true if this byte array view contains an occurrence of the sequence
975 of bytes viewed by \a bv or character \a ch, respectively; otherwise returns
978 \sa indexOf(), lastIndexOf()
982 \fn qsizetype QByteArrayView::lastIndexOf(QByteArrayView bv, qsizetype from) const
983 \fn qsizetype QByteArrayView::lastIndexOf(char ch, qsizetype from = -1) const
985 Returns the index position of either the start of the last occurrence of
986 the sequence of bytes viewed by \a bv or the last occurrence of byte \a ch,
987 respectively, in this byte array view, searching backward from index position
990 \include qstring.qdocinc negative-index-start-search-from-end
992 Returns -1 if no match is found.
994 \note When searching for a 0-length \a bv, the match at the end of
995 the data is excluded from the search by a negative \a from, even
996 though \c{-1} is normally thought of as searching from the end of
997 the view: the match at the end is \e after the last character, so
998 it is excluded. To include such a final empty match, either give a
999 positive value for \a from or omit the \a from parameter entirely.
1001 \sa indexOf(), contains()
1005 \fn qsizetype QByteArrayView::lastIndexOf(QByteArrayView bv) const
1009 Returns the index position of the start of the last
1010 occurrence of the sequence of bytes viewed by \a bv in this byte
1011 array view, searching backward from the end of this byte array
1012 view. Returns -1 if no match is found.
1014 \sa indexOf(), contains()
1018 \fn qsizetype QByteArrayView::count(QByteArrayView bv) const
1020 Returns the number of (potentially overlapping) occurrences of the
1021 sequence of bytes viewed by \a bv in this byte array view.
1023 \sa contains(), indexOf()
1027 \fn bool QByteArrayView::count(char ch) const
1030 Returns the number of occurrences of byte \a ch in this byte array view.
1032 \sa contains(), indexOf()
1036 \fn QByteArrayView qToByteArrayViewIgnoringNull(const QByteArray &b);
1039 Convert \a b to a QByteArrayView ignoring \c{b.isNull()}.
1041 Returns a byte array view that references \a{b}'s data, but is never null.
1043 This is a faster way to convert a QByteArray to a QByteArrayView,
1044 if null QByteArray can legitimately be treated as empty ones.
1046 \sa QByteArray::isNull(), QByteArrayView
1050 \fn QByteArrayView::operator std::string_view() const
1053 Converts this QByteArrayView object to a \c{std::string_view} object.
1054 The returned view will have the same data pointer and length of