8#ifndef QLATIN1STRINGVIEW_H
9#define QLATIN1STRINGVIEW_H
11#include <QtCore/qchar.h>
12#include <QtCore/qcompare.h>
13#include <QtCore/qcontainerfwd.h>
14#include <QtCore/qnamespace.h>
15#include <QtCore/qtversionchecks.h>
16#include <QtCore/qstringfwd.h>
17#include <QtCore/qstringview.h>
21#pragma qt_class(QLatin1String)
22#pragma qt_class(QLatin1StringView)
29#ifdef Q_L1S_VIEW_IS_PRIMARY
30class QLatin1StringView
36#ifdef Q_L1S_VIEW_IS_PRIMARY
64 constexpr const char *
latin1()
const noexcept {
return m_data; }
66 constexpr const char *
data()
const noexcept {
return m_data; }
77 constexpr bool isEmpty()
const noexcept {
return !size(); }
81 template <
typename...Args>
82 [[nodiscard]]
inline QString
arg(Args &&...args)
const;
88 return QLatin1Char(m_data[i]);
96 {
return QtPrivate::compareStrings(*
this, other, cs); }
98 {
return QtPrivate::compareStrings(*
this, other, cs); }
101 {
return isEmpty() ? -1 : front() == c ?
int(size() > 1) : uchar(m_data[0]) - c.unicode(); }
103 {
return QtPrivate::compareStrings(*
this, QStringView(&c, 1), cs); }
106 {
return QtPrivate::startsWith(*
this, s, cs); }
108 {
return QtPrivate::startsWith(*
this, s, cs); }
110 {
return !isEmpty() && front() == c; }
112 {
return QtPrivate::startsWith(*
this, QStringView(&c, 1), cs); }
115 {
return QtPrivate::endsWith(*
this, s, cs); }
117 {
return QtPrivate::endsWith(*
this, s, cs); }
119 {
return !isEmpty() && back() == c; }
121 {
return QtPrivate::endsWith(*
this, QStringView(&c, 1), cs); }
124 {
return QtPrivate::findString(*
this, from, s, cs); }
126 {
return QtPrivate::findString(*
this, from, s, cs); }
128 {
return QtPrivate::findString(*
this, from, QStringView(&c, 1), cs); }
131 {
return indexOf(s, 0, cs) != -1; }
133 {
return indexOf(s, 0, cs) != -1; }
135 {
return indexOf(c, 0, cs) != -1; }
138 {
return lastIndexOf(s, size(), cs); }
140 {
return QtPrivate::lastIndexOf(*
this, from, s, cs); }
142 {
return lastIndexOf(s, size(), cs); }
144 {
return QtPrivate::lastIndexOf(*
this, from, s, cs); }
146 {
return lastIndexOf(c, -1, cs); }
148 {
return QtPrivate::lastIndexOf(*
this, from, QStringView(&c, 1), cs); }
151 {
return QtPrivate::count(*
this, str, cs); }
153 {
return QtPrivate::count(*
this, str, cs); }
155 {
return QtPrivate::count(*
this, ch, cs); }
158 {
return QtPrivate::toIntegral<
short>(QByteArrayView(*
this), ok, base); }
160 {
return QtPrivate::toIntegral<ushort>(QByteArrayView(*
this), ok, base); }
162 {
return QtPrivate::toIntegral<
int>(QByteArrayView(*
this), ok, base); }
164 {
return QtPrivate::toIntegral<uint>(QByteArrayView(*
this), ok, base); }
166 {
return QtPrivate::toIntegral<
long>(QByteArrayView(*
this), ok, base); }
168 {
return QtPrivate::toIntegral<ulong>(QByteArrayView(*
this), ok, base); }
170 {
return QtPrivate::toIntegral<qlonglong>(QByteArrayView(*
this), ok, base); }
172 {
return QtPrivate::toIntegral<qulonglong>(QByteArrayView(*
this), ok, base); }
175 const auto r = QtPrivate::toFloat(*
this);
178 return r.value_or(0.0f);
182 const auto r = QtPrivate::toDouble(*
this);
185 return r.value_or(0.0);
216 return QtPrivate::MaxAllocSize - 1;
221 using namespace QtPrivate;
222 auto result = QContainerImplHelper::mid(size(), &pos, &n);
223 return result == QContainerImplHelper::Null ? QLatin1StringView()
224 : QLatin1StringView(m_data + pos, n);
228 if (size_t(n) >= size_t(size()))
234 if (size_t(n) >= size_t(size()))
236 return {m_data + m_size - n, n};
240 { verify(pos, 0);
return {m_data + pos, m_size - pos}; }
242 { verify(pos, n);
return {m_data + pos, n}; }
244 { verify(0, n);
return sliced(0, n); }
246 { verify(0, n);
return sliced(size() - n, n); }
248 { verify(0, n);
return sliced(0, size() - n); }
251 { *
this = sliced(pos);
return *
this; }
253 { *
this = sliced(pos, n);
return *
this; }
255 constexpr void chop(qsizetype n)
256 { verify(0, n); m_size -= n; }
258 { verify(0, n); m_size = n; }
262 template <
typename Needle,
typename...Flags>
263 [[nodiscard]]
constexpr auto tokenize(Needle &&needle, Flags...flags)
const
267 {
return qTokenize(*
this, std::forward<Needle>(needle), flags...); }
269 friend bool comparesEqual(
const QLatin1StringView &s1,
const QLatin1StringView &s2)
noexcept
270 {
return s1.size() == s2.size() && QtPrivate::equalStrings(s1, s2); }
274 const int res = QtPrivate::compareStrings(s1, s2);
275 return Qt::compareThreeWay(res, 0);
277 Q_DECLARE_STRONGLY_ORDERED(QLatin1StringView)
332#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
350 Q_CORE_EXPORT
static int compare_helper(
const QLatin1StringView &s1,
const char *s2, qsizetype len)
noexcept;
351 Q_CORE_EXPORT
static int compare_helper(
const QChar *data1, qsizetype length1,
352 QLatin1StringView s2,
353 Qt::CaseSensitivity cs = Qt::CaseSensitive)
noexcept;
354#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
) || defined(QT_BOOTSTRAPPED)
355 const char *
m_data =
nullptr;
364#ifdef Q_L1S_VIEW_IS_PRIMARY
365Q_DECLARE_TYPEINFO(QLatin1StringView, Q_RELOCATABLE_TYPE);
376 return {str, qsizetype(size)};
385#ifdef Q_L1S_VIEW_IS_PRIMARY
386# undef Q_L1S_VIEW_IS_PRIMARY
const_reverse_iterator rend() const noexcept
long toLong(bool *ok=nullptr, int base=10) const
constexpr QLatin1String(const char *s, qsizetype sz) noexcept
constexpr int compare(QChar c) const noexcept
qulonglong toULongLong(bool *ok=nullptr, int base=10) const
constexpr const_iterator cbegin() const noexcept
qsizetype indexOf(QStringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QLatin1StringView mid(qsizetype pos, qsizetype n=-1) const
constexpr bool startsWith(QChar c) const noexcept
constexpr QLatin1StringView & slice(qsizetype pos, qsizetype n)
bool endsWith(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QLatin1Char back() const
constexpr void truncate(qsizetype n)
constexpr QLatin1Char at(qsizetype i) const
constexpr const char * constBegin() const noexcept
constexpr bool isNull() const noexcept
QLatin1StringView trimmed() const noexcept
constexpr QLatin1String() noexcept
constexpr qsizetype size() const noexcept
const_reverse_iterator crbegin() const noexcept
int compare(QStringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
ulong toULong(bool *ok=nullptr, int base=10) const
double toDouble(bool *ok=nullptr) const
ushort toUShort(bool *ok=nullptr, int base=10) const
const_reverse_iterator rbegin() const noexcept
constexpr QLatin1StringView last(qsizetype n) const
constexpr const char * latin1() const noexcept
QLatin1String(const QByteArray &s) noexcept
constexpr const_iterator cend() const noexcept
constexpr QLatin1String(const char *f, const char *l)
QByteArray toUtf8() const
constexpr QLatin1Char operator[](qsizetype i) const
qlonglong toLongLong(bool *ok=nullptr, int base=10) const
constexpr QLatin1String(QByteArrayView s) noexcept
constexpr const char * constData() const noexcept
constexpr QLatin1StringView & slice(qsizetype pos)
short toShort(bool *ok=nullptr, int base=10) const
constexpr QLatin1StringView right(qsizetype n) const
const_reverse_iterator crend() const noexcept
uint toUInt(bool *ok=nullptr, int base=10) const
float toFloat(bool *ok=nullptr) const
qsizetype lastIndexOf(QStringView s, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
static constexpr qsizetype maxSize() noexcept
QString arg(Args &&...args) const
constexpr QLatin1Char last() const
constexpr bool isEmpty() const noexcept
constexpr qsizetype max_size() const noexcept
constexpr QLatin1String(const char *s) noexcept
constexpr QLatin1StringView left(qsizetype n) const
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...))
bool contains(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr void chop(qsizetype n)
constexpr const_iterator begin() const noexcept
constexpr const_iterator end() const noexcept
constexpr QLatin1StringView chopped(qsizetype n) const
constexpr bool endsWith(QChar c) const noexcept
constexpr QLatin1StringView first(qsizetype n) const
constexpr const char * data() const noexcept
constexpr QLatin1StringView sliced(qsizetype pos, qsizetype n) const
constexpr QLatin1StringView sliced(qsizetype pos) const
int toInt(bool *ok=nullptr, int base=10) const
constexpr qsizetype length() const noexcept
bool startsWith(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr bool empty() const noexcept
reference const_reference
constexpr const char * constEnd() const noexcept
constexpr QLatin1Char front() const
qsizetype count(QStringView str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
qsizetype lastIndexOf(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QLatin1Char first() const
constexpr QLatin1StringView operator""_L1(const char *str, size_t size) noexcept
bool comparesEqual(const QFileInfo &lhs, const QFileInfo &rhs)
Q_DECLARE_TYPEINFO(QLatin1String, Q_RELOCATABLE_TYPE)
Qt::strong_ordering compareThreeWay(const QByteArrayView &lhs, const QChar &rhs) noexcept