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