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