Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4/*!
5 \class QByteArrayView
6 \inmodule QtCore
7 \brief The QByteArrayView class provides a view on an array of bytes with a read-only
8 subset of the QByteArray API.
9 \since 6.0
10
11 \ingroup tools
12 \ingroup shared
13 \ingroup string-processing
14
15 \reentrant
16
17 \compares strong
18 \compareswith strong QByteArray {const char *}
19 \endcompareswith
20 \compareswith strong QString QStringView QUtf8StringView QLatin1StringView \
21 QChar char16_t
22 When comparing with string and Unicode character types, the content is
23 interpreted as UTF-8.
24 \endcompareswith
25
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.
29
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.
33
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.
39
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
44 to the function.
45
46 QByteArrayView should be passed by value, not by reference-to-const:
47 \snippet code/src_corelib_text_qbytearrayview.cpp 0
48
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
51 overloads for
52
53 \list
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.
60 \endlist
61
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.
67
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.
73
74 \section1 Compatible Byte Types
75
76 QByteArrayView can be constructed on any container of bytes, where the byte type
77 is one of:
78
79 \list
80 \li \c char (both signed and unsigned)
81 \li \c std::byte
82 \endlist
83
84 \sa QByteArray, QStringView
85*/
86
87/*!
88 \typedef QByteArrayView::storage_type
89
90 Alias for \c char.
91*/
92
93/*!
94 \typedef QByteArrayView::value_type
95
96 Alias for \c{const char}. Provided for compatibility with the STL.
97*/
98
99/*!
100 \typedef QByteArrayView::difference_type
101
102 Alias for \c{std::ptrdiff_t}. Provided for compatibility with the STL.
103*/
104
105/*!
106 \typedef QByteArrayView::size_type
107
108 Alias for qsizetype. Provided for compatibility with the STL.
109*/
110
111/*!
112 \typedef QByteArrayView::reference
113
114 Alias for \c{value_type &}. Provided for compatibility with the STL.
115
116 QByteArrayView does not support mutable references, so this is the same
117 as const_reference.
118*/
119
120/*!
121 \typedef QByteArrayView::const_reference
122
123 Alias for \c{value_type &}. Provided for compatibility with the STL.
124*/
125
126/*!
127 \typedef QByteArrayView::pointer
128
129 Alias for \c{value_type *}. Provided for compatibility with the STL.
130
131 QByteArrayView does not support mutable pointers, so this is the same
132 as const_pointer.
133*/
134
135/*!
136 \typedef QByteArrayView::const_pointer
137
138 Alias for \c{value_type *}. Provided for compatibility with the STL.
139*/
140
141/*!
142 \typedef QByteArrayView::iterator
143
144 This typedef provides an STL-style const iterator for QByteArrayView.
145
146 QByteArrayView does not support mutable iterators, so this is the same
147 as const_iterator.
148
149 \sa const_iterator, reverse_iterator
150*/
151
152/*!
153 \typedef QByteArrayView::const_iterator
154
155 This typedef provides an STL-style const iterator for QByteArrayView.
156
157 \sa iterator, const_reverse_iterator
158*/
159
160/*!
161 \typedef QByteArrayView::reverse_iterator
162
163 This typedef provides an STL-style const reverse iterator for QByteArrayView.
164
165 QByteArrayView does not support mutable reverse iterators, so this is the
166 same as const_reverse_iterator.
167
168 \sa const_reverse_iterator, iterator
169*/
170
171/*!
172 \typedef QByteArrayView::const_reverse_iterator
173
174 This typedef provides an STL-style const reverse iterator for QByteArrayView.
175
176 \sa reverse_iterator, const_iterator
177*/
178
179/*!
180 \fn QByteArrayView::QByteArrayView()
181
182 Constructs a null byte array view.
183
184 \sa isNull()
185*/
186
187/*!
188 \fn QByteArrayView::QByteArrayView(std::nullptr_t)
189
190 Constructs a null byte array view.
191
192 \sa isNull()
193*/
194
195/*!
196 \fn template <typename Byte, QByteArrayView::if_compatible_byte<Byte> = true> QByteArrayView::QByteArrayView(const Byte *data, qsizetype len)
197
198 Constructs a byte array view on \a data with length \a len.
199
200 The range \c{[data,len)} must remain valid for the lifetime of this QByteArrayView.
201
202 Passing \nullptr as \a data is safe if \a len is 0, too, and results in a null
203 byte array view.
204
205 The behavior is undefined if \a len is negative or, when positive, if \a data is \nullptr.
206
207 This constructor only participates in overload resolution if \c Byte is a compatible
208 byte type.
209
210 \sa {Compatible Byte Types}
211*/
212
213/*!
214 \fn template <typename Byte, QByteArrayView::if_compatible_byte<Byte> = true> QByteArrayView::QByteArrayView(const Byte *first, const Byte *last)
215
216 Constructs a byte array view on \a first with length (\a last - \a first).
217
218 The range \c{[first,last)} must remain valid for the lifetime of
219 this QByteArrayView.
220
221 Passing \c \nullptr as \a first is safe if \a last is \nullptr, too,
222 and results in a null byte array view.
223
224 The behavior is undefined if \a last precedes \a first, or \a first
225 is \nullptr and \a last is not.
226
227 This constructor only participates in overload resolution if \c Byte is
228 a compatible byte type.
229
230 \sa {Compatible Byte Types}
231*/
232
233/*!
234 \fn template <typename Byte> QByteArrayView::QByteArrayView(const Byte *data)
235
236 Constructs a byte array view on \a data. The length is determined
237 by scanning for the first \c{Byte(0)}.
238
239 \a data must remain valid for the lifetime of this byte array view object.
240
241 Passing \nullptr as \a data is safe and results in a null byte array view.
242
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.
245
246 \sa {Compatible Byte Types}
247*/
248
249/*!
250 \fn template <size_t Size> QByteArrayView::QByteArrayView(const char (&data)[Size])
251
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.
256
257 \a data must remain valid for the lifetime of this byte array view
258 object.
259
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.
267
268 \sa fromArray
269*/
270
271/*!
272 \fn QByteArrayView::QByteArrayView(const QByteArray &byteArray)
273
274 Constructs a byte array view on \a byteArray.
275
276 \c{byteArray.data()} must remain valid for the lifetime of this byte array view object.
277
278 The byte array view will be null if and only if \c{byteArray.isNull()}.
279*/
280
281/*!
282 \fn template <typename Container, QByteArrayView::if_compatible_container<Container> = true> QByteArrayView::QByteArrayView(const Container &c)
283
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.
286
287 The container's data must remain valid for the lifetime of this byte array view object.
288
289 This constructor participates in overload resolution if \a c is any contiguous
290 container with elements of a compatible byte type.
291
292 \sa {Compatible Byte Types}
293*/
294
295/*!
296 \fn template <typename Byte, size_t Size> QByteArrayView QByteArrayView::fromArray(const Byte (&data)[Size])
297
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.
304
305 This function will work with any array literal of a compatible byte type.
306
307 \sa {Compatible Byte Types}, QByteArrayView
308*/
309
310/*!
311 \fn QByteArray QByteArrayView::toByteArray() const
312
313 Returns a deep copy of this byte array view's data as a QByteArray.
314
315 The return value will be a null QByteArray if and only if this byte array
316 view is null.
317*/
318
319/*!
320 \fn const char *QByteArrayView::data() const
321
322 Returns a const \c char pointer to the first byte in the byte array view.
323
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().
327
328 \sa begin(), end()
329*/
330
331/*!
332 \fn const char *QByteArrayView::constData() const
333
334 Returns a const \c char pointer to the first byte in the byte array view.
335
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().
339
340 \sa data(), begin(), end()
341*/
342
343/*! //! friend
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)
350
351 Comparison operators for QByteArrayView.
352*/
353
354/*!
355 \fn int QByteArrayView::compare(QByteArrayView bv, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
356 \since 6.2
357
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
361 sensitivity \a cs.
362
363 \sa operator==()
364*/
365
366/*!
367 \fn QByteArrayView::isValidUtf8() const
368
369 Returns \c true if this byte array view contains valid UTF-8 encoded data,
370 or \c false otherwise.
371
372 \since 6.3
373*/
374
375/*!
376 \fn QByteArrayView::const_iterator QByteArrayView::begin() const
377
378 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the
379 first byte in the byte array view.
380
381 This function is provided for STL compatibility.
382
383 \sa end(), cbegin(), rbegin(), data()
384*/
385
386/*!
387 \fn QByteArrayView::const_iterator QByteArrayView::cbegin() const
388
389 Same as begin().
390
391 This function is provided for STL compatibility.
392
393 \sa cend(), begin(), crbegin(), data()
394*/
395
396/*!
397 \fn QByteArrayView::const_iterator QByteArrayView::end() const
398
399 Returns a const \l{STL-style iterators}{STL-style iterator} pointing
400 just after the last byte in the byte array view.
401
402 This function is provided for STL compatibility.
403
404 \sa begin(), cend(), rend()
405*/
406
407/*! \fn QByteArrayView::const_iterator QByteArrayView::cend() const
408
409 Same as end().
410
411 This function is provided for STL compatibility.
412
413 \sa cbegin(), end(), crend()
414*/
415
416/*!
417 \fn QByteArrayView::const_reverse_iterator QByteArrayView::rbegin() const
418
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.
421
422 This function is provided for STL compatibility.
423
424 \sa rend(), crbegin(), begin()
425*/
426
427/*!
428 \fn QByteArrayView::const_reverse_iterator QByteArrayView::crbegin() const
429
430 Same as rbegin().
431
432 This function is provided for STL compatibility.
433
434 \sa crend(), rbegin(), cbegin()
435*/
436
437/*!
438 \fn QByteArrayView::const_reverse_iterator QByteArrayView::rend() const
439
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.
442
443 This function is provided for STL compatibility.
444
445 \sa rbegin(), crend(), end()
446*/
447
448/*!
449 \fn QByteArrayView::const_reverse_iterator QByteArrayView::crend() const
450
451 Same as rend().
452
453 This function is provided for STL compatibility.
454
455 \sa crbegin(), rend(), cend()
456*/
457
458/*!
459 \fn bool QByteArrayView::empty() const
460
461 Returns \c true if this byte array view is empty - that is, \c{size() == 0}.
462
463 This function is provided for STL compatibility.
464
465 \sa isEmpty(), isNull(), size()
466*/
467
468/*!
469 \fn bool QByteArrayView::isEmpty() const
470
471 Returns \c true if this byte array view is empty - that is, \c{size() == 0}.
472
473 \sa empty(), isNull(), size()
474*/
475
476/*!
477 \fn bool QByteArrayView::isNull() const
478
479 Returns \c true if this byte array view is null - that is, \c{data() == nullptr}.
480
481 \sa empty(), isEmpty(), size()
482*/
483
484/*!
485 \fn qsizetype QByteArrayView::size() const
486
487 Returns the number of bytes in this byte array view.
488
489 \sa empty(), isEmpty(), isNull()
490*/
491
492/*!
493 \fn QByteArrayView::length() const
494
495 Same as size().
496
497 \sa empty(), isEmpty(), isNull(), size()
498*/
499
500/*!
501 \fn char QByteArrayView::operator[](qsizetype n) const
502
503 Returns the character at position \a n in this byte array view.
504
505 The behavior is undefined if \a n is negative or not less than size().
506
507 \sa at(), front(), back()
508*/
509
510/*!
511 \fn char QByteArrayView::at(qsizetype n) const
512
513 Returns the character at position \a n in this byte array view.
514
515 The behavior is undefined if \a n is negative or not less than size().
516
517 \sa operator[](), front(), back()
518*/
519
520/*!
521 \fn char QByteArrayView::front() const
522
523 Returns the first byte in the byte array view.
524
525 This function is provided for STL compatibility.
526
527 \warning Calling this function on an empty byte array view constitutes
528 undefined behavior.
529
530 \sa back()
531*/
532
533/*!
534 \fn char QByteArrayView::back() const
535
536 Returns the last byte in the byte array view.
537
538 This function is provided for STL compatibility.
539
540 \warning Calling this function on an empty byte array view constitutes
541 undefined behavior.
542
543 \sa front()
544*/
545
546/*!
547 \fn QByteArrayView QByteArrayView::first(qsizetype n) const
548
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)}.
551
552 \note The behavior is undefined when \a n < 0 or \a n > size().
553
554 \sa last(), startsWith(), chopped(), chop(), truncate()
555*/
556
557/*!
558 \fn QByteArrayView QByteArrayView::last(qsizetype n) const
559
560 Returns a byte array view that points to the last \a n bytes
561 of this byte array view.
562
563 \note The behavior is undefined when \a n < 0 or \a n > size().
564
565 \sa first(), endsWith(), chopped(), chop(), truncate()
566*/
567
568/*!
569 \fn QByteArrayView QByteArrayView::sliced(qsizetype pos, qsizetype n) const
570
571 Returns a byte array view that points to \a n bytes of this byte array
572 view, starting at position \a pos.
573
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]
578
579 \sa first(), last(), chopped(), chop(), truncate()
580*/
581
582/*!
583 \fn QByteArrayView QByteArrayView::sliced(qsizetype pos) const
584
585 Returns a byte array view starting at position \a pos in this object,
586 and extending to its end.
587
588//! [UB-sliced-index-only]
589 \note The behavior is undefined when \a pos < 0 or \a pos > size().
590//! [UB-sliced-index-only]
591
592 \sa first(), last(), chopped(), chop(), truncate()
593*/
594
595/*!
596 \fn QByteArrayView QByteArrayView::chopped(qsizetype length) const
597
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.
601
602 Same as \c{first(size() - length)}.
603
604 \note The behavior is undefined when \a length < 0 or \a length > size().
605
606 \sa first(), last(), sliced(), chop(), truncate()
607*/
608
609/*!
610 \fn void QByteArrayView::truncate(qsizetype length)
611
612 Truncates this byte array view to length \a length.
613
614 Same as \c{*this = first(length)}.
615
616 \note The behavior is undefined when \a length < 0 or \a length > size().
617
618 \sa first(), last(), sliced(), chopped(), chop()
619*/
620
621/*!
622 \fn void QByteArrayView::chop(qsizetype length)
623
624 Truncates this byte array view by \a length characters.
625
626 Same as \c{*this = first(size() - length)}.
627
628 \note The behavior is undefined when \a length < 0 or \a length > size().
629
630 \sa sliced(), first(), last(), chopped(), truncate()
631*/
632
633/*!
634 \fn QByteArrayView QByteArrayView::mid(qsizetype start, qsizetype length) const
635 \since 6.5
636
637 \deprecated Use sliced() instead in new code.
638
639 Returns the subarray of length \a length starting at position
640 \a start in this object.
641
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.
647
648 \sa first(), last(), sliced(), chopped(), chop(), truncate()
649*/
650
651/*!
652 \fn QByteArrayView QByteArrayView::left(qsizetype length) const
653 \since 6.5
654
655 \deprecated Use first() instead in new code.
656
657 Returns the subarray of length \a length starting at position
658 0 in this object.
659
660 The entire byte array view is returned if \a length is greater than or equal
661 to size(), or less than zero.
662
663 \sa first(), last(), sliced(), startsWith(), chopped(), chop(), truncate()
664*/
665
666/*!
667 \fn QByteArrayView QByteArrayView::right(qsizetype length) const
668 \since 6.5
669
670 \deprecated Use last() instead in new code.
671
672 Returns the subarray of length \a length starting at position
673 size() - \a length in this object.
674
675 The entire byte array view is returned if \a length is greater than or equal
676 to size(), or less than zero.
677
678 \sa first(), last(), sliced(), endsWith(), chopped(), chop(), truncate()
679*/
680
681/*!
682 \fn QByteArrayView QByteArrayView::trimmed() const noexcept
683 \since 6.3
684
685 Returns a copy of this byte array view with spacing characters
686 removed from the start and end.
687
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 ' '.
692
693 \sa QChar::SpecialCharacter, {QByteArray#Spacing Characters}{Spacing Characters}
694*/
695
696/*!
697 \fn qlonglong QByteArrayView::toLongLong(bool *ok, int base) const
698 \since 6.3
699
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.
703
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.
708
709 Returns 0 if the conversion fails.
710
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.
713
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.
717*/
718
719/*!
720 \fn qulonglong QByteArrayView::toULongLong(bool *ok, int base) const
721 \since 6.3
722
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
726 on.
727
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.
732
733 Returns 0 if the conversion fails.
734
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.
737
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.
741*/
742
743/*!
744 \fn int QByteArrayView::toInt(bool *ok, int base) const
745 \since 6.3
746
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.
750
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.
755
756 Returns 0 if the conversion fails.
757
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.
760
761 \snippet code/src_corelib_text_qbytearrayview.cpp 2
762
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.
766*/
767
768/*!
769 \fn uint QByteArrayView::toUInt(bool *ok, int base) const
770 \since 6.3
771
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.
775
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.
780
781 Returns 0 if the conversion fails.
782
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.
785
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.
789*/
790
791/*!
792 \fn long QByteArrayView::toLong(bool *ok, int base) const
793 \since 6.3
794
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.
798
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.
803
804 Returns 0 if the conversion fails.
805
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.
808
809 \snippet code/src_corelib_text_qbytearrayview.cpp 3
810
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.
814*/
815
816/*!
817 \fn ulong QByteArrayView::toULong(bool *ok, int base) const
818 \since 6.3
819
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
823 on.
824
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.
829
830 Returns 0 if the conversion fails.
831
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.
834
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.
838*/
839
840/*!
841 \fn short QByteArrayView::toShort(bool *ok, int base) const
842 \since 6.3
843
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.
847
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.
852
853 Returns 0 if the conversion fails.
854
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.
857
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.
861*/
862
863/*!
864 \fn ushort QByteArrayView::toUShort(bool *ok, int base) const
865 \since 6.3
866
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.
870
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.
875
876 Returns 0 if the conversion fails.
877
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.
880
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.
884*/
885
886/*!
887 \fn double QByteArrayView::toDouble(bool *ok) const
888 \since 6.3
889
890 Returns this byte array view converted to a \c double value.
891
892 Returns an infinity if the conversion overflows or 0.0 if the
893 conversion fails for other reasons (e.g. underflow).
894
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.
897
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.
902
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.
906
907 This function ignores leading and trailing spacing characters.
908*/
909
910/*!
911 \fn float QByteArrayView::toFloat(bool *ok) const
912 \since 6.3
913
914 Returns this byte array view converted to a \c float value.
915
916 Returns an infinity if the conversion overflows or 0.0 if the
917 conversion fails for other reasons (e.g. underflow).
918
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.
921
922 \snippet code/src_corelib_text_qbytearrayview.cpp 4
923
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.
928
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.
932
933 This function ignores leading and trailing whitespace.
934*/
935
936/*!
937 \fn bool QByteArrayView::startsWith(QByteArrayView bv) const
938 \fn bool QByteArrayView::startsWith(char ch) const
939
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.
942
943 \sa endsWith()
944*/
945
946/*!
947 \fn bool QByteArrayView::endsWith(QByteArrayView bv) const
948 \fn bool QByteArrayView::endsWith(char ch) const
949
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.
952
953 \sa startsWith()
954*/
955
956/*!
957 \fn qsizetype QByteArrayView::indexOf(QByteArrayView bv, qsizetype from = 0) const
958 \fn qsizetype QByteArrayView::indexOf(char ch, qsizetype from = 0) const
959
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.
964
965 \include qstring.qdocinc negative-index-start-search-from-end
966
967 \sa lastIndexOf(), contains()
968*/
969
970/*!
971 \fn bool QByteArrayView::contains(QByteArrayView bv) const
972 \fn bool QByteArrayView::contains(char ch) const
973
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
976 \c false.
977
978 \sa indexOf(), lastIndexOf()
979*/
980
981/*!
982 \fn qsizetype QByteArrayView::lastIndexOf(QByteArrayView bv, qsizetype from) const
983 \fn qsizetype QByteArrayView::lastIndexOf(char ch, qsizetype from = -1) const
984
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
988 \a from.
989
990 \include qstring.qdocinc negative-index-start-search-from-end
991
992 Returns -1 if no match is found.
993
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.
1000
1001 \sa indexOf(), contains()
1002*/
1003
1004/*!
1005 \fn qsizetype QByteArrayView::lastIndexOf(QByteArrayView bv) const
1006 \since 6.2
1007 \overload
1008
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.
1013
1014 \sa indexOf(), contains()
1015*/
1016
1017/*!
1018 \fn qsizetype QByteArrayView::count(QByteArrayView bv) const
1019
1020 Returns the number of (potentially overlapping) occurrences of the
1021 sequence of bytes viewed by \a bv in this byte array view.
1022
1023 \sa contains(), indexOf()
1024*/
1025
1026/*!
1027 \fn bool QByteArrayView::count(char ch) const
1028 \overload
1029
1030 Returns the number of occurrences of byte \a ch in this byte array view.
1031
1032 \sa contains(), indexOf()
1033*/
1034
1035/*!
1036 \fn QByteArrayView qToByteArrayViewIgnoringNull(const QByteArray &b);
1037 \internal
1038
1039 Convert \a b to a QByteArrayView ignoring \c{b.isNull()}.
1040
1041 Returns a byte array view that references \a{b}'s data, but is never null.
1042
1043 This is a faster way to convert a QByteArray to a QByteArrayView,
1044 if null QByteArray can legitimately be treated as empty ones.
1045
1046 \sa QByteArray::isNull(), QByteArrayView
1047*/
1048
1049/*!
1050 \fn QByteArrayView::operator std::string_view() const
1051 \since 6.7
1052
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
1055 this view.
1056*/