1 | // Copyright (C) 2020 The Qt Company Ltd. |
2 | // Copyright (C) 2019 Intel Corporation. |
3 | // Copyright (C) 2019 Mail.ru Group. |
4 | // Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com> |
5 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
6 | |
7 | #ifndef QLATIN1STRINGVIEW_H |
8 | #define QLATIN1STRINGVIEW_H |
9 | |
10 | #include <QtCore/qchar.h> |
11 | #include <QtCore/qnamespace.h> |
12 | #include <QtCore/qtversionchecks.h> |
13 | #include <QtCore/qstringview.h> |
14 | |
15 | #if 0 |
16 | // Workaround for generating forward headers |
17 | #pragma qt_class(QLatin1String) |
18 | #pragma qt_class(QLatin1StringView) |
19 | #endif |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class QString; |
24 | |
25 | #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED) || defined(Q_QDOC) |
26 | # define Q_L1S_VIEW_IS_PRIMARY |
27 | class QLatin1StringView |
28 | #else |
29 | class QLatin1String |
30 | #endif |
31 | { |
32 | public: |
33 | #ifdef Q_L1S_VIEW_IS_PRIMARY |
34 | constexpr QLatin1StringView() noexcept {} |
35 | constexpr QLatin1StringView(std::nullptr_t) noexcept : QLatin1StringView() {} |
36 | constexpr explicit QLatin1StringView(const char *s) noexcept |
37 | : QLatin1StringView(s, s ? qsizetype(QtPrivate::lengthHelperPointer(s)) : 0) {} |
38 | constexpr QLatin1StringView(const char *f, const char *l) |
39 | : QLatin1StringView(f, qsizetype(l - f)) {} |
40 | constexpr QLatin1StringView(const char *s, qsizetype sz) noexcept : m_data(s), m_size(sz) {} |
41 | explicit QLatin1StringView(const QByteArray &s) noexcept |
42 | : QLatin1StringView(s.constData(), s.size()) {} |
43 | constexpr explicit QLatin1StringView(QByteArrayView s) noexcept |
44 | : QLatin1StringView(s.constData(), s.size()) {} |
45 | #else |
46 | constexpr QLatin1String() noexcept : m_size(0), m_data(nullptr) {} |
47 | Q_WEAK_OVERLOAD |
48 | constexpr QLatin1String(std::nullptr_t) noexcept : QLatin1String() {} |
49 | constexpr explicit QLatin1String(const char *s) noexcept |
50 | : m_size(s ? qsizetype(QtPrivate::lengthHelperPointer(data: s)) : 0), m_data(s) {} |
51 | constexpr QLatin1String(const char *f, const char *l) |
52 | : QLatin1String(f, qsizetype(l - f)) {} |
53 | constexpr QLatin1String(const char *s, qsizetype sz) noexcept : m_size(sz), m_data(s) {} |
54 | explicit QLatin1String(const QByteArray &s) noexcept : m_size(s.size()), m_data(s.constData()) {} |
55 | constexpr explicit QLatin1String(QByteArrayView s) noexcept : m_size(s.size()), m_data(s.data()) {} |
56 | #endif // !Q_L1S_VIEW_IS_PRIMARY |
57 | |
58 | inline QString toString() const; |
59 | |
60 | constexpr const char *latin1() const noexcept { return m_data; } |
61 | constexpr qsizetype size() const noexcept { return m_size; } |
62 | constexpr const char *data() const noexcept { return m_data; } |
63 | [[nodiscard]] constexpr const char *constData() const noexcept { return data(); } |
64 | [[nodiscard]] constexpr const char *constBegin() const noexcept { return begin(); } |
65 | [[nodiscard]] constexpr const char *constEnd() const noexcept { return end(); } |
66 | |
67 | [[nodiscard]] constexpr QLatin1Char first() const { return front(); } |
68 | [[nodiscard]] constexpr QLatin1Char last() const { return back(); } |
69 | |
70 | [[nodiscard]] constexpr qsizetype length() const noexcept { return size(); } |
71 | |
72 | constexpr bool isNull() const noexcept { return !data(); } |
73 | constexpr bool isEmpty() const noexcept { return !size(); } |
74 | |
75 | [[nodiscard]] constexpr bool empty() const noexcept { return size() == 0; } |
76 | |
77 | template <typename...Args> |
78 | [[nodiscard]] inline QString arg(Args &&...args) const; |
79 | |
80 | [[nodiscard]] constexpr QLatin1Char at(qsizetype i) const |
81 | { |
82 | Q_ASSERT(i >= 0); |
83 | Q_ASSERT(i < size()); |
84 | return QLatin1Char(m_data[i]); |
85 | } |
86 | [[nodiscard]] constexpr QLatin1Char operator[](qsizetype i) const { return at(i); } |
87 | |
88 | [[nodiscard]] constexpr QLatin1Char front() const { return at(i: 0); } |
89 | [[nodiscard]] constexpr QLatin1Char back() const { return at(i: size() - 1); } |
90 | |
91 | [[nodiscard]] int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
92 | { return QtPrivate::compareStrings(lhs: *this, rhs: other, cs); } |
93 | [[nodiscard]] int compare(QLatin1StringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
94 | { return QtPrivate::compareStrings(lhs: *this, rhs: other, cs); } |
95 | [[nodiscard]] inline int compare(QUtf8StringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; |
96 | [[nodiscard]] constexpr int compare(QChar c) const noexcept |
97 | { return isEmpty() ? -1 : front() == c ? int(size() > 1) : uchar(m_data[0]) - c.unicode(); } |
98 | [[nodiscard]] int compare(QChar c, Qt::CaseSensitivity cs) const noexcept |
99 | { return QtPrivate::compareStrings(lhs: *this, rhs: QStringView(&c, 1), cs); } |
100 | |
101 | [[nodiscard]] bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
102 | { return QtPrivate::startsWith(haystack: *this, needle: s, cs); } |
103 | [[nodiscard]] bool startsWith(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
104 | { return QtPrivate::startsWith(haystack: *this, needle: s, cs); } |
105 | [[nodiscard]] constexpr bool startsWith(QChar c) const noexcept |
106 | { return !isEmpty() && front() == c; } |
107 | [[nodiscard]] bool startsWith(QChar c, Qt::CaseSensitivity cs) const noexcept |
108 | { return QtPrivate::startsWith(haystack: *this, needle: QStringView(&c, 1), cs); } |
109 | |
110 | [[nodiscard]] bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
111 | { return QtPrivate::endsWith(haystack: *this, needle: s, cs); } |
112 | [[nodiscard]] bool endsWith(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
113 | { return QtPrivate::endsWith(haystack: *this, needle: s, cs); } |
114 | [[nodiscard]] constexpr bool endsWith(QChar c) const noexcept |
115 | { return !isEmpty() && back() == c; } |
116 | [[nodiscard]] bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept |
117 | { return QtPrivate::endsWith(haystack: *this, needle: QStringView(&c, 1), cs); } |
118 | |
119 | [[nodiscard]] qsizetype indexOf(QStringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
120 | { return QtPrivate::findString(haystack: *this, from, needle: s, cs); } |
121 | [[nodiscard]] qsizetype indexOf(QLatin1StringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
122 | { return QtPrivate::findString(haystack: *this, from, needle: s, cs); } |
123 | [[nodiscard]] qsizetype indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
124 | { return QtPrivate::findString(haystack: *this, from, needle: QStringView(&c, 1), cs); } |
125 | |
126 | [[nodiscard]] bool contains(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
127 | { return indexOf(s, from: 0, cs) != -1; } |
128 | [[nodiscard]] bool contains(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
129 | { return indexOf(s, from: 0, cs) != -1; } |
130 | [[nodiscard]] bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
131 | { return indexOf(s: QStringView(&c, 1), from: 0, cs) != -1; } |
132 | |
133 | [[nodiscard]] qsizetype lastIndexOf(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
134 | { return lastIndexOf(s, from: size(), cs); } |
135 | [[nodiscard]] qsizetype lastIndexOf(QStringView s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
136 | { return QtPrivate::lastIndexOf(haystack: *this, from, needle: s, cs); } |
137 | [[nodiscard]] qsizetype lastIndexOf(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
138 | { return lastIndexOf(s, from: size(), cs); } |
139 | [[nodiscard]] qsizetype lastIndexOf(QLatin1StringView s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
140 | { return QtPrivate::lastIndexOf(haystack: *this, from, needle: s, cs); } |
141 | [[nodiscard]] qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
142 | { return lastIndexOf(c, from: -1, cs); } |
143 | [[nodiscard]] qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
144 | { return QtPrivate::lastIndexOf(haystack: *this, from, needle: QStringView(&c, 1), cs); } |
145 | |
146 | [[nodiscard]] qsizetype count(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
147 | { return QtPrivate::count(haystack: *this, needle: str, cs); } |
148 | [[nodiscard]] qsizetype count(QLatin1StringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
149 | { return QtPrivate::count(haystack: *this, needle: str, cs); } |
150 | [[nodiscard]] qsizetype count(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
151 | { return QtPrivate::count(haystack: *this, needle: ch, cs); } |
152 | |
153 | [[nodiscard]] short toShort(bool *ok = nullptr, int base = 10) const |
154 | { return QtPrivate::toIntegral<short>(data: QByteArrayView(*this), ok, base); } |
155 | [[nodiscard]] ushort toUShort(bool *ok = nullptr, int base = 10) const |
156 | { return QtPrivate::toIntegral<ushort>(data: QByteArrayView(*this), ok, base); } |
157 | [[nodiscard]] int toInt(bool *ok = nullptr, int base = 10) const |
158 | { return QtPrivate::toIntegral<int>(data: QByteArrayView(*this), ok, base); } |
159 | [[nodiscard]] uint toUInt(bool *ok = nullptr, int base = 10) const |
160 | { return QtPrivate::toIntegral<uint>(data: QByteArrayView(*this), ok, base); } |
161 | [[nodiscard]] long toLong(bool *ok = nullptr, int base = 10) const |
162 | { return QtPrivate::toIntegral<long>(data: QByteArrayView(*this), ok, base); } |
163 | [[nodiscard]] ulong toULong(bool *ok = nullptr, int base = 10) const |
164 | { return QtPrivate::toIntegral<ulong>(data: QByteArrayView(*this), ok, base); } |
165 | [[nodiscard]] qlonglong toLongLong(bool *ok = nullptr, int base = 10) const |
166 | { return QtPrivate::toIntegral<qlonglong>(data: QByteArrayView(*this), ok, base); } |
167 | [[nodiscard]] qulonglong toULongLong(bool *ok = nullptr, int base = 10) const |
168 | { return QtPrivate::toIntegral<qulonglong>(data: QByteArrayView(*this), ok, base); } |
169 | [[nodiscard]] float toFloat(bool *ok = nullptr) const |
170 | { |
171 | const auto r = QtPrivate::toFloat(a: *this); |
172 | if (ok) |
173 | *ok = bool(r); |
174 | return r.value_or(u: 0.0f); |
175 | } |
176 | [[nodiscard]] double toDouble(bool *ok = nullptr) const |
177 | { |
178 | const auto r = QtPrivate::toDouble(a: *this); |
179 | if (ok) |
180 | *ok = bool(r); |
181 | return r.value_or(u: 0.0); |
182 | } |
183 | |
184 | using value_type = const char; |
185 | using reference = value_type&; |
186 | using const_reference = reference; |
187 | using iterator = value_type*; |
188 | using const_iterator = iterator; |
189 | using difference_type = qsizetype; // violates Container concept requirements |
190 | using size_type = qsizetype; // violates Container concept requirements |
191 | |
192 | constexpr const_iterator begin() const noexcept { return data(); } |
193 | constexpr const_iterator cbegin() const noexcept { return data(); } |
194 | constexpr const_iterator end() const noexcept { return data() + size(); } |
195 | constexpr const_iterator cend() const noexcept { return data() + size(); } |
196 | |
197 | using reverse_iterator = std::reverse_iterator<iterator>; |
198 | using const_reverse_iterator = reverse_iterator; |
199 | |
200 | const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } |
201 | const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } |
202 | const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } |
203 | const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } |
204 | |
205 | [[nodiscard]] constexpr QLatin1StringView mid(qsizetype pos, qsizetype n = -1) const |
206 | { |
207 | using namespace QtPrivate; |
208 | auto result = QContainerImplHelper::mid(originalLength: size(), position: &pos, length: &n); |
209 | return result == QContainerImplHelper::Null ? QLatin1StringView() |
210 | : QLatin1StringView(m_data + pos, n); |
211 | } |
212 | [[nodiscard]] constexpr QLatin1StringView left(qsizetype n) const |
213 | { |
214 | if (size_t(n) >= size_t(size())) |
215 | n = size(); |
216 | return {m_data, n}; |
217 | } |
218 | [[nodiscard]] constexpr QLatin1StringView right(qsizetype n) const |
219 | { |
220 | if (size_t(n) >= size_t(size())) |
221 | n = size(); |
222 | return {m_data + m_size - n, n}; |
223 | } |
224 | |
225 | [[nodiscard]] constexpr QLatin1StringView sliced(qsizetype pos) const |
226 | { verify(pos); return {m_data + pos, m_size - pos}; } |
227 | [[nodiscard]] constexpr QLatin1StringView sliced(qsizetype pos, qsizetype n) const |
228 | { verify(pos, n); return {m_data + pos, n}; } |
229 | [[nodiscard]] constexpr QLatin1StringView first(qsizetype n) const |
230 | { verify(pos: n); return {m_data, n}; } |
231 | [[nodiscard]] constexpr QLatin1StringView last(qsizetype n) const |
232 | { verify(pos: n); return {m_data + size() - n, n}; } |
233 | [[nodiscard]] constexpr QLatin1StringView chopped(qsizetype n) const |
234 | { verify(pos: n); return {m_data, size() - n}; } |
235 | |
236 | constexpr void chop(qsizetype n) |
237 | { verify(pos: n); m_size -= n; } |
238 | constexpr void truncate(qsizetype n) |
239 | { verify(pos: n); m_size = n; } |
240 | |
241 | [[nodiscard]] QLatin1StringView trimmed() const noexcept { return QtPrivate::trimmed(s: *this); } |
242 | |
243 | template <typename Needle, typename...Flags> |
244 | [[nodiscard]] constexpr auto tokenize(Needle &&needle, Flags...flags) const |
245 | noexcept(noexcept(qTokenize(std::declval<const QLatin1StringView &>(), |
246 | std::forward<Needle>(needle), flags...))) |
247 | -> decltype(qTokenize(*this, std::forward<Needle>(needle), flags...)) |
248 | { return qTokenize(*this, std::forward<Needle>(needle), flags...); } |
249 | |
250 | friend bool operator==(QLatin1StringView s1, QLatin1StringView s2) noexcept |
251 | { return QByteArrayView(s1) == QByteArrayView(s2); } |
252 | friend bool operator!=(QLatin1StringView s1, QLatin1StringView s2) noexcept |
253 | { return !(s1 == s2); } |
254 | friend bool operator<(QLatin1StringView s1, QLatin1StringView s2) noexcept |
255 | { |
256 | const qsizetype len = qMin(a: s1.size(), b: s2.size()); |
257 | const int r = len ? memcmp(s1: s1.latin1(), s2: s2.latin1(), n: len) : 0; |
258 | return r < 0 || (r == 0 && s1.size() < s2.size()); |
259 | } |
260 | friend bool operator>(QLatin1StringView s1, QLatin1StringView s2) noexcept |
261 | { return s2 < s1; } |
262 | friend bool operator<=(QLatin1StringView s1, QLatin1StringView s2) noexcept |
263 | { return !(s1 > s2); } |
264 | friend bool operator>=(QLatin1StringView s1, QLatin1StringView s2) noexcept |
265 | { return !(s1 < s2); } |
266 | |
267 | // QChar <> QLatin1StringView |
268 | friend bool operator==(QChar lhs, QLatin1StringView rhs) noexcept { return rhs.size() == 1 && lhs == rhs.front(); } |
269 | friend bool operator< (QChar lhs, QLatin1StringView rhs) noexcept { return compare_helper(data1: &lhs, length1: 1, s2: rhs) < 0; } |
270 | friend bool operator> (QChar lhs, QLatin1StringView rhs) noexcept { return compare_helper(data1: &lhs, length1: 1, s2: rhs) > 0; } |
271 | friend bool operator!=(QChar lhs, QLatin1StringView rhs) noexcept { return !(lhs == rhs); } |
272 | friend bool operator<=(QChar lhs, QLatin1StringView rhs) noexcept { return !(lhs > rhs); } |
273 | friend bool operator>=(QChar lhs, QLatin1StringView rhs) noexcept { return !(lhs < rhs); } |
274 | |
275 | friend bool operator==(QLatin1StringView lhs, QChar rhs) noexcept { return rhs == lhs; } |
276 | friend bool operator!=(QLatin1StringView lhs, QChar rhs) noexcept { return !(rhs == lhs); } |
277 | friend bool operator< (QLatin1StringView lhs, QChar rhs) noexcept { return rhs > lhs; } |
278 | friend bool operator> (QLatin1StringView lhs, QChar rhs) noexcept { return rhs < lhs; } |
279 | friend bool operator<=(QLatin1StringView lhs, QChar rhs) noexcept { return !(rhs < lhs); } |
280 | friend bool operator>=(QLatin1StringView lhs, QChar rhs) noexcept { return !(rhs > lhs); } |
281 | |
282 | // QStringView <> QLatin1StringView |
283 | friend bool operator==(QStringView lhs, QLatin1StringView rhs) noexcept |
284 | { return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); } |
285 | friend bool operator!=(QStringView lhs, QLatin1StringView rhs) noexcept { return !(lhs == rhs); } |
286 | friend bool operator< (QStringView lhs, QLatin1StringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; } |
287 | friend bool operator<=(QStringView lhs, QLatin1StringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; } |
288 | friend bool operator> (QStringView lhs, QLatin1StringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; } |
289 | friend bool operator>=(QStringView lhs, QLatin1StringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; } |
290 | |
291 | friend bool operator==(QLatin1StringView lhs, QStringView rhs) noexcept |
292 | { return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); } |
293 | friend bool operator!=(QLatin1StringView lhs, QStringView rhs) noexcept { return !(lhs == rhs); } |
294 | friend bool operator< (QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; } |
295 | friend bool operator<=(QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; } |
296 | friend bool operator> (QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; } |
297 | friend bool operator>=(QLatin1StringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; } |
298 | |
299 | |
300 | #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) |
301 | QT_ASCII_CAST_WARN inline bool operator==(const char *s) const; |
302 | QT_ASCII_CAST_WARN inline bool operator!=(const char *s) const; |
303 | QT_ASCII_CAST_WARN inline bool operator<(const char *s) const; |
304 | QT_ASCII_CAST_WARN inline bool operator>(const char *s) const; |
305 | QT_ASCII_CAST_WARN inline bool operator<=(const char *s) const; |
306 | QT_ASCII_CAST_WARN inline bool operator>=(const char *s) const; |
307 | |
308 | QT_ASCII_CAST_WARN inline bool operator==(const QByteArray &s) const; |
309 | QT_ASCII_CAST_WARN inline bool operator!=(const QByteArray &s) const; |
310 | QT_ASCII_CAST_WARN inline bool operator<(const QByteArray &s) const; |
311 | QT_ASCII_CAST_WARN inline bool operator>(const QByteArray &s) const; |
312 | QT_ASCII_CAST_WARN inline bool operator<=(const QByteArray &s) const; |
313 | QT_ASCII_CAST_WARN inline bool operator>=(const QByteArray &s) const; |
314 | |
315 | QT_ASCII_CAST_WARN friend bool operator==(const char *s1, QLatin1StringView s2) { return compare_helper(s1: s2, s2: s1) == 0; } |
316 | QT_ASCII_CAST_WARN friend bool operator!=(const char *s1, QLatin1StringView s2) { return compare_helper(s1: s2, s2: s1) != 0; } |
317 | QT_ASCII_CAST_WARN friend bool operator< (const char *s1, QLatin1StringView s2) { return compare_helper(s1: s2, s2: s1) > 0; } |
318 | QT_ASCII_CAST_WARN friend bool operator> (const char *s1, QLatin1StringView s2) { return compare_helper(s1: s2, s2: s1) < 0; } |
319 | QT_ASCII_CAST_WARN friend bool operator<=(const char *s1, QLatin1StringView s2) { return compare_helper(s1: s2, s2: s1) >= 0; } |
320 | QT_ASCII_CAST_WARN friend bool operator>=(const char *s1, QLatin1StringView s2) { return compare_helper(s1: s2, s2: s1) <= 0; } |
321 | #endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) |
322 | |
323 | private: |
324 | Q_ALWAYS_INLINE constexpr void verify(qsizetype pos, qsizetype n = 0) const |
325 | { |
326 | Q_ASSERT(pos >= 0); |
327 | Q_ASSERT(pos <= size()); |
328 | Q_ASSERT(n >= 0); |
329 | Q_ASSERT(n <= size() - pos); |
330 | } |
331 | static int compare_helper(const QLatin1StringView &s1, const char *s2) noexcept |
332 | { return compare_helper(s1, s2, len: qstrlen(str: s2)); } |
333 | Q_CORE_EXPORT static int compare_helper(const QLatin1StringView &s1, const char *s2, qsizetype len) noexcept; |
334 | Q_CORE_EXPORT static int compare_helper(const QChar *data1, qsizetype length1, |
335 | QLatin1StringView s2, |
336 | Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; |
337 | #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED) |
338 | const char *m_data = nullptr; |
339 | qsizetype m_size = 0; |
340 | #else |
341 | qsizetype m_size; |
342 | const char *m_data; |
343 | #endif |
344 | }; |
345 | #ifdef Q_L1S_VIEW_IS_PRIMARY |
346 | Q_DECLARE_TYPEINFO(QLatin1StringView, Q_RELOCATABLE_TYPE); |
347 | #else |
348 | Q_DECLARE_TYPEINFO(QLatin1String, Q_RELOCATABLE_TYPE); |
349 | #endif |
350 | |
351 | namespace Qt { |
352 | inline namespace Literals { |
353 | inline namespace StringLiterals { |
354 | |
355 | constexpr inline QLatin1StringView operator""_L1 (const char *str, size_t size) noexcept |
356 | { |
357 | return {str, qsizetype(size)}; |
358 | } |
359 | |
360 | } // StringLiterals |
361 | } // Literals |
362 | } // Qt |
363 | |
364 | QT_END_NAMESPACE |
365 | |
366 | #ifdef Q_L1S_VIEW_IS_PRIMARY |
367 | # undef Q_L1S_VIEW_IS_PRIMARY |
368 | #endif |
369 | |
370 | #endif // QLATIN1STRINGVIEW_H |
371 | |