Untangle QLatin1StringView from qstring.{h,cpp}
Searching in qstring.{h,cpp} is slightly easier (it's already too
long).
From the task:
Having similarly-structured header files for all the view classes would
help rebasing the different view classes onto a common template come Qt
7.
Diff best viewed in terminal with git's diff.colorMoved config set to
default.
Task-number: QTBUG-103509
Change-Id: Ie791760bb5bfa23def98d67c206ae8fd00c5f6e6
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
parent
0b92502de2
commit
c630b231ec
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#ifndef QANYSTRINGVIEW_H
|
||||
#define QANYSTRINGVIEW_H
|
||||
|
||||
#include <QtCore/qlatin1stringview.h>
|
||||
#include <QtCore/qstringview.h>
|
||||
#include <QtCore/qutf8stringview.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 <marc.mutz@kdab.com>
|
||||
// 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 <QtCore/qchar.h>
|
||||
#include <QtCore/qnamespace.h>
|
||||
#include <QtCore/qtversionchecks.h>
|
||||
#include <QtCore/qstringview.h>
|
||||
|
||||
#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 <typename...Args>
|
||||
[[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<bool UseChar8T>
|
||||
[[nodiscard]] int compare(QBasicUtf8StringView<UseChar8T> 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<short>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] ushort toUShort(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<ushort>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] int toInt(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<int>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] uint toUInt(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<uint>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] long toLong(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<long>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] ulong toULong(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<ulong>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] qlonglong toLongLong(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<qlonglong>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] qulonglong toULongLong(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<qulonglong>(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<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 <typename Needle, typename...Flags>
|
||||
[[nodiscard]] inline constexpr auto tokenize(Needle &&needle, Flags...flags) const
|
||||
noexcept(noexcept(qTokenize(std::declval<const QLatin1StringView &>(),
|
||||
std::forward<Needle>(needle), flags...)))
|
||||
-> decltype(qTokenize(*this, std::forward<Needle>(needle), flags...))
|
||||
{ return qTokenize(*this, std::forward<Needle>(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
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -15,6 +15,7 @@
|
|||
#include <QtCore/qbytearray.h>
|
||||
#include <QtCore/qbytearrayview.h>
|
||||
#include <QtCore/qarraydata.h>
|
||||
#include <QtCore/qlatin1stringview.h>
|
||||
#include <QtCore/qnamespace.h>
|
||||
#include <QtCore/qstringliteral.h>
|
||||
#include <QtCore/qstringalgorithms.h>
|
||||
|
|
@ -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 <bool...B> 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 <typename...Args>
|
||||
[[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<bool UseChar8T>
|
||||
[[nodiscard]] int compare(QBasicUtf8StringView<UseChar8T> 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<short>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] ushort toUShort(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<ushort>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] int toInt(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<int>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] uint toUInt(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<uint>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] long toLong(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<long>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] ulong toULong(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<ulong>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] qlonglong toLongLong(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<qlonglong>(QByteArrayView(*this), ok, base); }
|
||||
[[nodiscard]] qulonglong toULongLong(bool *ok = nullptr, int base = 10) const
|
||||
{ return QtPrivate::toIntegral<qulonglong>(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<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 <typename Needle, typename...Flags>
|
||||
[[nodiscard]] inline constexpr auto tokenize(Needle &&needle, Flags...flags) const
|
||||
noexcept(noexcept(qTokenize(std::declval<const QLatin1StringView &>(),
|
||||
std::forward<Needle>(needle), flags...)))
|
||||
-> decltype(qTokenize(*this, std::forward<Needle>(needle), flags...))
|
||||
{ return qTokenize(*this, std::forward<Needle>(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 <typename Visitor>
|
||||
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<char16_t *>(str), qsizetype(size)));
|
||||
|
|
|
|||
Loading…
Reference in New Issue