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
6/*! \class QLatin1StringView
8 \brief The QLatin1StringView class provides a thin wrapper around
9 a US-ASCII/Latin-1 encoded string literal.
11 \ingroup string-processing
15 \compareswith strong char16_t QChar QStringView QUtf8StringView QString \
18 \compareswith strong {const char *} QByteArray QByteArrayView
19 The byte array data is interpreted as utf-8.
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,
31 \snippet code/src_corelib_text_qstring.cpp 3
35 \snippet code/src_corelib_text_qstring.cpp 4
37 because it doesn't construct four temporary QString objects and
38 make a deep copy of the character data.
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
44 \snippet code/src_corelib_text_qstring.cpp 4bis
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
53 \snippet code/src_corelib_text_qstring.cpp 5
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().
59 Thanks to the QString(QLatin1StringView) constructor,
60 QLatin1StringView can be used everywhere a QString is expected. For
63 \snippet code/src_corelib_text_qstring.cpp 6
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
72 \sa QString, QLatin1Char, {QStringLiteral()}{QStringLiteral},
79 \brief QLatin1String is the same as QLatin1StringView.
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.
85 Please see the QLatin1StringView documentation for details.
89 \typedef QLatin1StringView::value_type
92 Alias for \c{const char}. Provided for compatibility with the STL.
96 \typedef QLatin1StringView::difference_type
99 Alias for \c{qsizetype}. Provided for compatibility with the STL.
103 \typedef QLatin1StringView::size_type
106 Alias for \c{qsizetype}. Provided for compatibility with the STL.
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.
114 \typedef QLatin1StringView::pointer
115 \typedef QLatin1StringView::const_pointer
118 Alias for \c{value_type *}. Provided for compatibility with the STL.
122 \typedef QLatin1StringView::reference
125 Alias for \c{value_type &}. Provided for compatibility with the STL.
129 \typedef QLatin1StringView::const_reference
132 Alias for \c{reference}. Provided for compatibility with the STL.
136 \typedef QLatin1StringView::iterator
139 QLatin1StringView does not support mutable iterators, so this is the same
142 \sa const_iterator, reverse_iterator
146 \typedef QLatin1StringView::const_iterator
149 \sa iterator, const_reverse_iterator
153 \typedef QLatin1StringView::reverse_iterator
156 QLatin1StringView does not support mutable reverse iterators, so this is the
157 same as const_reverse_iterator.
159 \sa const_reverse_iterator, iterator
163 \typedef QLatin1StringView::const_reverse_iterator
166 \sa reverse_iterator, const_iterator
169/*! \fn QLatin1StringView::QLatin1StringView()
172 Constructs a QLatin1StringView object that stores a \nullptr.
174 \sa data(), isEmpty(), isNull(), {Distinction Between Null and Empty Strings}
177/*! \fn QLatin1StringView::QLatin1StringView(std::nullptr_t)
180 Constructs a QLatin1StringView object that stores a \nullptr.
182 \sa data(), isEmpty(), isNull(), {Distinction Between Null and Empty Strings}
185/*! \fn QLatin1StringView::QLatin1StringView(const char *str)
187 Constructs a QLatin1StringView object that stores \a str.
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.
196/*! \fn QLatin1StringView::QLatin1StringView(const char *str, qsizetype size)
198 Constructs a QLatin1StringView object that stores \a str with \a size.
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.
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.
212 \fn QLatin1StringView::QLatin1StringView(const char *first, const char *last)
215 Constructs a QLatin1StringView object that stores \a first with length
216 (\a last - \a first).
218 The range \c{[first,last)} must remain valid for the lifetime of
219 this Latin-1 string object.
221 Passing \nullptr as \a first is safe if \a last is \nullptr,
222 too, and results in a null Latin-1 string.
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 >
229/*! \fn QLatin1StringView::QLatin1StringView(const QByteArray &str)
231 Constructs a QLatin1StringView object as a view on \a str.
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.
240/*! \fn QLatin1StringView::QLatin1StringView(QByteArrayView str)
243 Constructs a QLatin1StringView object as a view on \a str.
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.
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.
259 \fn QString QLatin1StringView::toString() const
262 Converts this Latin-1 string into a QString. Equivalent to
264 return QString(*this);
268/*! \fn const char *QLatin1StringView::latin1() const
270 Returns the start of the Latin-1 string referenced by this object.
273/*! \fn const char *QLatin1StringView::data() const
275 Returns the start of the Latin-1 string referenced by this object.
278/*! \fn const char *QLatin1StringView::constData() const
281 Returns the start of the Latin-1 string referenced by this object.
283 This function is provided for compatibility with other Qt containers.
288/*! \fn qsizetype QLatin1StringView::size() const
290 Returns the size of the Latin-1 string referenced by this object.
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.
297/*! \fn qsizetype QLatin1StringView::length() const
302 This function is provided for compatibility with other Qt containers.
305/*! \fn bool QLatin1StringView::isNull() const
308 Returns whether the Latin-1 string referenced by this object is null
309 (\c{data() == nullptr}) or not.
311 \sa isEmpty(), data()
314/*! \fn bool QLatin1StringView::isEmpty() const
317 Returns whether the Latin-1 string referenced by this object is empty
318 (\c{size() == 0}) or not.
323/*! \fn bool QLatin1StringView::empty() const
326 Returns whether the Latin-1 string referenced by this object is empty
327 (\c{size() == 0}) or not.
329 This function is provided for STL compatibility.
331 \sa isEmpty(), isNull(), size()
334/*! \fn QLatin1Char QLatin1StringView::at(qsizetype pos) const
337 Returns the character at position \a pos in this object.
339 \note This function performs no error checking.
340 The behavior is undefined when \a pos < 0 or \a pos >= size().
345/*! \fn QLatin1Char QLatin1StringView::operator[](qsizetype pos) const
348 Returns the character at position \a pos in this object.
350 \note This function performs no error checking.
351 The behavior is undefined when \a pos < 0 or \a pos >= size().
357 \fn QLatin1Char QLatin1StringView::front() const
360 Returns the first character in the string.
363 This function is provided for STL compatibility.
365 \warning Calling this function on an empty string constitutes
368 \sa back(), at(), operator[]()
372 \fn QLatin1Char QLatin1StringView::first() const
375 Returns the first character in the string.
376 Same as \c{at(0)} or front().
378 This function is provided for compatibility with other Qt containers.
380 \warning Calling this function on an empty string constitutes
383 \sa last(), front(), back()
387 \fn QLatin1Char QLatin1StringView::back() const
390 Returns the last character in the string.
391 Same as \c{at(size() - 1)}.
393 This function is provided for STL compatibility.
395 \warning Calling this function on an empty string constitutes
398 \sa front(), at(), operator[]()
402 \fn QLatin1Char QLatin1StringView::last() const
405 Returns the last character in the string.
406 Same as \c{at(size() - 1)} or back().
408 This function is provided for compatibility with other Qt containers.
410 \warning Calling this function on an empty string constitutes
413 \sa first(), back(), front()
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
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.
428 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
430 \sa operator==(), operator<(), operator>()
434 \fn int QLatin1StringView::compare(QUtf8StringView str, Qt::CaseSensitivity cs) const
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.
441 \include qstring.qdocinc {search-comparison-case-sensitivity} {comparison}
443 \sa operator==(), operator<(), operator>()
448 \fn bool QLatin1StringView::startsWith(QStringView str, Qt::CaseSensitivity cs) const
450 \fn bool QLatin1StringView::startsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const
452 \fn bool QLatin1StringView::startsWith(QChar ch) const
454 \fn bool QLatin1StringView::startsWith(QChar ch, Qt::CaseSensitivity cs) const
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.
461 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
467 \fn bool QLatin1StringView::endsWith(QStringView str, Qt::CaseSensitivity cs) const
469 \fn bool QLatin1StringView::endsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const
471 \fn bool QLatin1StringView::endsWith(QChar ch) const
473 \fn bool QLatin1StringView::endsWith(QChar ch, Qt::CaseSensitivity cs) const
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.
480 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
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
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
497 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
499 \include qstring.qdocinc negative-index-start-search-from-end
501 \sa QString::indexOf()
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
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.
514 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
516 \sa indexOf(), QStringView::contains(), QStringView::indexOf(),
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
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
532 \include qstring.qdocinc negative-index-start-search-from-end
534 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
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
544 \sa indexOf(), QStringView::lastIndexOf(), QStringView::indexOf(),
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
552 \overload lastIndexOf()
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,
559 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
563 \fn qsizetype QLatin1StringView::lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const
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
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.
578 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
580 \sa contains(), indexOf()
584 \fn QLatin1StringView::const_iterator QLatin1StringView::begin() const
587 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the
588 first character in the string.
590 This function is provided for STL compatibility.
592 \sa end(), cbegin(), rbegin(), data()
596 \fn QLatin1StringView::const_iterator QLatin1StringView::cbegin() const
601 This function is provided for STL compatibility.
603 \sa cend(), begin(), crbegin(), data()
607 \fn QLatin1StringView::const_iterator QLatin1StringView::constBegin() const
612 This function is provided for compatibility with other Qt containers.
614 \sa constEnd(), begin(), cbegin(), data()
618 \fn QLatin1StringView::const_iterator QLatin1StringView::end() const
621 Returns a const \l{STL-style iterators}{STL-style iterator} pointing just
622 after the last character in the string.
624 This function is provided for STL compatibility.
626 \sa begin(), cend(), rend()
629/*! \fn QLatin1StringView::const_iterator QLatin1StringView::cend() const
634 This function is provided for STL compatibility.
636 \sa cbegin(), end(), crend()
639/*! \fn QLatin1StringView::const_iterator QLatin1StringView::constEnd() const
644 This function is provided for compatibility with other Qt containers.
646 \sa constBegin(), end(), cend(), crend()
650 \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::rbegin() const
653 Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing
654 to the first character in the string, in reverse order.
656 This function is provided for STL compatibility.
658 \sa rend(), crbegin(), begin()
662 \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::crbegin() const
667 This function is provided for STL compatibility.
669 \sa crend(), rbegin(), cbegin()
673 \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::rend() const
676 Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing just
677 after the last character in the string, in reverse order.
679 This function is provided for STL compatibility.
681 \sa rbegin(), crend(), end()
685 \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::crend() const
690 This function is provided for STL compatibility.
692 \sa crbegin(), rend(), cend()
696 \fn QLatin1StringView QLatin1StringView::mid(qsizetype start, qsizetype length) const
699 Returns the substring of length \a length starting at position
700 \a start in this Latin-1 string view.
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.
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
711 \sa first(), last(), sliced(), chopped(), chop(), truncate()
715 \fn QLatin1StringView QLatin1StringView::left(qsizetype length) const
718 If you know that \a length cannot be out of bounds, use first() instead in
719 new code, because it is faster.
721 Returns the substring of length \a length starting at position
722 0 in this Latin-1 string view.
724 The entire Latin-1 string view is returned if \a length is greater
725 than or equal to size(), or less than zero.
727 \sa first(), last(), sliced(), startsWith(), chopped(), chop(), truncate()
731 \fn QLatin1StringView QLatin1StringView::right(qsizetype length) const
734 If you know that \a length cannot be out of bounds, use last() instead in
735 new code, because it is faster.
737 Returns the substring of length \a length starting at position
738 size() - \a length in this Latin-1 string view.
740 The entire Latin-1 string view is returned if \a length is greater
741 than or equal to size(), or less than zero.
743 \sa first(), last(), sliced(), endsWith(), chopped(), chop(), truncate()
747 \fn QLatin1StringView QLatin1StringView::first(qsizetype n) const
750 Returns a Latin-1 string view that contains the first \a n characters
753 \note The behavior is undefined when \a n < 0 or \a n > size().
755 \sa last(), startsWith(), chopped(), chop(), truncate()
759 \fn QLatin1StringView QLatin1StringView::last(qsizetype n) const
762 Returns a Latin-1 string view that contains the last \a n characters
765 \note The behavior is undefined when \a n < 0 or \a n > size().
767 \sa first(), endsWith(), chopped(), chop(), truncate()
771 \fn QLatin1StringView QLatin1StringView::sliced(qsizetype pos, qsizetype n) const
774 Returns a Latin-1 string view that points to \a n characters of this
775 string view, starting at position \a pos.
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]
782 \sa first(), last(), chopped(), chop(), truncate()
786 \fn QLatin1StringView QLatin1StringView::sliced(qsizetype pos) const
789 Returns a Latin-1 string view starting at position \a pos in this
790 string view, and extending to its end.
792//! [UB-sliced-index-only]
793 \note The behavior is undefined when \a pos < 0 or \a pos > size().
794//! [UB-sliced-index-only]
796 \sa first(), last(), chopped(), chop(), truncate()
800 \fn QLatin1StringView QLatin1StringView::chopped(qsizetype length) const
803 Returns the substring of length size() - \a length starting at the
804 beginning of this object.
806 Same as \c{left(size() - length)}.
808 \note The behavior is undefined when \a length < 0 or \a length > size().
810 \sa sliced(), first(), last(), chop(), truncate()
814 \fn void QLatin1StringView::truncate(qsizetype length)
817 Truncates this string to length \a length.
819 Same as \c{*this = left(length)}.
821 \note The behavior is undefined when \a length < 0 or \a length > size().
823 \sa sliced(), first(), last(), chopped(), chop()
827 \fn void QLatin1StringView::chop(qsizetype length)
830 Truncates this string by \a length characters.
832 Same as \c{*this = left(size() - length)}.
834 \note The behavior is undefined when \a length < 0 or \a length > size().
836 \sa sliced(), first(), last(), chopped(), truncate()
840 \fn QLatin1StringView QLatin1StringView::trimmed() const
843 Strips leading and trailing whitespace and returns the result.
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 ' '.
851 \fn bool QLatin1StringView::operator==(const QLatin1StringView &lhs, const char * const &rhs)
854 Returns \c true if the string \a lhs is equal to const char pointer \a rhs;
855 otherwise returns \c false.
857 The \a rhs const char pointer is converted to a QUtf8StringView.
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.
864 \sa {Comparing Strings}
868 \fn bool QLatin1StringView::operator==(const QLatin1StringView &lhs, const QByteArray &rhs)
872 The \a rhs byte array is converted to a QUtf8StringView.
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.
881 \fn bool QLatin1StringView::operator!=(const QLatin1StringView &lhs, const char * const &rhs)
884 Returns \c true if the string \a lhs is not equal to const char pointer \a rhs;
885 otherwise returns \c false.
887 The \a rhs const char pointer is converted to a QUtf8StringView.
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.
894 \sa {Comparing Strings}
898 \fn bool QLatin1StringView::operator!=(const QLatin1StringView &lhs, const QByteArray &rhs)
900 \overload operator!=()
902 The \a rhs byte array is converted to a QUtf8StringView.
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.
911 \fn bool QLatin1StringView::operator>(const QLatin1StringView &lhs, const char * const &rhs)
914 Returns \c true if the string \a lhs is lexically greater than const char pointer
915 \a rhs; otherwise returns \c false.
917 The \a rhs const char pointer is converted to a QUtf8StringView.
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(),
924 \sa {Comparing Strings}
928 \fn bool QLatin1StringView::operator>(const QLatin1StringView &lhs, const QByteArray &rhs)
932 The \a rhs byte array is converted to a QUtf8StringView.
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(),
941 \fn bool QLatin1StringView::operator<(const QLatin1StringView &lhs, const char * const &rhs)
944 Returns \c true if the string \a lhs is lexically less than const char pointer
945 \a rhs; otherwise returns \c false.
947 The \a rhs const char pointer is converted to a QUtf8StringView.
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.
954 \sa {Comparing Strings}
958 \fn bool QLatin1StringView::operator<(const QLatin1StringView &lhs, const QByteArray &rhs)
962 The \a rhs byte array is converted to a QUtf8StringView.
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.
971 \fn bool QLatin1StringView::operator>=(const QLatin1StringView &lhs, const char * const &rhs)
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.
977 The \a rhs const char pointer is converted to a QUtf8StringView.
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.
984 \sa {Comparing Strings}
988 \fn bool QLatin1StringView::operator>=(const QLatin1StringView &lhs, const QByteArray &rhs)
992 The \a rhs byte array is converted to a QUtf8StringView.
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.
1001 \fn bool QLatin1StringView::operator<=(const QLatin1StringView &lhs, const char * const &rhs)
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.
1007 The \a rhs const char pointer is converted to a QUtf8StringView.
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.
1014 \sa {Comparing Strings}
1018 \fn bool QLatin1StringView::operator<=(const QLatin1StringView &lhs, const QByteArray &rhs)
1022 The \a rhs byte array is converted to a QUtf8StringView.
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.
1030/*! \fn bool QLatin1StringView::operator==(const QLatin1StringView &lhs, const QLatin1StringView &rhs)
1032 Returns \c true if string \a lhs is lexically equal to string \a rhs;
1033 otherwise returns \c false.
1035/*! \fn bool QLatin1StringView::operator!=(const QLatin1StringView &lhs, const QLatin1StringView &rhs)
1037 Returns \c true if string \a lhs is lexically not equal to string \a rhs;
1038 otherwise returns \c false.
1040/*! \fn bool QLatin1StringView::operator<(const QLatin1StringView &lhs, const QLatin1StringView &rhs)
1042 Returns \c true if string \a lhs is lexically less than string \a rhs;
1043 otherwise returns \c false.
1045/*! \fn bool QLatin1StringView::operator<=(const QLatin1StringView &lhs, const QLatin1StringView &rhs)
1047 Returns \c true if string \a lhs is lexically less than or equal to
1048 string \a rhs; otherwise returns \c false.
1050/*! \fn bool QLatin1StringView::operator>(const QLatin1StringView &lhs, const QLatin1StringView &rhs)
1052 Returns \c true if string \a lhs is lexically greater than string \a rhs;
1053 otherwise returns \c false.
1055/*! \fn bool QLatin1StringView::operator>=(const QLatin1StringView &lhs, const QLatin1StringView &rhs)
1057 Returns \c true if string \a lhs is lexically greater than or equal
1058 to string \a rhs; otherwise returns \c false.
1061/*! \fn bool QLatin1StringView::operator==(const QChar &lhs, const QLatin1StringView &rhs)
1063 Returns \c true if char \a lhs is lexically equal to string \a rhs;
1064 otherwise returns \c false.
1066/*! \fn bool QLatin1StringView::operator<(const QChar &lhs, const QLatin1StringView &rhs)
1068 Returns \c true if char \a lhs is lexically less than string \a rhs;
1069 otherwise returns \c false.
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.
1075/*! \fn bool QLatin1StringView::operator!=(const QChar &lhs, const QLatin1StringView &rhs)
1077 Returns \c true if char \a lhs is lexically not equal to string \a rhs;
1078 otherwise returns \c false.
1080/*! \fn bool QLatin1StringView::operator<=(const QChar &lhs, const QLatin1StringView &rhs)
1082 Returns \c true if char \a lhs is lexically less than or equal to
1083 string \a rhs; otherwise returns \c false.
1085/*! \fn bool QLatin1StringView::operator>=(const QChar &lhs, const QLatin1StringView &rhs)
1087 Returns \c true if char \a lhs is lexically greater than or equal to
1088 string \a rhs; otherwise returns \c false.
1091/*! \fn bool QLatin1StringView::operator==(const QLatin1StringView &lhs, const QChar &rhs)
1093 Returns \c true if string \a lhs is lexically equal to char \a rhs;
1094 otherwise returns \c false.
1096/*! \fn bool QLatin1StringView::operator<(const QLatin1StringView &lhs, const QChar &rhs)
1098 Returns \c true if string \a lhs is lexically less than char \a rhs;
1099 otherwise returns \c false.
1101/*! \fn bool QLatin1StringView::operator>(const QLatin1StringView &lhs, const QChar &rhs)
1103 Returns \c true if string \a lhs is lexically greater than char \a rhs;
1104 otherwise returns \c false.
1106/*! \fn bool QLatin1StringView::operator!=(const QLatin1StringView &lhs, const QChar &rhs)
1108 Returns \c true if string \a lhs is lexically not equal to char \a rhs;
1109 otherwise returns \c false.
1111/*! \fn bool QLatin1StringView::operator<=(const QLatin1StringView &lhs, const QChar &rhs)
1113 Returns \c true if string \a lhs is lexically less than or equal to
1114 char \a rhs; otherwise returns \c false.
1116/*! \fn bool QLatin1StringView::operator>=(const QLatin1StringView &lhs, const QChar &rhs)
1118 Returns \c true if string \a lhs is lexically greater than or equal to
1119 char \a rhs; otherwise returns \c false.
1122/*! \fn bool QLatin1StringView::operator==(const QStringView &lhs, const QLatin1StringView &rhs)
1124 Returns \c true if string view \a lhs is lexically equal to string \a rhs;
1125 otherwise returns \c false.
1127/*! \fn bool QLatin1StringView::operator<(const QStringView &lhs, const QLatin1StringView &rhs)
1129 Returns \c true if string view \a lhs is lexically less than string \a rhs;
1130 otherwise returns \c false.
1132/*! \fn bool QLatin1StringView::operator>(const QStringView &lhs, const QLatin1StringView &rhs)
1134 Returns \c true if string view \a lhs is lexically greater than string \a rhs;
1135 otherwise returns \c false.
1137/*! \fn bool QLatin1StringView::operator!=(const QStringView &lhs, const QLatin1StringView &rhs)
1139 Returns \c true if string view \a lhs is lexically not equal to string \a rhs;
1140 otherwise returns \c false.
1142/*! \fn bool QLatin1StringView::operator<=(const QStringView &lhs, const QLatin1StringView &rhs)
1144 Returns \c true if string view \a lhs is lexically less than or equal to
1145 string \a rhs; otherwise returns \c false.
1147/*! \fn bool QLatin1StringView::operator>=(const QStringView &lhs, const QLatin1StringView &rhs)
1149 Returns \c true if string view \a lhs is lexically greater than or equal to
1150 string \a rhs; otherwise returns \c false.
1153/*! \fn bool QLatin1StringView::operator==(const QLatin1StringView &lhs, const QStringView &rhs)
1155 Returns \c true if string \a lhs is lexically equal to string view \a rhs;
1156 otherwise returns \c false.
1158/*! \fn bool QLatin1StringView::operator<(const QLatin1StringView &lhs, const QStringView &rhs)
1160 Returns \c true if string \a lhs is lexically less than string view \a rhs;
1161 otherwise returns \c false.
1163/*! \fn bool QLatin1StringView::operator>(const QLatin1StringView &lhs, const QStringView &rhs)
1165 Returns \c true if string \a lhs is lexically greater than string view \a rhs;
1166 otherwise returns \c false.
1168/*! \fn bool QLatin1StringView::operator!=(const QLatin1StringView &lhs, const QStringView &rhs)
1170 Returns \c true if string \a lhs is lexically not equal to string view \a rhs;
1171 otherwise returns \c false.
1173/*! \fn bool QLatin1StringView::operator<=(const QLatin1StringView &lhs, const QStringView &rhs)
1175 Returns \c true if string \a lhs is lexically less than or equal to
1176 string view \a rhs; otherwise returns \c false.
1178/*! \fn bool QLatin1StringView::operator>=(const QLatin1StringView &lhs, const QStringView &rhs)
1180 Returns \c true if string \a lhs is lexically greater than or equal to
1181 string view \a rhs; otherwise returns \c false.
1184/*! \fn bool QLatin1StringView::operator==(const char * const &lhs, const QLatin1StringView &rhs)
1186 Returns \c true if const char pointer \a lhs is lexically equal to
1187 string \a rhs; otherwise returns \c false.
1189/*! \fn bool QLatin1StringView::operator<(const char * const &lhs, const QLatin1StringView &rhs)
1191 Returns \c true if const char pointer \a lhs is lexically less than
1192 string \a rhs; otherwise returns \c false.
1194/*! \fn bool QLatin1StringView::operator>(const char * const &lhs, const QLatin1StringView &rhs)
1196 Returns \c true if const char pointer \a lhs is lexically greater than
1197 string \a rhs; otherwise returns \c false.
1199/*! \fn bool QLatin1StringView::operator!=(const char * const &lhs, const QLatin1StringView &rhs)
1201 Returns \c true if const char pointer \a lhs is lexically not equal to
1202 string \a rhs; otherwise returns \c false.
1204/*! \fn bool QLatin1StringView::operator<=(const char * const &lhs, const QLatin1StringView &rhs)
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.
1209/*! \fn bool QLatin1StringView::operator>=(const char * const &lhs, const QLatin1StringView &rhs)
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.
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
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.
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:
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
1241 Returns 0 if the conversion fails.
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.
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.
1251 This function ignores leading and trailing spacing characters.
1252//! [latin1-numeric-conversion-note]
1254 \note Support for the "0b" prefix was added in Qt 6.4.
1258 \fn double QLatin1StringView::toDouble(bool *ok) const
1259 \fn float QLatin1StringView::toFloat(bool *ok) const
1262 Returns this QLatin1StringView converted to a corresponding floating-point value.
1264 Returns an infinity if the conversion overflows or 0.0 if the
1265 conversion fails for other reasons (e.g. underflow).
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.
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.
1275 \include qlatin1stringview.qdoc latin1-numeric-conversion-note
1279 \fn Qt::Literals::StringLiterals::operator""_L1(const char *str, size_t size)
1281 \relates QLatin1StringView
1284 Literal operator that creates a QLatin1StringView out of the first \a size
1285 characters in the char string literal \a str.
1287 The following code creates a QLatin1StringView:
1289 using namespace Qt::Literals::StringLiterals;
1291 auto str = "hello"_L1;
1294 \sa Qt::Literals::StringLiterals