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
qlatin1stringview.qdoc
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// Copyright (C) 2022 Intel Corporation.
3// Copyright (C) 2019 Mail.ru Group.
4// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5// Qt-Security score:insignificant reason:docs
6
7/*! \class QLatin1StringView
8 \inmodule QtCore
9 \brief The QLatin1StringView class provides a thin wrapper around
10 a US-ASCII/Latin-1 encoded string literal.
11
12 \ingroup string-processing
13 \reentrant
14
15 \compares strong
16 \compareswith strong char16_t QChar QStringView QUtf8StringView QString \
17 {const char16_t *}
18 \endcompareswith
19 \compareswith strong {const char *} QByteArray QByteArrayView
20 The byte array data is interpreted as UTF-8.
21 \endcompareswith
22
23 Many of QString's member functions are overloaded to accept
24 \c{const char *} instead of QString. This includes the copy
25 constructor, the assignment operator, the comparison operators,
26 and various other functions such as \l{QString::insert()}{insert()},
27 \l{QString::append()}{append()}, and \l{QString::prepend()}{prepend()}.
28 Some of these functions are optimized to avoid constructing a
29 QString object for the \c{const char *} data. For example,
30 assuming \c str is a QString,
31
32 \snippet code/src_corelib_text_qstring.cpp 3
33
34 is much faster than
35
36 \snippet code/src_corelib_text_qstring.cpp 4
37
38 because it doesn't construct four temporary QString objects and
39 make a deep copy of the character data.
40
41 However, that is not true for all QString member functions that take
42 \c{const char *} and therefore applications should assume a temporary will
43 be created, such as in
44
45 \snippet code/src_corelib_text_qstring.cpp 4bis
46
47 Applications that define \l QT_NO_CAST_FROM_ASCII (as explained
48 in the QString documentation) don't have access to QString's
49 \c{const char *} API. To provide an efficient way of specifying
50 constant Latin-1 strings, Qt provides the QLatin1StringView, which is
51 just a very thin wrapper around a \c{const char *}. Using
52 QLatin1StringView, the example code above becomes
53
54 \snippet code/src_corelib_text_qstring.cpp 5
55
56 This is a bit longer to type, but it provides exactly the same
57 benefits as the first version of the code, and is faster than
58 converting the Latin-1 strings using QString::fromLatin1().
59
60 Thanks to the QString(QLatin1StringView) constructor,
61 QLatin1StringView can be used everywhere a QString is expected. For
62 example:
63
64 \snippet code/src_corelib_text_qstring.cpp 6
65
66 \note If the function you're calling with a QLatin1StringView
67 argument isn't actually overloaded to take QLatin1StringView, the
68 implicit conversion to QString will trigger a memory allocation,
69 which is usually what you want to avoid by using QLatin1StringView
70 in the first place. In those cases, using QStringLiteral may be
71 the better option.
72
73 \note Only US-ASCII literals can be used in QLatin1StringView if the source
74 code file is encoded in UTF-8, as \l{unicode}{Qt requires}. Non-US-ASCII
75 literals like \c{QLatin1StringView("é")} will not be represented correctly.
76 You can use octal or hex notation instead:
77 \c{QLatin1StringView("\351")} or \c{QLatin1StringView("\xe9")},
78 respectively.
79
80 \sa QString, QLatin1Char, {QStringLiteral()}{QStringLiteral},
81 QT_NO_CAST_FROM_ASCII
82*/
83
84/*!
85 \class QLatin1String
86 \inmodule QtCore
87 \brief QLatin1String is the same as QLatin1StringView.
88
89 QLatin1String is a view to a Latin-1 string. It's the same as
90 QLatin1StringView and is kept for compatibility reasons. It is
91 recommended to use QLatin1StringView instead.
92
93 Please see the QLatin1StringView documentation for details.
94*/
95
96/*!
97 \typedef QLatin1StringView::value_type
98 \since 5.10
99
100 Alias for \c{const char}. Provided for compatibility with the STL.
101*/
102
103/*!
104 \typedef QLatin1StringView::difference_type
105 \since 5.10
106
107 Alias for \c{qsizetype}. Provided for compatibility with the STL.
108*/
109
110/*!
111 \typedef QLatin1StringView::size_type
112 \since 5.10
113
114 Alias for \c{qsizetype}. Provided for compatibility with the STL.
115
116 \note In version prior to Qt 6, this was an alias for \c{int},
117 restricting the amount of data that could be held in a QLatin1StringView
118 on 64-bit architectures.
119*/
120
121/*!
122 \typedef QLatin1StringView::pointer
123 \typedef QLatin1StringView::const_pointer
124 \since 6.7
125
126 Alias for \c{value_type *}. Provided for compatibility with the STL.
127*/
128
129/*!
130 \typedef QLatin1StringView::reference
131 \since 5.10
132
133 Alias for \c{value_type &}. Provided for compatibility with the STL.
134*/
135
136/*!
137 \typedef QLatin1StringView::const_reference
138 \since 5.11
139
140 Alias for \c{reference}. Provided for compatibility with the STL.
141*/
142
143/*!
144 \typedef QLatin1StringView::iterator
145 \since 5.10
146
147 QLatin1StringView does not support mutable iterators, so this is the same
148 as const_iterator.
149
150 \sa const_iterator, reverse_iterator
151*/
152
153/*!
154 \typedef QLatin1StringView::const_iterator
155 \since 5.10
156
157 \sa iterator, const_reverse_iterator
158*/
159
160/*!
161 \typedef QLatin1StringView::reverse_iterator
162 \since 5.10
163
164 QLatin1StringView 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 QLatin1StringView::const_reverse_iterator
172 \since 5.10
173
174 \sa reverse_iterator, const_iterator
175*/
176
177/*! \fn QLatin1StringView::QLatin1StringView()
178 \since 5.6
179
180 Constructs a QLatin1StringView object that stores a \nullptr.
181
182 \sa data(), isEmpty(), isNull(), {Distinction Between Null and Empty Strings}
183*/
184
185/*! \fn QLatin1StringView::QLatin1StringView(std::nullptr_t)
186 \since 6.4
187
188 Constructs a QLatin1StringView object that stores a \nullptr.
189
190 \sa data(), isEmpty(), isNull(), {Distinction Between Null and Empty Strings}
191*/
192
193/*! \fn QLatin1StringView::QLatin1StringView(const char *str)
194
195 Constructs a QLatin1StringView object that stores \a str.
196
197 The string data is \e not copied. The caller must be able to
198 guarantee that \a str will not be deleted or modified as long as
199 the QLatin1StringView object exists.
200
201 \sa latin1()
202*/
203
204/*! \fn QLatin1StringView::QLatin1StringView(const char *str, qsizetype size)
205
206 Constructs a QLatin1StringView object that stores \a str with \a size.
207
208 The string data is \e not copied. The caller must be able to
209 guarantee that \a str will not be deleted or modified as long as
210 the QLatin1StringView object exists.
211
212 \note: any null ('\\0') bytes in the byte array will be included in this
213 string, which will be converted to Unicode null characters (U+0000) if this
214 string is used by QString. This behavior is different from Qt 5.x.
215
216 \sa latin1()
217*/
218
219/*!
220 \fn QLatin1StringView::QLatin1StringView(const char *first, const char *last)
221 \since 5.10
222
223 Constructs a QLatin1StringView object that stores \a first with length
224 (\a last - \a first).
225
226 The range \c{[first,last)} must remain valid for the lifetime of
227 this Latin-1 string object.
228
229 Passing \nullptr as \a first is safe if \a last is \nullptr,
230 too, and results in a null Latin-1 string.
231
232 The behavior is undefined if \a last precedes \a first, \a first
233 is \nullptr and \a last is not, or if \c{last - first >
234 INT_MAX}.
235*/
236
237/*! \fn QLatin1StringView::QLatin1StringView(const QByteArray &str)
238
239 Constructs a QLatin1StringView object as a view on \a str.
240
241 The string data is \e not copied. The caller must be able to
242 guarantee that \a str will not be deleted or modified as long as
243 the QLatin1StringView object exists.
244
245 \sa latin1()
246*/
247
248/*! \fn QLatin1StringView::QLatin1StringView(QByteArrayView str)
249 \since 6.3
250
251 Constructs a QLatin1StringView object as a view on \a str.
252
253 The string data is \e not copied. The caller must be able to
254 guarantee that the data which \a str is pointing to will not
255 be deleted or modified as long as the QLatin1StringView object
256 exists. The size is obtained from \a str as-is, without checking
257 for a null-terminator.
258
259 \note: any null ('\\0') bytes in the byte array will be included in this
260 string, which will be converted to Unicode null characters (U+0000) if this
261 string is used by QString.
262
263 \sa latin1()
264*/
265
266/*!
267 \fn QString QLatin1StringView::toString() const
268 \since 6.0
269
270 Converts this Latin-1 string into a QString. Equivalent to
271 \code
272 return QString(*this);
273 \endcode
274
275 \sa toUtf8()
276*/
277
278/*!
279 \fn QByteArray QLatin1StringView::toUtf8() const
280 \since 6.9
281
282 Returns a UTF-8 representation of the string as a QByteArray. This function
283 is more efficient than converting first to QString.
284
285 \sa toString(), QString::toUtf8()
286*/
287
288/*! \fn const char *QLatin1StringView::latin1() const
289
290 Returns the start of the Latin-1 string referenced by this object.
291*/
292
293/*! \fn const char *QLatin1StringView::data() const
294
295 Returns the start of the Latin-1 string referenced by this object.
296*/
297
298/*! \fn const char *QLatin1StringView::constData() const
299 \since 6.4
300
301 Returns the start of the Latin-1 string referenced by this object.
302
303 This function is provided for compatibility with other Qt containers.
304
305 \sa data()
306*/
307
308/*! \fn qsizetype QLatin1StringView::size() const
309
310 Returns the size of the Latin-1 string referenced by this object.
311
312 \note In version prior to Qt 6, this function returned \c{int},
313 restricting the amount of data that could be held in a QLatin1StringView
314 on 64-bit architectures.
315*/
316
317/*! \fn qsizetype QLatin1StringView::length() const
318 \since 6.4
319
320 Same as size().
321
322 This function is provided for compatibility with other Qt containers.
323*/
324
325/*! \fn bool QLatin1StringView::isNull() const
326 \since 5.10
327
328 Returns whether the Latin-1 string referenced by this object is null
329 (\c{data() == nullptr}) or not.
330
331 \sa isEmpty(), data()
332*/
333
334/*! \fn bool QLatin1StringView::isEmpty() const
335 \since 5.10
336
337 Returns whether the Latin-1 string referenced by this object is empty
338 (\c{size() == 0}) or not.
339
340 \sa isNull(), size()
341*/
342
343/*! \fn bool QLatin1StringView::empty() const
344 \since 6.4
345
346 Returns whether the Latin-1 string referenced by this object is empty
347 (\c{size() == 0}) or not.
348
349 This function is provided for STL compatibility.
350
351 \sa isEmpty(), isNull(), size()
352*/
353
354/*! \fn QLatin1Char QLatin1StringView::at(qsizetype pos) const
355 \since 5.8
356
357 Returns the character at position \a pos in this object.
358
359 \note This function performs no error checking.
360 The behavior is undefined when \a pos < 0 or \a pos >= size().
361
362 \sa operator[]()
363*/
364
365/*! \fn QLatin1Char QLatin1StringView::operator[](qsizetype pos) const
366 \since 5.8
367
368 Returns the character at position \a pos in this object.
369
370 \note This function performs no error checking.
371 The behavior is undefined when \a pos < 0 or \a pos >= size().
372
373 \sa at()
374*/
375
376/*!
377 \fn QLatin1Char QLatin1StringView::front() const
378 \since 5.10
379
380 Returns the first character in the string.
381 Same as \c{at(0)}.
382
383 This function is provided for STL compatibility.
384
385 \warning Calling this function on an empty string constitutes
386 undefined behavior.
387
388 \sa back(), at(), operator[]()
389*/
390
391/*!
392 \fn QLatin1Char QLatin1StringView::first() const
393 \since 6.4
394
395 Returns the first character in the string.
396 Same as \c{at(0)} or front().
397
398 This function is provided for compatibility with other Qt containers.
399
400 \warning Calling this function on an empty string constitutes
401 undefined behavior.
402
403 \sa last(), front(), back()
404*/
405
406/*!
407 \fn QLatin1Char QLatin1StringView::back() const
408 \since 5.10
409
410 Returns the last character in the string.
411 Same as \c{at(size() - 1)}.
412
413 This function is provided for STL compatibility.
414
415 \warning Calling this function on an empty string constitutes
416 undefined behavior.
417
418 \sa front(), at(), operator[]()
419*/
420
421/*!
422 \fn QLatin1Char QLatin1StringView::last() const
423 \since 6.4
424
425 Returns the last character in the string.
426 Same as \c{at(size() - 1)} or back().
427
428 This function is provided for compatibility with other Qt containers.
429
430 \warning Calling this function on an empty string constitutes
431 undefined behavior.
432
433 \sa first(), back(), front()
434*/
435
436/*!
437 \fn int QLatin1StringView::compare(QStringView str, Qt::CaseSensitivity cs) const
438 \fn int QLatin1StringView::compare(QLatin1StringView l1, Qt::CaseSensitivity cs) const
439 \fn int QLatin1StringView::compare(QChar ch) const
440 \fn int QLatin1StringView::compare(QChar ch, Qt::CaseSensitivity cs) const
441 \since 5.14
442
443 Compares this string view with UTF-16 string view \a str, Latin-1 string view \a l1,
444 or the character \a ch, respectively. Returns a negative integer if this
445 string is less than \a str, \a l1 or \a ch, returns a positive integer if it
446 is greater than \a str, \a l1 or \a ch, and zero if they are equal.
447
448 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
449
450 \sa operator==(), operator<(), operator>()
451*/
452
453/*!
454 \fn int QLatin1StringView::compare(QUtf8StringView str, Qt::CaseSensitivity cs) const
455 \since 6.5
456
457 Compares this string view with \a str and returns a negative integer if
458 this string view is less than \a str, a positive integer if it is greater than
459 \a str, and zero if they are equal.
460
461 \include qstring.qdocinc {search-comparison-case-sensitivity} {comparison}
462
463 \sa operator==(), operator<(), operator>()
464*/
465
466
467/*!
468 \fn bool QLatin1StringView::startsWith(QStringView str, Qt::CaseSensitivity cs) const
469 \since 5.10
470 \fn bool QLatin1StringView::startsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const
471 \since 5.10
472 \fn bool QLatin1StringView::startsWith(QChar ch) const
473 \since 5.10
474 \fn bool QLatin1StringView::startsWith(QChar ch, Qt::CaseSensitivity cs) const
475 \since 5.10
476
477 Returns \c true if this Latin-1 string view starts with the UTF-16
478 string viewed by \a str, the Latin-1 string viewed by \a l1, or the
479 character \a ch, respectively; otherwise returns \c false.
480
481 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
482
483 \sa endsWith()
484*/
485
486/*!
487 \fn bool QLatin1StringView::endsWith(QStringView str, Qt::CaseSensitivity cs) const
488 \since 5.10
489 \fn bool QLatin1StringView::endsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const
490 \since 5.10
491 \fn bool QLatin1StringView::endsWith(QChar ch) const
492 \since 5.10
493 \fn bool QLatin1StringView::endsWith(QChar ch, Qt::CaseSensitivity cs) const
494 \since 5.10
495
496 Returns \c true if this Latin-1 string view ends with the UTF-16 string
497 viewed \a str, the Latin-1 string viewed by \a l1, or the character \a ch,
498 respectively; otherwise returns \c false.
499
500 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
501
502 \sa startsWith()
503*/
504
505/*!
506 \fn qsizetype QLatin1StringView::indexOf(QStringView str, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
507 \fn qsizetype QLatin1StringView::indexOf(QLatin1StringView l1, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
508 \fn qsizetype QLatin1StringView::indexOf(QChar c, qsizetype from = 0) const
509 \fn qsizetype QLatin1StringView::indexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const
510 \since 5.14
511
512 Returns the index position in this Latin-1 string view of the first
513 occurrence of the UTF-16 string viewed by \a str, the Latin-1 string
514 viewed by \a l1, or the character \a ch, respectively, searching forward
515 from index position \a from. Returns -1 if \a str, \a l1 or \a c is not
516 found, respectively.
517
518 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
519
520 \include qstring.qdocinc negative-index-start-search-from-end
521
522 \sa QString::indexOf()
523*/
524
525/*!
526 \fn bool QLatin1StringView::contains(QStringView str, Qt::CaseSensitivity cs) const
527 \fn bool QLatin1StringView::contains(QLatin1StringView l1, Qt::CaseSensitivity cs) const
528 \fn bool QLatin1StringView::contains(QChar c, Qt::CaseSensitivity cs) const
529 \since 5.14
530
531 Returns \c true if this Latin-1 string view contains an occurrence of the
532 UTF-16 string viewed by \a str, the Latin-1 string viewed by \a l1, or the
533 character \a ch, respectively; otherwise returns \c false.
534
535 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
536
537 \sa indexOf(), QStringView::contains(), QStringView::indexOf(),
538 QString::indexOf()
539*/
540
541/*!
542 \fn qsizetype QLatin1StringView::lastIndexOf(QStringView str, qsizetype from, Qt::CaseSensitivity cs) const
543 \fn qsizetype QLatin1StringView::lastIndexOf(QLatin1StringView l1, qsizetype from, Qt::CaseSensitivity cs) const
544 \fn qsizetype QLatin1StringView::lastIndexOf(QChar c) const
545 \fn qsizetype QLatin1StringView::lastIndexOf(QChar c, Qt::CaseSensitivity cs) const
546 \fn qsizetype QLatin1StringView::lastIndexOf(QChar c, qsizetype from) const
547 \fn qsizetype QLatin1StringView::lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const
548 \since 5.14
549
550 Returns the index position in this Latin-1 string view of the last
551 occurrence of the UTF-16 string viewed by \a str, the Latin-1 string
552 viewed by \a l1, or the character \a ch, respectively, searching backward
553 from index position \a from; returns -1 if \a str, \a l1 or \a ch is not
554 found, respectively.
555
556 \include qstring.qdocinc negative-index-start-search-from-end
557
558 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
559
560 \note When searching for a 0-length \a str or \a l1, the match at
561 the end of the data is excluded from the search by a negative \a
562 from, even though \c{-1} is normally thought of as searching from
563 the end of the string: the match at the end is \e after the last
564 character, so it is excluded. To include such a final empty match,
565 either give a positive value for \a from or omit the \a from
566 parameter entirely.
567
568 \sa indexOf(), QStringView::lastIndexOf(), QStringView::indexOf(),
569 QString::indexOf()
570*/
571
572/*!
573 \fn qsizetype QLatin1StringView::lastIndexOf(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
574 \fn qsizetype QLatin1StringView::lastIndexOf(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
575 \since 6.2
576 \overload lastIndexOf()
577
578 Returns the index position in this Latin-1 string view of the last
579 occurrence of the UTF-16 string viewed by \a str or the Latin-1 string
580 viewed by \a l1, respectively. Returns -1 if \a str or \a l1 is not found,
581 respectively.
582
583 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
584*/
585
586/*!
587 \fn qsizetype QLatin1StringView::lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const
588 \since 6.3
589 \overload
590*/
591
592/*!
593 \fn qsizetype QLatin1StringView::count(QStringView str, Qt::CaseSensitivity cs) const
594 \fn qsizetype QLatin1StringView::count(QLatin1StringView l1, Qt::CaseSensitivity cs) const
595 \fn qsizetype QLatin1StringView::count(QChar ch, Qt::CaseSensitivity cs) const
596 \since 6.4
597
598 Returns the number of (potentially overlapping) occurrences of the
599 UTF-16 string viewed by \a str, the Latin-1 string viewed by \a l1,
600 or the character \a ch, respectively, in this string view.
601
602 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
603
604 \sa contains(), indexOf()
605*/
606
607/*!
608 \fn QLatin1StringView::const_iterator QLatin1StringView::begin() const
609 \since 5.10
610
611 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the
612 first character in the string.
613
614 This function is provided for STL compatibility.
615
616 \sa end(), cbegin(), rbegin(), data()
617*/
618
619/*!
620 \fn QLatin1StringView::const_iterator QLatin1StringView::cbegin() const
621 \since 5.10
622
623 Same as begin().
624
625 This function is provided for STL compatibility.
626
627 \sa cend(), begin(), crbegin(), data()
628*/
629
630/*!
631 \fn QLatin1StringView::const_iterator QLatin1StringView::constBegin() const
632 \since 6.4
633
634 Same as begin().
635
636 This function is provided for compatibility with other Qt containers.
637
638 \sa constEnd(), begin(), cbegin(), data()
639*/
640
641/*!
642 \fn QLatin1StringView::const_iterator QLatin1StringView::end() const
643 \since 5.10
644
645 Returns a const \l{STL-style iterators}{STL-style iterator} pointing just
646 after the last character in the string.
647
648 This function is provided for STL compatibility.
649
650 \sa begin(), cend(), rend()
651*/
652
653/*! \fn QLatin1StringView::const_iterator QLatin1StringView::cend() const
654 \since 5.10
655
656 Same as end().
657
658 This function is provided for STL compatibility.
659
660 \sa cbegin(), end(), crend()
661*/
662
663/*! \fn QLatin1StringView::const_iterator QLatin1StringView::constEnd() const
664 \since 6.4
665
666 Same as end().
667
668 This function is provided for compatibility with other Qt containers.
669
670 \sa constBegin(), end(), cend(), crend()
671*/
672
673/*!
674 \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::rbegin() const
675 \since 5.10
676
677 Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing
678 to the first character in the string, in reverse order.
679
680 This function is provided for STL compatibility.
681
682 \sa rend(), crbegin(), begin()
683*/
684
685/*!
686 \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::crbegin() const
687 \since 5.10
688
689 Same as rbegin().
690
691 This function is provided for STL compatibility.
692
693 \sa crend(), rbegin(), cbegin()
694*/
695
696/*!
697 \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::rend() const
698 \since 5.10
699
700 Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing just
701 after the last character in the string, in reverse order.
702
703 This function is provided for STL compatibility.
704
705 \sa rbegin(), crend(), end()
706*/
707
708/*!
709 \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::crend() const
710 \since 5.10
711
712 Same as rend().
713
714 This function is provided for STL compatibility.
715
716 \sa crbegin(), rend(), cend()
717*/
718
719/*!
720 \fn QLatin1StringView QLatin1StringView::mid(qsizetype start, qsizetype length) const
721 \since 5.8
722
723 Returns the substring of length \a length starting at position
724 \a start in this Latin-1 string view.
725
726 If you know that \a start and \a length cannot be out of bounds, use
727 sliced() instead in new code, because it is faster.
728
729 Returns an empty Latin-1 string view if \a start exceeds the length
730 of this string view. If there are less than \a length characters available
731 in this string view starting at \a start, or if \a length is negative
732 (default), the function returns all characters that are available from
733 \a start.
734
735 \sa first(), last(), sliced(), chopped(), chop(), truncate(), slice()
736*/
737
738/*!
739 \fn QLatin1StringView QLatin1StringView::left(qsizetype length) const
740 \since 5.8
741
742 If you know that \a length cannot be out of bounds, use first() instead in
743 new code, because it is faster.
744
745 Returns the substring of length \a length starting at position
746 0 in this Latin-1 string view.
747
748 The entire Latin-1 string view is returned if \a length is greater
749 than or equal to size(), or less than zero.
750
751 \sa first(), last(), sliced(), startsWith(), chopped(), chop(), truncate(), slice()
752*/
753
754/*!
755 \fn QLatin1StringView QLatin1StringView::right(qsizetype length) const
756 \since 5.8
757
758 If you know that \a length cannot be out of bounds, use last() instead in
759 new code, because it is faster.
760
761 Returns the substring of length \a length starting at position
762 size() - \a length in this Latin-1 string view.
763
764 The entire Latin-1 string view is returned if \a length is greater
765 than or equal to size(), or less than zero.
766
767 \sa first(), last(), sliced(), endsWith(), chopped(), chop(), truncate(), slice()
768*/
769
770/*!
771 \fn QLatin1StringView QLatin1StringView::first(qsizetype n) const
772 \since 6.0
773
774 Returns a Latin-1 string view that contains the first \a n characters
775 of this string view.
776
777 \note The behavior is undefined when \a n < 0 or \a n > size().
778
779 \sa last(), startsWith(), chopped(), chop(), truncate(), slice()
780*/
781
782/*!
783 \fn QLatin1StringView QLatin1StringView::last(qsizetype n) const
784 \since 6.0
785
786 Returns a Latin-1 string view that contains the last \a n characters
787 of this string view.
788
789 \note The behavior is undefined when \a n < 0 or \a n > size().
790
791 \sa first(), endsWith(), chopped(), chop(), truncate(), slice()
792*/
793
794/*!
795 \fn QLatin1StringView QLatin1StringView::sliced(qsizetype pos, qsizetype n) const
796 \since 6.0
797
798 Returns a Latin-1 string view that points to \a n characters of this
799 string view, starting at position \a pos.
800
801//! [UB-sliced-index-length]
802 \note The behavior is undefined when \a pos < 0, \a n < 0,
803 or \c{pos + n > size()}.
804//! [UB-sliced-index-length]
805
806 \sa first(), last(), chopped(), chop(), truncate(), slice()
807*/
808
809/*!
810 \fn QLatin1StringView QLatin1StringView::sliced(qsizetype pos) const
811 \since 6.0
812
813 Returns a Latin-1 string view starting at position \a pos in this
814 string view, and extending to its end.
815
816//! [UB-sliced-index-only]
817 \note The behavior is undefined when \a pos < 0 or \a pos > size().
818//! [UB-sliced-index-only]
819
820 \sa first(), last(), chopped(), chop(), truncate(), slice()
821*/
822
823/*!
824 \fn QLatin1StringView &QLatin1StringView::slice(qsizetype pos, qsizetype n)
825 \since 6.8
826 \overload
827
828 Modifies this Latin-1 string view to start at position \a pos,
829 extending for \a n characters.
830
831 \include qlatin1stringview.qdoc UB-sliced-index-length
832
833 \sa sliced(), first(), last(), chopped(), chop(), truncate()
834*/
835
836/*!
837 \fn QLatin1StringView &QLatin1StringView::slice(qsizetype pos)
838 \since 6.8
839
840 Modifies this Latin-1 string view to start at position \a pos, extending
841 to its end.
842
843 \include qlatin1stringview.qdoc UB-sliced-index-only
844
845 \sa sliced(), first(), last(), chopped(), chop(), truncate()
846*/
847
848/*!
849 \fn QLatin1StringView QLatin1StringView::chopped(qsizetype length) const
850 \since 5.10
851
852 Returns the substring of length size() - \a length starting at the
853 beginning of this object.
854
855 Same as \c{left(size() - length)}.
856
857 \note The behavior is undefined when \a length < 0 or \a length > size().
858
859 \sa sliced(), first(), last(), chop(), truncate(), slice()
860*/
861
862/*!
863 \fn void QLatin1StringView::truncate(qsizetype length)
864 \since 5.10
865
866 Truncates this string to length \a length.
867
868 Same as \c{*this = left(length)}.
869
870 \note The behavior is undefined when \a length < 0 or \a length > size().
871
872 \sa sliced(), first(), last(), chopped(), chop()
873*/
874
875/*!
876 \fn void QLatin1StringView::chop(qsizetype length)
877 \since 5.10
878
879 Truncates this string by \a length characters.
880
881 Same as \c{*this = left(size() - length)}.
882
883 \note The behavior is undefined when \a length < 0 or \a length > size().
884
885 \sa sliced(), first(), last(), chopped(), truncate(), slice()
886*/
887
888/*!
889 \fn QLatin1StringView QLatin1StringView::trimmed() const
890 \since 5.10
891
892 Strips leading and trailing whitespace and returns the result.
893
894 Whitespace means any character for which QChar::isSpace() returns
895 \c true. This includes the ASCII characters '\\t', '\\n', '\\v',
896 '\\f', '\\r', and ' '.
897*/
898
899/*!
900 \fn bool QLatin1StringView::operator==(const QLatin1StringView &lhs, const char * const &rhs)
901 \since 4.3
902
903 Returns \c true if the string \a lhs is equal to const char pointer \a rhs;
904 otherwise returns \c false.
905
906 The \a rhs const char pointer is converted to a QUtf8StringView.
907
908 You can disable this operator by defining
909 \l QT_NO_CAST_FROM_ASCII when you compile your applications. This
910 can be useful if you want to ensure that all user-visible strings
911 go through QObject::tr(), for example.
912
913 \sa {Comparing Strings}
914*/
915
916/*!
917 \fn bool QLatin1StringView::operator==(const QLatin1StringView &lhs, const QByteArray &rhs)
918 \since 5.0
919 \overload
920
921 The \a rhs byte array is converted to a QUtf8StringView.
922
923 You can disable this operator by defining
924 \l QT_NO_CAST_FROM_ASCII when you compile your applications. This
925 can be useful if you want to ensure that all user-visible strings
926 go through QObject::tr(), for example.
927*/
928
929/*!
930 \fn bool QLatin1StringView::operator!=(const QLatin1StringView &lhs, const char * const &rhs)
931 \since 4.3
932
933 Returns \c true if the string \a lhs is not equal to const char pointer \a rhs;
934 otherwise returns \c false.
935
936 The \a rhs const char pointer is converted to a QUtf8StringView.
937
938 You can disable this operator by defining
939 \l QT_NO_CAST_FROM_ASCII when you compile your applications. This
940 can be useful if you want to ensure that all user-visible strings
941 go through QObject::tr(), for example.
942
943 \sa {Comparing Strings}
944*/
945
946/*!
947 \fn bool QLatin1StringView::operator!=(const QLatin1StringView &lhs, const QByteArray &rhs)
948 \since 5.0
949 \overload operator!=()
950
951 The \a rhs byte array is converted to a QUtf8StringView.
952
953 You can disable this operator by defining
954 \l QT_NO_CAST_FROM_ASCII when you compile your applications. This
955 can be useful if you want to ensure that all user-visible strings
956 go through QObject::tr(), for example.
957*/
958
959/*!
960 \fn bool QLatin1StringView::operator>(const QLatin1StringView &lhs, const char * const &rhs)
961 \since 4.3
962
963 Returns \c true if the string \a lhs is lexically greater than const char pointer
964 \a rhs; otherwise returns \c false.
965
966 The \a rhs const char pointer is converted to a QUtf8StringView.
967
968 You can disable this operator by defining \l QT_NO_CAST_FROM_ASCII
969 when you compile your applications. This can be useful if you want
970 to ensure that all user-visible strings go through QObject::tr(),
971 for example.
972
973 \sa {Comparing Strings}
974*/
975
976/*!
977 \fn bool QLatin1StringView::operator>(const QLatin1StringView &lhs, const QByteArray &rhs)
978 \since 5.0
979 \overload
980
981 The \a rhs byte array is converted to a QUtf8StringView.
982
983 You can disable this operator by defining \l QT_NO_CAST_FROM_ASCII
984 when you compile your applications. This can be useful if you want
985 to ensure that all user-visible strings go through QObject::tr(),
986 for example.
987*/
988
989/*!
990 \fn bool QLatin1StringView::operator<(const QLatin1StringView &lhs, const char * const &rhs)
991 \since 4.3
992
993 Returns \c true if the string \a lhs is lexically less than const char pointer
994 \a rhs; otherwise returns \c false.
995
996 The \a rhs const char pointer is converted to a QUtf8StringView.
997
998 You can disable this operator by defining
999 \l QT_NO_CAST_FROM_ASCII when you compile your applications. This
1000 can be useful if you want to ensure that all user-visible strings
1001 go through QObject::tr(), for example.
1002
1003 \sa {Comparing Strings}
1004*/
1005
1006/*!
1007 \fn bool QLatin1StringView::operator<(const QLatin1StringView &lhs, const QByteArray &rhs)
1008 \since 5.0
1009 \overload
1010
1011 The \a rhs byte array is converted to a QUtf8StringView.
1012
1013 You can disable this operator by defining
1014 \l QT_NO_CAST_FROM_ASCII when you compile your applications. This
1015 can be useful if you want to ensure that all user-visible strings
1016 go through QObject::tr(), for example.
1017*/
1018
1019/*!
1020 \fn bool QLatin1StringView::operator>=(const QLatin1StringView &lhs, const char * const &rhs)
1021 \since 4.3
1022
1023 Returns \c true if the string \a lhs is lexically greater than or equal to
1024 const char pointer \a rhs; otherwise returns \c false.
1025
1026 The \a rhs const char pointer is converted to a QUtf8StringView.
1027
1028 You can disable this operator by defining
1029 \l QT_NO_CAST_FROM_ASCII when you compile your applications. This
1030 can be useful if you want to ensure that all user-visible strings
1031 go through QObject::tr(), for example.
1032
1033 \sa {Comparing Strings}
1034*/
1035
1036/*!
1037 \fn bool QLatin1StringView::operator>=(const QLatin1StringView &lhs, const QByteArray &rhs)
1038 \since 5.0
1039 \overload
1040
1041 The \a rhs byte array is converted to a QUtf8StringView.
1042
1043 You can disable this operator by defining
1044 \l QT_NO_CAST_FROM_ASCII when you compile your applications. This
1045 can be useful if you want to ensure that all user-visible strings
1046 go through QObject::tr(), for example.
1047*/
1048
1049/*!
1050 \fn bool QLatin1StringView::operator<=(const QLatin1StringView &lhs, const char * const &rhs)
1051 \since 4.3
1052
1053 Returns \c true if the string \a lhs is lexically less than or equal to
1054 const char pointer \a rhs; otherwise returns \c false.
1055
1056 The \a rhs const char pointer is converted to a QUtf8StringView.
1057
1058 You can disable this operator by defining
1059 \l QT_NO_CAST_FROM_ASCII when you compile your applications. This
1060 can be useful if you want to ensure that all user-visible strings
1061 go through QObject::tr(), for example.
1062
1063 \sa {Comparing Strings}
1064*/
1065
1066/*!
1067 \fn bool QLatin1StringView::operator<=(const QLatin1StringView &lhs, const QByteArray &rhs)
1068 \since 5.0
1069 \overload
1070
1071 The \a rhs byte array is converted to a QUtf8StringView.
1072
1073 You can disable this operator by defining
1074 \l QT_NO_CAST_FROM_ASCII when you compile your applications. This
1075 can be useful if you want to ensure that all user-visible strings
1076 go through QObject::tr(), for example.
1077*/
1078
1079/*! \fn bool QLatin1StringView::operator==(const QLatin1StringView &lhs, const QLatin1StringView &rhs)
1080
1081 Returns \c true if string \a lhs is lexically equal to string \a rhs;
1082 otherwise returns \c false.
1083*/
1084/*! \fn bool QLatin1StringView::operator!=(const QLatin1StringView &lhs, const QLatin1StringView &rhs)
1085
1086 Returns \c true if string \a lhs is lexically not equal to string \a rhs;
1087 otherwise returns \c false.
1088*/
1089/*! \fn bool QLatin1StringView::operator<(const QLatin1StringView &lhs, const QLatin1StringView &rhs)
1090
1091 Returns \c true if string \a lhs is lexically less than string \a rhs;
1092 otherwise returns \c false.
1093*/
1094/*! \fn bool QLatin1StringView::operator<=(const QLatin1StringView &lhs, const QLatin1StringView &rhs)
1095
1096 Returns \c true if string \a lhs is lexically less than or equal to
1097 string \a rhs; otherwise returns \c false.
1098*/
1099/*! \fn bool QLatin1StringView::operator>(const QLatin1StringView &lhs, const QLatin1StringView &rhs)
1100
1101 Returns \c true if string \a lhs is lexically greater than string \a rhs;
1102 otherwise returns \c false.
1103*/
1104/*! \fn bool QLatin1StringView::operator>=(const QLatin1StringView &lhs, const QLatin1StringView &rhs)
1105
1106 Returns \c true if string \a lhs is lexically greater than or equal
1107 to string \a rhs; otherwise returns \c false.
1108*/
1109
1110/*! \fn bool QLatin1StringView::operator==(const QChar &lhs, const QLatin1StringView &rhs)
1111
1112 Returns \c true if char \a lhs is lexically equal to string \a rhs;
1113 otherwise returns \c false.
1114*/
1115/*! \fn bool QLatin1StringView::operator<(const QChar &lhs, const QLatin1StringView &rhs)
1116
1117 Returns \c true if char \a lhs is lexically less than string \a rhs;
1118 otherwise returns \c false.
1119*/
1120/*! \fn bool QLatin1StringView::operator>(const QChar &lhs, const QLatin1StringView &rhs)
1121 Returns \c true if char \a lhs is lexically greater than string \a rhs;
1122 otherwise returns \c false.
1123*/
1124/*! \fn bool QLatin1StringView::operator!=(const QChar &lhs, const QLatin1StringView &rhs)
1125
1126 Returns \c true if char \a lhs is lexically not equal to string \a rhs;
1127 otherwise returns \c false.
1128*/
1129/*! \fn bool QLatin1StringView::operator<=(const QChar &lhs, const QLatin1StringView &rhs)
1130
1131 Returns \c true if char \a lhs is lexically less than or equal to
1132 string \a rhs; otherwise returns \c false.
1133*/
1134/*! \fn bool QLatin1StringView::operator>=(const QChar &lhs, const QLatin1StringView &rhs)
1135
1136 Returns \c true if char \a lhs is lexically greater than or equal to
1137 string \a rhs; otherwise returns \c false.
1138*/
1139
1140/*! \fn bool QLatin1StringView::operator==(const QLatin1StringView &lhs, const QChar &rhs)
1141
1142 Returns \c true if string \a lhs is lexically equal to char \a rhs;
1143 otherwise returns \c false.
1144*/
1145/*! \fn bool QLatin1StringView::operator<(const QLatin1StringView &lhs, const QChar &rhs)
1146
1147 Returns \c true if string \a lhs is lexically less than char \a rhs;
1148 otherwise returns \c false.
1149*/
1150/*! \fn bool QLatin1StringView::operator>(const QLatin1StringView &lhs, const QChar &rhs)
1151
1152 Returns \c true if string \a lhs is lexically greater than char \a rhs;
1153 otherwise returns \c false.
1154*/
1155/*! \fn bool QLatin1StringView::operator!=(const QLatin1StringView &lhs, const QChar &rhs)
1156
1157 Returns \c true if string \a lhs is lexically not equal to char \a rhs;
1158 otherwise returns \c false.
1159*/
1160/*! \fn bool QLatin1StringView::operator<=(const QLatin1StringView &lhs, const QChar &rhs)
1161
1162 Returns \c true if string \a lhs is lexically less than or equal to
1163 char \a rhs; otherwise returns \c false.
1164*/
1165/*! \fn bool QLatin1StringView::operator>=(const QLatin1StringView &lhs, const QChar &rhs)
1166
1167 Returns \c true if string \a lhs is lexically greater than or equal to
1168 char \a rhs; otherwise returns \c false.
1169*/
1170
1171/*! \fn bool QLatin1StringView::operator==(const QStringView &lhs, const QLatin1StringView &rhs)
1172
1173 Returns \c true if string view \a lhs is lexically equal to string \a rhs;
1174 otherwise returns \c false.
1175*/
1176/*! \fn bool QLatin1StringView::operator<(const QStringView &lhs, const QLatin1StringView &rhs)
1177
1178 Returns \c true if string view \a lhs is lexically less than string \a rhs;
1179 otherwise returns \c false.
1180*/
1181/*! \fn bool QLatin1StringView::operator>(const QStringView &lhs, const QLatin1StringView &rhs)
1182
1183 Returns \c true if string view \a lhs is lexically greater than string \a rhs;
1184 otherwise returns \c false.
1185*/
1186/*! \fn bool QLatin1StringView::operator!=(const QStringView &lhs, const QLatin1StringView &rhs)
1187
1188 Returns \c true if string view \a lhs is lexically not equal to string \a rhs;
1189 otherwise returns \c false.
1190*/
1191/*! \fn bool QLatin1StringView::operator<=(const QStringView &lhs, const QLatin1StringView &rhs)
1192
1193 Returns \c true if string view \a lhs is lexically less than or equal to
1194 string \a rhs; otherwise returns \c false.
1195*/
1196/*! \fn bool QLatin1StringView::operator>=(const QStringView &lhs, const QLatin1StringView &rhs)
1197
1198 Returns \c true if string view \a lhs is lexically greater than or equal to
1199 string \a rhs; otherwise returns \c false.
1200*/
1201
1202/*! \fn bool QLatin1StringView::operator==(const QLatin1StringView &lhs, const QStringView &rhs)
1203
1204 Returns \c true if string \a lhs is lexically equal to string view \a rhs;
1205 otherwise returns \c false.
1206*/
1207/*! \fn bool QLatin1StringView::operator<(const QLatin1StringView &lhs, const QStringView &rhs)
1208
1209 Returns \c true if string \a lhs is lexically less than string view \a rhs;
1210 otherwise returns \c false.
1211*/
1212/*! \fn bool QLatin1StringView::operator>(const QLatin1StringView &lhs, const QStringView &rhs)
1213
1214 Returns \c true if string \a lhs is lexically greater than string view \a rhs;
1215 otherwise returns \c false.
1216*/
1217/*! \fn bool QLatin1StringView::operator!=(const QLatin1StringView &lhs, const QStringView &rhs)
1218
1219 Returns \c true if string \a lhs is lexically not equal to string view \a rhs;
1220 otherwise returns \c false.
1221*/
1222/*! \fn bool QLatin1StringView::operator<=(const QLatin1StringView &lhs, const QStringView &rhs)
1223
1224 Returns \c true if string \a lhs is lexically less than or equal to
1225 string view \a rhs; otherwise returns \c false.
1226*/
1227/*! \fn bool QLatin1StringView::operator>=(const QLatin1StringView &lhs, const QStringView &rhs)
1228
1229 Returns \c true if string \a lhs is lexically greater than or equal to
1230 string view \a rhs; otherwise returns \c false.
1231*/
1232
1233/*! \fn bool QLatin1StringView::operator==(const char * const &lhs, const QLatin1StringView &rhs)
1234
1235 Returns \c true if const char pointer \a lhs is lexically equal to
1236 string \a rhs; otherwise returns \c false.
1237*/
1238/*! \fn bool QLatin1StringView::operator<(const char * const &lhs, const QLatin1StringView &rhs)
1239
1240 Returns \c true if const char pointer \a lhs is lexically less than
1241 string \a rhs; otherwise returns \c false.
1242*/
1243/*! \fn bool QLatin1StringView::operator>(const char * const &lhs, const QLatin1StringView &rhs)
1244
1245 Returns \c true if const char pointer \a lhs is lexically greater than
1246 string \a rhs; otherwise returns \c false.
1247*/
1248/*! \fn bool QLatin1StringView::operator!=(const char * const &lhs, const QLatin1StringView &rhs)
1249
1250 Returns \c true if const char pointer \a lhs is lexically not equal to
1251 string \a rhs; otherwise returns \c false.
1252*/
1253/*! \fn bool QLatin1StringView::operator<=(const char * const &lhs, const QLatin1StringView &rhs)
1254
1255 Returns \c true if const char pointer \a lhs is lexically less than or
1256 equal to string \a rhs; otherwise returns \c false.
1257*/
1258/*! \fn bool QLatin1StringView::operator>=(const char * const &lhs, const QLatin1StringView &rhs)
1259
1260 Returns \c true if const char pointer \a lhs is lexically greater than or
1261 equal to string \a rhs; otherwise returns \c false.
1262*/
1263
1264/*!
1265 \fn qlonglong QLatin1StringView::toLongLong(bool *ok, int base) const
1266 \fn qulonglong QLatin1StringView::toULongLong(bool *ok, int base) const
1267 \fn int QLatin1StringView::toInt(bool *ok, int base) const
1268 \fn uint QLatin1StringView::toUInt(bool *ok, int base) const
1269 \fn long QLatin1StringView::toLong(bool *ok, int base) const
1270 \fn ulong QLatin1StringView::toULong(bool *ok, int base) const
1271 \fn short QLatin1StringView::toShort(bool *ok, int base) const
1272 \fn ushort QLatin1StringView::toUShort(bool *ok, int base) const
1273
1274 \since 6.4
1275
1276 Returns this QLatin1StringView converted to a corresponding numeric value using
1277 base \a base, which is ten by default. Bases 0 and 2 through 36 are supported,
1278 using letters for digits beyond 9; A is ten, B is eleven and so on.
1279
1280 If \a base is 0, the base is determined automatically using the following
1281 rules (in this order), if the Latin-1 string view begins with:
1282
1283 \list
1284 \li \c "0x", the rest of it is read as hexadecimal (base 16)
1285 \li \c "0b", the rest of it is read as binary (base 2)
1286 \li \c "0", the rest of it is read as octal (base 8)
1287 \li otherwise it is read as decimal
1288 \endlist
1289
1290 Returns 0 if the conversion fails.
1291
1292 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
1293 to \c false, and success by setting *\a{ok} to \c true.
1294
1295//! [latin1-numeric-conversion-note]
1296 \note The conversion of the number is performed in the default C locale,
1297 regardless of the user's locale. Use QLocale to perform locale-aware
1298 conversions between numbers and strings.
1299
1300 This function ignores leading and trailing spacing characters.
1301//! [latin1-numeric-conversion-note]
1302
1303 \note Support for the "0b" prefix was added in Qt 6.4.
1304*/
1305
1306/*!
1307 \fn double QLatin1StringView::toDouble(bool *ok) const
1308 \fn float QLatin1StringView::toFloat(bool *ok) const
1309 \since 6.4
1310
1311 Returns this QLatin1StringView converted to a corresponding floating-point value.
1312
1313 Returns an infinity if the conversion overflows or 0.0 if the
1314 conversion fails for other reasons (e.g. underflow).
1315
1316 If \a ok is not \nullptr, failure is reported by setting *\a{ok}
1317 to \c false, and success by setting *\a{ok} to \c true.
1318
1319 \warning The QLatin1StringView content may only contain valid numerical
1320 characters which includes the plus/minus sign, the character e used in
1321 scientific notation, and the decimal point. Including the unit or additional
1322 characters leads to a conversion error.
1323
1324 \include qlatin1stringview.qdoc latin1-numeric-conversion-note
1325*/
1326
1327/*!
1328 \fn Qt::Literals::StringLiterals::operator""_L1(const char *str, size_t size)
1329
1330 \relates QLatin1StringView
1331 \since 6.4
1332
1333 Literal operator that creates a QLatin1StringView out of the first \a size
1334 characters in the char string literal \a str.
1335
1336 The following code creates a QLatin1StringView:
1337 \code
1338 using namespace Qt::StringLiterals;
1339
1340 auto str = "hello"_L1;
1341 \endcode
1342
1343 \sa Qt::Literals::StringLiterals
1344*/
1345
1346/*!
1347 \fn QLatin1StringView::maxSize()
1348 \since 6.8
1349
1350 It returns the maximum number of elements that the string view can
1351 theoretically represent. In practice, the number can be much smaller,
1352 limited by the amount of memory available to the system.
1353*/
1354
1355/*!
1356 \fn QLatin1StringView::max_size() const
1357 \since 6.8
1358
1359 This function is provided for STL compatibility.
1360
1361 Returns maxSize().
1362*/