diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 8fc301e27f..c42f01c3c9 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -218,6 +218,7 @@ qt_internal_add_module(Core text/qcollator.cpp text/qcollator.h text/qcollator_p.h text/qdoublescanprint_p.h text/qlatin1stringmatcher.cpp text/qlatin1stringmatcher.h + text/qlatin1stringview.h text/qlocale.cpp text/qlocale.h text/qlocale_p.h text/qlocale_data_p.h text/qlocale_tools.cpp text/qlocale_tools_p.h diff --git a/src/corelib/text/qanystringview.h b/src/corelib/text/qanystringview.h index ff9d0f9d8f..a3117a4b79 100644 --- a/src/corelib/text/qanystringview.h +++ b/src/corelib/text/qanystringview.h @@ -4,6 +4,7 @@ #ifndef QANYSTRINGVIEW_H #define QANYSTRINGVIEW_H +#include #include #include diff --git a/src/corelib/text/qlatin1stringview.h b/src/corelib/text/qlatin1stringview.h new file mode 100644 index 0000000000..46675916b1 --- /dev/null +++ b/src/corelib/text/qlatin1stringview.h @@ -0,0 +1,371 @@ +// Copyright (C) 2020 The Qt Company Ltd. +// Copyright (C) 2019 Intel Corporation. +// Copyright (C) 2019 Mail.ru Group. +// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef QLATIN1STRINGVIEW +#define QLATIN1STRINGVIEW + +#include +#include +#include +#include + +#if 0 +// Workaround for generating forward headers +#pragma qt_class(QLatin1String) +#pragma qt_class(QLatin1StringView) +#endif + +QT_BEGIN_NAMESPACE + +class QString; + +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED) || defined(Q_QDOC) +# define Q_L1S_VIEW_IS_PRIMARY +class QLatin1StringView +#else +class QLatin1String +#endif +{ +public: +#ifdef Q_L1S_VIEW_IS_PRIMARY + constexpr inline QLatin1StringView() noexcept {} + constexpr QLatin1StringView(std::nullptr_t) noexcept : QLatin1StringView() {} + constexpr inline explicit QLatin1StringView(const char *s) noexcept + : QLatin1StringView(s, s ? qsizetype(QtPrivate::lengthHelperPointer(s)) : 0) {} + constexpr QLatin1StringView(const char *f, const char *l) + : QLatin1StringView(f, qsizetype(l - f)) {} + constexpr inline QLatin1StringView(const char *s, qsizetype sz) noexcept : m_data(s), m_size(sz) {} + explicit QLatin1StringView(const QByteArray &s) noexcept + : QLatin1StringView(s.constData(), s.size()) {} + constexpr explicit QLatin1StringView(QByteArrayView s) noexcept + : QLatin1StringView(s.constData(), s.size()) {} +#else + constexpr inline QLatin1String() noexcept : m_size(0), m_data(nullptr) {} + Q_WEAK_OVERLOAD + constexpr QLatin1String(std::nullptr_t) noexcept : QLatin1String() {} + constexpr inline explicit QLatin1String(const char *s) noexcept + : m_size(s ? qsizetype(QtPrivate::lengthHelperPointer(s)) : 0), m_data(s) {} + constexpr QLatin1String(const char *f, const char *l) + : QLatin1String(f, qsizetype(l - f)) {} + constexpr inline QLatin1String(const char *s, qsizetype sz) noexcept : m_size(sz), m_data(s) {} + explicit QLatin1String(const QByteArray &s) noexcept : m_size(s.size()), m_data(s.constData()) {} + constexpr explicit QLatin1String(QByteArrayView s) noexcept : m_size(s.size()), m_data(s.data()) {} +#endif // !Q_L1S_VIEW_IS_PRIMARY + + inline QString toString() const; + + constexpr const char *latin1() const noexcept { return m_data; } + constexpr qsizetype size() const noexcept { return m_size; } + constexpr const char *data() const noexcept { return m_data; } + [[nodiscard]] constexpr const char *constData() const noexcept { return data(); } + [[nodiscard]] constexpr const char *constBegin() const noexcept { return begin(); } + [[nodiscard]] constexpr const char *constEnd() const noexcept { return end(); } + + [[nodiscard]] constexpr QLatin1Char first() const { return front(); } + [[nodiscard]] constexpr QLatin1Char last() const { return back(); } + + [[nodiscard]] constexpr qsizetype length() const noexcept { return size(); } + + constexpr bool isNull() const noexcept { return !data(); } + constexpr bool isEmpty() const noexcept { return !size(); } + + [[nodiscard]] constexpr bool empty() const noexcept { return size() == 0; } + + template + [[nodiscard]] inline QString arg(Args &&...args) const; + + [[nodiscard]] constexpr QLatin1Char at(qsizetype i) const + { return Q_ASSERT(i >= 0), Q_ASSERT(i < size()), QLatin1Char(m_data[i]); } + [[nodiscard]] constexpr QLatin1Char operator[](qsizetype i) const { return at(i); } + + [[nodiscard]] constexpr QLatin1Char front() const { return at(0); } + [[nodiscard]] constexpr QLatin1Char back() const { return at(size() - 1); } + + [[nodiscard]] int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::compareStrings(*this, other, cs); } + [[nodiscard]] int compare(QLatin1StringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::compareStrings(*this, other, cs); } + [[nodiscard]] constexpr int compare(QChar c) const noexcept + { return isEmpty() ? -1 : front() == c ? int(size() > 1) : uchar(m_data[0]) - c.unicode(); } + [[nodiscard]] int compare(QChar c, Qt::CaseSensitivity cs) const noexcept + { return QtPrivate::compareStrings(*this, QStringView(&c, 1), cs); } + template + [[nodiscard]] int compare(QBasicUtf8StringView other, + Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { + return QtPrivate::compareStrings(*this, other, cs); + } + + [[nodiscard]] bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::startsWith(*this, s, cs); } + [[nodiscard]] bool startsWith(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::startsWith(*this, s, cs); } + [[nodiscard]] constexpr bool startsWith(QChar c) const noexcept + { return !isEmpty() && front() == c; } + [[nodiscard]] inline bool startsWith(QChar c, Qt::CaseSensitivity cs) const noexcept + { return QtPrivate::startsWith(*this, QStringView(&c, 1), cs); } + + [[nodiscard]] bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::endsWith(*this, s, cs); } + [[nodiscard]] bool endsWith(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::endsWith(*this, s, cs); } + [[nodiscard]] constexpr bool endsWith(QChar c) const noexcept + { return !isEmpty() && back() == c; } + [[nodiscard]] inline bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept + { return QtPrivate::endsWith(*this, QStringView(&c, 1), cs); } + + [[nodiscard]] qsizetype indexOf(QStringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::findString(*this, from, s, cs); } + [[nodiscard]] qsizetype indexOf(QLatin1StringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::findString(*this, from, s, cs); } + [[nodiscard]] qsizetype indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::findString(*this, from, QStringView(&c, 1), cs); } + + [[nodiscard]] bool contains(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return indexOf(s, 0, cs) != -1; } + [[nodiscard]] bool contains(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return indexOf(s, 0, cs) != -1; } + [[nodiscard]] inline bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return indexOf(QStringView(&c, 1), 0, cs) != -1; } + + [[nodiscard]] qsizetype lastIndexOf(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return lastIndexOf(s, size(), cs); } + [[nodiscard]] qsizetype lastIndexOf(QStringView s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::lastIndexOf(*this, from, s, cs); } + [[nodiscard]] qsizetype lastIndexOf(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return lastIndexOf(s, size(), cs); } + [[nodiscard]] qsizetype lastIndexOf(QLatin1StringView s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::lastIndexOf(*this, from, s, cs); } + [[nodiscard]] qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return lastIndexOf(c, -1, cs); } + [[nodiscard]] qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::lastIndexOf(*this, from, QStringView(&c, 1), cs); } + + [[nodiscard]] qsizetype count(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + { return QtPrivate::count(*this, str, cs); } + [[nodiscard]] qsizetype count(QLatin1StringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + { return QtPrivate::count(*this, str, cs); } + [[nodiscard]] qsizetype count(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::count(*this, ch, cs); } + + [[nodiscard]] short toShort(bool *ok = nullptr, int base = 10) const + { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } + [[nodiscard]] ushort toUShort(bool *ok = nullptr, int base = 10) const + { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } + [[nodiscard]] int toInt(bool *ok = nullptr, int base = 10) const + { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } + [[nodiscard]] uint toUInt(bool *ok = nullptr, int base = 10) const + { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } + [[nodiscard]] long toLong(bool *ok = nullptr, int base = 10) const + { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } + [[nodiscard]] ulong toULong(bool *ok = nullptr, int base = 10) const + { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } + [[nodiscard]] qlonglong toLongLong(bool *ok = nullptr, int base = 10) const + { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } + [[nodiscard]] qulonglong toULongLong(bool *ok = nullptr, int base = 10) const + { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } + [[nodiscard]] float toFloat(bool *ok = nullptr) const + { + const auto r = QtPrivate::toFloat(*this); + if (ok) + *ok = bool(r); + return r.value_or(0.0f); + } + [[nodiscard]] double toDouble(bool *ok = nullptr) const + { + const auto r = QtPrivate::toDouble(*this); + if (ok) + *ok = bool(r); + return r.value_or(0.0); + } + + using value_type = const char; + using reference = value_type&; + using const_reference = reference; + using iterator = value_type*; + using const_iterator = iterator; + using difference_type = qsizetype; // violates Container concept requirements + using size_type = qsizetype; // violates Container concept requirements + + constexpr const_iterator begin() const noexcept { return data(); } + constexpr const_iterator cbegin() const noexcept { return data(); } + constexpr const_iterator end() const noexcept { return data() + size(); } + constexpr const_iterator cend() const noexcept { return data() + size(); } + + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = reverse_iterator; + + const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } + + [[nodiscard]] constexpr QLatin1StringView mid(qsizetype pos, qsizetype n = -1) const + { + using namespace QtPrivate; + auto result = QContainerImplHelper::mid(size(), &pos, &n); + return result == QContainerImplHelper::Null ? QLatin1StringView() + : QLatin1StringView(m_data + pos, n); + } + [[nodiscard]] constexpr QLatin1StringView left(qsizetype n) const + { + if (size_t(n) >= size_t(size())) + n = size(); + return {m_data, n}; + } + [[nodiscard]] constexpr QLatin1StringView right(qsizetype n) const + { + if (size_t(n) >= size_t(size())) + n = size(); + return {m_data + m_size - n, n}; + } + + [[nodiscard]] constexpr QLatin1StringView sliced(qsizetype pos) const + { verify(pos); return {m_data + pos, m_size - pos}; } + [[nodiscard]] constexpr QLatin1StringView sliced(qsizetype pos, qsizetype n) const + { verify(pos, n); return {m_data + pos, n}; } + [[nodiscard]] constexpr QLatin1StringView first(qsizetype n) const + { verify(n); return {m_data, n}; } + [[nodiscard]] constexpr QLatin1StringView last(qsizetype n) const + { verify(n); return {m_data + size() - n, n}; } + [[nodiscard]] constexpr QLatin1StringView chopped(qsizetype n) const + { verify(n); return {m_data, size() - n}; } + + constexpr void chop(qsizetype n) + { verify(n); m_size -= n; } + constexpr void truncate(qsizetype n) + { verify(n); m_size = n; } + + [[nodiscard]] QLatin1StringView trimmed() const noexcept { return QtPrivate::trimmed(*this); } + + template + [[nodiscard]] inline constexpr auto tokenize(Needle &&needle, Flags...flags) const + noexcept(noexcept(qTokenize(std::declval(), + std::forward(needle), flags...))) + -> decltype(qTokenize(*this, std::forward(needle), flags...)) + { return qTokenize(*this, std::forward(needle), flags...); } + + friend inline bool operator==(QLatin1StringView s1, QLatin1StringView s2) noexcept + { return QByteArrayView(s1) == QByteArrayView(s2); } + friend inline bool operator!=(QLatin1StringView s1, QLatin1StringView s2) noexcept + { return !(s1 == s2); } + friend inline bool operator<(QLatin1StringView s1, QLatin1StringView s2) noexcept + { + const qsizetype len = qMin(s1.size(), s2.size()); + const int r = len ? memcmp(s1.latin1(), s2.latin1(), len) : 0; + return r < 0 || (r == 0 && s1.size() < s2.size()); + } + friend inline bool operator>(QLatin1StringView s1, QLatin1StringView s2) noexcept + { return s2 < s1; } + friend inline bool operator<=(QLatin1StringView s1, QLatin1StringView s2) noexcept + { return !(s1 > s2); } + friend inline bool operator>=(QLatin1StringView s1, QLatin1StringView s2) noexcept + { return !(s1 < s2); } + + // QChar <> QLatin1StringView + friend inline bool operator==(QChar lhs, QLatin1StringView rhs) noexcept { return rhs.size() == 1 && lhs == rhs.front(); } + friend inline bool operator< (QChar lhs, QLatin1StringView rhs) noexcept { return compare_helper(&lhs, 1, rhs) < 0; } + friend inline bool operator> (QChar lhs, QLatin1StringView rhs) noexcept { return compare_helper(&lhs, 1, rhs) > 0; } + friend inline bool operator!=(QChar lhs, QLatin1StringView rhs) noexcept { return !(lhs == rhs); } + friend inline bool operator<=(QChar lhs, QLatin1StringView rhs) noexcept { return !(lhs > rhs); } + friend inline bool operator>=(QChar lhs, QLatin1StringView rhs) noexcept { return !(lhs < rhs); } + + friend inline bool operator==(QLatin1StringView lhs, QChar rhs) noexcept { return rhs == lhs; } + friend inline bool operator!=(QLatin1StringView lhs, QChar rhs) noexcept { return !(rhs == lhs); } + friend inline bool operator< (QLatin1StringView lhs, QChar rhs) noexcept { return rhs > lhs; } + friend inline bool operator> (QLatin1StringView lhs, QChar rhs) noexcept { return rhs < lhs; } + friend inline bool operator<=(QLatin1StringView lhs, QChar rhs) noexcept { return !(rhs < lhs); } + friend inline bool operator>=(QLatin1StringView lhs, QChar rhs) noexcept { return !(rhs > lhs); } + + // QStringView <> QLatin1StringView + friend inline bool operator==(QStringView lhs, QLatin1StringView rhs) noexcept + { return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); } + friend inline bool operator!=(QStringView lhs, QLatin1StringView rhs) noexcept { return !(lhs == rhs); } + friend inline bool operator< (QStringView lhs, QLatin1StringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; } + friend inline bool operator<=(QStringView lhs, QLatin1StringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; } + friend inline bool operator> (QStringView lhs, QLatin1StringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; } + friend inline bool operator>=(QStringView lhs, QLatin1StringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; } + + friend inline bool operator==(QLatin1StringView lhs, QStringView rhs) noexcept + { return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); } + friend inline bool operator!=(QLatin1StringView lhs, QStringView rhs) noexcept { return !(lhs == rhs); } + friend inline bool operator< (QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; } + friend inline bool operator<=(QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; } + friend inline bool operator> (QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; } + friend inline bool operator>=(QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; } + + +#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) + QT_ASCII_CAST_WARN inline bool operator==(const char *s) const; + QT_ASCII_CAST_WARN inline bool operator!=(const char *s) const; + QT_ASCII_CAST_WARN inline bool operator<(const char *s) const; + QT_ASCII_CAST_WARN inline bool operator>(const char *s) const; + QT_ASCII_CAST_WARN inline bool operator<=(const char *s) const; + QT_ASCII_CAST_WARN inline bool operator>=(const char *s) const; + + QT_ASCII_CAST_WARN inline bool operator==(const QByteArray &s) const; + QT_ASCII_CAST_WARN inline bool operator!=(const QByteArray &s) const; + QT_ASCII_CAST_WARN inline bool operator<(const QByteArray &s) const; + QT_ASCII_CAST_WARN inline bool operator>(const QByteArray &s) const; + QT_ASCII_CAST_WARN inline bool operator<=(const QByteArray &s) const; + QT_ASCII_CAST_WARN inline bool operator>=(const QByteArray &s) const; + + QT_ASCII_CAST_WARN friend bool operator==(const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) == 0; } + QT_ASCII_CAST_WARN friend bool operator!=(const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) != 0; } + QT_ASCII_CAST_WARN friend bool operator< (const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) > 0; } + QT_ASCII_CAST_WARN friend bool operator> (const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) < 0; } + QT_ASCII_CAST_WARN friend bool operator<=(const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) >= 0; } + QT_ASCII_CAST_WARN friend bool operator>=(const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) <= 0; } +#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) + +private: +#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) + static inline int compare_helper(const QLatin1StringView &s1, const char *s2); +#endif + Q_ALWAYS_INLINE constexpr void verify(qsizetype pos, qsizetype n = 0) const + { + Q_ASSERT(pos >= 0); + Q_ASSERT(pos <= size()); + Q_ASSERT(n >= 0); + Q_ASSERT(n <= size() - pos); + } + Q_CORE_EXPORT static int compare_helper(const QChar *data1, qsizetype length1, + QLatin1StringView s2, + Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED) + const char *m_data = nullptr; + qsizetype m_size = 0; +#else + qsizetype m_size; + const char *m_data; +#endif +}; +#ifdef Q_L1S_VIEW_IS_PRIMARY +Q_DECLARE_TYPEINFO(QLatin1StringView, Q_RELOCATABLE_TYPE); +#else +Q_DECLARE_TYPEINFO(QLatin1String, Q_RELOCATABLE_TYPE); +#endif + +namespace Qt { +inline namespace Literals { +inline namespace StringLiterals { + +constexpr inline QLatin1StringView operator"" _L1(const char *str, size_t size) noexcept +{ + return {str, qsizetype(size)}; +} + +} // StringLiterals +} // Literals +} // Qt + +QT_END_NAMESPACE + +#ifdef Q_L1S_VIEW_IS_PRIMARY +# undef Q_L1S_VIEW_IS_PRIMARY +#endif + +#endif // QLATIN1STRINGVIEW diff --git a/src/corelib/text/qlatin1stringview.qdoc b/src/corelib/text/qlatin1stringview.qdoc new file mode 100644 index 0000000000..422b7eb1c7 --- /dev/null +++ b/src/corelib/text/qlatin1stringview.qdoc @@ -0,0 +1,1273 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// Copyright (C) 2022 Intel Corporation. +// Copyright (C) 2019 Mail.ru Group. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +/*! \class QLatin1StringView + \inmodule QtCore + \brief The QLatin1StringView class provides a thin wrapper around + a US-ASCII/Latin-1 encoded string literal. + + \ingroup string-processing + \reentrant + + Many of QString's member functions are overloaded to accept + \c{const char *} instead of QString. This includes the copy + constructor, the assignment operator, the comparison operators, + and various other functions such as \l{QString::insert()}{insert()}, + \l{QString::append()}{append()}, and \l{QString::prepend()}{prepend()}. + Some of these functions are optimized to avoid constructing a + QString object for the \c{const char *} data. For example, + assuming \c str is a QString, + + \snippet code/src_corelib_text_qstring.cpp 3 + + is much faster than + + \snippet code/src_corelib_text_qstring.cpp 4 + + because it doesn't construct four temporary QString objects and + make a deep copy of the character data. + + However, that is not true for all QString member functions that take + \c{const char *} and therefore applications should assume a temporary will + be created, such as in + + \snippet code/src_corelib_text_qstring.cpp 4bis + + Applications that define \l QT_NO_CAST_FROM_ASCII (as explained + in the QString documentation) don't have access to QString's + \c{const char *} API. To provide an efficient way of specifying + constant Latin-1 strings, Qt provides the QLatin1StringView, which is + just a very thin wrapper around a \c{const char *}. Using + QLatin1StringView, the example code above becomes + + \snippet code/src_corelib_text_qstring.cpp 5 + + This is a bit longer to type, but it provides exactly the same + benefits as the first version of the code, and is faster than + converting the Latin-1 strings using QString::fromLatin1(). + + Thanks to the QString(QLatin1StringView) constructor, + QLatin1StringView can be used everywhere a QString is expected. For + example: + + \snippet code/src_corelib_text_qstring.cpp 6 + + \note If the function you're calling with a QLatin1StringView + argument isn't actually overloaded to take QLatin1StringView, the + implicit conversion to QString will trigger a memory allocation, + which is usually what you want to avoid by using QLatin1StringView + in the first place. In those cases, using QStringLiteral may be + the better option. + + \sa QString, QLatin1Char, {QStringLiteral()}{QStringLiteral}, + QT_NO_CAST_FROM_ASCII +*/ + +/*! + \class QLatin1String + \inmodule QtCore + \brief QLatin1String is the same as QLatin1StringView. + + QLatin1String is a view to a Latin-1 string. It's the same as + QLatin1StringView and is kept for compatibility reasons. It is + recommended to use QLatin1StringView instead. + + Please see the QLatin1StringView documentation for details. +*/ + +/*! + \typedef QLatin1StringView::value_type + \since 5.10 + + Alias for \c{const char}. Provided for compatibility with the STL. +*/ + +/*! + \typedef QLatin1StringView::difference_type + \since 5.10 + + Alias for \c{qsizetype}. Provided for compatibility with the STL. +*/ + +/*! + \typedef QLatin1StringView::size_type + \since 5.10 + + Alias for \c{qsizetype}. Provided for compatibility with the STL. + + \note In version prior to Qt 6, this was an alias for \c{int}, + restricting the amount of data that could be held in a QLatin1StringView + on 64-bit architectures. +*/ + +/*! + \typedef QLatin1StringView::reference + \since 5.10 + + Alias for \c{value_type &}. Provided for compatibility with the STL. +*/ + +/*! + \typedef QLatin1StringView::const_reference + \since 5.11 + + Alias for \c{reference}. Provided for compatibility with the STL. +*/ + +/*! + \typedef QLatin1StringView::iterator + \since 5.10 + + QLatin1StringView does not support mutable iterators, so this is the same + as const_iterator. + + \sa const_iterator, reverse_iterator +*/ + +/*! + \typedef QLatin1StringView::const_iterator + \since 5.10 + + \sa iterator, const_reverse_iterator +*/ + +/*! + \typedef QLatin1StringView::reverse_iterator + \since 5.10 + + QLatin1StringView does not support mutable reverse iterators, so this is the + same as const_reverse_iterator. + + \sa const_reverse_iterator, iterator +*/ + +/*! + \typedef QLatin1StringView::const_reverse_iterator + \since 5.10 + + \sa reverse_iterator, const_iterator +*/ + +/*! \fn QLatin1StringView::QLatin1StringView() + \since 5.6 + + Constructs a QLatin1StringView object that stores a \nullptr. + + \sa data(), isEmpty(), isNull(), {Distinction Between Null and Empty Strings} +*/ + +/*! \fn QLatin1StringView::QLatin1StringView(std::nullptr_t) + \since 6.4 + + Constructs a QLatin1StringView object that stores a \nullptr. + + \sa data(), isEmpty(), isNull(), {Distinction Between Null and Empty Strings} +*/ + +/*! \fn QLatin1StringView::QLatin1StringView(const char *str) + + Constructs a QLatin1StringView object that stores \a str. + + The string data is \e not copied. The caller must be able to + guarantee that \a str will not be deleted or modified as long as + the QLatin1StringView object exists. + + \sa latin1() +*/ + +/*! \fn QLatin1StringView::QLatin1StringView(const char *str, qsizetype size) + + Constructs a QLatin1StringView object that stores \a str with \a size. + + The string data is \e not copied. The caller must be able to + guarantee that \a str will not be deleted or modified as long as + the QLatin1StringView object exists. + + \note: any null ('\\0') bytes in the byte array will be included in this + string, which will be converted to Unicode null characters (U+0000) if this + string is used by QString. This behavior is different from Qt 5.x. + + \sa latin1() +*/ + +/*! + \fn QLatin1StringView::QLatin1StringView(const char *first, const char *last) + \since 5.10 + + Constructs a QLatin1StringView object that stores \a first with length + (\a last - \a first). + + The range \c{[first,last)} must remain valid for the lifetime of + this Latin-1 string object. + + Passing \nullptr as \a first is safe if \a last is \nullptr, + too, and results in a null Latin-1 string. + + The behavior is undefined if \a last precedes \a first, \a first + is \nullptr and \a last is not, or if \c{last - first > + INT_MAX}. +*/ + +/*! \fn QLatin1StringView::QLatin1StringView(const QByteArray &str) + + Constructs a QLatin1StringView object as a view on \a str. + + The string data is \e not copied. The caller must be able to + guarantee that \a str will not be deleted or modified as long as + the QLatin1StringView object exists. + + \sa latin1() +*/ + +/*! \fn QLatin1StringView::QLatin1StringView(QByteArrayView str) + \since 6.3 + + Constructs a QLatin1StringView object as a view on \a str. + + The string data is \e not copied. The caller must be able to + guarantee that the data which \a str is pointing to will not + be deleted or modified as long as the QLatin1StringView object + exists. The size is obtained from \a str as-is, without checking + for a null-terminator. + + \note: any null ('\\0') bytes in the byte array will be included in this + string, which will be converted to Unicode null characters (U+0000) if this + string is used by QString. + + \sa latin1() +*/ + +/*! + \fn QString QLatin1StringView::toString() const + \since 6.0 + + Converts this Latin-1 string into a QString. Equivalent to + \code + return QString(*this); + \endcode +*/ + +/*! \fn const char *QLatin1StringView::latin1() const + + Returns the start of the Latin-1 string referenced by this object. +*/ + +/*! \fn const char *QLatin1StringView::data() const + + Returns the start of the Latin-1 string referenced by this object. +*/ + +/*! \fn const char *QLatin1StringView::constData() const + \since 6.4 + + Returns the start of the Latin-1 string referenced by this object. + + This function is provided for compatibility with other Qt containers. + + \sa data() +*/ + +/*! \fn qsizetype QLatin1StringView::size() const + + Returns the size of the Latin-1 string referenced by this object. + + \note In version prior to Qt 6, this function returned \c{int}, + restricting the amount of data that could be held in a QLatin1StringView + on 64-bit architectures. +*/ + +/*! \fn qsizetype QLatin1StringView::length() const + \since 6.4 + + Same as size(). + + This function is provided for compatibility with other Qt containers. +*/ + +/*! \fn bool QLatin1StringView::isNull() const + \since 5.10 + + Returns whether the Latin-1 string referenced by this object is null + (\c{data() == nullptr}) or not. + + \sa isEmpty(), data() +*/ + +/*! \fn bool QLatin1StringView::isEmpty() const + \since 5.10 + + Returns whether the Latin-1 string referenced by this object is empty + (\c{size() == 0}) or not. + + \sa isNull(), size() +*/ + +/*! \fn bool QLatin1StringView::empty() const + \since 6.4 + + Returns whether the Latin-1 string referenced by this object is empty + (\c{size() == 0}) or not. + + This function is provided for STL compatibility. + + \sa isEmpty(), isNull(), size() +*/ + +/*! \fn QLatin1Char QLatin1StringView::at(qsizetype pos) const + \since 5.8 + + Returns the character at position \a pos in this object. + + \note This function performs no error checking. + The behavior is undefined when \a pos < 0 or \a pos >= size(). + + \sa operator[]() +*/ + +/*! \fn QLatin1Char QLatin1StringView::operator[](qsizetype pos) const + \since 5.8 + + Returns the character at position \a pos in this object. + + \note This function performs no error checking. + The behavior is undefined when \a pos < 0 or \a pos >= size(). + + \sa at() +*/ + +/*! + \fn QLatin1Char QLatin1StringView::front() const + \since 5.10 + + Returns the first character in the string. + Same as \c{at(0)}. + + This function is provided for STL compatibility. + + \warning Calling this function on an empty string constitutes + undefined behavior. + + \sa back(), at(), operator[]() +*/ + +/*! + \fn QLatin1Char QLatin1StringView::first() const + \since 6.4 + + Returns the first character in the string. + Same as \c{at(0)} or front(). + + This function is provided for compatibility with other Qt containers. + + \warning Calling this function on an empty string constitutes + undefined behavior. + + \sa last(), front(), back() +*/ + +/*! + \fn QLatin1Char QLatin1StringView::back() const + \since 5.10 + + Returns the last character in the string. + Same as \c{at(size() - 1)}. + + This function is provided for STL compatibility. + + \warning Calling this function on an empty string constitutes + undefined behavior. + + \sa front(), at(), operator[]() +*/ + +/*! + \fn QLatin1Char QLatin1StringView::last() const + \since 6.4 + + Returns the last character in the string. + Same as \c{at(size() - 1)} or back(). + + This function is provided for compatibility with other Qt containers. + + \warning Calling this function on an empty string constitutes + undefined behavior. + + \sa first(), back(), front() +*/ + +/*! + \fn int QLatin1StringView::compare(QStringView str, Qt::CaseSensitivity cs) const + \fn int QLatin1StringView::compare(QLatin1StringView l1, Qt::CaseSensitivity cs) const + \fn int QLatin1StringView::compare(QChar ch) const + \fn int QLatin1StringView::compare(QChar ch, Qt::CaseSensitivity cs) const + \since 5.14 + + Returns an integer that compares to zero as this string view compares + to the UTF-16 string viewed by \a str, the Latin-1 string viewed by \a l1, + or the character \a ch, respectively. + + \include qstring.qdocinc {search-comparison-case-sensitivity} {search} + + \sa operator==(), operator<(), operator>() +*/ + + +/*! + \fn bool QLatin1StringView::startsWith(QStringView str, Qt::CaseSensitivity cs) const + \since 5.10 + \fn bool QLatin1StringView::startsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const + \since 5.10 + \fn bool QLatin1StringView::startsWith(QChar ch) const + \since 5.10 + \fn bool QLatin1StringView::startsWith(QChar ch, Qt::CaseSensitivity cs) const + \since 5.10 + + Returns \c true if this Latin-1 string view starts with the UTF-16 + string viewed by \a str, the Latin-1 string viewed by \a l1, or the + character \a ch, respectively; otherwise returns \c false. + + \include qstring.qdocinc {search-comparison-case-sensitivity} {search} + + \sa endsWith() +*/ + +/*! + \fn bool QLatin1StringView::endsWith(QStringView str, Qt::CaseSensitivity cs) const + \since 5.10 + \fn bool QLatin1StringView::endsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const + \since 5.10 + \fn bool QLatin1StringView::endsWith(QChar ch) const + \since 5.10 + \fn bool QLatin1StringView::endsWith(QChar ch, Qt::CaseSensitivity cs) const + \since 5.10 + + Returns \c true if this Latin-1 string view ends with the UTF-16 string + viewed \a str, the Latin-1 string viewed by \a l1, or the character \a ch, + respectively; otherwise returns \c false. + + \include qstring.qdocinc {search-comparison-case-sensitivity} {search} + + \sa startsWith() +*/ + +/*! + \fn qsizetype QLatin1StringView::indexOf(QStringView str, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + \fn qsizetype QLatin1StringView::indexOf(QLatin1StringView l1, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + \fn qsizetype QLatin1StringView::indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + \since 5.14 + + Returns the index position in this Latin-1 string view of the first + occurrence of the UTF-16 string viewed by \a str, the Latin-1 string + viewed by \a l1, or the character \a ch, respectively, searching forward + from index position \a from. Returns -1 if \a str, \a l1 or \a c is not + found, respectively. + + \include qstring.qdocinc {search-comparison-case-sensitivity} {search} + + \include qstring.qdocinc negative-index-start-search-from-end + + \sa QString::indexOf() +*/ + +/*! + \fn bool QLatin1StringView::contains(QStringView str, Qt::CaseSensitivity cs) const + \fn bool QLatin1StringView::contains(QLatin1StringView l1, Qt::CaseSensitivity cs) const + \fn bool QLatin1StringView::contains(QChar c, Qt::CaseSensitivity cs) const + \since 5.14 + + Returns \c true if this Latin-1 string view contains an occurrence of the + UTF-16 string viewed by \a str, the Latin-1 string viewed by \a l1, or the + character \a ch, respectively; otherwise returns \c false. + + \include qstring.qdocinc {search-comparison-case-sensitivity} {search} + + \sa indexOf(), QStringView::contains(), QStringView::indexOf(), + QString::indexOf() +*/ + +/*! + \fn qsizetype QLatin1StringView::lastIndexOf(QStringView str, qsizetype from, Qt::CaseSensitivity cs) const + \fn qsizetype QLatin1StringView::lastIndexOf(QLatin1StringView l1, qsizetype from, Qt::CaseSensitivity cs) const + \fn qsizetype QLatin1StringView::lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const + \since 5.14 + + Returns the index position in this Latin-1 string view of the last + occurrence of the UTF-16 string viewed by \a str, the Latin-1 string + viewed by \a l1, or the character \a ch, respectively, searching backward + from index position \a from; returns -1 if \a str, \a l1 or \a ch is not + found, respectively. + + \include qstring.qdocinc negative-index-start-search-from-end + + \include qstring.qdocinc {search-comparison-case-sensitivity} {search} + + \note When searching for a 0-length \a str or \a l1, the match at + the end of the data is excluded from the search by a negative \a + from, even though \c{-1} is normally thought of as searching from + the end of the string: the match at the end is \e after the last + character, so it is excluded. To include such a final empty match, + either give a positive value for \a from or omit the \a from + parameter entirely. + + \sa indexOf(), QStringView::lastIndexOf(), QStringView::indexOf(), + QString::indexOf() +*/ + +/*! + \fn qsizetype QLatin1StringView::lastIndexOf(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + \fn qsizetype QLatin1StringView::lastIndexOf(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + \since 6.2 + \overload lastIndexOf() + + Returns the index position in this Latin-1 string view of the last + occurrence of the UTF-16 string viewed by \a str or the Latin-1 string + viewed by \a l1, respectively. Returns -1 if \a str or \a l1 is not found, + respectively. + + \include qstring.qdocinc {search-comparison-case-sensitivity} {search} +*/ + +/*! + \fn qsizetype QLatin1StringView::lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const + \since 6.3 + \overload +*/ + +/*! + \fn qsizetype QLatin1StringView::count(QStringView str, Qt::CaseSensitivity cs) const + \fn qsizetype QLatin1StringView::count(QLatin1StringView l1, Qt::CaseSensitivity cs) const + \fn qsizetype QLatin1StringView::count(QChar ch, Qt::CaseSensitivity cs) const + \since 6.4 + + Returns the number of (potentially overlapping) occurrences of the + UTF-16 string viewed by \a str, the Latin-1 string viewed by \a l1, + or the character \a ch, respectively, in this string view. + + \include qstring.qdocinc {search-comparison-case-sensitivity} {search} + + \sa contains(), indexOf() +*/ + +/*! + \fn QLatin1StringView::const_iterator QLatin1StringView::begin() const + \since 5.10 + + Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the + first character in the string. + + This function is provided for STL compatibility. + + \sa end(), cbegin(), rbegin(), data() +*/ + +/*! + \fn QLatin1StringView::const_iterator QLatin1StringView::cbegin() const + \since 5.10 + + Same as begin(). + + This function is provided for STL compatibility. + + \sa cend(), begin(), crbegin(), data() +*/ + +/*! + \fn QLatin1StringView::const_iterator QLatin1StringView::constBegin() const + \since 6.4 + + Same as begin(). + + This function is provided for compatibility with other Qt containers. + + \sa constEnd(), begin(), cbegin(), data() +*/ + +/*! + \fn QLatin1StringView::const_iterator QLatin1StringView::end() const + \since 5.10 + + Returns a const \l{STL-style iterators}{STL-style iterator} pointing just + after the last character in the string. + + This function is provided for STL compatibility. + + \sa begin(), cend(), rend() +*/ + +/*! \fn QLatin1StringView::const_iterator QLatin1StringView::cend() const + \since 5.10 + + Same as end(). + + This function is provided for STL compatibility. + + \sa cbegin(), end(), crend() +*/ + +/*! \fn QLatin1StringView::const_iterator QLatin1StringView::constEnd() const + \since 6.4 + + Same as end(). + + This function is provided for compatibility with other Qt containers. + + \sa constBegin(), end(), cend(), crend() +*/ + +/*! + \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::rbegin() const + \since 5.10 + + Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing + to the first character in the string, in reverse order. + + This function is provided for STL compatibility. + + \sa rend(), crbegin(), begin() +*/ + +/*! + \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::crbegin() const + \since 5.10 + + Same as rbegin(). + + This function is provided for STL compatibility. + + \sa crend(), rbegin(), cbegin() +*/ + +/*! + \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::rend() const + \since 5.10 + + Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing just + after the last character in the string, in reverse order. + + This function is provided for STL compatibility. + + \sa rbegin(), crend(), end() +*/ + +/*! + \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::crend() const + \since 5.10 + + Same as rend(). + + This function is provided for STL compatibility. + + \sa crbegin(), rend(), cend() +*/ + +/*! + \fn QLatin1StringView QLatin1StringView::mid(qsizetype start, qsizetype length) const + \since 5.8 + + Returns the substring of length \a length starting at position + \a start in this Latin-1 string view. + + If you know that \a start and \a length cannot be out of bounds, use + sliced() instead in new code, because it is faster. + + Returns an empty Latin-1 string view if \a start exceeds the length + of this string view. If there are less than \a length characters available + in this string view starting at \a start, or if \a length is negative + (default), the function returns all characters that are available from + \a start. + + \sa first(), last(), sliced(), chopped(), chop(), truncate() +*/ + +/*! + \fn QLatin1StringView QLatin1StringView::left(qsizetype length) const + \since 5.8 + + If you know that \a length cannot be out of bounds, use first() instead in + new code, because it is faster. + + Returns the substring of length \a length starting at position + 0 in this Latin-1 string view. + + The entire Latin-1 string view is returned if \a length is greater + than or equal to size(), or less than zero. + + \sa first(), last(), sliced(), startsWith(), chopped(), chop(), truncate() +*/ + +/*! + \fn QLatin1StringView QLatin1StringView::right(qsizetype length) const + \since 5.8 + + If you know that \a length cannot be out of bounds, use last() instead in + new code, because it is faster. + + Returns the substring of length \a length starting at position + size() - \a length in this Latin-1 string view. + + The entire Latin-1 string view is returned if \a length is greater + than or equal to size(), or less than zero. + + \sa first(), last(), sliced(), endsWith(), chopped(), chop(), truncate() +*/ + +/*! + \fn QLatin1StringView QLatin1StringView::first(qsizetype n) const + \since 6.0 + + Returns a Latin-1 string view that contains the first \a n characters + of this string view. + + \note The behavior is undefined when \a n < 0 or \a n > size(). + + \sa last(), startsWith(), chopped(), chop(), truncate() +*/ + +/*! + \fn QLatin1StringView QLatin1StringView::last(qsizetype n) const + \since 6.0 + + Returns a Latin-1 string view that contains the last \a n characters + of this string view. + + \note The behavior is undefined when \a n < 0 or \a n > size(). + + \sa first(), endsWith(), chopped(), chop(), truncate() +*/ + +/*! + \fn QLatin1StringView QLatin1StringView::sliced(qsizetype pos, qsizetype n) const + \since 6.0 + + Returns a Latin-1 string view that points to \a n characters of this + string view, starting at position \a pos. + + \note The behavior is undefined when \a pos < 0, \a n < 0, + or \c{pos + n > size()}. + + \sa first(), last(), chopped(), chop(), truncate() +*/ + +/*! + \fn QLatin1StringView QLatin1StringView::sliced(qsizetype pos) const + \since 6.0 + + Returns a Latin-1 string view starting at position \a pos in this + string view, and extending to its end. + + \note The behavior is undefined when \a pos < 0 or \a pos > size(). + + \sa first(), last(), chopped(), chop(), truncate() +*/ + +/*! + \fn QLatin1StringView QLatin1StringView::chopped(qsizetype length) const + \since 5.10 + + Returns the substring of length size() - \a length starting at the + beginning of this object. + + Same as \c{left(size() - length)}. + + \note The behavior is undefined when \a length < 0 or \a length > size(). + + \sa sliced(), first(), last(), chop(), truncate() +*/ + +/*! + \fn void QLatin1StringView::truncate(qsizetype length) + \since 5.10 + + Truncates this string to length \a length. + + Same as \c{*this = left(length)}. + + \note The behavior is undefined when \a length < 0 or \a length > size(). + + \sa sliced(), first(), last(), chopped(), chop() +*/ + +/*! + \fn void QLatin1StringView::chop(qsizetype length) + \since 5.10 + + Truncates this string by \a length characters. + + Same as \c{*this = left(size() - length)}. + + \note The behavior is undefined when \a length < 0 or \a length > size(). + + \sa sliced(), first(), last(), chopped(), truncate() +*/ + +/*! + \fn QLatin1StringView QLatin1StringView::trimmed() const + \since 5.10 + + Strips leading and trailing whitespace and returns the result. + + Whitespace means any character for which QChar::isSpace() returns + \c true. This includes the ASCII characters '\\t', '\\n', '\\v', + '\\f', '\\r', and ' '. +*/ + +/*! + \fn bool QLatin1StringView::operator==(const char *other) const + \since 4.3 + + Returns \c true if the string is equal to const char pointer \a other; + otherwise returns \c false. + + The \a other const char pointer is converted to a QString using + the QString::fromUtf8() function. + + You can disable this operator by defining + \l QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. + + \sa {Comparing Strings} +*/ + +/*! + \fn bool QLatin1StringView::operator==(const QByteArray &other) const + \since 5.0 + \overload + + The \a other byte array is converted to a QString using + the QString::fromUtf8() function. + + You can disable this operator by defining + \l QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. +*/ + +/*! + \fn bool QLatin1StringView::operator!=(const char *other) const + \since 4.3 + + Returns \c true if this string is not equal to const char pointer \a other; + otherwise returns \c false. + + The \a other const char pointer is converted to a QString using + the QString::fromUtf8() function. + + You can disable this operator by defining + \l QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. + + \sa {Comparing Strings} +*/ + +/*! + \fn bool QLatin1StringView::operator!=(const QByteArray &other) const + \since 5.0 + \overload operator!=() + + The \a other byte array is converted to a QString using + the QString::fromUtf8() function. + + You can disable this operator by defining + \l QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. +*/ + +/*! + \fn bool QLatin1StringView::operator>(const char *other) const + \since 4.3 + + Returns \c true if this string is lexically greater than const char pointer + \a other; otherwise returns \c false. + + The \a other const char pointer is converted to a QString using + the QString::fromUtf8() function. + + You can disable this operator by defining \l QT_NO_CAST_FROM_ASCII + when you compile your applications. This can be useful if you want + to ensure that all user-visible strings go through QObject::tr(), + for example. + + \sa {Comparing Strings} +*/ + +/*! + \fn bool QLatin1StringView::operator>(const QByteArray &other) const + \since 5.0 + \overload + + The \a other byte array is converted to a QString using + the QString::fromUtf8() function. + + You can disable this operator by defining \l QT_NO_CAST_FROM_ASCII + when you compile your applications. This can be useful if you want + to ensure that all user-visible strings go through QObject::tr(), + for example. +*/ + +/*! + \fn bool QLatin1StringView::operator<(const char *other) const + \since 4.3 + + Returns \c true if this string is lexically less than const char pointer + \a other; otherwise returns \c false. + + The \a other const char pointer is converted to a QString using + the QString::fromUtf8() function. + + You can disable this operator by defining + \l QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. + + \sa {Comparing Strings} +*/ + +/*! + \fn bool QLatin1StringView::operator<(const QByteArray &other) const + \since 5.0 + \overload + + The \a other byte array is converted to a QString using + the QString::fromUtf8() function. + + You can disable this operator by defining + \l QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. +*/ + +/*! + \fn bool QLatin1StringView::operator>=(const char *other) const + \since 4.3 + + Returns \c true if this string is lexically greater than or equal to + const char pointer \a other; otherwise returns \c false. + + The \a other const char pointer is converted to a QString using + the QString::fromUtf8() function. + + You can disable this operator by defining + \l QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. + + \sa {Comparing Strings} +*/ + +/*! + \fn bool QLatin1StringView::operator>=(const QByteArray &other) const + \since 5.0 + \overload + + The \a other byte array is converted to a QString using + the QString::fromUtf8() function. + + You can disable this operator by defining + \l QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. +*/ + +/*! + \fn bool QLatin1StringView::operator<=(const char *other) const + \since 4.3 + + Returns \c true if this string is lexically less than or equal to + const char pointer \a other; otherwise returns \c false. + + The \a other const char pointer is converted to a QString using + the QString::fromUtf8() function. + + You can disable this operator by defining + \l QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. + + \sa {Comparing Strings} +*/ + +/*! + \fn bool QLatin1StringView::operator<=(const QByteArray &other) const + \since 5.0 + \overload + + The \a other byte array is converted to a QString using + the QString::fromUtf8() function. + + You can disable this operator by defining + \l QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. +*/ + +/*! \fn bool QLatin1StringView::operator==(QLatin1StringView s1, QLatin1StringView s2) + + Returns \c true if string \a s1 is lexically equal to string \a s2; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator!=(QLatin1StringView s1, QLatin1StringView s2) + + Returns \c true if string \a s1 is lexically not equal to string \a s2; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator<(QLatin1StringView s1, QLatin1StringView s2) + + Returns \c true if string \a s1 is lexically less than string \a s2; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator<=(QLatin1StringView s1, QLatin1StringView s2) + + Returns \c true if string \a s1 is lexically less than or equal to + string \a s2; otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator>(QLatin1StringView s1, QLatin1StringView s2) + + Returns \c true if string \a s1 is lexically greater than string \a s2; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator>=(QLatin1StringView s1, QLatin1StringView s2) + + Returns \c true if string \a s1 is lexically greater than or equal + to string \a s2; otherwise returns \c false. +*/ + +/*! \fn bool QLatin1StringView::operator==(QChar ch, QLatin1StringView s) + + Returns \c true if char \a ch is lexically equal to string \a s; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator<(QChar ch, QLatin1StringView s) + + Returns \c true if char \a ch is lexically less than string \a s; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator>(QChar ch, QLatin1StringView s) + Returns \c true if char \a ch is lexically greater than string \a s; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator!=(QChar ch, QLatin1StringView s) + + Returns \c true if char \a ch is lexically not equal to string \a s; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator<=(QChar ch, QLatin1StringView s) + + Returns \c true if char \a ch is lexically less than or equal to + string \a s; otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator>=(QChar ch, QLatin1StringView s) + + Returns \c true if char \a ch is lexically greater than or equal to + string \a s; otherwise returns \c false. +*/ + +/*! \fn bool QLatin1StringView::operator==(QLatin1StringView s, QChar ch) + + Returns \c true if string \a s is lexically equal to char \a ch; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator<(QLatin1StringView s, QChar ch) + + Returns \c true if string \a s is lexically less than char \a ch; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator>(QLatin1StringView s, QChar ch) + + Returns \c true if string \a s is lexically greater than char \a ch; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator!=(QLatin1StringView s, QChar ch) + + Returns \c true if string \a s is lexically not equal to char \a ch; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator<=(QLatin1StringView s, QChar ch) + + Returns \c true if string \a s is lexically less than or equal to + char \a ch; otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator>=(QLatin1StringView s, QChar ch) + + Returns \c true if string \a s is lexically greater than or equal to + char \a ch; otherwise returns \c false. +*/ + +/*! \fn bool QLatin1StringView::operator==(QStringView s1, QLatin1StringView s2) + + Returns \c true if string view \a s1 is lexically equal to string \a s2; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator<(QStringView s1, QLatin1StringView s2) + + Returns \c true if string view \a s1 is lexically less than string \a s2; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator>(QStringView s1, QLatin1StringView s2) + + Returns \c true if string view \a s1 is lexically greater than string \a s2; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator!=(QStringView s1, QLatin1StringView s2) + + Returns \c true if string view \a s1 is lexically not equal to string \a s2; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator<=(QStringView s1, QLatin1StringView s2) + + Returns \c true if string view \a s1 is lexically less than or equal to + string \a s2; otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator>=(QStringView s1, QLatin1StringView s2) + + Returns \c true if string view \a s1 is lexically greater than or equal to + string \a s2; otherwise returns \c false. +*/ + +/*! \fn bool QLatin1StringView::operator==(QLatin1StringView s1, QStringView s2) + + Returns \c true if string \a s1 is lexically equal to string view \a s2; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator<(QLatin1StringView s1, QStringView s2) + + Returns \c true if string \a s1 is lexically less than string view \a s2; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator>(QLatin1StringView s1, QStringView s2) + + Returns \c true if string \a s1 is lexically greater than string view \a s2; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator!=(QLatin1StringView s1, QStringView s2) + + Returns \c true if string \a s1 is lexically not equal to string view \a s2; + otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator<=(QLatin1StringView s1, QStringView s2) + + Returns \c true if string \a s1 is lexically less than or equal to + string view \a s2; otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator>=(QLatin1StringView s1, QStringView s2) + + Returns \c true if string \a s1 is lexically greater than or equal to + string view \a s2; otherwise returns \c false. +*/ + +/*! \fn bool QLatin1StringView::operator==(const char *s1, QLatin1StringView s2) + + Returns \c true if const char pointer \a s1 is lexically equal to + string \a s2; otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator<(const char *s1, QLatin1StringView s2) + + Returns \c true if const char pointer \a s1 is lexically less than + string \a s2; otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator>(const char *s1, QLatin1StringView s2) + + Returns \c true if const char pointer \a s1 is lexically greater than + string \a s2; otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator!=(const char *s1, QLatin1StringView s2) + + Returns \c true if const char pointer \a s1 is lexically not equal to + string \a s2; otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator<=(const char *s1, QLatin1StringView s2) + + Returns \c true if const char pointer \a s1 is lexically less than or + equal to string \a s2; otherwise returns \c false. +*/ +/*! \fn bool QLatin1StringView::operator>=(const char *s1, QLatin1StringView s2) + + Returns \c true if const char pointer \a s1 is lexically greater than or + equal to string \a s2; otherwise returns \c false. +*/ + +/*! + \fn qlonglong QLatin1StringView::toLongLong(bool *ok, int base) const + \fn qulonglong QLatin1StringView::toULongLong(bool *ok, int base) const + \fn int QLatin1StringView::toInt(bool *ok, int base) const + \fn uint QLatin1StringView::toUInt(bool *ok, int base) const + \fn long QLatin1StringView::toLong(bool *ok, int base) const + \fn ulong QLatin1StringView::toULong(bool *ok, int base) const + \fn short QLatin1StringView::toShort(bool *ok, int base) const + \fn ushort QLatin1StringView::toUShort(bool *ok, int base) const + + \since 6.4 + + Returns this QLatin1StringView converted to a corresponding numeric value using + base \a base, which is ten by default. Bases 0 and 2 through 36 are supported, + using letters for digits beyond 9; A is ten, B is eleven and so on. + + If \a base is 0, the base is determined automatically using the following + rules (in this order), if the Latin-1 string view begins with: + + \list + \li \c "0x", the rest of it is read as hexadecimal (base 16) + \li \c "0b", the rest of it is read as binary (base 2) + \li \c "0", the rest of it is read as octal (base 8) + \li otherwise it is read as decimal + \endlist + + Returns 0 if the conversion fails. + + If \a ok is not \nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + +//! [latin1-numeric-conversion-note] + \note The conversion of the number is performed in the default C locale, + regardless of the user's locale. Use QLocale to perform locale-aware + conversions between numbers and strings. + + This function ignores leading and trailing spacing characters. +//! [latin1-numeric-conversion-note] + + \note Support for the "0b" prefix was added in Qt 6.4. +*/ + +/*! + \fn double QLatin1StringView::toDouble(bool *ok) const + \fn float QLatin1StringView::toFloat(bool *ok) const + \since 6.4 + + Returns this QLatin1StringView converted to a corresponding floating-point value. + + Returns an infinity if the conversion overflows or 0.0 if the + conversion fails for other reasons (e.g. underflow). + + If \a ok is not \nullptr, failure is reported by setting *\a{ok} + to \c false, and success by setting *\a{ok} to \c true. + + \warning The QLatin1StringView content may only contain valid numerical + characters which includes the plus/minus sign, the character e used in + scientific notation, and the decimal point. Including the unit or additional + characters leads to a conversion error. + + \include qlatin1stringview.qdoc latin1-numeric-conversion-note +*/ + +/*! + \fn Qt::Literals::StringLiterals::operator""_L1(const char *str, size_t size) + + \relates QLatin1StringView + \since 6.4 + + Literal operator that creates a QLatin1StringView out of the first \a size + characters in the char string literal \a str. + + The following code creates a QLatin1StringView: + \code + using namespace Qt::Literals::StringLiterals; + + auto str = "hello"_L1; + \endcode + + \sa Qt::Literals::StringLiterals +*/ diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 7527d34411..5de3043c69 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -9142,1256 +9142,6 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size) \sa toUcs4(), toStdWString(), toStdU16String() */ -/*! \class QLatin1StringView - \inmodule QtCore - \brief The QLatin1StringView class provides a thin wrapper around - a US-ASCII/Latin-1 encoded string literal. - - \ingroup string-processing - \reentrant - - Many of QString's member functions are overloaded to accept - \c{const char *} instead of QString. This includes the copy - constructor, the assignment operator, the comparison operators, - and various other functions such as \l{QString::insert()}{insert()}, - \l{QString::append()}{append()}, and \l{QString::prepend()}{prepend()}. - Some of these functions are optimized to avoid constructing a - QString object for the \c{const char *} data. For example, - assuming \c str is a QString, - - \snippet code/src_corelib_text_qstring.cpp 3 - - is much faster than - - \snippet code/src_corelib_text_qstring.cpp 4 - - because it doesn't construct four temporary QString objects and - make a deep copy of the character data. - - However, that is not true for all QString member functions that take - \c{const char *} and therefore applications should assume a temporary will - be created, such as in - - \snippet code/src_corelib_text_qstring.cpp 4bis - - Applications that define \l QT_NO_CAST_FROM_ASCII (as explained - in the QString documentation) don't have access to QString's - \c{const char *} API. To provide an efficient way of specifying - constant Latin-1 strings, Qt provides the QLatin1StringView, which is - just a very thin wrapper around a \c{const char *}. Using - QLatin1StringView, the example code above becomes - - \snippet code/src_corelib_text_qstring.cpp 5 - - This is a bit longer to type, but it provides exactly the same - benefits as the first version of the code, and is faster than - converting the Latin-1 strings using QString::fromLatin1(). - - Thanks to the QString(QLatin1StringView) constructor, - QLatin1StringView can be used everywhere a QString is expected. For - example: - - \snippet code/src_corelib_text_qstring.cpp 6 - - \note If the function you're calling with a QLatin1StringView - argument isn't actually overloaded to take QLatin1StringView, the - implicit conversion to QString will trigger a memory allocation, - which is usually what you want to avoid by using QLatin1StringView - in the first place. In those cases, using QStringLiteral may be - the better option. - - \sa QString, QLatin1Char, {QStringLiteral()}{QStringLiteral}, - QT_NO_CAST_FROM_ASCII -*/ - -/*! - \class QLatin1String - \inmodule QtCore - \brief QLatin1String is the same as QLatin1StringView. - - QLatin1String is a view to a Latin-1 string. It's the same as - QLatin1StringView and is kept for compatibility reasons. It is - recommended to use QLatin1StringView instead. - - Please see the QLatin1StringView documentation for details. -*/ - -/*! - \typedef QLatin1StringView::value_type - \since 5.10 - - Alias for \c{const char}. Provided for compatibility with the STL. -*/ - -/*! - \typedef QLatin1StringView::difference_type - \since 5.10 - - Alias for \c{qsizetype}. Provided for compatibility with the STL. -*/ - -/*! - \typedef QLatin1StringView::size_type - \since 5.10 - - Alias for \c{qsizetype}. Provided for compatibility with the STL. - - \note In version prior to Qt 6, this was an alias for \c{int}, - restricting the amount of data that could be held in a QLatin1StringView - on 64-bit architectures. -*/ - -/*! - \typedef QLatin1StringView::reference - \since 5.10 - - Alias for \c{value_type &}. Provided for compatibility with the STL. -*/ - -/*! - \typedef QLatin1StringView::const_reference - \since 5.11 - - Alias for \c{reference}. Provided for compatibility with the STL. -*/ - -/*! - \typedef QLatin1StringView::iterator - \since 5.10 - - QLatin1StringView does not support mutable iterators, so this is the same - as const_iterator. - - \sa const_iterator, reverse_iterator -*/ - -/*! - \typedef QLatin1StringView::const_iterator - \since 5.10 - - \sa iterator, const_reverse_iterator -*/ - -/*! - \typedef QLatin1StringView::reverse_iterator - \since 5.10 - - QLatin1StringView does not support mutable reverse iterators, so this is the - same as const_reverse_iterator. - - \sa const_reverse_iterator, iterator -*/ - -/*! - \typedef QLatin1StringView::const_reverse_iterator - \since 5.10 - - \sa reverse_iterator, const_iterator -*/ - -/*! \fn QLatin1StringView::QLatin1StringView() - \since 5.6 - - Constructs a QLatin1StringView object that stores a \nullptr. - - \sa data(), isEmpty(), isNull(), {Distinction Between Null and Empty Strings} -*/ - -/*! \fn QLatin1StringView::QLatin1StringView(std::nullptr_t) - \since 6.4 - - Constructs a QLatin1StringView object that stores a \nullptr. - - \sa data(), isEmpty(), isNull(), {Distinction Between Null and Empty Strings} -*/ - -/*! \fn QLatin1StringView::QLatin1StringView(const char *str) - - Constructs a QLatin1StringView object that stores \a str. - - The string data is \e not copied. The caller must be able to - guarantee that \a str will not be deleted or modified as long as - the QLatin1StringView object exists. - - \sa latin1() -*/ - -/*! \fn QLatin1StringView::QLatin1StringView(const char *str, qsizetype size) - - Constructs a QLatin1StringView object that stores \a str with \a size. - - The string data is \e not copied. The caller must be able to - guarantee that \a str will not be deleted or modified as long as - the QLatin1StringView object exists. - - \note: any null ('\\0') bytes in the byte array will be included in this - string, which will be converted to Unicode null characters (U+0000) if this - string is used by QString. This behavior is different from Qt 5.x. - - \sa latin1() -*/ - -/*! - \fn QLatin1StringView::QLatin1StringView(const char *first, const char *last) - \since 5.10 - - Constructs a QLatin1StringView object that stores \a first with length - (\a last - \a first). - - The range \c{[first,last)} must remain valid for the lifetime of - this Latin-1 string object. - - Passing \nullptr as \a first is safe if \a last is \nullptr, - too, and results in a null Latin-1 string. - - The behavior is undefined if \a last precedes \a first, \a first - is \nullptr and \a last is not, or if \c{last - first > - INT_MAX}. -*/ - -/*! \fn QLatin1StringView::QLatin1StringView(const QByteArray &str) - - Constructs a QLatin1StringView object as a view on \a str. - - The string data is \e not copied. The caller must be able to - guarantee that \a str will not be deleted or modified as long as - the QLatin1StringView object exists. - - \sa latin1() -*/ - -/*! \fn QLatin1StringView::QLatin1StringView(QByteArrayView str) - \since 6.3 - - Constructs a QLatin1StringView object as a view on \a str. - - The string data is \e not copied. The caller must be able to - guarantee that the data which \a str is pointing to will not - be deleted or modified as long as the QLatin1StringView object - exists. The size is obtained from \a str as-is, without checking - for a null-terminator. - - \note: any null ('\\0') bytes in the byte array will be included in this - string, which will be converted to Unicode null characters (U+0000) if this - string is used by QString. - - \sa latin1() -*/ - -/*! - \fn QString QLatin1StringView::toString() const - \since 6.0 - - Converts this Latin-1 string into a QString. Equivalent to - \code - return QString(*this); - \endcode -*/ - -/*! \fn const char *QLatin1StringView::latin1() const - - Returns the start of the Latin-1 string referenced by this object. -*/ - -/*! \fn const char *QLatin1StringView::data() const - - Returns the start of the Latin-1 string referenced by this object. -*/ - -/*! \fn const char *QLatin1StringView::constData() const - \since 6.4 - - Returns the start of the Latin-1 string referenced by this object. - - This function is provided for compatibility with other Qt containers. - - \sa data() -*/ - -/*! \fn qsizetype QLatin1StringView::size() const - - Returns the size of the Latin-1 string referenced by this object. - - \note In version prior to Qt 6, this function returned \c{int}, - restricting the amount of data that could be held in a QLatin1StringView - on 64-bit architectures. -*/ - -/*! \fn qsizetype QLatin1StringView::length() const - \since 6.4 - - Same as size(). - - This function is provided for compatibility with other Qt containers. -*/ - -/*! \fn bool QLatin1StringView::isNull() const - \since 5.10 - - Returns whether the Latin-1 string referenced by this object is null - (\c{data() == nullptr}) or not. - - \sa isEmpty(), data() -*/ - -/*! \fn bool QLatin1StringView::isEmpty() const - \since 5.10 - - Returns whether the Latin-1 string referenced by this object is empty - (\c{size() == 0}) or not. - - \sa isNull(), size() -*/ - -/*! \fn bool QLatin1StringView::empty() const - \since 6.4 - - Returns whether the Latin-1 string referenced by this object is empty - (\c{size() == 0}) or not. - - This function is provided for STL compatibility. - - \sa isEmpty(), isNull(), size() -*/ - -/*! \fn QLatin1Char QLatin1StringView::at(qsizetype pos) const - \since 5.8 - - Returns the character at position \a pos in this object. - - \note This function performs no error checking. - The behavior is undefined when \a pos < 0 or \a pos >= size(). - - \sa operator[]() -*/ - -/*! \fn QLatin1Char QLatin1StringView::operator[](qsizetype pos) const - \since 5.8 - - Returns the character at position \a pos in this object. - - \note This function performs no error checking. - The behavior is undefined when \a pos < 0 or \a pos >= size(). - - \sa at() -*/ - -/*! - \fn QLatin1Char QLatin1StringView::front() const - \since 5.10 - - Returns the first character in the string. - Same as \c{at(0)}. - - This function is provided for STL compatibility. - - \warning Calling this function on an empty string constitutes - undefined behavior. - - \sa back(), at(), operator[]() -*/ - -/*! - \fn QLatin1Char QLatin1StringView::first() const - \since 6.4 - - Returns the first character in the string. - Same as \c{at(0)} or front(). - - This function is provided for compatibility with other Qt containers. - - \warning Calling this function on an empty string constitutes - undefined behavior. - - \sa last(), front(), back() -*/ - -/*! - \fn QLatin1Char QLatin1StringView::back() const - \since 5.10 - - Returns the last character in the string. - Same as \c{at(size() - 1)}. - - This function is provided for STL compatibility. - - \warning Calling this function on an empty string constitutes - undefined behavior. - - \sa front(), at(), operator[]() -*/ - -/*! - \fn QLatin1Char QLatin1StringView::last() const - \since 6.4 - - Returns the last character in the string. - Same as \c{at(size() - 1)} or back(). - - This function is provided for compatibility with other Qt containers. - - \warning Calling this function on an empty string constitutes - undefined behavior. - - \sa first(), back(), front() -*/ - -/*! - \fn int QLatin1StringView::compare(QStringView str, Qt::CaseSensitivity cs) const - \fn int QLatin1StringView::compare(QLatin1StringView l1, Qt::CaseSensitivity cs) const - \fn int QLatin1StringView::compare(QChar ch) const - \fn int QLatin1StringView::compare(QChar ch, Qt::CaseSensitivity cs) const - \since 5.14 - - Returns an integer that compares to zero as this string view compares - to the UTF-16 string viewed by \a str, the Latin-1 string viewed by \a l1, - or the character \a ch, respectively. - - \include qstring.qdocinc {search-comparison-case-sensitivity} {search} - - \sa operator==(), operator<(), operator>() -*/ - - -/*! - \fn bool QLatin1StringView::startsWith(QStringView str, Qt::CaseSensitivity cs) const - \since 5.10 - \fn bool QLatin1StringView::startsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const - \since 5.10 - \fn bool QLatin1StringView::startsWith(QChar ch) const - \since 5.10 - \fn bool QLatin1StringView::startsWith(QChar ch, Qt::CaseSensitivity cs) const - \since 5.10 - - Returns \c true if this Latin-1 string view starts with the UTF-16 - string viewed by \a str, the Latin-1 string viewed by \a l1, or the - character \a ch, respectively; otherwise returns \c false. - - \include qstring.qdocinc {search-comparison-case-sensitivity} {search} - - \sa endsWith() -*/ - -/*! - \fn bool QLatin1StringView::endsWith(QStringView str, Qt::CaseSensitivity cs) const - \since 5.10 - \fn bool QLatin1StringView::endsWith(QLatin1StringView l1, Qt::CaseSensitivity cs) const - \since 5.10 - \fn bool QLatin1StringView::endsWith(QChar ch) const - \since 5.10 - \fn bool QLatin1StringView::endsWith(QChar ch, Qt::CaseSensitivity cs) const - \since 5.10 - - Returns \c true if this Latin-1 string view ends with the UTF-16 string - viewed \a str, the Latin-1 string viewed by \a l1, or the character \a ch, - respectively; otherwise returns \c false. - - \include qstring.qdocinc {search-comparison-case-sensitivity} {search} - - \sa startsWith() -*/ - -/*! - \fn qsizetype QLatin1StringView::indexOf(QStringView str, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \fn qsizetype QLatin1StringView::indexOf(QLatin1StringView l1, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \fn qsizetype QLatin1StringView::indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \since 5.14 - - Returns the index position in this Latin-1 string view of the first - occurrence of the UTF-16 string viewed by \a str, the Latin-1 string - viewed by \a l1, or the character \a ch, respectively, searching forward - from index position \a from. Returns -1 if \a str, \a l1 or \a c is not - found, respectively. - - \include qstring.qdocinc {search-comparison-case-sensitivity} {search} - - \include qstring.qdocinc negative-index-start-search-from-end - - \sa QString::indexOf() -*/ - -/*! - \fn bool QLatin1StringView::contains(QStringView str, Qt::CaseSensitivity cs) const - \fn bool QLatin1StringView::contains(QLatin1StringView l1, Qt::CaseSensitivity cs) const - \fn bool QLatin1StringView::contains(QChar c, Qt::CaseSensitivity cs) const - \since 5.14 - - Returns \c true if this Latin-1 string view contains an occurrence of the - UTF-16 string viewed by \a str, the Latin-1 string viewed by \a l1, or the - character \a ch, respectively; otherwise returns \c false. - - \include qstring.qdocinc {search-comparison-case-sensitivity} {search} - - \sa indexOf(), QStringView::contains(), QStringView::indexOf(), - QString::indexOf() -*/ - -/*! - \fn qsizetype QLatin1StringView::lastIndexOf(QStringView str, qsizetype from, Qt::CaseSensitivity cs) const - \fn qsizetype QLatin1StringView::lastIndexOf(QLatin1StringView l1, qsizetype from, Qt::CaseSensitivity cs) const - \fn qsizetype QLatin1StringView::lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const - \since 5.14 - - Returns the index position in this Latin-1 string view of the last - occurrence of the UTF-16 string viewed by \a str, the Latin-1 string - viewed by \a l1, or the character \a ch, respectively, searching backward - from index position \a from; returns -1 if \a str, \a l1 or \a ch is not - found, respectively. - - \include qstring.qdocinc negative-index-start-search-from-end - - \include qstring.qdocinc {search-comparison-case-sensitivity} {search} - - \note When searching for a 0-length \a str or \a l1, the match at - the end of the data is excluded from the search by a negative \a - from, even though \c{-1} is normally thought of as searching from - the end of the string: the match at the end is \e after the last - character, so it is excluded. To include such a final empty match, - either give a positive value for \a from or omit the \a from - parameter entirely. - - \sa indexOf(), QStringView::lastIndexOf(), QStringView::indexOf(), - QString::indexOf() -*/ - -/*! - \fn qsizetype QLatin1StringView::lastIndexOf(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \fn qsizetype QLatin1StringView::lastIndexOf(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \since 6.2 - \overload lastIndexOf() - - Returns the index position in this Latin-1 string view of the last - occurrence of the UTF-16 string viewed by \a str or the Latin-1 string - viewed by \a l1, respectively. Returns -1 if \a str or \a l1 is not found, - respectively. - - \include qstring.qdocinc {search-comparison-case-sensitivity} {search} -*/ - -/*! - \fn qsizetype QLatin1StringView::lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const - \since 6.3 - \overload -*/ - -/*! - \fn qsizetype QLatin1StringView::count(QStringView str, Qt::CaseSensitivity cs) const - \fn qsizetype QLatin1StringView::count(QLatin1StringView l1, Qt::CaseSensitivity cs) const - \fn qsizetype QLatin1StringView::count(QChar ch, Qt::CaseSensitivity cs) const - \since 6.4 - - Returns the number of (potentially overlapping) occurrences of the - UTF-16 string viewed by \a str, the Latin-1 string viewed by \a l1, - or the character \a ch, respectively, in this string view. - - \include qstring.qdocinc {search-comparison-case-sensitivity} {search} - - \sa contains(), indexOf() -*/ - -/*! - \fn QLatin1StringView::const_iterator QLatin1StringView::begin() const - \since 5.10 - - Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the - first character in the string. - - This function is provided for STL compatibility. - - \sa end(), cbegin(), rbegin(), data() -*/ - -/*! - \fn QLatin1StringView::const_iterator QLatin1StringView::cbegin() const - \since 5.10 - - Same as begin(). - - This function is provided for STL compatibility. - - \sa cend(), begin(), crbegin(), data() -*/ - -/*! - \fn QLatin1StringView::const_iterator QLatin1StringView::constBegin() const - \since 6.4 - - Same as begin(). - - This function is provided for compatibility with other Qt containers. - - \sa constEnd(), begin(), cbegin(), data() -*/ - -/*! - \fn QLatin1StringView::const_iterator QLatin1StringView::end() const - \since 5.10 - - Returns a const \l{STL-style iterators}{STL-style iterator} pointing just - after the last character in the string. - - This function is provided for STL compatibility. - - \sa begin(), cend(), rend() -*/ - -/*! \fn QLatin1StringView::const_iterator QLatin1StringView::cend() const - \since 5.10 - - Same as end(). - - This function is provided for STL compatibility. - - \sa cbegin(), end(), crend() -*/ - -/*! \fn QLatin1StringView::const_iterator QLatin1StringView::constEnd() const - \since 6.4 - - Same as end(). - - This function is provided for compatibility with other Qt containers. - - \sa constBegin(), end(), cend(), crend() -*/ - -/*! - \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::rbegin() const - \since 5.10 - - Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing - to the first character in the string, in reverse order. - - This function is provided for STL compatibility. - - \sa rend(), crbegin(), begin() -*/ - -/*! - \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::crbegin() const - \since 5.10 - - Same as rbegin(). - - This function is provided for STL compatibility. - - \sa crend(), rbegin(), cbegin() -*/ - -/*! - \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::rend() const - \since 5.10 - - Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing just - after the last character in the string, in reverse order. - - This function is provided for STL compatibility. - - \sa rbegin(), crend(), end() -*/ - -/*! - \fn QLatin1StringView::const_reverse_iterator QLatin1StringView::crend() const - \since 5.10 - - Same as rend(). - - This function is provided for STL compatibility. - - \sa crbegin(), rend(), cend() -*/ - -/*! - \fn QLatin1StringView QLatin1StringView::mid(qsizetype start, qsizetype length) const - \since 5.8 - - Returns the substring of length \a length starting at position - \a start in this Latin-1 string view. - - If you know that \a start and \a length cannot be out of bounds, use - sliced() instead in new code, because it is faster. - - Returns an empty Latin-1 string view if \a start exceeds the length - of this string view. If there are less than \a length characters available - in this string view starting at \a start, or if \a length is negative - (default), the function returns all characters that are available from - \a start. - - \sa first(), last(), sliced(), chopped(), chop(), truncate() -*/ - -/*! - \fn QLatin1StringView QLatin1StringView::left(qsizetype length) const - \since 5.8 - - If you know that \a length cannot be out of bounds, use first() instead in - new code, because it is faster. - - Returns the substring of length \a length starting at position - 0 in this Latin-1 string view. - - The entire Latin-1 string view is returned if \a length is greater - than or equal to size(), or less than zero. - - \sa first(), last(), sliced(), startsWith(), chopped(), chop(), truncate() -*/ - -/*! - \fn QLatin1StringView QLatin1StringView::right(qsizetype length) const - \since 5.8 - - If you know that \a length cannot be out of bounds, use last() instead in - new code, because it is faster. - - Returns the substring of length \a length starting at position - size() - \a length in this Latin-1 string view. - - The entire Latin-1 string view is returned if \a length is greater - than or equal to size(), or less than zero. - - \sa first(), last(), sliced(), endsWith(), chopped(), chop(), truncate() -*/ - -/*! - \fn QLatin1StringView QLatin1StringView::first(qsizetype n) const - \since 6.0 - - Returns a Latin-1 string view that contains the first \a n characters - of this string view. - - \note The behavior is undefined when \a n < 0 or \a n > size(). - - \sa last(), startsWith(), chopped(), chop(), truncate() -*/ - -/*! - \fn QLatin1StringView QLatin1StringView::last(qsizetype n) const - \since 6.0 - - Returns a Latin-1 string view that contains the last \a n characters - of this string view. - - \note The behavior is undefined when \a n < 0 or \a n > size(). - - \sa first(), endsWith(), chopped(), chop(), truncate() -*/ - -/*! - \fn QLatin1StringView QLatin1StringView::sliced(qsizetype pos, qsizetype n) const - \since 6.0 - - Returns a Latin-1 string view that points to \a n characters of this - string view, starting at position \a pos. - - \note The behavior is undefined when \a pos < 0, \a n < 0, - or \c{pos + n > size()}. - - \sa first(), last(), chopped(), chop(), truncate() -*/ - -/*! - \fn QLatin1StringView QLatin1StringView::sliced(qsizetype pos) const - \since 6.0 - - Returns a Latin-1 string view starting at position \a pos in this - string view, and extending to its end. - - \note The behavior is undefined when \a pos < 0 or \a pos > size(). - - \sa first(), last(), chopped(), chop(), truncate() -*/ - -/*! - \fn QLatin1StringView QLatin1StringView::chopped(qsizetype length) const - \since 5.10 - - Returns the substring of length size() - \a length starting at the - beginning of this object. - - Same as \c{left(size() - length)}. - - \note The behavior is undefined when \a length < 0 or \a length > size(). - - \sa sliced(), first(), last(), chop(), truncate() -*/ - -/*! - \fn void QLatin1StringView::truncate(qsizetype length) - \since 5.10 - - Truncates this string to length \a length. - - Same as \c{*this = left(length)}. - - \note The behavior is undefined when \a length < 0 or \a length > size(). - - \sa sliced(), first(), last(), chopped(), chop() -*/ - -/*! - \fn void QLatin1StringView::chop(qsizetype length) - \since 5.10 - - Truncates this string by \a length characters. - - Same as \c{*this = left(size() - length)}. - - \note The behavior is undefined when \a length < 0 or \a length > size(). - - \sa sliced(), first(), last(), chopped(), truncate() -*/ - -/*! - \fn QLatin1StringView QLatin1StringView::trimmed() const - \since 5.10 - - Strips leading and trailing whitespace and returns the result. - - Whitespace means any character for which QChar::isSpace() returns - \c true. This includes the ASCII characters '\\t', '\\n', '\\v', - '\\f', '\\r', and ' '. -*/ - -/*! - \fn bool QLatin1StringView::operator==(const char *other) const - \since 4.3 - - Returns \c true if the string is equal to const char pointer \a other; - otherwise returns \c false. - - The \a other const char pointer is converted to a QString using - the QString::fromUtf8() function. - - You can disable this operator by defining - \l QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. - - \sa {Comparing Strings} -*/ - -/*! - \fn bool QLatin1StringView::operator==(const QByteArray &other) const - \since 5.0 - \overload - - The \a other byte array is converted to a QString using - the QString::fromUtf8() function. - - You can disable this operator by defining - \l QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. -*/ - -/*! - \fn bool QLatin1StringView::operator!=(const char *other) const - \since 4.3 - - Returns \c true if this string is not equal to const char pointer \a other; - otherwise returns \c false. - - The \a other const char pointer is converted to a QString using - the QString::fromUtf8() function. - - You can disable this operator by defining - \l QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. - - \sa {Comparing Strings} -*/ - -/*! - \fn bool QLatin1StringView::operator!=(const QByteArray &other) const - \since 5.0 - \overload operator!=() - - The \a other byte array is converted to a QString using - the QString::fromUtf8() function. - - You can disable this operator by defining - \l QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. -*/ - -/*! - \fn bool QLatin1StringView::operator>(const char *other) const - \since 4.3 - - Returns \c true if this string is lexically greater than const char pointer - \a other; otherwise returns \c false. - - The \a other const char pointer is converted to a QString using - the QString::fromUtf8() function. - - You can disable this operator by defining \l QT_NO_CAST_FROM_ASCII - when you compile your applications. This can be useful if you want - to ensure that all user-visible strings go through QObject::tr(), - for example. - - \sa {Comparing Strings} -*/ - -/*! - \fn bool QLatin1StringView::operator>(const QByteArray &other) const - \since 5.0 - \overload - - The \a other byte array is converted to a QString using - the QString::fromUtf8() function. - - You can disable this operator by defining \l QT_NO_CAST_FROM_ASCII - when you compile your applications. This can be useful if you want - to ensure that all user-visible strings go through QObject::tr(), - for example. -*/ - -/*! - \fn bool QLatin1StringView::operator<(const char *other) const - \since 4.3 - - Returns \c true if this string is lexically less than const char pointer - \a other; otherwise returns \c false. - - The \a other const char pointer is converted to a QString using - the QString::fromUtf8() function. - - You can disable this operator by defining - \l QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. - - \sa {Comparing Strings} -*/ - -/*! - \fn bool QLatin1StringView::operator<(const QByteArray &other) const - \since 5.0 - \overload - - The \a other byte array is converted to a QString using - the QString::fromUtf8() function. - - You can disable this operator by defining - \l QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. -*/ - -/*! - \fn bool QLatin1StringView::operator>=(const char *other) const - \since 4.3 - - Returns \c true if this string is lexically greater than or equal to - const char pointer \a other; otherwise returns \c false. - - The \a other const char pointer is converted to a QString using - the QString::fromUtf8() function. - - You can disable this operator by defining - \l QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. - - \sa {Comparing Strings} -*/ - -/*! - \fn bool QLatin1StringView::operator>=(const QByteArray &other) const - \since 5.0 - \overload - - The \a other byte array is converted to a QString using - the QString::fromUtf8() function. - - You can disable this operator by defining - \l QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. -*/ - -/*! - \fn bool QLatin1StringView::operator<=(const char *other) const - \since 4.3 - - Returns \c true if this string is lexically less than or equal to - const char pointer \a other; otherwise returns \c false. - - The \a other const char pointer is converted to a QString using - the QString::fromUtf8() function. - - You can disable this operator by defining - \l QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. - - \sa {Comparing Strings} -*/ - -/*! - \fn bool QLatin1StringView::operator<=(const QByteArray &other) const - \since 5.0 - \overload - - The \a other byte array is converted to a QString using - the QString::fromUtf8() function. - - You can disable this operator by defining - \l QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. -*/ - -/*! \fn bool QLatin1StringView::operator==(QLatin1StringView s1, QLatin1StringView s2) - - Returns \c true if string \a s1 is lexically equal to string \a s2; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator!=(QLatin1StringView s1, QLatin1StringView s2) - - Returns \c true if string \a s1 is lexically not equal to string \a s2; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator<(QLatin1StringView s1, QLatin1StringView s2) - - Returns \c true if string \a s1 is lexically less than string \a s2; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator<=(QLatin1StringView s1, QLatin1StringView s2) - - Returns \c true if string \a s1 is lexically less than or equal to - string \a s2; otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator>(QLatin1StringView s1, QLatin1StringView s2) - - Returns \c true if string \a s1 is lexically greater than string \a s2; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator>=(QLatin1StringView s1, QLatin1StringView s2) - - Returns \c true if string \a s1 is lexically greater than or equal - to string \a s2; otherwise returns \c false. -*/ - -/*! \fn bool QLatin1StringView::operator==(QChar ch, QLatin1StringView s) - - Returns \c true if char \a ch is lexically equal to string \a s; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator<(QChar ch, QLatin1StringView s) - - Returns \c true if char \a ch is lexically less than string \a s; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator>(QChar ch, QLatin1StringView s) - Returns \c true if char \a ch is lexically greater than string \a s; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator!=(QChar ch, QLatin1StringView s) - - Returns \c true if char \a ch is lexically not equal to string \a s; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator<=(QChar ch, QLatin1StringView s) - - Returns \c true if char \a ch is lexically less than or equal to - string \a s; otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator>=(QChar ch, QLatin1StringView s) - - Returns \c true if char \a ch is lexically greater than or equal to - string \a s; otherwise returns \c false. -*/ - -/*! \fn bool QLatin1StringView::operator==(QLatin1StringView s, QChar ch) - - Returns \c true if string \a s is lexically equal to char \a ch; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator<(QLatin1StringView s, QChar ch) - - Returns \c true if string \a s is lexically less than char \a ch; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator>(QLatin1StringView s, QChar ch) - - Returns \c true if string \a s is lexically greater than char \a ch; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator!=(QLatin1StringView s, QChar ch) - - Returns \c true if string \a s is lexically not equal to char \a ch; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator<=(QLatin1StringView s, QChar ch) - - Returns \c true if string \a s is lexically less than or equal to - char \a ch; otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator>=(QLatin1StringView s, QChar ch) - - Returns \c true if string \a s is lexically greater than or equal to - char \a ch; otherwise returns \c false. -*/ - -/*! \fn bool QLatin1StringView::operator==(QStringView s1, QLatin1StringView s2) - - Returns \c true if string view \a s1 is lexically equal to string \a s2; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator<(QStringView s1, QLatin1StringView s2) - - Returns \c true if string view \a s1 is lexically less than string \a s2; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator>(QStringView s1, QLatin1StringView s2) - - Returns \c true if string view \a s1 is lexically greater than string \a s2; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator!=(QStringView s1, QLatin1StringView s2) - - Returns \c true if string view \a s1 is lexically not equal to string \a s2; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator<=(QStringView s1, QLatin1StringView s2) - - Returns \c true if string view \a s1 is lexically less than or equal to - string \a s2; otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator>=(QStringView s1, QLatin1StringView s2) - - Returns \c true if string view \a s1 is lexically greater than or equal to - string \a s2; otherwise returns \c false. -*/ - -/*! \fn bool QLatin1StringView::operator==(QLatin1StringView s1, QStringView s2) - - Returns \c true if string \a s1 is lexically equal to string view \a s2; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator<(QLatin1StringView s1, QStringView s2) - - Returns \c true if string \a s1 is lexically less than string view \a s2; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator>(QLatin1StringView s1, QStringView s2) - - Returns \c true if string \a s1 is lexically greater than string view \a s2; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator!=(QLatin1StringView s1, QStringView s2) - - Returns \c true if string \a s1 is lexically not equal to string view \a s2; - otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator<=(QLatin1StringView s1, QStringView s2) - - Returns \c true if string \a s1 is lexically less than or equal to - string view \a s2; otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator>=(QLatin1StringView s1, QStringView s2) - - Returns \c true if string \a s1 is lexically greater than or equal to - string view \a s2; otherwise returns \c false. -*/ - -/*! \fn bool QLatin1StringView::operator==(const char *s1, QLatin1StringView s2) - - Returns \c true if const char pointer \a s1 is lexically equal to - string \a s2; otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator<(const char *s1, QLatin1StringView s2) - - Returns \c true if const char pointer \a s1 is lexically less than - string \a s2; otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator>(const char *s1, QLatin1StringView s2) - - Returns \c true if const char pointer \a s1 is lexically greater than - string \a s2; otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator!=(const char *s1, QLatin1StringView s2) - - Returns \c true if const char pointer \a s1 is lexically not equal to - string \a s2; otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator<=(const char *s1, QLatin1StringView s2) - - Returns \c true if const char pointer \a s1 is lexically less than or - equal to string \a s2; otherwise returns \c false. -*/ -/*! \fn bool QLatin1StringView::operator>=(const char *s1, QLatin1StringView s2) - - Returns \c true if const char pointer \a s1 is lexically greater than or - equal to string \a s2; otherwise returns \c false. -*/ - -/*! - \fn qlonglong QLatin1StringView::toLongLong(bool *ok, int base) const - \fn qulonglong QLatin1StringView::toULongLong(bool *ok, int base) const - \fn int QLatin1StringView::toInt(bool *ok, int base) const - \fn uint QLatin1StringView::toUInt(bool *ok, int base) const - \fn long QLatin1StringView::toLong(bool *ok, int base) const - \fn ulong QLatin1StringView::toULong(bool *ok, int base) const - \fn short QLatin1StringView::toShort(bool *ok, int base) const - \fn ushort QLatin1StringView::toUShort(bool *ok, int base) const - - \since 6.4 - - Returns this QLatin1StringView converted to a corresponding numeric value using - base \a base, which is ten by default. Bases 0 and 2 through 36 are supported, - using letters for digits beyond 9; A is ten, B is eleven and so on. - - If \a base is 0, the base is determined automatically using the following - rules (in this order), if the Latin-1 string view begins with: - - \list - \li \c "0x", the rest of it is read as hexadecimal (base 16) - \li \c "0b", the rest of it is read as binary (base 2) - \li \c "0", the rest of it is read as octal (base 8) - \li otherwise it is read as decimal - \endlist - - Returns 0 if the conversion fails. - - If \a ok is not \nullptr, failure is reported by setting *\a{ok} - to \c false, and success by setting *\a{ok} to \c true. - -//! [latin1-numeric-conversion-note] - \note The conversion of the number is performed in the default C locale, - regardless of the user's locale. Use QLocale to perform locale-aware - conversions between numbers and strings. - - This function ignores leading and trailing spacing characters. -//! [latin1-numeric-conversion-note] - - \note Support for the "0b" prefix was added in Qt 6.4. -*/ - -/*! - \fn double QLatin1StringView::toDouble(bool *ok) const - \fn float QLatin1StringView::toFloat(bool *ok) const - \since 6.4 - - Returns this QLatin1StringView converted to a corresponding floating-point value. - - Returns an infinity if the conversion overflows or 0.0 if the - conversion fails for other reasons (e.g. underflow). - - If \a ok is not \nullptr, failure is reported by setting *\a{ok} - to \c false, and success by setting *\a{ok} to \c true. - - \warning The QLatin1StringView content may only contain valid numerical - characters which includes the plus/minus sign, the character e used in - scientific notation, and the decimal point. Including the unit or additional - characters leads to a conversion error. - - \include qstring.cpp latin1-numeric-conversion-note -*/ - #if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED) /*! \fn QDataStream &operator<<(QDataStream &stream, const QString &string) @@ -11120,25 +9870,6 @@ QString QString::toHtmlEscaped() const \sa Qt::Literals::StringLiterals */ -/*! - \fn Qt::Literals::StringLiterals::operator""_L1(const char *str, size_t size) - - \relates QLatin1StringView - \since 6.4 - - Literal operator that creates a QLatin1StringView out of the first \a size - characters in the char string literal \a str. - - The following code creates a QLatin1StringView: - \code - using namespace Qt::Literals::StringLiterals; - - auto str = "hello"_L1; - \endcode - - \sa Qt::Literals::StringLiterals -*/ - /*! \internal */ diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index d6bbbee26b..bde7041eef 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -35,12 +36,6 @@ Q_FORWARD_DECLARE_CF_TYPE(CFString); Q_FORWARD_DECLARE_OBJC_CLASS(NSString); #endif -#if 0 -// Workaround for generating forward headers -#pragma qt_class(QLatin1String) -#pragma qt_class(QLatin1StringView) -#endif - QT_BEGIN_NAMESPACE class QRegularExpression; @@ -51,333 +46,6 @@ namespace QtPrivate { template class BoolList; } -#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED) || defined(Q_QDOC) -# define Q_L1S_VIEW_IS_PRIMARY -class QLatin1StringView -#else -class QLatin1String -#endif -{ -public: -#ifdef Q_L1S_VIEW_IS_PRIMARY - constexpr inline QLatin1StringView() noexcept {} - constexpr QLatin1StringView(std::nullptr_t) noexcept : QLatin1StringView() {} - constexpr inline explicit QLatin1StringView(const char *s) noexcept - : QLatin1StringView(s, s ? qsizetype(QtPrivate::lengthHelperPointer(s)) : 0) {} - constexpr QLatin1StringView(const char *f, const char *l) - : QLatin1StringView(f, qsizetype(l - f)) {} - constexpr inline QLatin1StringView(const char *s, qsizetype sz) noexcept : m_data(s), m_size(sz) {} - explicit QLatin1StringView(const QByteArray &s) noexcept - : QLatin1StringView(s.constData(), s.size()) {} - constexpr explicit QLatin1StringView(QByteArrayView s) noexcept - : QLatin1StringView(s.constData(), s.size()) {} -#else - constexpr inline QLatin1String() noexcept : m_size(0), m_data(nullptr) {} - Q_WEAK_OVERLOAD - constexpr QLatin1String(std::nullptr_t) noexcept : QLatin1String() {} - constexpr inline explicit QLatin1String(const char *s) noexcept - : m_size(s ? qsizetype(QtPrivate::lengthHelperPointer(s)) : 0), m_data(s) {} - constexpr QLatin1String(const char *f, const char *l) - : QLatin1String(f, qsizetype(l - f)) {} - constexpr inline QLatin1String(const char *s, qsizetype sz) noexcept : m_size(sz), m_data(s) {} - explicit QLatin1String(const QByteArray &s) noexcept : m_size(s.size()), m_data(s.constData()) {} - constexpr explicit QLatin1String(QByteArrayView s) noexcept : m_size(s.size()), m_data(s.data()) {} -#endif // !Q_L1S_VIEW_IS_PRIMARY - - inline QString toString() const; - - constexpr const char *latin1() const noexcept { return m_data; } - constexpr qsizetype size() const noexcept { return m_size; } - constexpr const char *data() const noexcept { return m_data; } - [[nodiscard]] constexpr const char *constData() const noexcept { return data(); } - [[nodiscard]] constexpr const char *constBegin() const noexcept { return begin(); } - [[nodiscard]] constexpr const char *constEnd() const noexcept { return end(); } - - [[nodiscard]] constexpr QLatin1Char first() const { return front(); } - [[nodiscard]] constexpr QLatin1Char last() const { return back(); } - - [[nodiscard]] constexpr qsizetype length() const noexcept { return size(); } - - constexpr bool isNull() const noexcept { return !data(); } - constexpr bool isEmpty() const noexcept { return !size(); } - - [[nodiscard]] constexpr bool empty() const noexcept { return size() == 0; } - - template - [[nodiscard]] inline QString arg(Args &&...args) const; - - [[nodiscard]] constexpr QLatin1Char at(qsizetype i) const - { return Q_ASSERT(i >= 0), Q_ASSERT(i < size()), QLatin1Char(m_data[i]); } - [[nodiscard]] constexpr QLatin1Char operator[](qsizetype i) const { return at(i); } - - [[nodiscard]] constexpr QLatin1Char front() const { return at(0); } - [[nodiscard]] constexpr QLatin1Char back() const { return at(size() - 1); } - - [[nodiscard]] int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::compareStrings(*this, other, cs); } - [[nodiscard]] int compare(QLatin1StringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::compareStrings(*this, other, cs); } - [[nodiscard]] constexpr int compare(QChar c) const noexcept - { return isEmpty() ? -1 : front() == c ? int(size() > 1) : uchar(m_data[0]) - c.unicode(); } - [[nodiscard]] int compare(QChar c, Qt::CaseSensitivity cs) const noexcept - { return QtPrivate::compareStrings(*this, QStringView(&c, 1), cs); } - template - [[nodiscard]] int compare(QBasicUtf8StringView other, - Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { - return QtPrivate::compareStrings(*this, other, cs); - } - - [[nodiscard]] bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::startsWith(*this, s, cs); } - [[nodiscard]] bool startsWith(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::startsWith(*this, s, cs); } - [[nodiscard]] constexpr bool startsWith(QChar c) const noexcept - { return !isEmpty() && front() == c; } - [[nodiscard]] inline bool startsWith(QChar c, Qt::CaseSensitivity cs) const noexcept - { return QtPrivate::startsWith(*this, QStringView(&c, 1), cs); } - - [[nodiscard]] bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::endsWith(*this, s, cs); } - [[nodiscard]] bool endsWith(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::endsWith(*this, s, cs); } - [[nodiscard]] constexpr bool endsWith(QChar c) const noexcept - { return !isEmpty() && back() == c; } - [[nodiscard]] inline bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept - { return QtPrivate::endsWith(*this, QStringView(&c, 1), cs); } - - [[nodiscard]] qsizetype indexOf(QStringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::findString(*this, from, s, cs); } - [[nodiscard]] qsizetype indexOf(QLatin1StringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::findString(*this, from, s, cs); } - [[nodiscard]] qsizetype indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::findString(*this, from, QStringView(&c, 1), cs); } - - [[nodiscard]] bool contains(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return indexOf(s, 0, cs) != -1; } - [[nodiscard]] bool contains(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return indexOf(s, 0, cs) != -1; } - [[nodiscard]] inline bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return indexOf(QStringView(&c, 1), 0, cs) != -1; } - - [[nodiscard]] qsizetype lastIndexOf(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return lastIndexOf(s, size(), cs); } - [[nodiscard]] qsizetype lastIndexOf(QStringView s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::lastIndexOf(*this, from, s, cs); } - [[nodiscard]] qsizetype lastIndexOf(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return lastIndexOf(s, size(), cs); } - [[nodiscard]] qsizetype lastIndexOf(QLatin1StringView s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::lastIndexOf(*this, from, s, cs); } - [[nodiscard]] qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return lastIndexOf(c, -1, cs); } - [[nodiscard]] qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::lastIndexOf(*this, from, QStringView(&c, 1), cs); } - - [[nodiscard]] qsizetype count(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - { return QtPrivate::count(*this, str, cs); } - [[nodiscard]] qsizetype count(QLatin1StringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - { return QtPrivate::count(*this, str, cs); } - [[nodiscard]] qsizetype count(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::count(*this, ch, cs); } - - [[nodiscard]] short toShort(bool *ok = nullptr, int base = 10) const - { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } - [[nodiscard]] ushort toUShort(bool *ok = nullptr, int base = 10) const - { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } - [[nodiscard]] int toInt(bool *ok = nullptr, int base = 10) const - { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } - [[nodiscard]] uint toUInt(bool *ok = nullptr, int base = 10) const - { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } - [[nodiscard]] long toLong(bool *ok = nullptr, int base = 10) const - { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } - [[nodiscard]] ulong toULong(bool *ok = nullptr, int base = 10) const - { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } - [[nodiscard]] qlonglong toLongLong(bool *ok = nullptr, int base = 10) const - { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } - [[nodiscard]] qulonglong toULongLong(bool *ok = nullptr, int base = 10) const - { return QtPrivate::toIntegral(QByteArrayView(*this), ok, base); } - [[nodiscard]] float toFloat(bool *ok = nullptr) const - { - const auto r = QtPrivate::toFloat(*this); - if (ok) - *ok = bool(r); - return r.value_or(0.0f); - } - [[nodiscard]] double toDouble(bool *ok = nullptr) const - { - const auto r = QtPrivate::toDouble(*this); - if (ok) - *ok = bool(r); - return r.value_or(0.0); - } - - using value_type = const char; - using reference = value_type&; - using const_reference = reference; - using iterator = value_type*; - using const_iterator = iterator; - using difference_type = qsizetype; // violates Container concept requirements - using size_type = qsizetype; // violates Container concept requirements - - constexpr const_iterator begin() const noexcept { return data(); } - constexpr const_iterator cbegin() const noexcept { return data(); } - constexpr const_iterator end() const noexcept { return data() + size(); } - constexpr const_iterator cend() const noexcept { return data() + size(); } - - using reverse_iterator = std::reverse_iterator; - using const_reverse_iterator = reverse_iterator; - - const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } - const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } - const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } - const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } - - [[nodiscard]] constexpr QLatin1StringView mid(qsizetype pos, qsizetype n = -1) const - { - using namespace QtPrivate; - auto result = QContainerImplHelper::mid(size(), &pos, &n); - return result == QContainerImplHelper::Null ? QLatin1StringView() - : QLatin1StringView(m_data + pos, n); - } - [[nodiscard]] constexpr QLatin1StringView left(qsizetype n) const - { - if (size_t(n) >= size_t(size())) - n = size(); - return {m_data, n}; - } - [[nodiscard]] constexpr QLatin1StringView right(qsizetype n) const - { - if (size_t(n) >= size_t(size())) - n = size(); - return {m_data + m_size - n, n}; - } - - [[nodiscard]] constexpr QLatin1StringView sliced(qsizetype pos) const - { verify(pos); return {m_data + pos, m_size - pos}; } - [[nodiscard]] constexpr QLatin1StringView sliced(qsizetype pos, qsizetype n) const - { verify(pos, n); return {m_data + pos, n}; } - [[nodiscard]] constexpr QLatin1StringView first(qsizetype n) const - { verify(n); return {m_data, n}; } - [[nodiscard]] constexpr QLatin1StringView last(qsizetype n) const - { verify(n); return {m_data + size() - n, n}; } - [[nodiscard]] constexpr QLatin1StringView chopped(qsizetype n) const - { verify(n); return {m_data, size() - n}; } - - constexpr void chop(qsizetype n) - { verify(n); m_size -= n; } - constexpr void truncate(qsizetype n) - { verify(n); m_size = n; } - - [[nodiscard]] QLatin1StringView trimmed() const noexcept { return QtPrivate::trimmed(*this); } - - template - [[nodiscard]] inline constexpr auto tokenize(Needle &&needle, Flags...flags) const - noexcept(noexcept(qTokenize(std::declval(), - std::forward(needle), flags...))) - -> decltype(qTokenize(*this, std::forward(needle), flags...)) - { return qTokenize(*this, std::forward(needle), flags...); } - - friend inline bool operator==(QLatin1StringView s1, QLatin1StringView s2) noexcept - { return QByteArrayView(s1) == QByteArrayView(s2); } - friend inline bool operator!=(QLatin1StringView s1, QLatin1StringView s2) noexcept - { return !(s1 == s2); } - friend inline bool operator<(QLatin1StringView s1, QLatin1StringView s2) noexcept - { - const qsizetype len = qMin(s1.size(), s2.size()); - const int r = len ? memcmp(s1.latin1(), s2.latin1(), len) : 0; - return r < 0 || (r == 0 && s1.size() < s2.size()); - } - friend inline bool operator>(QLatin1StringView s1, QLatin1StringView s2) noexcept - { return s2 < s1; } - friend inline bool operator<=(QLatin1StringView s1, QLatin1StringView s2) noexcept - { return !(s1 > s2); } - friend inline bool operator>=(QLatin1StringView s1, QLatin1StringView s2) noexcept - { return !(s1 < s2); } - - // QChar <> QLatin1StringView - friend inline bool operator==(QChar lhs, QLatin1StringView rhs) noexcept { return rhs.size() == 1 && lhs == rhs.front(); } - friend inline bool operator< (QChar lhs, QLatin1StringView rhs) noexcept { return compare_helper(&lhs, 1, rhs) < 0; } - friend inline bool operator> (QChar lhs, QLatin1StringView rhs) noexcept { return compare_helper(&lhs, 1, rhs) > 0; } - friend inline bool operator!=(QChar lhs, QLatin1StringView rhs) noexcept { return !(lhs == rhs); } - friend inline bool operator<=(QChar lhs, QLatin1StringView rhs) noexcept { return !(lhs > rhs); } - friend inline bool operator>=(QChar lhs, QLatin1StringView rhs) noexcept { return !(lhs < rhs); } - - friend inline bool operator==(QLatin1StringView lhs, QChar rhs) noexcept { return rhs == lhs; } - friend inline bool operator!=(QLatin1StringView lhs, QChar rhs) noexcept { return !(rhs == lhs); } - friend inline bool operator< (QLatin1StringView lhs, QChar rhs) noexcept { return rhs > lhs; } - friend inline bool operator> (QLatin1StringView lhs, QChar rhs) noexcept { return rhs < lhs; } - friend inline bool operator<=(QLatin1StringView lhs, QChar rhs) noexcept { return !(rhs < lhs); } - friend inline bool operator>=(QLatin1StringView lhs, QChar rhs) noexcept { return !(rhs > lhs); } - - // QStringView <> QLatin1StringView - friend inline bool operator==(QStringView lhs, QLatin1StringView rhs) noexcept - { return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); } - friend inline bool operator!=(QStringView lhs, QLatin1StringView rhs) noexcept { return !(lhs == rhs); } - friend inline bool operator< (QStringView lhs, QLatin1StringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; } - friend inline bool operator<=(QStringView lhs, QLatin1StringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; } - friend inline bool operator> (QStringView lhs, QLatin1StringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; } - friend inline bool operator>=(QStringView lhs, QLatin1StringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; } - - friend inline bool operator==(QLatin1StringView lhs, QStringView rhs) noexcept - { return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); } - friend inline bool operator!=(QLatin1StringView lhs, QStringView rhs) noexcept { return !(lhs == rhs); } - friend inline bool operator< (QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; } - friend inline bool operator<=(QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; } - friend inline bool operator> (QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; } - friend inline bool operator>=(QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; } - - -#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) - QT_ASCII_CAST_WARN inline bool operator==(const char *s) const; - QT_ASCII_CAST_WARN inline bool operator!=(const char *s) const; - QT_ASCII_CAST_WARN inline bool operator<(const char *s) const; - QT_ASCII_CAST_WARN inline bool operator>(const char *s) const; - QT_ASCII_CAST_WARN inline bool operator<=(const char *s) const; - QT_ASCII_CAST_WARN inline bool operator>=(const char *s) const; - - QT_ASCII_CAST_WARN inline bool operator==(const QByteArray &s) const; - QT_ASCII_CAST_WARN inline bool operator!=(const QByteArray &s) const; - QT_ASCII_CAST_WARN inline bool operator<(const QByteArray &s) const; - QT_ASCII_CAST_WARN inline bool operator>(const QByteArray &s) const; - QT_ASCII_CAST_WARN inline bool operator<=(const QByteArray &s) const; - QT_ASCII_CAST_WARN inline bool operator>=(const QByteArray &s) const; - - QT_ASCII_CAST_WARN friend bool operator==(const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) == 0; } - QT_ASCII_CAST_WARN friend bool operator!=(const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) != 0; } - QT_ASCII_CAST_WARN friend bool operator< (const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) > 0; } - QT_ASCII_CAST_WARN friend bool operator> (const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) < 0; } - QT_ASCII_CAST_WARN friend bool operator<=(const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) >= 0; } - QT_ASCII_CAST_WARN friend bool operator>=(const char *s1, QLatin1StringView s2) { return compare_helper(s2, s1) <= 0; } -#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) - -private: -#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) - static inline int compare_helper(const QLatin1StringView &s1, const char *s2); -#endif - Q_ALWAYS_INLINE constexpr void verify(qsizetype pos, qsizetype n = 0) const - { - Q_ASSERT(pos >= 0); - Q_ASSERT(pos <= size()); - Q_ASSERT(n >= 0); - Q_ASSERT(n <= size() - pos); - } - Q_CORE_EXPORT static int compare_helper(const QChar *data1, qsizetype length1, - QLatin1StringView s2, - Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED) - const char *m_data = nullptr; - qsizetype m_size = 0; -#else - qsizetype m_size; - const char *m_data; -#endif -}; -#ifdef Q_L1S_VIEW_IS_PRIMARY -Q_DECLARE_TYPEINFO(QLatin1StringView, Q_RELOCATABLE_TYPE); -#else -Q_DECLARE_TYPEINFO(QLatin1String, Q_RELOCATABLE_TYPE); -#endif - // Qt 4.x compatibility // @@ -406,7 +74,6 @@ qsizetype QStringView::lastIndexOf(QLatin1StringView s, qsizetype from, Qt::Case qsizetype QStringView::count(QLatin1StringView s, Qt::CaseSensitivity cs) const { return QtPrivate::count(*this, s, cs); } - // // QAnyStringView members that require QLatin1StringView // @@ -420,6 +87,7 @@ constexpr QLatin1StringView QAnyStringView::asLatin1StringView() const return {m_data_utf8, size()}; } + template constexpr decltype(auto) QAnyStringView::visit(Visitor &&v) const { @@ -1437,6 +1105,9 @@ inline bool QString::operator<=(const char *s) const inline bool QString::operator>=(const char *s) const { return QString::compare_helper(constData(), size(), s, -1) >= 0; } +// +// QLatin1StringView inline members that require QString: +// QT_ASCII_CAST_WARN inline bool QLatin1StringView::operator==(const char *s) const { return QString::fromUtf8(s) == *this; } QT_ASCII_CAST_WARN inline bool QLatin1StringView::operator!=(const char *s) const @@ -1468,6 +1139,7 @@ inline int QLatin1StringView::compare_helper(const QLatin1StringView &s1, const return QString::compare(s1, QString::fromUtf8(s2)); } + QT_ASCII_CAST_WARN inline bool QString::operator==(const QByteArray &s) const { return QString::compare_helper(constData(), size(), s.constData(), s.size()) == 0; } QT_ASCII_CAST_WARN inline bool QString::operator!=(const QByteArray &s) const @@ -1678,12 +1350,6 @@ qsizetype erase_if(QString &s, Predicate pred) namespace Qt { inline namespace Literals { inline namespace StringLiterals { - -constexpr inline QLatin1StringView operator"" _L1(const char *str, size_t size) noexcept -{ - return {str, qsizetype(size)}; -} - inline QString operator"" _s(const char16_t *str, size_t size) noexcept { return QString(QStringPrivate(nullptr, const_cast(str), qsizetype(size)));