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
qstringview.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:docs-only
4
5
#
include
"qstringview.h"
6
7
QT_BEGIN_NAMESPACE
8
9
/*!
10
\class QStringView
11
\inmodule QtCore
12
\since 5.10
13
\brief The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QString API.
14
\reentrant
15
\ingroup tools
16
\ingroup string-processing
17
18
A QStringView references a contiguous portion of a UTF-16 string it does
19
not own. It acts as an interface type to all kinds of UTF-16 string,
20
without the need to construct a QString first.
21
22
The UTF-16 string may be represented as an array (or an array-compatible
23
data-structure such as QString,
24
std::basic_string, etc.) of QChar, \c ushort, \c char16_t or
25
(on platforms, such as Windows, where it is a 16-bit type) \c wchar_t.
26
27
QStringView is designed as an interface type; its main use-case is
28
as a function parameter type. When QStringViews are used as automatic
29
variables or data members, care must be taken to ensure that the referenced
30
string data (for example, owned by a QString) outlives the QStringView on all code paths,
31
lest the string view ends up referencing deleted data.
32
33
When used as an interface type, QStringView allows a single function to accept
34
a wide variety of UTF-16 string data sources. One function accepting QStringView
35
thus replaces three function overloads (taking QString and
36
\c{(const QChar*, qsizetype)}), while at the same time enabling even more string data
37
sources to be passed to the function, such as \c{u"Hello World"}, a \c char16_t
38
string literal.
39
40
QStringViews should be passed by value, not by reference-to-const:
41
\snippet code/src_corelib_text_qstringview.cpp 0
42
43
If you want to give your users maximum freedom in what strings they can pass
44
to your function, accompany the QStringView overload with overloads for
45
46
\list
47
\li \e QChar: this overload can delegate to the QStringView version:
48
\snippet code/src_corelib_text_qstringview.cpp 1
49
even though, for technical reasons, QStringView cannot provide a
50
QChar constructor by itself.
51
\li \e QString: if you store an unmodified copy of the string and thus would
52
like to take advantage of QString's implicit sharing.
53
\li QLatin1StringView: if you can implement the function without converting the
54
QLatin1StringView to UTF-16 first; users expect a function overloaded on
55
QLatin1StringView to perform strictly less memory allocations than the
56
semantically equivalent call of the QStringView version, involving
57
construction of a QString from the QLatin1StringView.
58
\endlist
59
60
QStringView can also be used as the return value of a function. If you call a
61
function returning QStringView, take extra care to not keep the QStringView
62
around longer than the function promises to keep the referenced string data alive.
63
If in doubt, obtain a strong reference to the data by calling toString() to convert
64
the QStringView into a QString.
65
66
QStringView is a \e{Literal Type}, but since it stores data as \c{char16_t}, iteration
67
is not \c constexpr (casts from \c{const char16_t*} to \c{const QChar*}, which is not
68
allowed in \c constexpr functions). You can use an indexed loop and/or utf16() in
69
\c constexpr contexts instead.
70
71
\sa {Which string class to use?}, QString
72
*/
73
74
/*!
75
\typedef QStringView::storage_type
76
77
Alias for \c{char16_t}.
78
*/
79
80
/*!
81
\typedef QStringView::value_type
82
83
Alias for \c{const QChar}. Provided for compatibility with the STL.
84
*/
85
86
/*!
87
\typedef QStringView::difference_type
88
89
Alias for \c{std::ptrdiff_t}. Provided for compatibility with the STL.
90
*/
91
92
/*!
93
\typedef QStringView::size_type
94
95
Alias for qsizetype. Provided for compatibility with the STL.
96
*/
97
98
/*!
99
\typedef QStringView::reference
100
101
Alias for \c{value_type &}. Provided for compatibility with the STL.
102
103
QStringView does not support mutable references, so this is the same
104
as const_reference.
105
*/
106
107
/*!
108
\typedef QStringView::const_reference
109
110
Alias for \c{value_type &}. Provided for compatibility with the STL.
111
*/
112
113
/*!
114
\typedef QStringView::pointer
115
116
Alias for \c{value_type *}. Provided for compatibility with the STL.
117
118
QStringView does not support mutable pointers, so this is the same
119
as const_pointer.
120
*/
121
122
/*!
123
\typedef QStringView::const_pointer
124
125
Alias for \c{value_type *}. Provided for compatibility with the STL.
126
*/
127
128
/*!
129
\typedef QStringView::iterator
130
131
This typedef provides an STL-style const iterator for QStringView.
132
133
QStringView does not support mutable iterators, so this is the same
134
as const_iterator.
135
136
\sa const_iterator, reverse_iterator
137
*/
138
139
/*!
140
\typedef QStringView::const_iterator
141
142
This typedef provides an STL-style const iterator for QStringView.
143
144
\sa iterator, const_reverse_iterator
145
*/
146
147
/*!
148
\typedef QStringView::reverse_iterator
149
150
This typedef provides an STL-style const reverse iterator for QStringView.
151
152
QStringView does not support mutable reverse iterators, so this is the
153
same as const_reverse_iterator.
154
155
\sa const_reverse_iterator, iterator
156
*/
157
158
/*!
159
\typedef QStringView::const_reverse_iterator
160
161
This typedef provides an STL-style const reverse iterator for QStringView.
162
163
\sa reverse_iterator, const_iterator
164
*/
165
166
/*!
167
\fn size_t qHash(QStringView key, size_t seed)
168
\since 5.10
169
\qhashold{QStringView}
170
*/
171
172
/*!
173
\fn QStringView::QStringView()
174
175
Constructs a null string view.
176
177
\sa isNull()
178
*/
179
180
/*!
181
\fn QStringView::QStringView(std::nullptr_t)
182
183
Constructs a null string view.
184
185
\sa isNull()
186
*/
187
188
/*!
189
\fn template <typename Char, QStringView::if_compatible_char<Char> = true> QStringView::QStringView(const Char *str, qsizetype len)
190
191
Constructs a string view on \a str with length \a len.
192
193
The range \c{[str,len)} must remain valid for the lifetime of this string view object.
194
195
Passing \nullptr as \a str is safe if \a len is 0, too, and results in a null string view.
196
197
The behavior is undefined if \a len is negative or, when positive, if \a str is \nullptr.
198
199
//! [compatible-char-types]
200
\constraints \c Char is a compatible
201
character type. The compatible character types are: \c QChar, \c ushort, \c char16_t and
202
(on platforms, such as Windows, where it is a 16-bit type) \c wchar_t.
203
//! [compatible-char-types]
204
*/
205
206
/*!
207
\fn template <typename Char, QStringView::if_compatible_char<Char> = true> QStringView::QStringView(const Char *first, const Char *last)
208
209
Constructs a string view on \a first with length (\a last - \a first).
210
211
The range \c{[first,last)} must remain valid for the lifetime of
212
this string view object.
213
214
Passing \c \nullptr as \a first is safe if \a last is \nullptr, too,
215
and results in a null string view.
216
217
The behavior is undefined if \a last precedes \a first, or \a first
218
is \nullptr and \a last is not.
219
220
\include qstringview.cpp compatible-char-types
221
*/
222
223
/*!
224
\fn template <typename Char> QStringView::QStringView(const Char *str)
225
226
Constructs a string view on \a str. The length is determined
227
by scanning for the first \c{Char(0)}.
228
229
\a str must remain valid for the lifetime of this string view object.
230
231
Passing \nullptr as \a str is safe and results in a null string view.
232
233
\include qstringview.cpp compatible-char-types
234
*/
235
236
/*!
237
\fn template <typename Char, size_t N> QStringView::QStringView(const Char (&string)[N])
238
239
Constructs a string view on the character string literal \a string.
240
The view covers the array until the first \c{Char(0)} is encountered,
241
or \c N, whichever comes first.
242
If you need the full array, use fromArray() instead.
243
244
\a string must remain valid for the lifetime of this string view
245
object.
246
247
\include qstringview.cpp compatible-char-types
248
249
\sa fromArray
250
*/
251
252
/*!
253
\fn QStringView::QStringView(const QString &str)
254
255
Constructs a string view on \a str.
256
257
\c{str.data()} must remain valid for the lifetime of this string view object.
258
259
The string view will be null if and only if \c{str.isNull()}.
260
*/
261
262
/*!
263
\fn template <typename Container, QStringView::if_compatible_container<Container>> QStringView::QStringView(const Container &str)
264
265
Constructs a string view on \a str. The length is taken from \c{std::size(str)}.
266
267
\c{std::data(str)} must remain valid for the lifetime of this string view object.
268
269
The string view will be empty if and only if \c{std::size(str) == 0}. It is unspecified
270
whether this constructor can result in a null string view (\c{std::data(str)} would
271
have to return \nullptr for this).
272
273
\constraints \c Container is a
274
container with a compatible character type as \c{value_type}. The
275
compatible character types are: \c QChar, \c ushort, \c char16_t and
276
(on platforms, such as Windows, where it is a 16-bit type) \c wchar_t.
277
278
\sa isNull(), isEmpty()
279
*/
280
281
/*!
282
\fn template <typename Char, size_t Size, QStringView::if_compatible_char<Char> = true> static QStringView QStringView::fromArray(const Char (&string)[Size]) noexcept
283
284
Constructs a string view on the full character string literal \a string,
285
including any trailing \c{Char(0)}. If you don't want the
286
null-terminator included in the view then you can chop() it off
287
when you are certain it is at the end. Alternatively you can use
288
the constructor overload taking an array literal which will create
289
a view up to, but not including, the first null-terminator in the data.
290
291
\a string must remain valid for the lifetime of this string view
292
object.
293
294
This function will work with any array literal if \c Char is a
295
compatible character type. The compatible character types are: \c QChar, \c ushort, \c
296
char16_t and (on platforms, such as Windows, where it is a 16-bit
297
type) \c wchar_t.
298
*/
299
300
/*!
301
\fn QString QStringView::toString() const
302
303
Returns a deep copy of this string view's data as a QString.
304
305
The return value will be the null QString if and only if this string view is null.
306
*/
307
308
/*!
309
\fn const QChar *QStringView::data() const
310
311
//! [const-pointer-to-first-ch]
312
Returns a const pointer to the first character in the string view.
313
314
\note The character array represented by the return value is \e not null-terminated.
315
//! [const-pointer-to-first-ch]
316
317
\sa begin(), end(), utf16()
318
*/
319
320
/*!
321
\fn const QChar *QStringView::constData() const
322
\since 6.0
323
324
\include qstringview.cpp const-pointer-to-first-ch
325
326
\sa data(), begin(), end(), utf16()
327
*/
328
329
/*!
330
\fn const storage_type *QStringView::utf16() const
331
332
\include qstringview.cpp const-pointer-to-first-ch
333
334
\c{storage_type} is \c{char16_t}.
335
336
\sa begin(), end(), data()
337
*/
338
339
/*!
340
\fn QStringView::const_iterator QStringView::begin() const
341
342
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in
343
the string view.
344
345
This function is provided for STL compatibility.
346
347
\sa end(), constBegin(), cbegin(), rbegin(), data()
348
*/
349
350
/*!
351
\fn QStringView::const_iterator QStringView::cbegin() const
352
353
Same as begin().
354
355
This function is provided for STL compatibility.
356
357
\sa cend(), begin(), constBegin(), crbegin(), data()
358
*/
359
360
/*!
361
\fn QStringView::const_iterator QStringView::constBegin() const
362
\since 6.1
363
364
Same as begin().
365
366
\sa constEnd(), begin(), cbegin(), crbegin(), data()
367
*/
368
369
/*!
370
\fn QStringView::const_iterator QStringView::end() const
371
372
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
373
character after the last character in the list.
374
375
This function is provided for STL compatibility.
376
377
\sa begin(), constEnd(), cend(), rend()
378
*/
379
380
/*! \fn QStringView::const_iterator QStringView::cend() const
381
382
Same as end().
383
384
This function is provided for STL compatibility.
385
386
\sa cbegin(), end(), constEnd(), crend()
387
*/
388
389
/*! \fn QStringView::const_iterator QStringView::constEnd() const
390
\since 6.1
391
392
Same as end().
393
394
\sa constBegin(), end(), cend(), crend()
395
*/
396
397
/*!
398
\fn QStringView::const_reverse_iterator QStringView::rbegin() const
399
400
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
401
character in the string view, in reverse order.
402
403
This function is provided for STL compatibility.
404
405
\sa rend(), crbegin(), begin()
406
*/
407
408
/*!
409
\fn QStringView::const_reverse_iterator QStringView::crbegin() const
410
411
Same as rbegin().
412
413
This function is provided for STL compatibility.
414
415
\sa crend(), rbegin(), cbegin()
416
*/
417
418
/*!
419
\fn QStringView::const_reverse_iterator QStringView::rend() const
420
421
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
422
the last character in the string view, in reverse order.
423
424
This function is provided for STL compatibility.
425
426
\sa rbegin(), crend(), end()
427
*/
428
429
/*!
430
\fn QStringView::const_reverse_iterator QStringView::crend() const
431
432
Same as rend().
433
434
This function is provided for STL compatibility.
435
436
\sa crbegin(), rend(), cend()
437
*/
438
439
/*!
440
\fn bool QStringView::empty() const
441
442
Returns whether this string view is empty - that is, whether \c{size() == 0}.
443
444
This function is provided for STL compatibility.
445
446
\sa isEmpty(), isNull(), size(), length()
447
*/
448
449
/*!
450
\fn bool QStringView::isEmpty() const
451
452
Returns whether this string view is empty - that is, whether \c{size() == 0}.
453
454
This function is provided for compatibility with other Qt containers.
455
456
\sa empty(), isNull(), size(), length()
457
*/
458
459
/*!
460
\fn bool QStringView::isNull() const
461
462
Returns whether this string view is null - that is, whether \c{data() == nullptr}.
463
464
This functions is provided for compatibility with other Qt containers.
465
466
\sa empty(), isEmpty(), size(), length()
467
*/
468
469
/*!
470
\fn qsizetype QStringView::size() const
471
472
Returns the size of this string view, in UTF-16 code units (that is,
473
surrogate pairs count as two for the purposes of this function, the same
474
as in QString).
475
476
\sa empty(), isEmpty(), isNull(), length()
477
*/
478
479
/*!
480
\fn QStringView::length() const
481
482
Same as size().
483
484
This function is provided for compatibility with other Qt containers.
485
486
\sa empty(), isEmpty(), isNull(), size()
487
*/
488
489
/*!
490
\fn QChar QStringView::operator[](qsizetype n) const
491
492
Returns the character at position \a n in this string view.
493
494
The behavior is undefined if \a n is negative or not less than size().
495
496
\sa at(), front(), back()
497
*/
498
499
/*!
500
\fn QChar QStringView::at(qsizetype n) const
501
502
Returns the character at position \a n in this string view.
503
504
The behavior is undefined if \a n is negative or not less than size().
505
506
\sa operator[](), front(), back()
507
*/
508
509
/*!
510
\fn template <typename...Args> QString QStringView::arg(Args &&...args) const
511
\fn template <typename...Args> QString QLatin1StringView::arg(Args &&...args) const
512
\fn template <typename...Args> QString QString::arg(Args &&...args) const
513
\since 5.14
514
515
//![qstring-multi-arg]
516
Replaces occurrences of \c{%N} in this string with the corresponding
517
argument from \a args. The arguments are not positional: the first of
518
the \a args replaces the \c{%N} with the lowest \c{N} (all of them), the
519
second of the \a args the \c{%N} with the next-lowest \c{N} etc.
520
521
\c Args can consist of anything that implicitly converts to QAnyStringView.
522
//![qstring-multi-arg]
523
524
\note In Qt versions prior to 6.9, QAnyStringView and UTF-8 strings
525
(QUtf8StringView, QByteArray, QByteArrayView, \c{const char8_t*}, etc) were
526
not supported as \a args.
527
528
\sa QString::arg()
529
*/
530
531
/*!
532
\fn QChar QStringView::front() const
533
534
Returns the first character in the string view. Same as first().
535
536
This function is provided for STL compatibility.
537
538
//! [calling-on-empty-is-UB]
539
\warning Calling this function on an empty string view constitutes
540
undefined behavior.
541
//! [calling-on-empty-is-UB]
542
543
\sa back(), first(), last()
544
*/
545
546
/*!
547
\fn QChar QStringView::back() const
548
549
Returns the last character in the string view. Same as last().
550
551
This function is provided for STL compatibility.
552
553
\include qstringview.cpp calling-on-empty-is-UB
554
555
\sa front(), first(), last()
556
*/
557
558
/*!
559
\fn QChar QStringView::first() const
560
561
Returns the first character in the string view. Same as front().
562
563
This function is provided for compatibility with other Qt containers.
564
565
\include qstringview.cpp calling-on-empty-is-UB
566
567
\sa front(), back(), last()
568
*/
569
570
/*!
571
\fn QChar QStringView::last() const
572
573
Returns the last character in the string view. Same as back().
574
575
This function is provided for compatibility with other Qt containers.
576
577
\include qstringview.cpp calling-on-empty-is-UB
578
579
\sa back(), front(), first()
580
*/
581
582
/*!
583
\fn QStringView QStringView::mid(qsizetype start, qsizetype length) const
584
585
Returns the substring of length \a length starting at position
586
\a start in this object.
587
588
\deprecated Use sliced() instead in new code.
589
590
Returns an empty string view if \a start exceeds the
591
length of the string view. If there are less than \a length characters
592
available in the string view starting at \a start, or if
593
\a length is negative (default), the function returns all characters that
594
are available from \a start.
595
596
\sa first(), last(), sliced(), chopped(), chop(), truncate(), slice()
597
*/
598
599
/*!
600
\fn QStringView QStringView::left(qsizetype length) const
601
602
\deprecated Use first() instead in new code.
603
604
Returns the substring of length \a length starting at position
605
0 in this object.
606
607
The entire string view is returned if \a length is greater than or equal
608
to size(), or less than zero.
609
610
\sa first(), last(), sliced(), startsWith(), chopped(), chop(), truncate(), slice()
611
*/
612
613
/*!
614
\fn QStringView QStringView::right(qsizetype length) const
615
616
\deprecated Use last() instead in new code.
617
618
Returns the substring of length \a length starting at position
619
size() - \a length in this object.
620
621
The entire string view is returned if \a length is greater than or equal
622
to size(), or less than zero.
623
624
\sa first(), last(), sliced(), endsWith(), chopped(), chop(), truncate(), slice()
625
*/
626
627
/*!
628
\fn QStringView QStringView::first(qsizetype n) const
629
\since 6.0
630
631
Returns a string view that points to the first \a n characters
632
of this string view.
633
634
\note The behavior is undefined when \a n < 0 or \a n > size().
635
636
\sa last(), sliced(), startsWith(), chopped(), chop(), truncate(), slice()
637
*/
638
639
/*!
640
\fn QStringView QStringView::last(qsizetype n) const
641
\since 6.0
642
643
Returns a string view that points to the last \a n characters of this string
644
view.
645
646
\note The behavior is undefined when \a n < 0 or \a n > size().
647
648
\sa first(), sliced(), endsWith(), chopped(), chop(), truncate(), slice()
649
*/
650
651
/*!
652
\fn QStringView QStringView::sliced(qsizetype pos, qsizetype n) const
653
\since 6.0
654
655
Returns a string view that points to \a n characters of this string view,
656
starting at position \a pos.
657
658
//! [UB-sliced-index-length]
659
\note The behavior is undefined when \a pos < 0, \a n < 0,
660
or \a pos + \a n > size().
661
//! [UB-sliced-index-length]
662
663
\sa first(), last(), chopped(), chop(), truncate(), slice()
664
*/
665
666
/*!
667
\fn QStringView QStringView::sliced(qsizetype pos) const
668
\since 6.0
669
\overload
670
671
Returns a string view starting at position \a pos in this object,
672
and extending to its end.
673
674
//! [UB-sliced-index-only]
675
\note The behavior is undefined when \a pos < 0 or \a pos > size().
676
//! [UB-sliced-index-only]
677
678
\sa first(), last(), chopped(), chop(), truncate(), slice()
679
*/
680
681
/*!
682
\fn QStringView &QStringView::slice(qsizetype pos, qsizetype n)
683
\since 6.8
684
685
Modifies this string view to start from position \a pos, extending
686
for \a n code points.
687
688
\include qstringview.cpp UB-sliced-index-length
689
690
\sa sliced(), first(), last(), chopped(), chop(), truncate()
691
*/
692
693
/*!
694
\fn QStringView &QStringView::slice(qsizetype pos)
695
\since 6.8
696
\overload
697
698
Modifies this string view to start from position \a pos, extending
699
to its end.
700
701
\include qstringview.cpp UB-sliced-index-only
702
703
\sa sliced(), first(), last(), chopped(), chop(), truncate()
704
*/
705
706
/*!
707
\fn QStringView QStringView::chopped(qsizetype length) const
708
709
Returns the substring of length size() - \a length starting at the
710
beginning of this object.
711
712
Same as \c{left(size() - length)}.
713
714
\note The behavior is undefined when \a length < 0 or \a length > size().
715
716
\sa sliced(), left(), right(), chop(), truncate(), slice()
717
*/
718
719
/*!
720
\fn void QStringView::truncate(qsizetype length)
721
722
Truncates this string view to length \a length.
723
724
Same as \c{*this = left(length)}.
725
726
\note The behavior is undefined when \a length < 0 or \a length > size().
727
728
\sa sliced(), left(), right(), chopped(), chop()
729
*/
730
731
/*!
732
\fn void QStringView::chop(qsizetype length)
733
734
Truncates this string view by \a length characters.
735
736
Same as \c{*this = left(size() - length)}.
737
738
\note The behavior is undefined when \a length < 0 or \a length > size().
739
740
\sa sliced(), left(), right(), chopped(), truncate(), slice()
741
*/
742
743
/*!
744
\fn QStringView QStringView::trimmed() const
745
746
Strips leading and trailing whitespace and returns the result.
747
748
Whitespace means any character for which QChar::isSpace() returns
749
\c true. This includes the ASCII characters '\\t', '\\n', '\\v',
750
'\\f', '\\r', and ' '.
751
*/
752
753
/*!
754
\fn int QStringView::compare(QStringView str, Qt::CaseSensitivity cs) const
755
\since 5.12
756
757
Compares this string view with string view \a str and returns a negative integer if
758
this string view is less than \a str, a positive integer if it is greater than
759
\a str, and zero if they are equal.
760
761
\include qstring.qdocinc {search-comparison-case-sensitivity} {comparison}
762
763
\sa operator==(), operator<(), operator>()
764
*/
765
766
/*!
767
\fn int QStringView::compare(QUtf8StringView str, Qt::CaseSensitivity cs) const
768
\since 6.5
769
770
Compares this string view with QUtf8StringView \a str and returns a negative integer if
771
this string view is less than \a str, a positive integer if it is greater than
772
\a str, and zero if they are equal.
773
774
\include qstring.qdocinc {search-comparison-case-sensitivity} {comparison}
775
776
\sa operator==(), operator<(), operator>()
777
*/
778
779
/*!
780
\fn int QStringView::compare(QLatin1StringView l1, Qt::CaseSensitivity cs) const
781
\fn int QStringView::compare(QChar ch) const
782
\fn int QStringView::compare(QChar ch, Qt::CaseSensitivity cs) const
783
\since 5.15
784
785
Compares this string view to the Latin-1 string view \a l1, or the character \a ch.
786
Returns a negative integer if this string view is less than \a l1 or \a ch,
787
a positive integer if it is greater than \a l1 or \a ch, and zero if they are equal.
788
789
\include qstring.qdocinc {search-comparison-case-sensitivity} {comparison}
790
791
\sa operator==(), operator<(), operator>()
792
*/
793
794
/*!
795
\fn QStringView::operator==(const QStringView &lhs, const QStringView &rhs)
796
\fn QStringView::operator!=(const QStringView &lhs, const QStringView &rhs)
797
\fn QStringView::operator< (const QStringView &lhs, const QStringView &rhs)
798
\fn QStringView::operator<=(const QStringView &lhs, const QStringView &rhs)
799
\fn QStringView::operator> (const QStringView &lhs, const QStringView &rhs)
800
\fn QStringView::operator>=(const QStringView &lhs, const QStringView &rhs)
801
802
Operators for comparing \a lhs to \a rhs.
803
804
\sa compare()
805
*/
806
807
/*!
808
\fn int QStringView::localeAwareCompare(QStringView other) const
809
\since 6.4
810
811
Compares this string view with the \a other string view and returns
812
an integer less than, equal to, or greater than zero if this string
813
view is less than, equal to, or greater than the \a other string view.
814
815
The comparison is performed in a locale- and also platform-dependent
816
manner. Use this function to present sorted lists of strings to the
817
user.
818
819
\sa {Comparing Strings}
820
*/
821
822
/*
823
//! [utf16-or-latin1-or-ch]
824
the UTF-16 string viewed by \a str, the Latin-1 string viewed by \a l1,
825
or the character \a ch
826
//! [utf16-or-latin1-or-ch]
827
*/
828
829
/*!
830
\fn bool QStringView::startsWith(QStringView str, Qt::CaseSensitivity cs) const
831
\fn bool QStringView::startsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const
832
\fn bool QStringView::startsWith(QChar ch) const
833
\fn bool QStringView::startsWith(QChar ch, Qt::CaseSensitivity cs) const
834
835
Returns \c true if this string view starts with
836
\include qstringview.cpp utf16-or-latin1-or-ch
837
respectively; otherwise returns \c false.
838
839
\include qstring.qdocinc {search-comparison-case-sensitivity} {search}
840
841
\sa endsWith()
842
*/
843
844
/*!
845
\fn bool QStringView::endsWith(QStringView str, Qt::CaseSensitivity cs) const
846
\fn bool QStringView::endsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const
847
\fn bool QStringView::endsWith(QChar ch) const
848
\fn bool QStringView::endsWith(QChar ch, Qt::CaseSensitivity cs) const
849
850
Returns \c true if this string view ends with
851
\include qstringview.cpp utf16-or-latin1-or-ch
852
respectively; otherwise returns \c false.
853
854
\include qstring.qdocinc {search-comparison-case-sensitivity} {search}
855
856
\sa startsWith()
857
*/
858
859
/*!
860
\fn qsizetype QStringView::indexOf(QStringView str, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
861
\fn qsizetype QStringView::indexOf(QLatin1StringView l1, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
862
\fn qsizetype QStringView::indexOf(QChar ch, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
863
\since 5.14
864
865
Returns the index position of the first occurrence of
866
\include qstringview.cpp utf16-or-latin1-or-ch
867
respectively, in this string view, searching forward from index position
868
\a from. Returns -1 if \a str, \a l1 or \a ch is not found, respectively.
869
870
\include qstring.qdocinc {search-comparison-case-sensitivity} {search}
871
872
\include qstring.qdocinc negative-index-start-search-from-end
873
874
\sa QString::indexOf()
875
*/
876
877
/*!
878
\fn bool QStringView::contains(QStringView str, Qt::CaseSensitivity cs) const
879
\fn bool QStringView::contains(QLatin1StringView l1, Qt::CaseSensitivity cs) const
880
\fn bool QStringView::contains(QChar ch, Qt::CaseSensitivity cs) const
881
\since 5.14
882
883
Returns \c true if this string view contains an occurrence of
884
\include qstringview.cpp utf16-or-latin1-or-ch
885
respectively; otherwise returns \c false.
886
887
\include qstring.qdocinc {search-comparison-case-sensitivity} {search}
888
889
\sa indexOf()
890
*/
891
892
/*!
893
\fn qsizetype QStringView::lastIndexOf(QStringView str, qsizetype from, Qt::CaseSensitivity cs) const
894
\fn qsizetype QStringView::lastIndexOf(QLatin1StringView l1, qsizetype from, Qt::CaseSensitivity cs) const
895
\fn qsizetype QStringView::lastIndexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const
896
\since 5.14
897
898
Returns the index position of the last occurrence of
899
\include qstringview.cpp utf16-or-latin1-or-ch
900
respectively, in this string view, searching backward from index
901
position \a from.
902
903
\include qstring.qdocinc negative-index-start-search-from-end
904
905
Returns -1 if \a str, \a l1 or \a ch is not found, respectively.
906
907
\include qstring.qdocinc {search-comparison-case-sensitivity} {search}
908
909
\note When searching for a 0-length \a str or \a l1, the match at
910
the end of the data is excluded from the search by a negative \a
911
from, even though \c{-1} is normally thought of as searching from
912
the end of the string view: the match at the end is \e after the
913
last character, so it is excluded. To include such a final empty
914
match, either give a positive value for \a from or omit the \a from
915
parameter entirely.
916
917
\sa QString::lastIndexOf()
918
*/
919
920
/*!
921
\fn qsizetype QStringView::lastIndexOf(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
922
\fn qsizetype QStringView::lastIndexOf(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
923
\since 6.2
924
\overload lastIndexOf()
925
926
Returns the index position of the last occurrence of the UTF-16 string viewed
927
by \a str or the Latin-1 string viewed by \a l1 respectively, in this string
928
view searching backward from the last character of this string view. Returns
929
-1 if \a str or \a l1 is not found, respectively.
930
931
\include qstring.qdocinc {search-comparison-case-sensitivity} {search}
932
933
\sa QString::lastIndexOf()
934
*/
935
936
/*!
937
\fn QStringView::lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const
938
\since 6.3
939
\overload lastIndexOf()
940
*/
941
942
#
if
QT_CONFIG
(
regularexpression
)
943
/*!
944
\fn qsizetype QStringView::indexOf(const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch) const
945
\since 6.1
946
947
Returns the index position of the first match of the regular
948
expression \a re in the string view, searching forward from index
949
position \a from. Returns -1 if \a re didn't match anywhere.
950
951
If the match is successful and \a rmatch is not \nullptr, it also
952
writes the results of the match into the QRegularExpressionMatch object
953
pointed to by \a rmatch.
954
955
\note Due to how the regular expression matching algorithm works,
956
this function will actually match repeatedly from the beginning of
957
the string view until the position \a from is reached.
958
*/
959
960
/*!
961
\fn qsizetype QStringView::lastIndexOf(const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch) const
962
\since 6.1
963
964
Returns the index position of the last match of the regular
965
expression \a re in the string view, which starts before the index
966
position \a from.
967
968
\include qstring.qdocinc negative-index-start-search-from-end
969
970
Returns -1 if \a re didn't match anywhere.
971
972
If the match is successful and \a rmatch is not \nullptr, it also
973
writes the results of the match into the QRegularExpressionMatch object
974
pointed to by \a rmatch.
975
976
\note Due to how the regular expression matching algorithm works,
977
this function will actually match repeatedly from the beginning of
978
the string view until the position \a from is reached.
979
980
\note When searching for a regular expression \a re that may match
981
0 characters, the match at the end of the data is excluded from the
982
search by a negative \a from, even though \c{-1} is normally
983
thought of as searching from the end of the string view: the match
984
at the end is \e after the last character, so it is excluded. To
985
include such a final empty match, either give a positive value for
986
\a from or omit the \a from parameter entirely.
987
*/
988
989
/*!
990
\fn qsizetype QStringView::lastIndexOf(const QRegularExpression &re, QRegularExpressionMatch *rmatch = nullptr) const
991
\since 6.2
992
993
Returns the index position of the last match of the regular
994
expression \a re in the string view. Returns -1 if \a re didn't match
995
anywhere.
996
997
If the match is successful and \a rmatch is not \nullptr, it also
998
writes the results of the match into the QRegularExpressionMatch object
999
pointed to by \a rmatch.
1000
1001
\note Due to how the regular expression matching algorithm works,
1002
this function will actually match repeatedly from the beginning of
1003
the string view until the end of the string view is reached.
1004
*/
1005
1006
/*!
1007
\fn bool QStringView::contains(const QRegularExpression &re, QRegularExpressionMatch *rmatch) const
1008
\since 6.1
1009
1010
Returns \c true if the regular expression \a re matches somewhere in this
1011
string view; otherwise returns \c false.
1012
1013
If the match is successful and \a rmatch is not \nullptr, it also
1014
writes the results of the match into the QRegularExpressionMatch object
1015
pointed to by \a rmatch.
1016
1017
\sa QRegularExpression::match()
1018
*/
1019
1020
/*!
1021
\fn qsizetype QStringView::count(const QRegularExpression &re) const
1022
\since 6.1
1023
1024
Returns the number of times the regular expression \a re matches
1025
in the string view.
1026
1027
For historical reasons, this function counts overlapping matches.
1028
This behavior is different from simply iterating over the matches
1029
in the string view using QRegularExpressionMatchIterator.
1030
1031
\sa QRegularExpression::globalMatch()
1032
1033
*/
1034
#
endif
// QT_CONFIG(regularexpression)
1035
1036
/*!
1037
\fn QByteArray QStringView::toLatin1() const
1038
1039
Returns a Latin-1 representation of the string as a QByteArray.
1040
1041
The behavior is undefined if the string contains non-Latin1 characters.
1042
1043
\sa toUtf8(), toLocal8Bit(), QStringEncoder
1044
*/
1045
1046
/*!
1047
\fn QByteArray QStringView::toLocal8Bit() const
1048
1049
Returns a local 8-bit representation of the string as a QByteArray.
1050
1051
On Unix systems this is equivalen to toUtf8(), on Windows the systems
1052
current code page is being used.
1053
1054
The behavior is undefined if the string contains characters not
1055
supported by the locale's 8-bit encoding.
1056
1057
\sa toLatin1(), toUtf8(), QStringEncoder
1058
*/
1059
1060
/*!
1061
\fn QByteArray QStringView::toUtf8() const
1062
1063
Returns a UTF-8 representation of the string view as a QByteArray.
1064
1065
UTF-8 is a Unicode codec and can represent all characters in a Unicode
1066
string like QString.
1067
1068
\sa toLatin1(), toLocal8Bit(), QStringEncoder
1069
*/
1070
1071
/*!
1072
\fn QList<uint> QStringView::toUcs4() const
1073
1074
Returns a UCS-4/UTF-32 representation of the string view as a QList<uint>.
1075
1076
UCS-4 is a Unicode codec and therefore it is lossless. All characters from
1077
this string view will be encoded in UCS-4. Any invalid sequence of code units in
1078
this string view is replaced by the Unicode replacement character
1079
(QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}).
1080
1081
The returned list is not 0-terminated.
1082
1083
\sa toUtf8(), toLatin1(), toLocal8Bit(), QStringEncoder
1084
*/
1085
1086
/*!
1087
\fn template <typename QStringLike> qToStringViewIgnoringNull(const QStringLike &s);
1088
\since 5.10
1089
\internal
1090
1091
Convert \a s to a QStringView ignoring \c{s.isNull()}.
1092
1093
Returns a string view that references \a{s}' data, but is never null.
1094
1095
This is a faster way to convert a QString to a QStringView,
1096
if null QStrings can legitimately be treated as empty ones.
1097
1098
\sa QString::isNull(), QStringView
1099
*/
1100
1101
/*!
1102
\fn bool QStringView::isRightToLeft() const
1103
\since 5.11
1104
1105
Returns \c true if the string view is read right to left.
1106
1107
\sa QString::isRightToLeft()
1108
*/
1109
1110
/*!
1111
\fn bool QStringView::isValidUtf16() const
1112
\since 5.15
1113
1114
Returns \c true if the string view contains valid UTF-16 encoded data,
1115
or \c false otherwise.
1116
1117
Note that this function does not perform any special validation of the
1118
data; it merely checks if it can be successfully decoded from UTF-16.
1119
The data is assumed to be in host byte order; the presence of a BOM
1120
is meaningless.
1121
1122
\sa QString::isValidUtf16()
1123
*/
1124
1125
/*!
1126
\fn bool QStringView::isLower() const
1127
\since 6.7
1128
Returns \c true if this view is identical to its lowercase folding.
1129
1130
Note that this does \e not mean that the string view does not contain
1131
uppercase letters (some uppercase letters do not have a lowercase
1132
folding; they are left unchanged by toString().toLower()).
1133
For more information, refer to the Unicode standard, section 3.13.
1134
1135
\sa QChar::toLower(), isUpper()
1136
*/
1137
1138
/*!
1139
\fn bool QStringView::isUpper() const
1140
\since 6.7
1141
Returns \c true if this view is identical to its uppercase folding.
1142
1143
Note that this does \e not mean that the the string view does not contain
1144
lowercase letters (some lowercase letters do not have a uppercase
1145
folding; they are left unchanged by toString().toUpper()).
1146
For more information, refer to the Unicode standard, section 3.13.
1147
1148
\sa QChar::toUpper(), isLower()
1149
*/
1150
1151
/*!
1152
\fn QStringView::toWCharArray(wchar_t *array) const
1153
\since 5.14
1154
1155
Transcribes this string view into the given \a array.
1156
1157
The caller is responsible for ensuring \a array is large enough to hold the
1158
\c wchar_t encoding of this string view (allocating the array with the same length
1159
as the string view is always sufficient). The array is encoded in UTF-16 on
1160
platforms where \c wchar_t is 2 bytes wide (e.g. Windows); otherwise (Unix
1161
systems), \c wchar_t is assumed to be 4 bytes wide and the data is written
1162
in UCS-4.
1163
1164
\note This function writes no null terminator to the end of \a array.
1165
1166
Returns the number of \c wchar_t entries written to \a array.
1167
1168
\sa QString::toWCharArray()
1169
*/
1170
1171
/*!
1172
\fn qsizetype QStringView::count(QChar ch, Qt::CaseSensitivity cs) const noexcept
1173
1174
\since 6.0
1175
\overload count()
1176
1177
Returns the number of occurrences of the character \a ch in the
1178
string view.
1179
1180
\include qstring.qdocinc {search-comparison-case-sensitivity} {search}
1181
1182
\sa QString::count(), contains(), indexOf()
1183
*/
1184
1185
/*!
1186
\fn qsizetype QStringView::count(QStringView str, Qt::CaseSensitivity cs) const noexcept
1187
1188
\since 6.0
1189
\overload count()
1190
1191
Returns the number of (potentially overlapping) occurrences of the
1192
string view \a str in this string view.
1193
1194
\include qstring.qdocinc {search-comparison-case-sensitivity} {search}
1195
1196
\sa QString::count(), contains(), indexOf()
1197
*/
1198
1199
/*!
1200
\fn qsizetype QStringView::count(QLatin1StringView l1, Qt::CaseSensitivity cs) const noexcept
1201
1202
\since 6.4
1203
\overload count()
1204
1205
Returns the number of (potentially overlapping) occurrences of the
1206
Latin-1 string viewed by \a l1 in this string view.
1207
1208
\include qstring.qdocinc {search-comparison-case-sensitivity} {search}
1209
1210
\sa QString::count(), contains(), indexOf()
1211
*/
1212
1213
/*!
1214
\fn qint64 QStringView::toLongLong(bool *ok, int base) const
1215
1216
Returns the string view converted to a \c{long long} using base \a
1217
base, which is 10 by default and must be between 2 and 36, or 0.
1218
Returns 0 if the conversion fails.
1219
1220
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
1221
to \c false, and success by setting *\a{ok} to \c true.
1222
1223
If \a base is 0, the C language convention is used: if the string view
1224
begins with "0x", base 16 is used; otherwise, if the string view begins with "0",
1225
base 8 is used; otherwise, base 10 is used.
1226
1227
The string conversion will always happen in the 'C' locale. For locale
1228
dependent conversion use QLocale::toLongLong()
1229
1230
\sa QString::toLongLong()
1231
1232
\since 6.0
1233
*/
1234
1235
/*!
1236
\fn quint64 QStringView::toULongLong(bool *ok, int base) const
1237
1238
Returns the string view converted to an \c{unsigned long long} using base \a
1239
base, which is 10 by default and must be between 2 and 36, or 0.
1240
Returns 0 if the conversion fails.
1241
1242
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
1243
to \c false, and success by setting *\a{ok} to \c true.
1244
1245
If \a base is 0, the C language convention is used: if the string view
1246
begins with "0x", base 16 is used; otherwise, if the string view begins with "0",
1247
base 8 is used; otherwise, base 10 is used.
1248
1249
The string conversion will always happen in the 'C' locale. For locale
1250
dependent conversion use QLocale::toULongLong()
1251
1252
\sa QString::toULongLong()
1253
1254
\since 6.0
1255
*/
1256
1257
/*!
1258
\fn long QStringView::toLong(bool *ok, int base) const
1259
1260
Returns the string view converted to a \c long using base \a
1261
base, which is 10 by default and must be between 2 and 36, or 0.
1262
Returns 0 if the conversion fails.
1263
1264
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
1265
to \c false, and success by setting *\a{ok} to \c true.
1266
1267
If \a base is 0, the C language convention is used: if the string view
1268
begins with "0x", base 16 is used; otherwise, if the string view begins with "0",
1269
base 8 is used; otherwise, base 10 is used.
1270
1271
The string conversion will always happen in the 'C' locale. For locale
1272
dependent conversion use QLocale::toLong()
1273
1274
\sa QString::toLong()
1275
1276
\since 6.0
1277
*/
1278
1279
/*!
1280
\fn ulong QStringView::toULong(bool *ok, int base) const
1281
1282
Returns the string view converted to an \c{unsigned long} using base \a
1283
base, which is 10 by default and must be between 2 and 36, or 0.
1284
Returns 0 if the conversion fails.
1285
1286
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
1287
to \c false, and success by setting *\a{ok} to \c true.
1288
1289
If \a base is 0, the C language convention is used: if the string view
1290
begins with "0x", base 16 is used; otherwise, if the string view begins with "0",
1291
base 8 is used; otherwise, base 10 is used.
1292
1293
The string conversion will always happen in the 'C' locale. For locale
1294
dependent conversion use QLocale::toULongLong()
1295
1296
\sa QString::toULong()
1297
1298
\since 6.0
1299
*/
1300
1301
/*!
1302
\fn int QStringView::toInt(bool *ok, int base) const
1303
1304
Returns the string view converted to an \c int using base \a
1305
base, which is 10 by default and must be between 2 and 36, or 0.
1306
Returns 0 if the conversion fails.
1307
1308
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
1309
to \c false, and success by setting *\a{ok} to \c true.
1310
1311
If \a base is 0, the C language convention is used: if the string view
1312
begins with "0x", base 16 is used; otherwise, if the string view begins with "0",
1313
base 8 is used; otherwise, base 10 is used.
1314
1315
The string conversion will always happen in the 'C' locale. For locale
1316
dependent conversion use QLocale::toInt()
1317
1318
\sa QString::toInt()
1319
1320
\since 6.0
1321
*/
1322
1323
/*!
1324
\fn uint QStringView::toUInt(bool *ok, int base) const
1325
1326
Returns the string view converted to an \c{unsigned int} using base \a
1327
base, which is 10 by default and must be between 2 and 36, or 0.
1328
Returns 0 if the conversion fails.
1329
1330
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
1331
to \c false, and success by setting *\a{ok} to \c true.
1332
1333
If \a base is 0, the C language convention is used: if the string view
1334
begins with "0x", base 16 is used; otherwise, if the string view begins with "0",
1335
base 8 is used; otherwise, base 10 is used.
1336
1337
The string conversion will always happen in the 'C' locale. For locale
1338
dependent conversion use QLocale::toUInt()
1339
1340
\sa QString::toUInt()
1341
1342
\since 6.0
1343
*/
1344
1345
/*!
1346
\fn short QStringView::toShort(bool *ok, int base) const
1347
1348
Returns the string view converted to a \c short using base \a
1349
base, which is 10 by default and must be between 2 and 36, or 0.
1350
Returns 0 if the conversion fails.
1351
1352
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
1353
to \c false, and success by setting *\a{ok} to \c true.
1354
1355
If \a base is 0, the C language convention is used: if the string view
1356
begins with "0x", base 16 is used; otherwise, if the string view begins with "0",
1357
base 8 is used; otherwise, base 10 is used.
1358
1359
The string conversion will always happen in the 'C' locale. For locale
1360
dependent conversion use QLocale::toShort()
1361
1362
\sa QString::toShort()
1363
1364
\since 6.0
1365
*/
1366
1367
/*!
1368
\fn ushort QStringView::toUShort(bool *ok, int base) const
1369
1370
Returns the string view converted to an \c{unsigned short} using base \a
1371
base, which is 10 by default and must be between 2 and 36, or 0.
1372
Returns 0 if the conversion fails.
1373
1374
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
1375
to \c false, and success by setting *\a{ok} to \c true.
1376
1377
If \a base is 0, the C language convention is used: if the string view
1378
begins with "0x", base 16 is used; otherwise, if the string view begins with "0",
1379
base 8 is used; otherwise, base 10 is used.
1380
1381
The string conversion will always happen in the 'C' locale. For locale
1382
dependent conversion use QLocale::toUShort()
1383
1384
\sa QString::toUShort()
1385
1386
\since 6.0
1387
*/
1388
1389
/*!
1390
\fn double QStringView::toDouble(bool *ok) const
1391
1392
Returns the string view converted to a \c double value.
1393
1394
Returns an infinity if the conversion overflows or 0.0 if the
1395
conversion fails for other reasons (e.g. underflow).
1396
1397
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
1398
to \c false, and success by setting *\a{ok} to \c true.
1399
1400
The string conversion will always happen in the 'C' locale. For locale
1401
dependent conversion use QLocale::toDouble()
1402
1403
For historic reasons, this function does not handle
1404
thousands group separators. If you need to convert such numbers,
1405
use QLocale::toDouble().
1406
1407
\sa QString::toDouble()
1408
1409
\since 6.0
1410
*/
1411
1412
/*!
1413
\fn float QStringView::toFloat(bool *ok) const
1414
1415
Returns the string view converted to a \c float value.
1416
1417
Returns an infinity if the conversion overflows or 0.0 if the
1418
conversion fails for other reasons (e.g. underflow).
1419
1420
If \a ok is not \nullptr, failure is reported by setting *\a{ok}
1421
to \c false, and success by setting *\a{ok} to \c true.
1422
1423
The string conversion will always happen in the 'C' locale. For locale
1424
dependent conversion use QLocale::toFloat()
1425
1426
\sa QString::toFloat()
1427
1428
\since 6.0
1429
*/
1430
1431
1432
/*!
1433
\fn template <typename Needle, typename...Flags> auto QStringView::tokenize(Needle &&sep, Flags...flags) const
1434
\fn template <typename Needle, typename...Flags> auto QLatin1StringView::tokenize(Needle &&sep, Flags...flags) const
1435
\fn template <typename Needle, typename...Flags> auto QString::tokenize(Needle &&sep, Flags...flags) const &
1436
\fn template <typename Needle, typename...Flags> auto QString::tokenize(Needle &&sep, Flags...flags) const &&
1437
\fn template <typename Needle, typename...Flags> auto QString::tokenize(Needle &&sep, Flags...flags) &&
1438
1439
Splits the string into substring views wherever \a sep occurs, and
1440
returns a lazy sequence of those strings.
1441
1442
Equivalent to
1443
1444
\code
1445
return QStringTokenizer{std::forward<Needle>(sep), flags...};
1446
\endcode
1447
1448
except it works without C++17 Class Template Argument Deduction (CTAD)
1449
enabled in the compiler.
1450
1451
See QStringTokenizer for how \a sep and \a flags interact to form
1452
the result.
1453
1454
\note While this function returns QStringTokenizer, you should never,
1455
ever, name its template arguments explicitly. If you can use C++17 Class
1456
Template Argument Deduction (CTAD), you may write
1457
\code
1458
QStringTokenizer result = sv.tokenize(sep);
1459
\endcode
1460
(without template arguments). If you can't use C++17 CTAD, you must store
1461
the return value only in \c{auto} variables:
1462
\code
1463
auto result = sv.tokenize(sep);
1464
\endcode
1465
This is because the template arguments of QStringTokenizer have a very
1466
subtle dependency on the specific tokenize() overload from which they are
1467
returned, and they don't usually correspond to the type used for the separator.
1468
1469
\since 6.0
1470
\sa QStringTokenizer, qTokenize()
1471
*/
1472
1473
/*!
1474
\fn QStringView::operator std::u16string_view() const
1475
\since 6.7
1476
1477
Converts this QStringView object to a \c{std::u16string_view} object.
1478
The returned view will have the same data pointer and length of
1479
this view.
1480
*/
1481
1482
/*!
1483
\fn QStringView::maxSize()
1484
\since 6.8
1485
1486
It returns the maximum number of elements that the view can
1487
theoretically represent. In practice, the number can be much smaller,
1488
limited by the amount of memory available to the system.
1489
*/
1490
1491
/*!
1492
\fn QStringView::max_size() const
1493
\since 6.8
1494
1495
This function is provided for STL compatibility.
1496
1497
Returns maxSize().
1498
*/
1499
1500
/*!
1501
\fn Qt::Literals::StringLiterals::operator""_sv(const char16_t *str, size_t size)
1502
1503
\internal
1504
\relates QStringView
1505
1506
Literal operator that creates a QStringView out of the first
1507
\a size characters in the char16_t string literal \a str.
1508
1509
There is rarely need to explicitly construct a QStringView from a
1510
char16_t string literal, as QStringView is implicitly constructible
1511
from one:
1512
1513
\code
1514
QStringView greeting = u"hello"; // OK even without _sv
1515
1516
void print(QStringView s);
1517
print(u"world"); // OK even without _sv
1518
\endcode
1519
1520
To use this operator, you need to be using the corresponding
1521
namespace(s):
1522
1523
\code
1524
using namespace Qt::StringLiterals;
1525
auto sv = u"peace"_sv;
1526
\endcode
1527
1528
Note that the returned QStringView will span over any NUL embedded
1529
in the string literal. This is different from passing the string
1530
literal to QStringView's constructor (explicitly or implicitly):
1531
1532
\code
1533
QStringView sv1 = u"abc\0def"; // sv1 == "abc"
1534
QStringView sv2 = u"abc\0def"_sv; // sv2 == "abc\0def"
1535
\endcode
1536
1537
\sa Qt::Literals::StringLiterals
1538
*/
1539
1540
QT_END_NAMESPACE
QPlatformGraphicsBufferHelper
\inmodule QtGui
qtbase
src
corelib
text
qstringview.cpp
Generated on
for Qt by
1.14.0