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 \a 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 of \a Size bytes.
313
The view covers the full array. That includes the trailing null-terminator
314
of \c{char} array literals. If you don't want the null-terminator included
315
in the view, you can chop() it off when you are certain it is at the end.
316
Alternatively you can use the constructor overload taking a char array
317
literal which will create a view up to, but not including, the first
318
null-terminator in the data.
319
320
This function will work with any array literal of a compatible byte type.
321
322
\sa {Compatible Byte Types}, QByteArrayView
323
*/
324
325
/*!
326
\fn QByteArray QByteArrayView::toByteArray() const
327
328
Returns a deep copy of this byte array view's data as a QByteArray.
329
330
The return value will be a null QByteArray if and only if this byte array
331
view is null.
332
*/
333
334
/*!
335
\fn const char *QByteArrayView::data() const
336
337
Returns a const \c char pointer to the first byte in the byte array view.
338
339
\note The character array represented by the return value is \e not guaranteed
340
to be null-terminated. The returned pointer is only safe to use for accessing
341
bytes at indices that are less than this byte array view's size().
342
343
\sa begin(), end()
344
*/
345
346
/*!
347
\fn const char *QByteArrayView::constData() const
348
349
Returns a const \c char pointer to the first byte in the byte array view.
350
351
\note The character array represented by the return value is \e not guaranteed
352
to be null-terminated. The returned pointer is only safe to use for accessing
353
bytes at indices that are less than this byte array view's size().
354
355
\sa data(), begin(), end()
356
*/
357
358
/*! //! friend
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
\fn int QByteArrayView::operator>=(const QByteArrayView &lhs, const QByteArrayView &rhs)
365
366
Comparison operators for QByteArrayView.
367
*/
368
369
/*!
370
\fn int QByteArrayView::compare(QByteArrayView bv, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
371
\since 6.2
372
373
Returns an integer less than, equal to, or greater than zero depending on
374
whether this QByteArrayView sorts before, at the same position as, or after
375
the QByteArrayView \a bv. The comparison is performed according to case
376
sensitivity \a cs.
377
378
\sa operator==()
379
*/
380
381
/*!
382
\fn QByteArrayView::isValidUtf8() const
383
384
Returns \c true if this byte array view contains valid UTF-8 encoded data,
385
or \c false otherwise.
386
387
\since 6.3
388
*/
389
390
/*!
391
\fn QByteArrayView::const_iterator QByteArrayView::begin() const
392
393
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the
394
first byte in the byte array view.
395
396
This function is provided for STL compatibility.
397
398
\sa end(), cbegin(), rbegin(), data()
399
*/
400
401
/*!
402
\fn QByteArrayView::const_iterator QByteArrayView::cbegin() const
403
404
Same as begin().
405
406
This function is provided for STL compatibility.
407
408
\sa cend(), begin(), crbegin(), data()
409
*/
410
411
/*!
412
\fn QByteArrayView::const_iterator QByteArrayView::end() const
413
414
Returns a const \l{STL-style iterators}{STL-style iterator} pointing
415
just after the last byte in the byte array view.
416
417
This function is provided for STL compatibility.
418
419
\sa begin(), cend(), rend()
420
*/
421
422
/*! \fn QByteArrayView::const_iterator QByteArrayView::cend() const
423
424
Same as end().
425
426
This function is provided for STL compatibility.
427
428
\sa cbegin(), end(), crend()
429
*/
430
431
/*!
432
\fn QByteArrayView::const_reverse_iterator QByteArrayView::rbegin() const
433
434
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing
435
to the first byte in the byte array view, in reverse order.
436
437
This function is provided for STL compatibility.
438
439
\sa rend(), crbegin(), begin()
440
*/
441
442
/*!
443
\fn QByteArrayView::const_reverse_iterator QByteArrayView::crbegin() const
444
445
Same as rbegin().
446
447
This function is provided for STL compatibility.
448
449
\sa crend(), rbegin(), cbegin()
450
*/
451
452
/*!
453
\fn QByteArrayView::const_reverse_iterator QByteArrayView::rend() const
454
455
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
456
the last byte in the byte array view, in reverse order.
457
458
This function is provided for STL compatibility.
459
460
\sa rbegin(), crend(), end()
461
*/
462
463
/*!
464
\fn QByteArrayView::const_reverse_iterator QByteArrayView::crend() const
465
466
Same as rend().
467
468
This function is provided for STL compatibility.
469
470
\sa crbegin(), rend(), cend()
471
*/
472
473
/*!
474
\fn bool QByteArrayView::empty() const
475
476
Returns \c true if this byte array view is empty - that is, \c{size() == 0}.
477
478
This function is provided for STL compatibility.
479
480
\sa isEmpty(), isNull(), size()
481
*/
482
483
/*!
484
\fn bool QByteArrayView::isEmpty() const
485
486
Returns \c true if this byte array view is empty - that is, \c{size() == 0}.
487
488
\sa empty(), isNull(), size()
489
*/
490
491
/*!
492
\fn bool QByteArrayView::isNull() const
493
494
Returns \c true if this byte array view is null - that is, \c{data() == nullptr}.
495
496
\sa empty(), isEmpty(), size()
497
*/
498
499
/*!
500
\fn qsizetype QByteArrayView::size() const
501
502
Returns the number of bytes in this byte array view.
503
504
\sa empty(), isEmpty(), isNull()
505
*/
506
507
/*!
508
\fn QByteArrayView::length() const
509
510
Same as size().
511
512
\sa empty(), isEmpty(), isNull(), size()
513
*/
514
515
/*!
516
\fn char QByteArrayView::operator[](qsizetype n) const
517
518
Returns the character at position \a n in this byte array view.
519
520
The behavior is undefined if \a n is negative or not less than size().
521
522
\sa at(), front(), back()
523
*/
524
525
/*!
526
\fn char QByteArrayView::at(qsizetype n) const
527
528
Returns the character at position \a n in this byte array view.
529
530
The behavior is undefined if \a n is negative or not less than size().
531
532
\sa operator[](), front(), back()
533
*/
534
535
/*!
536
\fn char QByteArrayView::front() const
537
538
Returns the first byte in the byte array view.
539
540
This function is provided for STL compatibility.
541
542
\warning Calling this function on an empty byte array view constitutes
543
undefined behavior.
544
545
\sa back()
546
*/
547
548
/*!
549
\fn char QByteArrayView::back() const
550
551
Returns the last byte in the byte array view.
552
553
This function is provided for STL compatibility.
554
555
\warning Calling this function on an empty byte array view constitutes
556
undefined behavior.
557
558
\sa front()
559
*/
560
561
/*!
562
\fn QByteArrayView QByteArrayView::first(qsizetype n) const
563
564
Returns a byte array view that points to the first \a n bytes
565
of this byte array view. Equivalent to \c{sliced(0, n)}.
566
567
\note The behavior is undefined when \a n < 0 or \a n > size().
568
569
\sa last(), startsWith(), chopped(), chop(), truncate(), sliced(), slice()
570
*/
571
572
/*!
573
\fn QByteArrayView QByteArrayView::last(qsizetype n) const
574
575
Returns a byte array view that points to the last \a n bytes
576
of this byte array view.
577
578
\note The behavior is undefined when \a n < 0 or \a n > size().
579
580
\sa first(), endsWith(), chopped(), chop(), truncate(), sliced(), slice()
581
*/
582
583
/*!
584
\fn QByteArrayView QByteArrayView::sliced(qsizetype pos, qsizetype n) const
585
586
Returns a byte array view that points to \a n bytes of this byte array
587
view, starting at position \a pos.
588
589
//! [UB-sliced-index-length]
590
\note The behavior is undefined when \a pos < 0, \a n < 0,
591
or \a pos + \a n > size().
592
//! [UB-sliced-index-length]
593
594
\sa first(), last(), chopped(), chop(), truncate(), slice()
595
*/
596
597
/*!
598
\fn QByteArrayView QByteArrayView::sliced(qsizetype pos) const
599
600
Returns a byte array view starting at position \a pos in this object,
601
and extending to its end.
602
603
//! [UB-sliced-index-only]
604
\note The behavior is undefined when \a pos < 0 or \a pos > size().
605
//! [UB-sliced-index-only]
606
607
\sa first(), last(), chopped(), chop(), truncate(), slice()
608
*/
609
610
/*!
611
\fn QByteArrayView &QByteArrayView::slice(qsizetype pos, qsizetype n)
612
\since 6.8
613
614
Modifies this byte array view to start at position \a pos, extending for
615
\a n bytes.
616
617
\include qbytearrayview.qdoc UB-sliced-index-length
618
619
\sa sliced(), first(), last(), chopped(), chop(), truncate()
620
*/
621
622
/*!
623
\fn QByteArrayView &QByteArrayView::slice(qsizetype pos)
624
\since 6.8
625
\overload
626
627
Modifies this byte array view to start at position \a pos, extending
628
to its end.
629
630
\include qbytearrayview.qdoc UB-sliced-index-only
631
632
\sa sliced(), first(), last(), chopped(), chop(), truncate()
633
*/
634
635
/*!
636
\fn QByteArrayView QByteArrayView::chopped(qsizetype length) const
637
638
Returns a copy of this byte array view that omits its last \a length bytes.
639
In other words, returns a byte array view of length size() - \a length starting
640
at the beginning of this object.
641
642
Same as \c{first(size() - length)}.
643
644
\note The behavior is undefined when \a length < 0 or \a length > size().
645
646
\sa first(), last(), sliced(), chop(), truncate(), slice()
647
*/
648
649
/*!
650
\fn void QByteArrayView::truncate(qsizetype length)
651
652
Truncates this byte array view to length \a length.
653
654
Same as \c{*this = first(length)}.
655
656
\note The behavior is undefined when \a length < 0 or \a length > size().
657
658
\sa first(), last(), sliced(), chopped(), chop()
659
*/
660
661
/*!
662
\fn void QByteArrayView::chop(qsizetype length)
663
664
Truncates this byte array view by \a length characters.
665
666
Same as \c{*this = first(size() - length)}.
667
668
\note The behavior is undefined when \a length < 0 or \a length > size().
669
670
\sa sliced(), first(), last(), chopped(), truncate(), slice()
671
*/
672
673
/*!
674
\fn QByteArrayView QByteArrayView::mid(qsizetype start, qsizetype length) const
675
\since 6.5
676
677
\deprecated Use sliced() instead in new code.
678
679
Returns the subarray of length \a length starting at position
680
\a start in this object.
681
682
Returns an empty byte array view if \a start exceeds the
683
length of the byte array view. If there are less than \a length characters
684
available in the byte array view starting at \a start, or if
685
\a length is negative (default), the function returns all characters that
686
are available from \a start.
687
688
\sa first(), last(), sliced(), chopped(), chop(), truncate(), slice()
689
*/
690
691
/*!
692
\fn QByteArrayView QByteArrayView::left(qsizetype length) const
693
\since 6.5
694
695
\deprecated Use first() instead in new code.
696
697
Returns the subarray of length \a length starting at position
698
0 in this object.
699
700
The entire byte array view is returned if \a length is greater than or equal
701
to size(), or less than zero.
702
703
\sa first(), last(), sliced(), startsWith(), chopped(), chop(), truncate(), slice()
704
*/
705
706
/*!
707
\fn QByteArrayView QByteArrayView::right(qsizetype length) const
708
\since 6.5
709
710
\deprecated Use last() instead in new code.
711
712
Returns the subarray of length \a length starting at position
713
size() - \a length in this object.
714
715
The entire byte array view is returned if \a length is greater than or equal
716
to size(), or less than zero.
717
718
\sa first(), last(), sliced(), endsWith(), chopped(), chop(), truncate(), slice()
719
*/
720
721
/*!
722
\fn QByteArrayView QByteArrayView::trimmed() const noexcept
723
\since 6.3
724
725
Returns a copy of this byte array view with spacing characters
726
removed from the start and end.
727
728
The spacing characters are those for which the standard C++ \c isspace()
729
function returns \c true in the C locale; these are the ASCII characters
730
tabulation '\\t', line feed '\\n', carriage return '\\r', vertical
731
tabulation '\\v', form feed '\\f', and space ' '.
732
733
\sa QChar::SpecialCharacter, {QByteArray#Spacing Characters}{Spacing Characters}
734
*/
735
736
/*!
737
\fn qlonglong QByteArrayView::toLongLong(bool *ok, int base) const
738
\since 6.3
739
740
Returns this byte array view converted to a \c {long long} using base \a
741
base, which is ten by default. Bases 0 and 2 through 36 are supported, using
742
letters for digits beyond 9; A is ten, B is eleven and so on.
743
744
If \a base is 0, the base is determined automatically using the following
745
rules: if the byte array view begins with "0x", the rest of it is read as
746
hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
747
read as octal (base 8); otherwise it is read as decimal.
748
749
Returns 0 if the conversion fails.
750
751
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
752
to \c false, and success by setting *\a{ok} to \c true.
753
754
\note The conversion of the number is performed in the default C locale,
755
regardless of the user's locale. Use QLocale to perform locale-aware
756
conversions between numbers and strings.
757
*/
758
759
/*!
760
\fn qulonglong QByteArrayView::toULongLong(bool *ok, int base) const
761
\since 6.3
762
763
Returns this byte array view converted to an \c {unsigned long long} using
764
base \a base, which is ten by default. Bases 0 and 2 through 36 are
765
supported, using letters for digits beyond 9; A is ten, B is eleven and so
766
on.
767
768
If \a base is 0, the base is determined automatically using the following
769
rules: if the byte array view begins with "0x", the rest of it is read as
770
hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
771
read as octal (base 8); otherwise it is read as decimal.
772
773
Returns 0 if the conversion fails.
774
775
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
776
to \c false, and success by setting *\a{ok} to \c true.
777
778
\note The conversion of the number is performed in the default C locale,
779
regardless of the user's locale. Use QLocale to perform locale-aware
780
conversions between numbers and strings.
781
*/
782
783
/*!
784
\fn int QByteArrayView::toInt(bool *ok, int base) const
785
\since 6.3
786
787
Returns this byte array view converted to an \c int using base \a base,
788
which is ten by default. Bases 0 and 2 through 36 are supported, using
789
letters for digits beyond 9; A is ten, B is eleven and so on.
790
791
If \a base is 0, the base is determined automatically using the following
792
rules: if the byte array view begins with "0x", the rest of it is read as
793
hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
794
read as octal (base 8); otherwise it is read as decimal.
795
796
Returns 0 if the conversion fails.
797
798
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
799
to \c false, and success by setting *\a{ok} to \c true.
800
801
\snippet code/src_corelib_text_qbytearrayview.cpp 2
802
803
\note The conversion of the number is performed in the default C locale,
804
regardless of the user's locale. Use QLocale to perform locale-aware
805
conversions between numbers and strings.
806
*/
807
808
/*!
809
\fn uint QByteArrayView::toUInt(bool *ok, int base) const
810
\since 6.3
811
812
Returns this byte array view converted to an \c {unsigned int} using base \a
813
base, which is ten by default. Bases 0 and 2 through 36 are supported, using
814
letters for digits beyond 9; A is ten, B is eleven and so on.
815
816
If \a base is 0, the base is determined automatically using the following
817
rules: if the byte array view begins with "0x", the rest of it is read as
818
hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
819
read as octal (base 8); otherwise it is read as decimal.
820
821
Returns 0 if the conversion fails.
822
823
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
824
to \c false, and success by setting *\a{ok} to \c true.
825
826
\note The conversion of the number is performed in the default C locale,
827
regardless of the user's locale. Use QLocale to perform locale-aware
828
conversions between numbers and strings.
829
*/
830
831
/*!
832
\fn long QByteArrayView::toLong(bool *ok, int base) const
833
\since 6.3
834
835
Returns this byte array view converted to a \c long int using base \a base,
836
which is ten by default. Bases 0 and 2 through 36 are supported, using
837
letters for digits beyond 9; A is ten, B is eleven and so on.
838
839
If \a base is 0, the base is determined automatically using the following
840
rules: if the byte array view begins with "0x", the rest of it is read as
841
hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
842
read as octal (base 8); otherwise it is read as decimal.
843
844
Returns 0 if the conversion fails.
845
846
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
847
to \c false, and success by setting *\a{ok} to \c true.
848
849
\snippet code/src_corelib_text_qbytearrayview.cpp 3
850
851
\note The conversion of the number is performed in the default C locale,
852
regardless of the user's locale. Use QLocale to perform locale-aware
853
conversions between numbers and strings.
854
*/
855
856
/*!
857
\fn ulong QByteArrayView::toULong(bool *ok, int base) const
858
\since 6.3
859
860
Returns this byte array view converted to an \c {unsigned long int} using
861
base \a base, which is ten by default. Bases 0 and 2 through 36 are
862
supported, using letters for digits beyond 9; A is ten, B is eleven and so
863
on.
864
865
If \a base is 0, the base is determined automatically using the following
866
rules: if the byte array view begins with "0x", the rest of it is read as
867
hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
868
read as octal (base 8); otherwise it is read as decimal.
869
870
Returns 0 if the conversion fails.
871
872
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
873
to \c false, and success by setting *\a{ok} to \c true.
874
875
\note The conversion of the number is performed in the default C locale,
876
regardless of the user's locale. Use QLocale to perform locale-aware
877
conversions between numbers and strings.
878
*/
879
880
/*!
881
\fn short QByteArrayView::toShort(bool *ok, int base) const
882
\since 6.3
883
884
Returns this byte array view converted to a \c short using base \a base,
885
which is ten by default. Bases 0 and 2 through 36 are supported, using
886
letters for digits beyond 9; A is ten, B is eleven and so on.
887
888
If \a base is 0, the base is determined automatically using the following
889
rules: if the byte array view begins with "0x", the rest of it is read as
890
hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
891
read as octal (base 8); otherwise it is read as decimal.
892
893
Returns 0 if the conversion fails.
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
\note The conversion of the number is performed in the default C locale,
899
regardless of the user's locale. Use QLocale to perform locale-aware
900
conversions between numbers and strings.
901
*/
902
903
/*!
904
\fn ushort QByteArrayView::toUShort(bool *ok, int base) const
905
\since 6.3
906
907
Returns this byte array view converted to an \c {unsigned short} using base
908
\a base, which is ten by default. Bases 0 and 2 through 36 are supported,
909
using letters for digits beyond 9; A is ten, B is eleven and so on.
910
911
If \a base is 0, the base is determined automatically using the following
912
rules: if the byte array view begins with "0x", the rest of it is read as
913
hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is
914
read as octal (base 8); otherwise it is read as decimal.
915
916
Returns 0 if the conversion fails.
917
918
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
919
to \c false, and success by setting *\a{ok} to \c true.
920
921
\note The conversion of the number is performed in the default C locale,
922
regardless of the user's locale. Use QLocale to perform locale-aware
923
conversions between numbers and strings.
924
*/
925
926
/*!
927
\fn double QByteArrayView::toDouble(bool *ok) const
928
\since 6.3
929
930
Returns this byte array view converted to a \c double value.
931
932
Returns an infinity if the conversion overflows or 0.0 if the
933
conversion fails for other reasons (e.g. underflow).
934
935
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
936
to \c false, and success by setting *\a{ok} to \c true.
937
938
\warning The QByteArrayView content may only contain valid numerical
939
characters which includes the plus/minus sign, the character e used in
940
scientific notation, and the decimal point. Including the unit or additional
941
characters leads to a conversion error.
942
943
\note The conversion of the number is performed in the default C locale,
944
regardless of the user's locale. Use QLocale to perform locale-aware
945
conversions between numbers and strings.
946
947
This function ignores leading and trailing spacing characters.
948
*/
949
950
/*!
951
\fn float QByteArrayView::toFloat(bool *ok) const
952
\since 6.3
953
954
Returns this byte array view converted to a \c float value.
955
956
Returns an infinity if the conversion overflows or 0.0 if the
957
conversion fails for other reasons (e.g. underflow).
958
959
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
960
to \c false, and success by setting *\a{ok} to \c true.
961
962
\snippet code/src_corelib_text_qbytearrayview.cpp 4
963
964
\warning The QByteArrayView content may only contain valid numerical
965
characters which includes the plus/minus sign, the character e used in
966
scientific notation, and the decimal point. Including the unit or additional
967
characters leads to a conversion error.
968
969
\note The conversion of the number is performed in the default C locale,
970
regardless of the user's locale. Use QLocale to perform locale-aware
971
conversions between numbers and strings.
972
973
This function ignores leading and trailing whitespace.
974
*/
975
976
/*!
977
\fn bool QByteArrayView::startsWith(QByteArrayView bv) const
978
\fn bool QByteArrayView::startsWith(char ch) const
979
980
Returns \c true if this byte array view starts with byte array view \a bv
981
or character \a ch, respectively; otherwise returns \c false.
982
983
\sa endsWith()
984
*/
985
986
/*!
987
\fn bool QByteArrayView::endsWith(QByteArrayView bv) const
988
\fn bool QByteArrayView::endsWith(char ch) const
989
990
Returns \c true if this byte array view ends with byte array view \a bv
991
or character \a ch, respectively; otherwise returns \c false.
992
993
\sa startsWith()
994
*/
995
996
/*!
997
\fn qsizetype QByteArrayView::indexOf(QByteArrayView bv, qsizetype from = 0) const
998
\fn qsizetype QByteArrayView::indexOf(char ch, qsizetype from = 0) const
999
1000
Returns the index position of either the start of the first occurrence of
1001
the sequence of bytes viewed by \a bv or the first occurrence of byte \a ch,
1002
respectively, in this byte array view, searching forward from index position
1003
\a from.Returns -1 if no match is found.
1004
1005
\include qstring.qdocinc negative-index-start-search-from-end
1006
1007
\sa lastIndexOf(), contains()
1008
*/
1009
1010
/*!
1011
\fn bool QByteArrayView::contains(QByteArrayView bv) const
1012
\fn bool QByteArrayView::contains(char ch) const
1013
1014
Returns \c true if this byte array view contains an occurrence of the sequence
1015
of bytes viewed by \a bv or character \a ch, respectively; otherwise returns
1016
\c false.
1017
1018
\sa indexOf(), lastIndexOf()
1019
*/
1020
1021
/*!
1022
\fn qsizetype QByteArrayView::lastIndexOf(QByteArrayView bv, qsizetype from) const
1023
\fn qsizetype QByteArrayView::lastIndexOf(char ch, qsizetype from = -1) const
1024
1025
Returns the index position of either the start of the last occurrence of
1026
the sequence of bytes viewed by \a bv or the last occurrence of byte \a ch,
1027
respectively, in this byte array view, searching backward from index position
1028
\a from.
1029
1030
\include qstring.qdocinc negative-index-start-search-from-end
1031
1032
Returns -1 if no match is found.
1033
1034
\note When searching for a 0-length \a bv, the match at the end of
1035
the data is excluded from the search by a negative \a from, even
1036
though \c{-1} is normally thought of as searching from the end of
1037
the view: the match at the end is \e after the last character, so
1038
it is excluded. To include such a final empty match, either give a
1039
positive value for \a from or omit the \a from parameter entirely.
1040
1041
\sa indexOf(), contains()
1042
*/
1043
1044
/*!
1045
\fn qsizetype QByteArrayView::lastIndexOf(QByteArrayView bv) const
1046
\since 6.2
1047
\overload
1048
1049
Returns the index position of the start of the last
1050
occurrence of the sequence of bytes viewed by \a bv in this byte
1051
array view, searching backward from the end of this byte array
1052
view. Returns -1 if no match is found.
1053
1054
\sa indexOf(), contains()
1055
*/
1056
1057
/*!
1058
\fn qsizetype QByteArrayView::count(QByteArrayView bv) const
1059
1060
Returns the number of (potentially overlapping) occurrences of the
1061
sequence of bytes viewed by \a bv in this byte array view.
1062
1063
\sa contains(), indexOf()
1064
*/
1065
1066
/*!
1067
\fn bool QByteArrayView::count(char ch) const
1068
\overload
1069
1070
Returns the number of occurrences of byte \a ch in this byte array view.
1071
1072
\sa contains(), indexOf()
1073
*/
1074
1075
/*!
1076
\fn QByteArrayView qToByteArrayViewIgnoringNull(const QByteArray &b);
1077
\internal
1078
1079
Convert \a b to a QByteArrayView ignoring \c{b.isNull()}.
1080
1081
Returns a byte array view that references \a{b}'s data, but is never null.
1082
1083
This is a faster way to convert a QByteArray to a QByteArrayView,
1084
if null QByteArray can legitimately be treated as empty ones.
1085
1086
\sa QByteArray::isNull(), QByteArrayView
1087
*/
1088
1089
/*!
1090
\fn QByteArrayView::operator std::string_view() const
1091
\since 6.7
1092
1093
Converts this QByteArrayView object to a \c{std::string_view} object.
1094
The returned view will have the same data pointer and length of
1095
this view.
1096
*/
1097
1098
/*!
1099
\fn QByteArrayView::maxSize()
1100
\since 6.8
1101
1102
It returns the maximum number of elements that the view can
1103
theoretically represent. In practice, the number can be much smaller,
1104
limited by the amount of memory available to the system.
1105
*/
1106
1107
/*!
1108
\fn QByteArrayView::max_size() const
1109
\since 6.8
1110
1111
This function is provided for STL compatibility.
1112
1113
Returns maxSize().
1114
*/
qtbase
src
corelib
text
qbytearrayview.qdoc
Generated on
for Qt by
1.16.1