4#ifndef QANYSTRINGVIEWUTILS_P_H
5#define QANYSTRINGVIEWUTILS_P_H
17#include <QtCore/private/qjson_p.h>
19#include <QtCore/qanystringview.h>
26inline bool endsWith(QAnyStringView whole, QLatin1StringView part)
28 Q_ASSERT(QtPrivate::isAscii(part));
29 return whole.length() >= part.length() && whole.last(part.length()) == part;
33inline bool startsWith(QAnyStringView whole, QLatin1StringView part)
35 Q_ASSERT(QtPrivate::isAscii(part));
36 return whole.length() >= part.length() && whole.first(part.length()) == part;
39inline bool doesContain(QStringView whole, QLatin1Char part) {
return whole.contains(part); }
40inline bool doesContain(QLatin1StringView whole, QLatin1Char part) {
return whole.contains(part); }
41inline bool doesContain(QUtf8StringView whole, QLatin1Char part)
43 return QByteArrayView(whole.data(), whole.size()).contains(part.toLatin1());
45inline bool contains(QAnyStringView whole, QLatin1Char part)
47 return whole.visit([&](
auto view) {
return doesContain(view, part); });
52 return whole.lastIndexOf(part);
56 return whole.lastIndexOf(part);
60 return QByteArrayView(whole.data(), whole.size()).lastIndexOf(part);
64 Q_ASSERT(QtPrivate::isAscii(part));
65 return whole.visit([&](
auto view) {
return getLastIndexOf(view, part); });
68inline int toInt(QUtf8StringView view)
70 return QByteArrayView(view.data(), view.length()).toInt();
72inline int toInt(QLatin1StringView view) {
return view.toInt(); }
73inline int toInt(QStringView view) {
return view.toInt(); }
75inline int toInt(QAnyStringView string)
77 return string.visit([](
auto view) {
return toInt(view); });
80template<
typename StringView>
83 if constexpr (std::is_same_v<StringView, QStringView>)
84 return string.trimmed();
85 if constexpr (std::is_same_v<StringView, QLatin1StringView>)
86 return string.trimmed();
87 if constexpr (std::is_same_v<StringView, QUtf8StringView>)
88 return QByteArrayView(string.data(), string.length()).trimmed();
94 return string.visit([](
auto data) {
95 return doTrimmed(data);
99template<
typename StringView,
typename Handler>
102 if constexpr (std::is_same_v<StringView, QStringView>)
103 return handler(QByteArrayView(string.toUtf8()));
104 if constexpr (std::is_same_v<StringView, QLatin1StringView>)
105 return handler(QByteArrayView(string.data(), string.length()));
106 if constexpr (std::is_same_v<StringView, QUtf8StringView>)
107 return handler(QByteArrayView(string.data(), string.length()));
108 if constexpr (std::is_same_v<StringView, QByteArrayView>)
109 return handler(string);
110 if constexpr (std::is_same_v<StringView, QByteArray>)
111 return handler(QByteArrayView(string));
112 if constexpr (std::is_same_v<StringView, QAnyStringView>) {
121 struct Wrapper { Handler handler; };
123 return string.visit([w = Wrapper { std::forward<Handler>(handler) }](
auto view)
mutable {
124 static_assert(!(std::is_same_v<
decltype(view), QAnyStringView>));
125 return processAsUtf8(std::move(view), std::forward<Handler>(w.handler));
134 Q_ASSERT(QtPrivate::isAscii(sep));
136 QList<QAnyStringView> list;
137 if (source.isEmpty()) {
143 qsizetype end = source.length();
145 for (qsizetype current = 0; current < end; ++current) {
146 if (source.mid(current, sep.length()) == sep) {
147 list.append(source.mid(start, current - start));
148 start = current + sep.length();
153 list.append(source.mid(start, end - start));
qsizetype lastIndexOf(QAnyStringView whole, QLatin1StringView part)
bool contains(QAnyStringView whole, QLatin1Char part)
QAnyStringView trimmed(QAnyStringView string)
int toInt(QUtf8StringView view)
QAnyStringView doTrimmed(StringView string)
auto processAsUtf8(StringView string, Handler &&handler)
bool endsWith(QAnyStringView whole, QLatin1StringView part)
qsizetype getLastIndexOf(QStringView whole, QLatin1StringView part)
bool doesContain(QStringView whole, QLatin1Char part)
bool startsWith(QAnyStringView whole, QLatin1StringView part)
QList< QAnyStringView > split(QAnyStringView source, QLatin1StringView sep)
QDebug warning(const MetaType &classDef)
Argument(const QCborMap &cbor)
BaseType(const QCborMap &cbor)
ClassInfo(const QCborMap &cbor)
QList< QAnyStringView > values
Enum(const QCborMap &cbor)
Interface(const QCborValue &cbor)
QAnyStringView returnType
Argument::Container arguments
bool isJavaScriptFunction
Method(const QCborMap &cbor, bool isConstructor)
static constexpr int InvalidIndex
QAnyStringView privateClass
Property(const QCborMap &cbor)
friend bool comparesEqual(const UsingDeclaration &a, const UsingDeclaration &b) noexcept
friend Qt::strong_ordering compareThreeWay(const UsingDeclaration &a, const UsingDeclaration &b) noexcept