Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qbytearrayview.qdoc
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3// Qt-Security score:insignificant reason:docs
4
5/*!
6 \class QByteArrayView
7 \inmodule QtCore
8 \brief The QByteArrayView class provides a view on an array of bytes with a read-only
9 subset of the QByteArray API.
10 \since 6.0
11
12 \ingroup tools
13 \ingroup shared
14 \ingroup string-processing
15
16 \reentrant
17
18 \compares strong
19 \compareswith strong QString QStringView QUtf8StringView QLatin1StringView \
20 QChar char16_t
21 When comparing with string and Unicode character types, the content is
22 interpreted as UTF-8.
23 \endcompareswith
24
25 A QByteArrayView references a contiguous portion of raw bytes it does
26 not own. It acts as an interface type to all kinds of byte-array-like data,
27 without the need to construct a QByteArray first.
28
29 The byte array data may be represented as an array (or an array-compatible
30 data-structure such as QByteArray, std::basic_string, etc.) of \c char,
31 \c{signed char}, \c{unsigned char} or \c std::byte.
32
33 QByteArrayView is designed as an interface type; its main use-case is
34 as a function parameter type. When QByteArrayViews are used as automatic
35 variables or data members, care must be taken to ensure that the referenced
36 data (for example, owned by a QByteArray) outlives the QByteArrayView on all
37 code paths, lest the byte array view ends up referencing deleted data.
38
39 When used as an interface type, QByteArrayView allows a single function to accept
40 a wide variety of byte-array-like data sources. One function accepting QByteArrayView
41 thus replaces several function overloads (taking, for example, QByteArray, const char *,
42 etc.) while at the same time enabling even more byte array data sources to be passed
43 to the function.
44
45 QByteArrayView should be passed by value, not by reference-to-const:
46 \snippet code/src_corelib_text_qbytearrayview.cpp 0
47
48 If you want to give your users maximum freedom in what type of data they
49 can pass to your function, accompany the QByteArrayView overload with
50 overloads for
51
52 \list
53 \li \e char: this overload can delegate to the QByteArrayView version:
54 \snippet code/src_corelib_text_qbytearrayview.cpp 1
55 even though, for technical reasons, QByteArrayView cannot provide a
56 char constructor by itself.
57 \li \e QByteArray: if you store an unmodified copy of the byte array and
58 thus would like to take advantage of QByteArray's implicit sharing.
59 \endlist
60
61 QByteArrayView can also be used as the return value of a function. If you call a
62 function returning QByteArrayView, take extra care to not keep the QByteArrayView
63 around longer than the function promises to keep the referenced data alive.
64 If in doubt, obtain a strong reference to the data by calling toByteArray() to convert
65 the QByteArrayView into a QByteArray.
66
67 The methods supported by QByteArrayView reflect those of \l QByteArray. In
68 particular, to the limited degree that it ascribes semantics (such as
69 character case, spacing, digits of numbers) to the character data viewed, it
70 uses the C locale and ASCII encoding. See \l {C locale and ASCII functions}
71 for details and the limitations on these methods.
72
73 \section1 Compatible Byte Types
74
75 QByteArrayView can be constructed on any container of bytes, where the byte type
76 is one of:
77
78 \list
79 \li \c char (both signed and unsigned)
80 \li \c std::byte
81 \endlist
82
83 \sa QByteArray, QStringView
84*/
85
86/*!
87 \typedef QByteArrayView::storage_type
88
89 Alias for \c char.
90*/
91
92/*!
93 \typedef QByteArrayView::value_type
94
95 Alias for \c{const char}. Provided for compatibility with the STL.
96*/
97
98/*!
99 \typedef QByteArrayView::difference_type
100
101 Alias for \c{std::ptrdiff_t}. Provided for compatibility with the STL.
102*/
103
104/*!
105 \typedef QByteArrayView::size_type
106
107 Alias for qsizetype. Provided for compatibility with the STL.
108*/
109
110/*!
111 \typedef QByteArrayView::reference
112
113 Alias for \c{value_type &}. Provided for compatibility with the STL.
114
115 QByteArrayView does not support mutable references, so this is the same
116 as const_reference.
117*/
118
119/*!
120 \typedef QByteArrayView::const_reference
121
122 Alias for \c{value_type &}. Provided for compatibility with the STL.
123*/
124
125/*!
126 \typedef QByteArrayView::pointer
127
128 Alias for \c{value_type *}. Provided for compatibility with the STL.
129
130 QByteArrayView does not support mutable pointers, so this is the same
131 as const_pointer.
132*/
133
134/*!
135 \typedef QByteArrayView::const_pointer
136
137 Alias for \c{value_type *}. Provided for compatibility with the STL.
138*/
139
140/*!
141 \typedef QByteArrayView::iterator
142
143 This typedef provides an STL-style const iterator for QByteArrayView.
144
145 QByteArrayView does not support mutable iterators, so this is the same
146 as const_iterator.
147
148 \sa const_iterator, reverse_iterator
149*/
150
151/*!
152 \typedef QByteArrayView::const_iterator
153
154 This typedef provides an STL-style const iterator for QByteArrayView.
155
156 \sa iterator, const_reverse_iterator
157*/
158
159/*!
160 \typedef QByteArrayView::reverse_iterator
161
162 This typedef provides an STL-style const reverse iterator for QByteArrayView.
163
164 QByteArrayView does not support mutable reverse iterators, so this is the
165 same as const_reverse_iterator.
166
167 \sa const_reverse_iterator, iterator
168*/
169
170/*!
171 \typedef QByteArrayView::const_reverse_iterator
172
173 This typedef provides an STL-style const reverse iterator for QByteArrayView.
174
175 \sa reverse_iterator, const_iterator
176*/
177
178/*!
179 \fn QByteArrayView::QByteArrayView()
180
181 Constructs a null byte array view.
182
183 \sa isNull()
184*/
185
186/*!
187 \fn QByteArrayView::QByteArrayView(std::nullptr_t)
188
189 Constructs a null byte array view.
190
191 \sa isNull()
192*/
193
194/*!
195 \fn template <typename Byte, QByteArrayView::if_compatible_byte<Byte> = true> QByteArrayView::QByteArrayView(const Byte *data, qsizetype len)
196
197 Constructs a byte array view on \a data with length \a len.
198
199 The range \c{[data,len)} must remain valid for the lifetime of this QByteArrayView.
200
201 Passing \nullptr as \a data is safe if \a len is 0, too, and results in a null
202 byte array view.
203
204 The behavior is undefined if \a len is negative or, when positive, if \a data is \nullptr.
205
206 \constraints \c Byte is a compatible byte type.
207
208 \sa {Compatible Byte Types}
209*/
210
211/*!
212 \fn template <typename Byte, QByteArrayView::if_compatible_byte<Byte> = true> QByteArrayView::QByteArrayView(const Byte *first, const Byte *last)
213
214 Constructs a byte array view on \a first with length (\a last - \a first).
215
216 The range \c{[first,last)} must remain valid for the lifetime of
217 this QByteArrayView.
218
219 Passing \c \nullptr as \a first is safe if \a last is \nullptr, too,
220 and results in a null byte array view.
221
222 The behavior is undefined if \a last precedes \a first, or \a first
223 is \nullptr and \a last is not.
224
225 \constraints \c Byte is a compatible byte type.
226
227 \sa {Compatible Byte Types}
228*/
229
230/*!
231 \fn template <typename Byte> QByteArrayView::QByteArrayView(const Byte *data)
232
233 Constructs a byte array view on \a data. The length is determined
234 by scanning for the first \c{Byte(0)}.
235
236 \a data must remain valid for the lifetime of this byte array view object.
237
238 Passing \nullptr as \a data is safe and results in a null byte array view.
239
240 \constraints \a data is not an array and \c Byte is a
241 compatible byte type.
242
243 \sa {Compatible Byte Types}
244*/
245
246/*!
247 \fn template <typename Byte, QByteArrayView::if_compatible_byte<Byte>> QByteArrayView::QByteArrayView(const Byte (&data)[])
248 \since 6.9
249
250 Constructs a byte array view on \a data, an array of unknown size. The
251 length is determined by scanning for the first \c{Byte(0)}.
252
253 \a data must remain valid for the lifetime of this byte array view object.
254
255 \constraints \c Byte is a compatible byte type.
256
257 \sa {Compatible Byte Types}
258*/
259
260/*!
261 \fn template <size_t Size> QByteArrayView::QByteArrayView(const char (&data)[Size])
262
263 Constructs a byte array view on the char array \a data.
264 The view covers the array until the first \c{'\0'} is encountered,
265 or \c Size, whichever comes first.
266 If you need the full array, use fromArray() instead.
267
268 \a data must remain valid for the lifetime of this byte array view
269 object.
270
271 \note This constructor is only available for char array literals.
272 The reasoning behind that is for compatibility with C-libraries
273 which predefine "large-enough" arrays, but only use some of the
274 preallocated space. To support this in an intuitive way in an
275 implicit constructor overload, we need to stop at the first
276 \c{char(0)}. This is logical for a char array, but not
277 for a \c{std::byte} array.
278 It is, however, inconsistent with the corresponding pointer (\c{Byte*}) and
279 unknown-length-array (\c{Byte[]}) constructors, and so might change in a
280 future version of Qt.
281
282 \sa fromArray
283*/
284
285/*!
286 \fn QByteArrayView::QByteArrayView(const QByteArray &byteArray)
287
288 Constructs a byte array view on \a byteArray.
289
290 \c{byteArray.data()} must remain valid for the lifetime of this byte array view object.
291
292 The byte array view will be null if and only if \c{byteArray.isNull()}.
293*/
294
295/*!
296 \fn template <typename Container, QByteArrayView::if_compatible_container<Container> = true> QByteArrayView::QByteArrayView(const Container &c)
297
298 Constructs a byte array view on the array-like container \a c. The length and data
299 are set via \c{std::size(c)} and \c{std::data(c)} respectively.
300
301 The container's data must remain valid for the lifetime of this byte array view object.
302
303 \constraints \a c is any contiguous
304 container with elements of a compatible byte type.
305
306 \sa {Compatible Byte Types}
307*/
308
309/*!
310 \fn template <typename Byte, size_t Size> QByteArrayView QByteArrayView::fromArray(const Byte (&data)[Size])
311
312 Constructs a byte array view on the array literal \a data. The view covers the full
313 array. That includes the trailing null-terminator of \c{char} array literals.
314 If you don't want the null-terminator included in the view, you can chop() it off
315 when you are certain it is at the end. Alternatively you can use the constructor
316 overload taking a char array literal which will create a view up to, but not including,
317 the first null-terminator in the data.
318
319 This function will work with any array literal of a compatible byte type.
320
321 \sa {Compatible Byte Types}, QByteArrayView
322*/
323
324/*!
325 \fn QByteArray QByteArrayView::toByteArray() const
326
327 Returns a deep copy of this byte array view's data as a QByteArray.
328
329 The return value will be a null QByteArray if and only if this byte array
330 view is null.
331*/
332
333/*!
334 \fn const char *QByteArrayView::data() const
335
336 Returns a const \c char pointer to the first byte in the byte array view.
337
338 \note The character array represented by the return value is \e not guaranteed
339 to be null-terminated. The returned pointer is only safe to use for accessing
340 bytes at indices that are less than this byte array view's size().
341
342 \sa begin(), end()
343*/
344
345/*!
346 \fn const char *QByteArrayView::constData() const
347
348 Returns a const \c char pointer to the first byte in the byte array view.
349
350 \note The character array represented by the return value is \e not guaranteed
351 to be null-terminated. The returned pointer is only safe to use for accessing
352 bytes at indices that are less than this byte array view's size().
353
354 \sa data(), begin(), end()
355*/
356
357/*! //! friend
358 \fn int QByteArrayView::operator==(const QByteArrayView &lhs, const QByteArrayView &rhs)
359 \fn int QByteArrayView::operator!=(const QByteArrayView &lhs, const QByteArrayView &rhs)
360 \fn int QByteArrayView::operator< (const QByteArrayView &lhs, const QByteArrayView &rhs)
361 \fn int QByteArrayView::operator<=(const QByteArrayView &lhs, const QByteArrayView &rhs)
362 \fn int QByteArrayView::operator> (const QByteArrayView &lhs, const QByteArrayView &rhs)
363 \fn int QByteArrayView::operator>=(const QByteArrayView &lhs, const QByteArrayView &rhs)
364
365 Comparison operators for QByteArrayView.
366*/
367
368/*!
369 \fn int QByteArrayView::compare(QByteArrayView bv, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
370 \since 6.2
371
372 Returns an integer less than, equal to, or greater than zero depending on
373 whether this QByteArrayView sorts before, at the same position as, or after
374 the QByteArrayView \a bv. The comparison is performed according to case
375 sensitivity \a cs.
376
377 \sa operator==()
378*/
379
380/*!
381 \fn QByteArrayView::isValidUtf8() const
382
383 Returns \c true if this byte array view contains valid UTF-8 encoded data,
384 or \c false otherwise.
385
386 \since 6.3
387*/
388
389/*!
390 \fn QByteArrayView::const_iterator QByteArrayView::begin() const
391
392 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the
393 first byte in the byte array view.
394
395 This function is provided for STL compatibility.
396
397 \sa end(), cbegin(), rbegin(), data()
398*/
399
400/*!
401 \fn QByteArrayView::const_iterator QByteArrayView::cbegin() const
402
403 Same as begin().
404
405 This function is provided for STL compatibility.
406
407 \sa cend(), begin(), crbegin(), data()
408*/
409
410/*!
411 \fn QByteArrayView::const_iterator QByteArrayView::end() const
412
413 Returns a const \l{STL-style iterators}{STL-style iterator} pointing
414 just after the last byte in the byte array view.
415
416 This function is provided for STL compatibility.
417
418 \sa begin(), cend(), rend()
419*/
420
421/*! \fn QByteArrayView::const_iterator QByteArrayView::cend() const
422
423 Same as end().
424
425 This function is provided for STL compatibility.
426
427 \sa cbegin(), end(), crend()
428*/
429
430/*!
431 \fn QByteArrayView::const_reverse_iterator QByteArrayView::rbegin() const
432
433 Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing
434 to the first byte in the byte array view, in reverse order.
435
436 This function is provided for STL compatibility.
437
438 \sa rend(), crbegin(), begin()
439*/
440
441/*!
442 \fn QByteArrayView::const_reverse_iterator QByteArrayView::crbegin() const
443
444 Same as rbegin().
445
446 This function is provided for STL compatibility.
447
448 \sa crend(), rbegin(), cbegin()
449*/
450
451/*!
452 \fn QByteArrayView::const_reverse_iterator QByteArrayView::rend() const
453
454 Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
455 the last byte in the byte array view, in reverse order.
456
457 This function is provided for STL compatibility.
458
459 \sa rbegin(), crend(), end()
460*/
461
462/*!
463 \fn QByteArrayView::const_reverse_iterator QByteArrayView::crend() const
464
465 Same as rend().
466
467 This function is provided for STL compatibility.
468
469 \sa crbegin(), rend(), cend()
470*/
471
472/*!
473 \fn bool QByteArrayView::empty() const
474
475 Returns \c true if this byte array view is empty - that is, \c{size() == 0}.
476
477 This function is provided for STL compatibility.
478
479 \sa isEmpty(), isNull(), size()
480*/
481
482/*!
483 \fn bool QByteArrayView::isEmpty() const
484
485 Returns \c true if this byte array view is empty - that is, \c{size() == 0}.
486
487 \sa empty(), isNull(), size()
488*/
489
490/*!
491 \fn bool QByteArrayView::isNull() const
492
493 Returns \c true if this byte array view is null - that is, \c{data() == nullptr}.
494
495 \sa empty(), isEmpty(), size()
496*/
497
498/*!
499 \fn qsizetype QByteArrayView::size() const
500
501 Returns the number of bytes in this byte array view.
502
503 \sa empty(), isEmpty(), isNull()
504*/
505
506/*!
507 \fn QByteArrayView::length() const
508
509 Same as size().
510
511 \sa empty(), isEmpty(), isNull(), size()
512*/
513
514/*!
515 \fn char QByteArrayView::operator[](qsizetype n) const
516
517 Returns the character at position \a n in this byte array view.
518
519 The behavior is undefined if \a n is negative or not less than size().
520
521 \sa at(), front(), back()
522*/
523
524/*!
525 \fn char QByteArrayView::at(qsizetype n) const
526
527 Returns the character at position \a n in this byte array view.
528
529 The behavior is undefined if \a n is negative or not less than size().
530
531 \sa operator[](), front(), back()
532*/
533
534/*!
535 \fn char QByteArrayView::front() const
536
537 Returns the first byte in the byte array view.
538
539 This function is provided for STL compatibility.
540
541 \warning Calling this function on an empty byte array view constitutes
542 undefined behavior.
543
544 \sa back()
545*/
546
547/*!
548 \fn char QByteArrayView::back() const
549
550 Returns the last byte in the byte array view.
551
552 This function is provided for STL compatibility.
553
554 \warning Calling this function on an empty byte array view constitutes
555 undefined behavior.
556
557 \sa front()
558*/
559
560/*!
561 \fn QByteArrayView QByteArrayView::first(qsizetype n) const
562
563 Returns a byte array view that points to the first \a n bytes
564 of this byte array view. Equivalent to \c{sliced(0, n)}.
565
566 \note The behavior is undefined when \a n < 0 or \a n > size().
567
568 \sa last(), startsWith(), chopped(), chop(), truncate(), sliced(), slice()
569*/
570
571/*!
572 \fn QByteArrayView QByteArrayView::last(qsizetype n) const
573
574 Returns a byte array view that points to the last \a n bytes
575 of this byte array view.
576
577 \note The behavior is undefined when \a n < 0 or \a n > size().
578
579 \sa first(), endsWith(), chopped(), chop(), truncate(), sliced(), slice()
580*/
581
582/*!
583 \fn QByteArrayView QByteArrayView::sliced(qsizetype pos, qsizetype n) const
584
585 Returns a byte array view that points to \a n bytes of this byte array
586 view, starting at position \a pos.
587
588//! [UB-sliced-index-length]
589 \note The behavior is undefined when \a pos < 0, \a n < 0,
590 or \a pos + \a n > size().
591//! [UB-sliced-index-length]
592
593 \sa first(), last(), chopped(), chop(), truncate(), slice()
594*/
595
596/*!
597 \fn QByteArrayView QByteArrayView::sliced(qsizetype pos) const
598
599 Returns a byte array view starting at position \a pos in this object,
600 and extending to its end.
601
602//! [UB-sliced-index-only]
603 \note The behavior is undefined when \a pos < 0 or \a pos > size().
604//! [UB-sliced-index-only]
605
606 \sa first(), last(), chopped(), chop(), truncate(), slice()
607*/
608
609/*!
610 \fn QByteArrayView &QByteArrayView::slice(qsizetype pos, qsizetype n)
611 \since 6.8
612
613 Modifies this byte array view to start at position \a pos, extending for
614 \a n bytes.
615
616 \include qbytearrayview.qdoc UB-sliced-index-length
617
618 \sa sliced(), first(), last(), chopped(), chop(), truncate()
619*/
620
621/*!
622 \fn QByteArrayView &QByteArrayView::slice(qsizetype pos)
623 \since 6.8
624 \overload
625
626 Modifies this byte array view to start at position \a pos, extending
627 to its end.
628
629 \include qbytearrayview.qdoc UB-sliced-index-only
630
631 \sa sliced(), first(), last(), chopped(), chop(), truncate()
632*/
633
634/*!
635 \fn QByteArrayView QByteArrayView::chopped(qsizetype length) const
636
637 Returns a copy of this byte array view that omits its last \a length bytes.
638 In other words, returns a byte array view of length size() - \a length starting
639 at the beginning of this object.
640
641 Same as \c{first(size() - length)}.
642
643 \note The behavior is undefined when \a length < 0 or \a length > size().
644
645 \sa first(), last(), sliced(), chop(), truncate(), slice()
646*/
647
648/*!
649 \fn void QByteArrayView::truncate(qsizetype length)
650
651 Truncates this byte array view to length \a length.
652
653 Same as \c{*this = first(length)}.
654
655 \note The behavior is undefined when \a length < 0 or \a length > size().
656
657 \sa first(), last(), sliced(), chopped(), chop()
658*/
659
660/*!
661 \fn void QByteArrayView::chop(qsizetype length)
662
663 Truncates this byte array view by \a length characters.
664
665 Same as \c{*this = first(size() - length)}.
666
667 \note The behavior is undefined when \a length < 0 or \a length > size().
668
669 \sa sliced(), first(), last(), chopped(), truncate(), slice()
670*/
671
672/*!
673 \fn QByteArrayView QByteArrayView::mid(qsizetype start, qsizetype length) const
674 \since 6.5
675
676 \deprecated Use sliced() instead in new code.
677
678 Returns the subarray of length \a length starting at position
679 \a start in this object.
680
681 Returns an empty byte array view if \a start exceeds the
682 length of the byte array view. If there are less than \a length characters
683 available in the byte array view starting at \a start, or if
684 \a length is negative (default), the function returns all characters that
685 are available from \a start.
686
687 \sa first(), last(), sliced(), chopped(), chop(), truncate(), slice()
688*/
689
690/*!
691 \fn QByteArrayView QByteArrayView::left(qsizetype length) const
692 \since 6.5
693
694 \deprecated Use first() instead in new code.
695
696 Returns the subarray of length \a length starting at position
697 0 in this object.
698
699 The entire byte array view is returned if \a length is greater than or equal
700 to size(), or less than zero.
701
702 \sa first(), last(), sliced(), startsWith(), chopped(), chop(), truncate(), slice()
703*/
704
705/*!
706 \fn QByteArrayView QByteArrayView::right(qsizetype length) const
707 \since 6.5
708
709 \deprecated Use last() instead in new code.
710
711 Returns the subarray of length \a length starting at position
712 size() - \a length in this object.
713
714 The entire byte array view is returned if \a length is greater than or equal
715 to size(), or less than zero.
716
717 \sa first(), last(), sliced(), endsWith(), chopped(), chop(), truncate(), slice()
718*/
719
720/*!
721 \fn QByteArrayView QByteArrayView::trimmed() const noexcept
722 \since 6.3
723
724 Returns a copy of this byte array view with spacing characters
725 removed from the start and end.
726
727 The spacing characters are those for which the standard C++ \c isspace()
728 function returns \c true in the C locale; these are the ASCII characters
729 tabulation '\\t', line feed '\\n', carriage return '\\r', vertical
730 tabulation '\\v', form feed '\\f', and space ' '.
731
732 \sa QChar::SpecialCharacter, {QByteArray#Spacing Characters}{Spacing Characters}
733*/
734
735/*!
736 \fn qlonglong QByteArrayView::toLongLong(bool *ok, int base) const
737 \since 6.3
738
739 Returns this byte array view converted to a \c {long long} using base \a
740 base, which is ten by default. Bases 0 and 2 through 36 are supported, using
741 letters for digits beyond 9; A is ten, B is eleven and so on.
742
743 If \a base is 0, the base is determined automatically using the following
744 rules: if the byte array view begins with "0x", the rest of it is read as
745 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
746 read as octal (base 8); otherwise it is read as decimal.
747
748 Returns 0 if the conversion fails.
749
750 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
751 to \c false, and success by setting *\a{ok} to \c true.
752
753 \note The conversion of the number is performed in the default C locale,
754 regardless of the user's locale. Use QLocale to perform locale-aware
755 conversions between numbers and strings.
756*/
757
758/*!
759 \fn qulonglong QByteArrayView::toULongLong(bool *ok, int base) const
760 \since 6.3
761
762 Returns this byte array view converted to an \c {unsigned long long} using
763 base \a base, which is ten by default. Bases 0 and 2 through 36 are
764 supported, using letters for digits beyond 9; A is ten, B is eleven and so
765 on.
766
767 If \a base is 0, the base is determined automatically using the following
768 rules: if the byte array view begins with "0x", the rest of it is read as
769 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
770 read as octal (base 8); otherwise it is read as decimal.
771
772 Returns 0 if the conversion fails.
773
774 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
775 to \c false, and success by setting *\a{ok} to \c true.
776
777 \note The conversion of the number is performed in the default C locale,
778 regardless of the user's locale. Use QLocale to perform locale-aware
779 conversions between numbers and strings.
780*/
781
782/*!
783 \fn int QByteArrayView::toInt(bool *ok, int base) const
784 \since 6.3
785
786 Returns this byte array view converted to an \c int using base \a base,
787 which is ten by default. Bases 0 and 2 through 36 are supported, using
788 letters for digits beyond 9; A is ten, B is eleven and so on.
789
790 If \a base is 0, the base is determined automatically using the following
791 rules: if the byte array view begins with "0x", the rest of it is read as
792 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
793 read as octal (base 8); otherwise it is read as decimal.
794
795 Returns 0 if the conversion fails.
796
797 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
798 to \c false, and success by setting *\a{ok} to \c true.
799
800 \snippet code/src_corelib_text_qbytearrayview.cpp 2
801
802 \note The conversion of the number is performed in the default C locale,
803 regardless of the user's locale. Use QLocale to perform locale-aware
804 conversions between numbers and strings.
805*/
806
807/*!
808 \fn uint QByteArrayView::toUInt(bool *ok, int base) const
809 \since 6.3
810
811 Returns this byte array view converted to an \c {unsigned int} using base \a
812 base, which is ten by default. Bases 0 and 2 through 36 are supported, using
813 letters for digits beyond 9; A is ten, B is eleven and so on.
814
815 If \a base is 0, the base is determined automatically using the following
816 rules: if the byte array view begins with "0x", the rest of it is read as
817 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
818 read as octal (base 8); otherwise it is read as decimal.
819
820 Returns 0 if the conversion fails.
821
822 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
823 to \c false, and success by setting *\a{ok} to \c true.
824
825 \note The conversion of the number is performed in the default C locale,
826 regardless of the user's locale. Use QLocale to perform locale-aware
827 conversions between numbers and strings.
828*/
829
830/*!
831 \fn long QByteArrayView::toLong(bool *ok, int base) const
832 \since 6.3
833
834 Returns this byte array view converted to a \c long int using base \a base,
835 which is ten by default. Bases 0 and 2 through 36 are supported, using
836 letters for digits beyond 9; A is ten, B is eleven and so on.
837
838 If \a base is 0, the base is determined automatically using the following
839 rules: if the byte array view begins with "0x", the rest of it is read as
840 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
841 read as octal (base 8); otherwise it is read as decimal.
842
843 Returns 0 if the conversion fails.
844
845 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
846 to \c false, and success by setting *\a{ok} to \c true.
847
848 \snippet code/src_corelib_text_qbytearrayview.cpp 3
849
850 \note The conversion of the number is performed in the default C locale,
851 regardless of the user's locale. Use QLocale to perform locale-aware
852 conversions between numbers and strings.
853*/
854
855/*!
856 \fn ulong QByteArrayView::toULong(bool *ok, int base) const
857 \since 6.3
858
859 Returns this byte array view converted to an \c {unsigned long int} using
860 base \a base, which is ten by default. Bases 0 and 2 through 36 are
861 supported, using letters for digits beyond 9; A is ten, B is eleven and so
862 on.
863
864 If \a base is 0, the base is determined automatically using the following
865 rules: if the byte array view begins with "0x", the rest of it is read as
866 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
867 read as octal (base 8); otherwise it is read as decimal.
868
869 Returns 0 if the conversion fails.
870
871 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
872 to \c false, and success by setting *\a{ok} to \c true.
873
874 \note The conversion of the number is performed in the default C locale,
875 regardless of the user's locale. Use QLocale to perform locale-aware
876 conversions between numbers and strings.
877*/
878
879/*!
880 \fn short QByteArrayView::toShort(bool *ok, int base) const
881 \since 6.3
882
883 Returns this byte array view converted to a \c short using base \a base,
884 which is ten by default. Bases 0 and 2 through 36 are supported, using
885 letters for digits beyond 9; A is ten, B is eleven and so on.
886
887 If \a base is 0, the base is determined automatically using the following
888 rules: if the byte array view begins with "0x", the rest of it is read as
889 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
890 read as octal (base 8); otherwise it is read as decimal.
891
892 Returns 0 if the conversion fails.
893
894 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
895 to \c false, and success by setting *\a{ok} to \c true.
896
897 \note The conversion of the number is performed in the default C locale,
898 regardless of the user's locale. Use QLocale to perform locale-aware
899 conversions between numbers and strings.
900*/
901
902/*!
903 \fn ushort QByteArrayView::toUShort(bool *ok, int base) const
904 \since 6.3
905
906 Returns this byte array view converted to an \c {unsigned short} using base
907 \a base, which is ten by default. Bases 0 and 2 through 36 are supported,
908 using letters for digits beyond 9; A is ten, B is eleven and so on.
909
910 If \a base is 0, the base is determined automatically using the following
911 rules: if the byte array view begins with "0x", the rest of it is read as
912 hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
913 read as octal (base 8); otherwise it is read as decimal.
914
915 Returns 0 if the conversion fails.
916
917 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
918 to \c false, and success by setting *\a{ok} to \c true.
919
920 \note The conversion of the number is performed in the default C locale,
921 regardless of the user's locale. Use QLocale to perform locale-aware
922 conversions between numbers and strings.
923*/
924
925/*!
926 \fn double QByteArrayView::toDouble(bool *ok) const
927 \since 6.3
928
929 Returns this byte array view converted to a \c double value.
930
931 Returns an infinity if the conversion overflows or 0.0 if the
932 conversion fails for other reasons (e.g. underflow).
933
934 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
935 to \c false, and success by setting *\a{ok} to \c true.
936
937 \warning The QByteArrayView content may only contain valid numerical
938 characters which includes the plus/minus sign, the character e used in
939 scientific notation, and the decimal point. Including the unit or additional
940 characters leads to a conversion error.
941
942 \note The conversion of the number is performed in the default C locale,
943 regardless of the user's locale. Use QLocale to perform locale-aware
944 conversions between numbers and strings.
945
946 This function ignores leading and trailing spacing characters.
947*/
948
949/*!
950 \fn float QByteArrayView::toFloat(bool *ok) const
951 \since 6.3
952
953 Returns this byte array view converted to a \c float value.
954
955 Returns an infinity if the conversion overflows or 0.0 if the
956 conversion fails for other reasons (e.g. underflow).
957
958 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
959 to \c false, and success by setting *\a{ok} to \c true.
960
961 \snippet code/src_corelib_text_qbytearrayview.cpp 4
962
963 \warning The QByteArrayView content may only contain valid numerical
964 characters which includes the plus/minus sign, the character e used in
965 scientific notation, and the decimal point. Including the unit or additional
966 characters leads to a conversion error.
967
968 \note The conversion of the number is performed in the default C locale,
969 regardless of the user's locale. Use QLocale to perform locale-aware
970 conversions between numbers and strings.
971
972 This function ignores leading and trailing whitespace.
973*/
974
975/*!
976 \fn bool QByteArrayView::startsWith(QByteArrayView bv) const
977 \fn bool QByteArrayView::startsWith(char ch) const
978
979 Returns \c true if this byte array view starts with byte array view \a bv
980 or character \a ch, respectively; otherwise returns \c false.
981
982 \sa endsWith()
983*/
984
985/*!
986 \fn bool QByteArrayView::endsWith(QByteArrayView bv) const
987 \fn bool QByteArrayView::endsWith(char ch) const
988
989 Returns \c true if this byte array view ends with byte array view \a bv
990 or character \a ch, respectively; otherwise returns \c false.
991
992 \sa startsWith()
993*/
994
995/*!
996 \fn qsizetype QByteArrayView::indexOf(QByteArrayView bv, qsizetype from = 0) const
997 \fn qsizetype QByteArrayView::indexOf(char ch, qsizetype from = 0) const
998
999 Returns the index position of either the start of the first occurrence of
1000 the sequence of bytes viewed by \a bv or the first occurrence of byte \a ch,
1001 respectively, in this byte array view, searching forward from index position
1002 \a from.Returns -1 if no match is found.
1003
1004 \include qstring.qdocinc negative-index-start-search-from-end
1005
1006 \sa lastIndexOf(), contains()
1007*/
1008
1009/*!
1010 \fn bool QByteArrayView::contains(QByteArrayView bv) const
1011 \fn bool QByteArrayView::contains(char ch) const
1012
1013 Returns \c true if this byte array view contains an occurrence of the sequence
1014 of bytes viewed by \a bv or character \a ch, respectively; otherwise returns
1015 \c false.
1016
1017 \sa indexOf(), lastIndexOf()
1018*/
1019
1020/*!
1021 \fn qsizetype QByteArrayView::lastIndexOf(QByteArrayView bv, qsizetype from) const
1022 \fn qsizetype QByteArrayView::lastIndexOf(char ch, qsizetype from = -1) const
1023
1024 Returns the index position of either the start of the last occurrence of
1025 the sequence of bytes viewed by \a bv or the last occurrence of byte \a ch,
1026 respectively, in this byte array view, searching backward from index position
1027 \a from.
1028
1029 \include qstring.qdocinc negative-index-start-search-from-end
1030
1031 Returns -1 if no match is found.
1032
1033 \note When searching for a 0-length \a bv, the match at the end of
1034 the data is excluded from the search by a negative \a from, even
1035 though \c{-1} is normally thought of as searching from the end of
1036 the view: the match at the end is \e after the last character, so
1037 it is excluded. To include such a final empty match, either give a
1038 positive value for \a from or omit the \a from parameter entirely.
1039
1040 \sa indexOf(), contains()
1041*/
1042
1043/*!
1044 \fn qsizetype QByteArrayView::lastIndexOf(QByteArrayView bv) const
1045 \since 6.2
1046 \overload
1047
1048 Returns the index position of the start of the last
1049 occurrence of the sequence of bytes viewed by \a bv in this byte
1050 array view, searching backward from the end of this byte array
1051 view. Returns -1 if no match is found.
1052
1053 \sa indexOf(), contains()
1054*/
1055
1056/*!
1057 \fn qsizetype QByteArrayView::count(QByteArrayView bv) const
1058
1059 Returns the number of (potentially overlapping) occurrences of the
1060 sequence of bytes viewed by \a bv in this byte array view.
1061
1062 \sa contains(), indexOf()
1063*/
1064
1065/*!
1066 \fn bool QByteArrayView::count(char ch) const
1067 \overload
1068
1069 Returns the number of occurrences of byte \a ch in this byte array view.
1070
1071 \sa contains(), indexOf()
1072*/
1073
1074/*!
1075 \fn QByteArrayView qToByteArrayViewIgnoringNull(const QByteArray &b);
1076 \internal
1077
1078 Convert \a b to a QByteArrayView ignoring \c{b.isNull()}.
1079
1080 Returns a byte array view that references \a{b}'s data, but is never null.
1081
1082 This is a faster way to convert a QByteArray to a QByteArrayView,
1083 if null QByteArray can legitimately be treated as empty ones.
1084
1085 \sa QByteArray::isNull(), QByteArrayView
1086*/
1087
1088/*!
1089 \fn QByteArrayView::operator std::string_view() const
1090 \since 6.7
1091
1092 Converts this QByteArrayView object to a \c{std::string_view} object.
1093 The returned view will have the same data pointer and length of
1094 this view.
1095*/
1096
1097/*!
1098 \fn QByteArrayView::maxSize()
1099 \since 6.8
1100
1101 It returns the maximum number of elements that the view can
1102 theoretically represent. In practice, the number can be much smaller,
1103 limited by the amount of memory available to the system.
1104*/
1105
1106/*!
1107 \fn QByteArrayView::max_size() const
1108 \since 6.8
1109
1110 This function is provided for STL compatibility.
1111
1112 Returns maxSize().
1113*/