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
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
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,
23 \snippet code/src_corelib_text_qstring.cpp 3
27 \snippet code/src_corelib_text_qstring.cpp 4
29 because it doesn't construct four temporary QString objects and
30 make a deep copy of the character data.
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
36 \snippet code/src_corelib_text_qstring.cpp 4bis
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
45 \snippet code/src_corelib_text_qstring.cpp 5
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().
51 Thanks to the QString(QLatin1StringView) constructor,
52 QLatin1StringView can be used everywhere a QString is expected. For
55 \snippet code/src_corelib_text_qstring.cpp 6
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
64 \sa QString, QLatin1Char, {QStringLiteral()}{QStringLiteral},
71 \brief QLatin1String is the same as QLatin1StringView.
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.
77 Please see the QLatin1StringView documentation for details.
81 \typedef QLatin1StringView::value_type
84 Alias for \c{const char}. Provided for compatibility with the STL.
88 \typedef QLatin1StringView::difference_type
91 Alias for \c{qsizetype}. Provided for compatibility with the STL.
95 \typedef QLatin1StringView::size_type
98 Alias for \c{qsizetype}. Provided for compatibility with the STL.
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.
106 \typedef QLatin1StringView::reference
109 Alias for \c{value_type &}. Provided for compatibility with the STL.
113 \typedef QLatin1StringView::const_reference
116 Alias for \c{reference}. Provided for compatibility with the STL.
120 \typedef QLatin1StringView::iterator
123 QLatin1StringView does not support mutable iterators, so this is the same
126 \sa const_iterator, reverse_iterator
130 \typedef QLatin1StringView::const_iterator
133 \sa iterator, const_reverse_iterator
137 \typedef QLatin1StringView::reverse_iterator
140 QLatin1StringView does not support mutable reverse iterators, so this is the
141 same as const_reverse_iterator.
143 \sa const_reverse_iterator, iterator
147 \typedef QLatin1StringView::const_reverse_iterator
150 \sa reverse_iterator, const_iterator
153/*! \fn QLatin1StringView::QLatin1StringView()
156 Constructs a QLatin1StringView object that stores a \nullptr.
158 \sa data(), isEmpty(), isNull(), {Distinction Between Null and Empty Strings}
161/*! \fn QLatin1StringView::QLatin1StringView(std::nullptr_t)
164 Constructs a QLatin1StringView object that stores a \nullptr.
166 \sa data(), isEmpty(), isNull(), {Distinction Between Null and Empty Strings}
169/*! \fn QLatin1StringView::QLatin1StringView(const char *str)
171 Constructs a QLatin1StringView object that stores \a str.
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.
180/*! \fn QLatin1StringView::QLatin1StringView(const char *str, qsizetype size)
182 Constructs a QLatin1StringView object that stores \a str with \a size.
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.
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.
196 \fn QLatin1StringView::QLatin1StringView(const char *first, const char *last)
199 Constructs a QLatin1StringView object that stores \a first with length
200 (\a last - \a first).
202 The range \c{[first,last)} must remain valid for the lifetime of
203 this Latin-1 string object.
205 Passing \nullptr as \a first is safe if \a last is \nullptr,
206 too, and results in a null Latin-1 string.
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 >
213/*! \fn QLatin1StringView::QLatin1StringView(const QByteArray &str)
215 Constructs a QLatin1StringView object as a view on \a str.
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.
224/*! \fn QLatin1StringView::QLatin1StringView(QByteArrayView str)
227 Constructs a QLatin1StringView object as a view on \a str.
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.
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.
243 \fn QString QLatin1StringView::toString() const
246 Converts this Latin-1 string into a QString. Equivalent to
248 return QString(*this);
252/*! \fn const char *QLatin1StringView::latin1() const
254 Returns the start of the Latin-1 string referenced by this object.
257/*! \fn const char *QLatin1StringView::data() const
259 Returns the start of the Latin-1 string referenced by this object.
262/*! \fn const char *QLatin1StringView::constData() const
265 Returns the start of the Latin-1 string referenced by this object.
267 This function is provided for compatibility with other Qt containers.
272/*! \fn qsizetype QLatin1StringView::size() const
274 Returns the size of the Latin-1 string referenced by this object.
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.
281/*! \fn qsizetype QLatin1StringView::length() const
286 This function is provided for compatibility with other Qt containers.
289/*! \fn bool QLatin1StringView::isNull() const
292 Returns whether the Latin-1 string referenced by this object is null
293 (\c{data() == nullptr}) or not.
295 \sa isEmpty(), data()
298/*! \fn bool QLatin1StringView::isEmpty() const
301 Returns whether the Latin-1 string referenced by this object is empty
302 (\c{size() == 0}) or not.
307/*! \fn bool QLatin1StringView::empty() const
310 Returns whether the Latin-1 string referenced by this object is empty
311 (\c{size() == 0}) or not.
313 This function is provided for STL compatibility.
315 \sa isEmpty(), isNull(), size()
318/*! \fn QLatin1Char QLatin1StringView::at(qsizetype pos) const
321 Returns the character at position \a pos in this object.
323 \note This function performs no error checking.
324 The behavior is undefined when \a pos < 0 or \a pos >= size().
329/*! \fn QLatin1Char QLatin1StringView::operator[](qsizetype pos) const
332 Returns the character at position \a pos in this object.
334 \note This function performs no error checking.
335 The behavior is undefined when \a pos < 0 or \a pos >= size().
341 \fn QLatin1Char QLatin1StringView::front() const
344 Returns the first character in the string.
347 This function is provided for STL compatibility.
349 \warning Calling this function on an empty string constitutes
352 \sa back(), at(), operator[]()
356 \fn QLatin1Char QLatin1StringView::first() const
359 Returns the first character in the string.
360 Same as \c{at(0)} or front().
362 This function is provided for compatibility with other Qt containers.
364 \warning Calling this function on an empty string constitutes
367 \sa last(), front(), back()
371 \fn QLatin1Char QLatin1StringView::back() const
374 Returns the last character in the string.
375 Same as \c{at(size() - 1)}.
377 This function is provided for STL compatibility.
379 \warning Calling this function on an empty string constitutes
382 \sa front(), at(), operator[]()
386 \fn QLatin1Char QLatin1StringView::last() const
389 Returns the last character in the string.
390 Same as \c{at(size() - 1)} or back().
392 This function is provided for compatibility with other Qt containers.
394 \warning Calling this function on an empty string constitutes
397 \sa first(), back(), front()
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
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.
411 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
413 \sa operator==(), operator<(), operator>()
417 \fn int QLatin1StringView::compare(QUtf8StringView str, Qt::CaseSensitivity cs) const
420 Returns an integer that compares to zero as this string view compares to the
423 \include qstring.qdocinc {search-comparison-case-sensitivity} {comparison}
425 \sa operator==(), operator<(), operator>()
430 \fn bool QLatin1StringView::startsWith(QStringView str, Qt::CaseSensitivity cs) const
432 \fn bool QLatin1StringView::startsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const
434 \fn bool QLatin1StringView::startsWith(QChar ch) const
436 \fn bool QLatin1StringView::startsWith(QChar ch, Qt::CaseSensitivity cs) const
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.
443 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
449 \fn bool QLatin1StringView::endsWith(QStringView str, Qt::CaseSensitivity cs) const
451 \fn bool QLatin1StringView::endsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const
453 \fn bool QLatin1StringView::endsWith(QChar ch) const
455 \fn bool QLatin1StringView::endsWith(QChar ch, Qt::CaseSensitivity cs) const
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.
462 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
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
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
479 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
481 \include qstring.qdocinc negative-index-start-search-from-end
483 \sa QString::indexOf()
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
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.
496 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
498 \sa indexOf(), QStringView::contains(), QStringView::indexOf(),
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
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
514 \include qstring.qdocinc negative-index-start-search-from-end
516 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
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
526 \sa indexOf(), QStringView::lastIndexOf(), QStringView::indexOf(),
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
534 \overload lastIndexOf()
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,
541 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
545 \fn qsizetype QLatin1StringView::lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const
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
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.
560 \include qstring.qdocinc {search-comparison-case-sensitivity} {search}
562 \sa contains(), indexOf()
566 \fn QLatin1StringView::const_iterator QLatin1StringView::begin() const
569 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the
570 first character in the string.
572 This function is provided for STL compatibility.
574 \sa end(), cbegin(), rbegin(), data()
578 \fn QLatin1StringView::const_iterator QLatin1StringView::cbegin() const
583 This function is provided for STL compatibility.
585 \sa cend(), begin(), crbegin(), data()
589 \fn QLatin1StringView::const_iterator QLatin1StringView::constBegin() const
594 This function is provided for compatibility with other Qt containers.
596 \sa constEnd(), begin(), cbegin(), data()
600 \fn QLatin1StringView::const_iterator QLatin1StringView::end() const
603 Returns a const \l{STL-style iterators}{STL-style iterator} pointing just
604 after the last character in the string.
606 This function is provided for STL compatibility.
608 \sa begin(), cend(), rend()
611/*! \fn QLatin1StringView::const_iterator QLatin1StringView::cend() const
616 This function is provided for STL compatibility.
618 \sa cbegin(), end(), crend()
621/*! \fn QLatin1StringView::const_iterator QLatin1StringView::constEnd() const
626 This function is provided for compatibility with other Qt containers.
628 \sa constBegin(), end(), cend(), crend()
632 \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::rbegin() const
635 Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing
636 to the first character in the string, in reverse order.
638 This function is provided for STL compatibility.
640 \sa rend(), crbegin(), begin()
644 \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::crbegin() const
649 This function is provided for STL compatibility.
651 \sa crend(), rbegin(), cbegin()
655 \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::rend() const
658 Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing just
659 after the last character in the string, in reverse order.
661 This function is provided for STL compatibility.
663 \sa rbegin(), crend(), end()
667 \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::crend() const
672 This function is provided for STL compatibility.
674 \sa crbegin(), rend(), cend()
678 \fn QLatin1StringView QLatin1StringView::mid(qsizetype start, qsizetype length) const
681 Returns the substring of length \a length starting at position
682 \a start in this Latin-1 string view.
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.
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
693 \sa first(), last(), sliced(), chopped(), chop(), truncate()
697 \fn QLatin1StringView QLatin1StringView::left(qsizetype length) const
700 If you know that \a length cannot be out of bounds, use first() instead in
701 new code, because it is faster.
703 Returns the substring of length \a length starting at position
704 0 in this Latin-1 string view.
706 The entire Latin-1 string view is returned if \a length is greater
707 than or equal to size(), or less than zero.
709 \sa first(), last(), sliced(), startsWith(), chopped(), chop(), truncate()
713 \fn QLatin1StringView QLatin1StringView::right(qsizetype length) const
716 If you know that \a length cannot be out of bounds, use last() instead in
717 new code, because it is faster.
719 Returns the substring of length \a length starting at position
720 size() - \a length in this Latin-1 string view.
722 The entire Latin-1 string view is returned if \a length is greater
723 than or equal to size(), or less than zero.
725 \sa first(), last(), sliced(), endsWith(), chopped(), chop(), truncate()
729 \fn QLatin1StringView QLatin1StringView::first(qsizetype n) const
732 Returns a Latin-1 string view that contains the first \a n characters
735 \note The behavior is undefined when \a n < 0 or \a n > size().
737 \sa last(), startsWith(), chopped(), chop(), truncate()
741 \fn QLatin1StringView QLatin1StringView::last(qsizetype n) const
744 Returns a Latin-1 string view that contains the last \a n characters
747 \note The behavior is undefined when \a n < 0 or \a n > size().
749 \sa first(), endsWith(), chopped(), chop(), truncate()
753 \fn QLatin1StringView QLatin1StringView::sliced(qsizetype pos, qsizetype n) const
756 Returns a Latin-1 string view that points to \a n characters of this
757 string view, starting at position \a pos.
759 \note The behavior is undefined when \a pos < 0, \a n < 0,
760 or \c{pos + n > size()}.
762 \sa first(), last(), chopped(), chop(), truncate()
766 \fn QLatin1StringView QLatin1StringView::sliced(qsizetype pos) const
769 Returns a Latin-1 string view starting at position \a pos in this
770 string view, and extending to its end.
772 \note The behavior is undefined when \a pos < 0 or \a pos > size().
774 \sa first(), last(), chopped(), chop(), truncate()
778 \fn QLatin1StringView QLatin1StringView::chopped(qsizetype length) const
781 Returns the substring of length size() - \a length starting at the
782 beginning of this object.
784 Same as \c{left(size() - length)}.
786 \note The behavior is undefined when \a length < 0 or \a length > size().
788 \sa sliced(), first(), last(), chop(), truncate()
792 \fn void QLatin1StringView::truncate(qsizetype length)
795 Truncates this string to length \a length.
797 Same as \c{*this = left(length)}.
799 \note The behavior is undefined when \a length < 0 or \a length > size().
801 \sa sliced(), first(), last(), chopped(), chop()
805 \fn void QLatin1StringView::chop(qsizetype length)
808 Truncates this string by \a length characters.
810 Same as \c{*this = left(size() - length)}.
812 \note The behavior is undefined when \a length < 0 or \a length > size().
814 \sa sliced(), first(), last(), chopped(), truncate()
818 \fn QLatin1StringView QLatin1StringView::trimmed() const
821 Strips leading and trailing whitespace and returns the result.
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 ' '.
829 \fn bool QLatin1StringView::operator==(const char *other) const
832 Returns \c true if the string is equal to const char pointer \a other;
833 otherwise returns \c false.
835 The \a other const char pointer is converted to a QString using
836 the QString::fromUtf8() function.
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.
843 \sa {Comparing Strings}
847 \fn bool QLatin1StringView::operator==(const QByteArray &other) const
851 The \a other byte array is converted to a QString using
852 the QString::fromUtf8() function.
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.
861 \fn bool QLatin1StringView::operator!=(const char *other) const
864 Returns \c true if this string is not equal to const char pointer \a other;
865 otherwise returns \c false.
867 The \a other const char pointer is converted to a QString using
868 the QString::fromUtf8() function.
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.
875 \sa {Comparing Strings}
879 \fn bool QLatin1StringView::operator!=(const QByteArray &other) const
881 \overload operator!=()
883 The \a other byte array is converted to a QString using
884 the QString::fromUtf8() function.
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.
893 \fn bool QLatin1StringView::operator>(const char *other) const
896 Returns \c true if this string is lexically greater than const char pointer
897 \a other; otherwise returns \c false.
899 The \a other const char pointer is converted to a QString using
900 the QString::fromUtf8() function.
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(),
907 \sa {Comparing Strings}
911 \fn bool QLatin1StringView::operator>(const QByteArray &other) const
915 The \a other byte array is converted to a QString using
916 the QString::fromUtf8() function.
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(),
925 \fn bool QLatin1StringView::operator<(const char *other) const
928 Returns \c true if this string is lexically less than const char pointer
929 \a other; otherwise returns \c false.
931 The \a other const char pointer is converted to a QString using
932 the QString::fromUtf8() function.
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.
939 \sa {Comparing Strings}
943 \fn bool QLatin1StringView::operator<(const QByteArray &other) const
947 The \a other byte array is converted to a QString using
948 the QString::fromUtf8() function.
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.
957 \fn bool QLatin1StringView::operator>=(const char *other) const
960 Returns \c true if this string is lexically greater than or equal to
961 const char pointer \a other; otherwise returns \c false.
963 The \a other const char pointer is converted to a QString using
964 the QString::fromUtf8() function.
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.
971 \sa {Comparing Strings}
975 \fn bool QLatin1StringView::operator>=(const QByteArray &other) const
979 The \a other byte array is converted to a QString using
980 the QString::fromUtf8() function.
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.
989 \fn bool QLatin1StringView::operator<=(const char *other) const
992 Returns \c true if this string is lexically less than or equal to
993 const char pointer \a other; otherwise returns \c false.
995 The \a other const char pointer is converted to a QString using
996 the QString::fromUtf8() function.
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.
1003 \sa {Comparing Strings}
1007 \fn bool QLatin1StringView::operator<=(const QByteArray &other) const
1011 The \a other byte array is converted to a QString using
1012 the QString::fromUtf8() function.
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.
1020/*! \fn bool QLatin1StringView::operator==(QLatin1StringView s1, QLatin1StringView s2)
1022 Returns \c true if string \a s1 is lexically equal to string \a s2;
1023 otherwise returns \c false.
1025/*! \fn bool QLatin1StringView::operator!=(QLatin1StringView s1, QLatin1StringView s2)
1027 Returns \c true if string \a s1 is lexically not equal to string \a s2;
1028 otherwise returns \c false.
1030/*! \fn bool QLatin1StringView::operator<(QLatin1StringView s1, QLatin1StringView s2)
1032 Returns \c true if string \a s1 is lexically less than string \a s2;
1033 otherwise returns \c false.
1035/*! \fn bool QLatin1StringView::operator<=(QLatin1StringView s1, QLatin1StringView s2)
1037 Returns \c true if string \a s1 is lexically less than or equal to
1038 string \a s2; otherwise returns \c false.
1040/*! \fn bool QLatin1StringView::operator>(QLatin1StringView s1, QLatin1StringView s2)
1042 Returns \c true if string \a s1 is lexically greater than string \a s2;
1043 otherwise returns \c false.
1045/*! \fn bool QLatin1StringView::operator>=(QLatin1StringView s1, QLatin1StringView s2)
1047 Returns \c true if string \a s1 is lexically greater than or equal
1048 to string \a s2; otherwise returns \c false.
1051/*! \fn bool QLatin1StringView::operator==(QChar ch, QLatin1StringView s)
1053 Returns \c true if char \a ch is lexically equal to string \a s;
1054 otherwise returns \c false.
1056/*! \fn bool QLatin1StringView::operator<(QChar ch, QLatin1StringView s)
1058 Returns \c true if char \a ch is lexically less than string \a s;
1059 otherwise returns \c false.
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.
1065/*! \fn bool QLatin1StringView::operator!=(QChar ch, QLatin1StringView s)
1067 Returns \c true if char \a ch is lexically not equal to string \a s;
1068 otherwise returns \c false.
1070/*! \fn bool QLatin1StringView::operator<=(QChar ch, QLatin1StringView s)
1072 Returns \c true if char \a ch is lexically less than or equal to
1073 string \a s; otherwise returns \c false.
1075/*! \fn bool QLatin1StringView::operator>=(QChar ch, QLatin1StringView s)
1077 Returns \c true if char \a ch is lexically greater than or equal to
1078 string \a s; otherwise returns \c false.
1081/*! \fn bool QLatin1StringView::operator==(QLatin1StringView s, QChar ch)
1083 Returns \c true if string \a s is lexically equal to char \a ch;
1084 otherwise returns \c false.
1086/*! \fn bool QLatin1StringView::operator<(QLatin1StringView s, QChar ch)
1088 Returns \c true if string \a s is lexically less than char \a ch;
1089 otherwise returns \c false.
1091/*! \fn bool QLatin1StringView::operator>(QLatin1StringView s, QChar ch)
1093 Returns \c true if string \a s is lexically greater than char \a ch;
1094 otherwise returns \c false.
1096/*! \fn bool QLatin1StringView::operator!=(QLatin1StringView s, QChar ch)
1098 Returns \c true if string \a s is lexically not equal to char \a ch;
1099 otherwise returns \c false.
1101/*! \fn bool QLatin1StringView::operator<=(QLatin1StringView s, QChar ch)
1103 Returns \c true if string \a s is lexically less than or equal to
1104 char \a ch; otherwise returns \c false.
1106/*! \fn bool QLatin1StringView::operator>=(QLatin1StringView s, QChar ch)
1108 Returns \c true if string \a s is lexically greater than or equal to
1109 char \a ch; otherwise returns \c false.
1112/*! \fn bool QLatin1StringView::operator==(QStringView s1, QLatin1StringView s2)
1114 Returns \c true if string view \a s1 is lexically equal to string \a s2;
1115 otherwise returns \c false.
1117/*! \fn bool QLatin1StringView::operator<(QStringView s1, QLatin1StringView s2)
1119 Returns \c true if string view \a s1 is lexically less than string \a s2;
1120 otherwise returns \c false.
1122/*! \fn bool QLatin1StringView::operator>(QStringView s1, QLatin1StringView s2)
1124 Returns \c true if string view \a s1 is lexically greater than string \a s2;
1125 otherwise returns \c false.
1127/*! \fn bool QLatin1StringView::operator!=(QStringView s1, QLatin1StringView s2)
1129 Returns \c true if string view \a s1 is lexically not equal to string \a s2;
1130 otherwise returns \c false.
1132/*! \fn bool QLatin1StringView::operator<=(QStringView s1, QLatin1StringView s2)
1134 Returns \c true if string view \a s1 is lexically less than or equal to
1135 string \a s2; otherwise returns \c false.
1137/*! \fn bool QLatin1StringView::operator>=(QStringView s1, QLatin1StringView s2)
1139 Returns \c true if string view \a s1 is lexically greater than or equal to
1140 string \a s2; otherwise returns \c false.
1143/*! \fn bool QLatin1StringView::operator==(QLatin1StringView s1, QStringView s2)
1145 Returns \c true if string \a s1 is lexically equal to string view \a s2;
1146 otherwise returns \c false.
1148/*! \fn bool QLatin1StringView::operator<(QLatin1StringView s1, QStringView s2)
1150 Returns \c true if string \a s1 is lexically less than string view \a s2;
1151 otherwise returns \c false.
1153/*! \fn bool QLatin1StringView::operator>(QLatin1StringView s1, QStringView s2)
1155 Returns \c true if string \a s1 is lexically greater than string view \a s2;
1156 otherwise returns \c false.
1158/*! \fn bool QLatin1StringView::operator!=(QLatin1StringView s1, QStringView s2)
1160 Returns \c true if string \a s1 is lexically not equal to string view \a s2;
1161 otherwise returns \c false.
1163/*! \fn bool QLatin1StringView::operator<=(QLatin1StringView s1, QStringView s2)
1165 Returns \c true if string \a s1 is lexically less than or equal to
1166 string view \a s2; otherwise returns \c false.
1168/*! \fn bool QLatin1StringView::operator>=(QLatin1StringView s1, QStringView s2)
1170 Returns \c true if string \a s1 is lexically greater than or equal to
1171 string view \a s2; otherwise returns \c false.
1174/*! \fn bool QLatin1StringView::operator==(const char *s1, QLatin1StringView s2)
1176 Returns \c true if const char pointer \a s1 is lexically equal to
1177 string \a s2; otherwise returns \c false.
1179/*! \fn bool QLatin1StringView::operator<(const char *s1, QLatin1StringView s2)
1181 Returns \c true if const char pointer \a s1 is lexically less than
1182 string \a s2; otherwise returns \c false.
1184/*! \fn bool QLatin1StringView::operator>(const char *s1, QLatin1StringView s2)
1186 Returns \c true if const char pointer \a s1 is lexically greater than
1187 string \a s2; otherwise returns \c false.
1189/*! \fn bool QLatin1StringView::operator!=(const char *s1, QLatin1StringView s2)
1191 Returns \c true if const char pointer \a s1 is lexically not equal to
1192 string \a s2; otherwise returns \c false.
1194/*! \fn bool QLatin1StringView::operator<=(const char *s1, QLatin1StringView s2)
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.
1199/*! \fn bool QLatin1StringView::operator>=(const char *s1, QLatin1StringView s2)
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.
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
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.
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:
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
1231 Returns 0 if the conversion fails.
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.
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.
1241 This function ignores leading and trailing spacing characters.
1242//! [latin1-numeric-conversion-note]
1244 \note Support for the "0b" prefix was added in Qt 6.4.
1248 \fn double QLatin1StringView::toDouble(bool *ok) const
1249 \fn float QLatin1StringView::toFloat(bool *ok) const
1252 Returns this QLatin1StringView converted to a corresponding floating-point value.
1254 Returns an infinity if the conversion overflows or 0.0 if the
1255 conversion fails for other reasons (e.g. underflow).
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.
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.
1265 \include qlatin1stringview.qdoc latin1-numeric-conversion-note
1269 \fn Qt::Literals::StringLiterals::operator""_L1(const char *str, size_t size)
1271 \relates QLatin1StringView
1274 Literal operator that creates a QLatin1StringView out of the first \a size
1275 characters in the char string literal \a str.
1277 The following code creates a QLatin1StringView:
1279 using namespace Qt::Literals::StringLiterals;
1281 auto str = "hello"_L1;
1284 \sa Qt::Literals::StringLiterals