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