5#ifndef QANYSTRINGVIEWUTILS_P_H
6#define QANYSTRINGVIEWUTILS_P_H
18#include <QtCore/private/qjson_p.h>
20#include <QtCore/qanystringview.h>
27inline bool endsWith(QAnyStringView whole, QLatin1StringView part)
29 Q_ASSERT(QtPrivate::isAscii(part));
30 return whole.length() >= part.length() && whole.last(part.length()) == part;
34inline bool startsWith(QAnyStringView whole, QLatin1StringView part)
36 Q_ASSERT(QtPrivate::isAscii(part));
37 return whole.length() >= part.length() && whole.first(part.length()) == part;
40inline bool doesContain(QStringView whole, QLatin1Char part) {
return whole.contains(part); }
41inline bool doesContain(QLatin1StringView whole, QLatin1Char part) {
return whole.contains(part); }
42inline bool doesContain(QUtf8StringView whole, QLatin1Char part)
44 return QByteArrayView(whole.data(), whole.size()).contains(part.toLatin1());
46inline bool contains(QAnyStringView whole, QLatin1Char part)
48 return whole.visit([&](
auto view) {
return doesContain(view, part); });
53 return whole.lastIndexOf(part);
57 return whole.lastIndexOf(part);
61 return QByteArrayView(whole.data(), whole.size()).lastIndexOf(part);
65 Q_ASSERT(QtPrivate::isAscii(part));
66 return whole.visit([&](
auto view) {
return getLastIndexOf(view, part); });
69inline int toInt(QUtf8StringView view)
71 return QByteArrayView(view.data(), view.length()).toInt();
73inline int toInt(QLatin1StringView view) {
return view.toInt(); }
74inline int toInt(QStringView view) {
return view.toInt(); }
76inline int toInt(QAnyStringView string)
78 return string.visit([](
auto view) {
return toInt(view); });
81template<
typename StringView>
84 if constexpr (std::is_same_v<StringView, QStringView>)
85 return string.trimmed();
86 if constexpr (std::is_same_v<StringView, QLatin1StringView>)
87 return string.trimmed();
88 if constexpr (std::is_same_v<StringView, QUtf8StringView>)
89 return QByteArrayView(string.data(), string.length()).trimmed();
95 return string.visit([](
auto data) {
96 return doTrimmed(data);
100template<
typename StringView,
typename Handler>
103 if constexpr (std::is_same_v<StringView, QStringView>)
104 return handler(QByteArrayView(string.toUtf8()));
105 if constexpr (std::is_same_v<StringView, QLatin1StringView>)
106 return handler(QByteArrayView(string.data(), string.length()));
107 if constexpr (std::is_same_v<StringView, QUtf8StringView>)
108 return handler(QByteArrayView(string.data(), string.length()));
109 if constexpr (std::is_same_v<StringView, QByteArrayView>)
110 return handler(string);
111 if constexpr (std::is_same_v<StringView, QByteArray>)
112 return handler(QByteArrayView(string));
113 if constexpr (std::is_same_v<StringView, QAnyStringView>) {
122 struct Wrapper { Handler handler; };
124 return string.visit([w = Wrapper { std::forward<Handler>(handler) }](
auto view)
mutable {
125 static_assert(!(std::is_same_v<
decltype(view), QAnyStringView>));
126 return processAsUtf8(std::move(view), std::forward<Handler>(w.handler));
135 Q_ASSERT(QtPrivate::isAscii(sep));
137 QList<QAnyStringView> list;
138 if (source.isEmpty()) {
144 qsizetype end = source.length();
146 for (qsizetype current = 0; current < end; ++current) {
147 if (source.mid(current, sep.length()) == sep) {
148 list.append(source.mid(start, current - start));
149 start = current + sep.length();
154 list.append(source.mid(start, end - start));
163constexpr inline size_t qHash(QAnyStringView string, size_t seed = 0)
165 return string.visit([seed](
auto view) {
166 if constexpr (std::is_same_v<
decltype(view), QStringView>)
167 return qHash(view, seed);
168 if constexpr (std::is_same_v<
decltype(view), QLatin1StringView>)
169 return qHash(view, seed);
170 if constexpr (std::is_same_v<
decltype(view), QUtf8StringView>)
171 return qHash(QByteArrayView(view.data(), view.length()), seed);
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)
Combined button and popup list for selecting options.
size_t qHash(QByteArrayView key, size_t seed) noexcept
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