Qt 6.x
The Qt SDK
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qstringview.h
Go to the documentation of this file.
1// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
2// Copyright (C) 2019 Mail.ru Group.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4#ifndef QSTRINGVIEW_H
5#define QSTRINGVIEW_H
6
7#include <QtCore/qchar.h>
8#include <QtCore/qbytearray.h>
9#include <QtCore/qstringliteral.h>
10#include <QtCore/qstringalgorithms.h>
11
12#include <string>
13#include <QtCore/q20type_traits.h>
14
15#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
18#endif
19
21
22class QString;
23class QStringView;
26#ifdef Q_QDOC
27class QUtf8StringView;
28#endif
29
30namespace QtPrivate {
31template <typename Char>
33 : std::integral_constant<bool,
34 std::is_same<Char, QChar>::value ||
35 std::is_same<Char, ushort>::value ||
36 std::is_same<Char, char16_t>::value ||
37 (std::is_same<Char, wchar_t>::value && sizeof(wchar_t) == sizeof(QChar))> {};
38template <typename Char>
40 : IsCompatibleCharTypeHelper<q20::remove_cvref_t<Char>> {};
41
42template <typename Pointer>
43struct IsCompatiblePointerHelper : std::false_type {};
44template <typename Char>
47template <typename Pointer>
49 : IsCompatiblePointerHelper<q20::remove_cvref_t<Pointer>> {};
50
51template <typename T, typename Enable = void>
52struct IsContainerCompatibleWithQStringView : std::false_type {};
53
54template <typename T>
55struct IsContainerCompatibleWithQStringView<T, std::enable_if_t<std::conjunction_v<
56 // lacking concepts and ranges, we accept any T whose std::data yields a suitable pointer ...
57 IsCompatiblePointer<decltype( std::data(std::declval<const T &>()) )>,
58 // ... and that has a suitable size ...
59 std::is_convertible<decltype( std::size(std::declval<const T &>()) ), qsizetype>,
60 // ... and it's a range as it defines an iterator-like API
61 IsCompatibleCharType<typename std::iterator_traits<decltype( std::begin(std::declval<const T &>()) )>::value_type>,
62 std::is_convertible<
63 decltype( std::begin(std::declval<const T &>()) != std::end(std::declval<const T &>()) ),
64 bool>,
65
66 // These need to be treated specially due to the empty vs null distinction
67 std::negation<std::is_same<std::decay_t<T>, QString>>,
68
69 // Don't make an accidental copy constructor
70 std::negation<std::is_same<std::decay_t<T>, QStringView>>
71 >>> : std::true_type {};
72
73} // namespace QtPrivate
74
76{
77public:
78 typedef char16_t storage_type;
79 typedef const QChar value_type;
80 typedef std::ptrdiff_t difference_type;
86
89 typedef std::reverse_iterator<iterator> reverse_iterator;
90 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
91
92private:
93 template <typename Char>
94 using if_compatible_char = typename std::enable_if<QtPrivate::IsCompatibleCharType<Char>::value, bool>::type;
95
96 template <typename Pointer>
97 using if_compatible_pointer = typename std::enable_if<QtPrivate::IsCompatiblePointer<Pointer>::value, bool>::type;
98
99 template <typename T>
100 using if_compatible_qstring_like = typename std::enable_if<std::is_same<T, QString>::value, bool>::type;
101
102 template <typename T>
103 using if_compatible_container = typename std::enable_if<QtPrivate::IsContainerCompatibleWithQStringView<T>::value, bool>::type;
104
105 template <typename Char>
106 static constexpr qsizetype lengthHelperPointer(const Char *str) noexcept
107 {
108#if defined(QT_SUPPORTS_IS_CONSTANT_EVALUATED)
109 if (qIsConstantEvaluated())
110 return std::char_traits<Char>::length(str);
111#endif
112 return QtPrivate::qustrlen(reinterpret_cast<const char16_t *>(str));
113 }
114 static qsizetype lengthHelperPointer(const QChar *str) noexcept
115 {
116 return QtPrivate::qustrlen(reinterpret_cast<const char16_t *>(str));
117 }
118
119 template <typename Char>
120 static const storage_type *castHelper(const Char *str) noexcept
121 { return reinterpret_cast<const storage_type*>(str); }
122 static constexpr const storage_type *castHelper(const storage_type *str) noexcept
123 { return str; }
124
125public:
126 constexpr QStringView() noexcept {}
127 constexpr QStringView(std::nullptr_t) noexcept
128 : QStringView() {}
129
130 template <typename Char, if_compatible_char<Char> = true>
131 constexpr QStringView(const Char *str, qsizetype len)
132#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED)
133 : m_data(castHelper(str)),
134 m_size((Q_ASSERT(len >= 0), Q_ASSERT(str || !len), len))
135#else
136 : m_size((Q_ASSERT(len >= 0), Q_ASSERT(str || !len), len)),
137 m_data(castHelper(str))
138#endif
139 {}
140
141 template <typename Char, if_compatible_char<Char> = true>
142 constexpr QStringView(const Char *f, const Char *l)
143 : QStringView(f, l - f) {}
144
145#ifdef Q_QDOC
146 template <typename Char, size_t N>
147 constexpr QStringView(const Char (&array)[N]) noexcept;
148
149 template <typename Char>
150 constexpr QStringView(const Char *str) noexcept;
151#else
152
153 template <typename Pointer, if_compatible_pointer<Pointer> = true>
154 constexpr QStringView(const Pointer &str) noexcept
155 : QStringView(str, str ? lengthHelperPointer(str) : 0) {}
156#endif
157
158#ifdef Q_QDOC
159 QStringView(const QString &str) noexcept;
160#else
161 template <typename String, if_compatible_qstring_like<String> = true>
162 QStringView(const String &str) noexcept
163 : QStringView(str.isNull() ? nullptr : str.data(), qsizetype(str.size())) {}
164#endif
165
166 template <typename Container, if_compatible_container<Container> = true>
167 constexpr Q_ALWAYS_INLINE QStringView(const Container &c) noexcept
169
170 template <typename Char, size_t Size, if_compatible_char<Char> = true>
171 [[nodiscard]] constexpr static QStringView fromArray(const Char (&string)[Size]) noexcept
172 { return QStringView(string, Size); }
173
174 [[nodiscard]] inline QString toString() const; // defined in qstring.h
175#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
176 // defined in qcore_foundation.mm
177 [[nodiscard]] Q_CORE_EXPORT CFStringRef toCFString() const Q_DECL_CF_RETURNS_RETAINED;
178 [[nodiscard]] Q_CORE_EXPORT NSString *toNSString() const Q_DECL_NS_RETURNS_AUTORELEASED;
179#endif
180
181 [[nodiscard]] constexpr qsizetype size() const noexcept { return m_size; }
182 [[nodiscard]] const_pointer data() const noexcept { return reinterpret_cast<const_pointer>(m_data); }
183 [[nodiscard]] const_pointer constData() const noexcept { return data(); }
184 [[nodiscard]] constexpr const storage_type *utf16() const noexcept { return m_data; }
185
186 [[nodiscard]] constexpr QChar operator[](qsizetype n) const
187 { return Q_ASSERT(n >= 0), Q_ASSERT(n < size()), QChar(m_data[n]); }
188
189 //
190 // QString API
191 //
192
193 template <typename...Args>
194 [[nodiscard]] inline QString arg(Args &&...args) const; // defined in qstring.h
195
196 [[nodiscard]] QByteArray toLatin1() const { return QtPrivate::convertToLatin1(*this); }
197 [[nodiscard]] QByteArray toUtf8() const { return QtPrivate::convertToUtf8(*this); }
198 [[nodiscard]] QByteArray toLocal8Bit() const { return QtPrivate::convertToLocal8Bit(*this); }
199 [[nodiscard]] inline QList<uint> toUcs4() const; // defined in qlist.h ### Qt 7 char32_t
200
201 [[nodiscard]] constexpr QChar at(qsizetype n) const noexcept { return (*this)[n]; }
202
203 [[nodiscard]] constexpr QStringView mid(qsizetype pos, qsizetype n = -1) const noexcept
204 {
205 using namespace QtPrivate;
206 auto result = QContainerImplHelper::mid(size(), &pos, &n);
207 return result == QContainerImplHelper::Null ? QStringView() : QStringView(m_data + pos, n);
208 }
209 [[nodiscard]] constexpr QStringView left(qsizetype n) const noexcept
210 {
211 if (size_t(n) >= size_t(size()))
212 n = size();
213 return QStringView(m_data, n);
214 }
215 [[nodiscard]] constexpr QStringView right(qsizetype n) const noexcept
216 {
217 if (size_t(n) >= size_t(size()))
218 n = size();
219 return QStringView(m_data + m_size - n, n);
220 }
221
222 [[nodiscard]] constexpr QStringView first(qsizetype n) const noexcept
223 { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QStringView(m_data, n); }
224 [[nodiscard]] constexpr QStringView last(qsizetype n) const noexcept
225 { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QStringView(m_data + size() - n, n); }
226 [[nodiscard]] constexpr QStringView sliced(qsizetype pos) const noexcept
227 { Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QStringView(m_data + pos, size() - pos); }
228 [[nodiscard]] constexpr QStringView sliced(qsizetype pos, qsizetype n) const noexcept
229 { Q_ASSERT(pos >= 0); Q_ASSERT(n >= 0); Q_ASSERT(size_t(pos) + size_t(n) <= size_t(size())); return QStringView(m_data + pos, n); }
230 [[nodiscard]] constexpr QStringView chopped(qsizetype n) const noexcept
231 { return Q_ASSERT(n >= 0), Q_ASSERT(n <= size()), QStringView(m_data, m_size - n); }
232
233 constexpr void truncate(qsizetype n) noexcept
234 { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size = n; }
235 constexpr void chop(qsizetype n) noexcept
236 { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size -= n; }
237
238 [[nodiscard]] QStringView trimmed() const noexcept { return QtPrivate::trimmed(*this); }
239
240 template <typename Needle, typename...Flags>
241 [[nodiscard]] constexpr inline auto tokenize(Needle &&needle, Flags...flags) const
242 noexcept(noexcept(qTokenize(std::declval<const QStringView&>(), std::forward<Needle>(needle), flags...)))
243 -> decltype(qTokenize(*this, std::forward<Needle>(needle), flags...))
244 { return qTokenize(*this, std::forward<Needle>(needle), flags...); }
245
246 [[nodiscard]] int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
247 { return QtPrivate::compareStrings(*this, other, cs); }
248 [[nodiscard]] inline int compare(QLatin1StringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
249 [[nodiscard]] inline int compare(QUtf8StringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
250 [[nodiscard]] constexpr int compare(QChar c) const noexcept
251 { return size() >= 1 ? compare_single_char_helper(*utf16() - c.unicode()) : -1; }
252 [[nodiscard]] int compare(QChar c, Qt::CaseSensitivity cs) const noexcept
253 { return QtPrivate::compareStrings(*this, QStringView(&c, 1), cs); }
254
255 [[nodiscard]] inline int localeAwareCompare(QStringView other) const;
256
257 [[nodiscard]] bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
258 { return QtPrivate::startsWith(*this, s, cs); }
259 [[nodiscard]] inline bool startsWith(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
260 [[nodiscard]] bool startsWith(QChar c) const noexcept
261 { return !empty() && front() == c; }
262 [[nodiscard]] bool startsWith(QChar c, Qt::CaseSensitivity cs) const noexcept
263 { return QtPrivate::startsWith(*this, QStringView(&c, 1), cs); }
264
265 [[nodiscard]] bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
266 { return QtPrivate::endsWith(*this, s, cs); }
267 [[nodiscard]] inline bool endsWith(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
268 [[nodiscard]] bool endsWith(QChar c) const noexcept
269 { return !empty() && back() == c; }
270 [[nodiscard]] bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept
271 { return QtPrivate::endsWith(*this, QStringView(&c, 1), cs); }
272
273 [[nodiscard]] qsizetype indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
274 { return QtPrivate::findString(*this, from, QStringView(&c, 1), cs); }
275 [[nodiscard]] qsizetype indexOf(QStringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
276 { return QtPrivate::findString(*this, from, s, cs); }
277 [[nodiscard]] inline qsizetype indexOf(QLatin1StringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
278
279 [[nodiscard]] bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
280 { return indexOf(QStringView(&c, 1), 0, cs) != qsizetype(-1); }
281 [[nodiscard]] bool contains(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
282 { return indexOf(s, 0, cs) != qsizetype(-1); }
283 [[nodiscard]] inline bool contains(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
284
285 [[nodiscard]] qsizetype count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
286 { return QtPrivate::count(*this, c, cs); }
288 { return QtPrivate::count(*this, s, cs); }
290
292 { return lastIndexOf(c, -1, cs); }
294 { return QtPrivate::lastIndexOf(*this, from, QStringView(&c, 1), cs); }
296 { return lastIndexOf(s, size(), cs); }
298 { return QtPrivate::lastIndexOf(*this, from, s, cs); }
299 [[nodiscard]] inline qsizetype lastIndexOf(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
300 [[nodiscard]] inline qsizetype lastIndexOf(QLatin1StringView s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
301
302#if QT_CONFIG(regularexpression)
303 [[nodiscard]] qsizetype indexOf(const QRegularExpression &re, qsizetype from = 0, QRegularExpressionMatch *rmatch = nullptr) const
304 {
305 return QtPrivate::indexOf(*this, re, from, rmatch);
306 }
307#ifdef Q_QDOC
308 [[nodiscard]] qsizetype lastIndexOf(const QRegularExpression &re, QRegularExpressionMatch *rmatch = nullptr) const;
309#else
310 // prevent an ambiguity when called like this: lastIndexOf(re, 0)
311 template <typename T = QRegularExpressionMatch, std::enable_if_t<std::is_same_v<T, QRegularExpressionMatch>, bool> = false>
312 [[nodiscard]] qsizetype lastIndexOf(const QRegularExpression &re, T *rmatch = nullptr) const
313 {
314 return QtPrivate::lastIndexOf(*this, re, size(), rmatch);
315 }
316#endif
317 [[nodiscard]] qsizetype lastIndexOf(const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch = nullptr) const
318 {
319 return QtPrivate::lastIndexOf(*this, re, from, rmatch);
320 }
321 [[nodiscard]] bool contains(const QRegularExpression &re, QRegularExpressionMatch *rmatch = nullptr) const
322 {
323 return QtPrivate::contains(*this, re, rmatch);
324 }
325 [[nodiscard]] qsizetype count(const QRegularExpression &re) const
326 {
327 return QtPrivate::count(*this, re);
328 }
329#endif
330
331 [[nodiscard]] bool isRightToLeft() const noexcept
332 { return QtPrivate::isRightToLeft(*this); }
333 [[nodiscard]] bool isValidUtf16() const noexcept
334 { return QtPrivate::isValidUtf16(*this); }
335
336 [[nodiscard]] inline short toShort(bool *ok = nullptr, int base = 10) const;
337 [[nodiscard]] inline ushort toUShort(bool *ok = nullptr, int base = 10) const;
338 [[nodiscard]] inline int toInt(bool *ok = nullptr, int base = 10) const;
339 [[nodiscard]] inline uint toUInt(bool *ok = nullptr, int base = 10) const;
340 [[nodiscard]] inline long toLong(bool *ok = nullptr, int base = 10) const;
341 [[nodiscard]] inline ulong toULong(bool *ok = nullptr, int base = 10) const;
342 [[nodiscard]] inline qlonglong toLongLong(bool *ok = nullptr, int base = 10) const;
343 [[nodiscard]] inline qulonglong toULongLong(bool *ok = nullptr, int base = 10) const;
344 [[nodiscard]] Q_CORE_EXPORT float toFloat(bool *ok = nullptr) const;
345 [[nodiscard]] Q_CORE_EXPORT double toDouble(bool *ok = nullptr) const;
346
347 [[nodiscard]] inline qsizetype toWCharArray(wchar_t *array) const; // defined in qstring.h
348
349
350 [[nodiscard]] Q_CORE_EXPORT
352 Qt::SplitBehavior behavior = Qt::KeepEmptyParts,
354 [[nodiscard]] Q_CORE_EXPORT
355 QList<QStringView> split(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts,
357
358#if QT_CONFIG(regularexpression)
359 [[nodiscard]] Q_CORE_EXPORT
361 Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const;
362#endif
363
364 // QStringView <> QStringView
365 friend bool operator==(QStringView lhs, QStringView rhs) noexcept { return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); }
366 friend bool operator!=(QStringView lhs, QStringView rhs) noexcept { return !(lhs == rhs); }
367 friend bool operator< (QStringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; }
368 friend bool operator<=(QStringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; }
369 friend bool operator> (QStringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; }
370 friend bool operator>=(QStringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; }
371
372 // QStringView <> QChar
373 friend bool operator==(QStringView lhs, QChar rhs) noexcept { return lhs == QStringView(&rhs, 1); }
374 friend bool operator!=(QStringView lhs, QChar rhs) noexcept { return lhs != QStringView(&rhs, 1); }
375 friend bool operator< (QStringView lhs, QChar rhs) noexcept { return lhs < QStringView(&rhs, 1); }
376 friend bool operator<=(QStringView lhs, QChar rhs) noexcept { return lhs <= QStringView(&rhs, 1); }
377 friend bool operator> (QStringView lhs, QChar rhs) noexcept { return lhs > QStringView(&rhs, 1); }
378 friend bool operator>=(QStringView lhs, QChar rhs) noexcept { return lhs >= QStringView(&rhs, 1); }
379
380 friend bool operator==(QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) == rhs; }
381 friend bool operator!=(QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) != rhs; }
382 friend bool operator< (QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) < rhs; }
383 friend bool operator<=(QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) <= rhs; }
384 friend bool operator> (QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) > rhs; }
385 friend bool operator>=(QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) >= rhs; }
386
387 //
388 // STL compatibility API:
389 //
390 [[nodiscard]] const_iterator begin() const noexcept { return data(); }
391 [[nodiscard]] const_iterator end() const noexcept { return data() + size(); }
392 [[nodiscard]] const_iterator cbegin() const noexcept { return begin(); }
393 [[nodiscard]] const_iterator cend() const noexcept { return end(); }
394 [[nodiscard]] const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); }
395 [[nodiscard]] const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); }
396 [[nodiscard]] const_reverse_iterator crbegin() const noexcept { return rbegin(); }
397 [[nodiscard]] const_reverse_iterator crend() const noexcept { return rend(); }
398
399 [[nodiscard]] constexpr bool empty() const noexcept { return size() == 0; }
400 [[nodiscard]] constexpr QChar front() const { return Q_ASSERT(!empty()), QChar(m_data[0]); }
401 [[nodiscard]] constexpr QChar back() const { return Q_ASSERT(!empty()), QChar(m_data[m_size - 1]); }
402
403 //
404 // Qt compatibility API:
405 //
406 [[nodiscard]] const_iterator constBegin() const noexcept { return begin(); }
407 [[nodiscard]] const_iterator constEnd() const noexcept { return end(); }
408 [[nodiscard]] constexpr bool isNull() const noexcept { return !m_data; }
409 [[nodiscard]] constexpr bool isEmpty() const noexcept { return empty(); }
410 [[nodiscard]] constexpr qsizetype length() const noexcept
411 { return size(); }
412 [[nodiscard]] constexpr QChar first() const { return front(); }
413 [[nodiscard]] constexpr QChar last() const { return back(); }
414private:
415#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED)
416 const storage_type *m_data = nullptr;
417 qsizetype m_size = 0;
418#else
419 qsizetype m_size = 0;
420 const storage_type *m_data = nullptr;
421#endif
422
423 constexpr int compare_single_char_helper(int diff) const noexcept
424 { return diff ? diff : size() > 1 ? 1 : 0; }
425};
427
428template <typename QStringLike, typename std::enable_if<
429 std::is_same<QStringLike, QString>::value,
430 bool>::type = true>
431inline QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept
432{ return QStringView(s.data(), s.size()); }
433
434// QChar inline functions:
435
436[[nodiscard]] constexpr auto QChar::fromUcs4(char32_t c) noexcept
437{
438 struct R {
439 char16_t chars[2];
440 [[nodiscard]] constexpr operator QStringView() const noexcept { return {begin(), end()}; }
441 [[nodiscard]] constexpr qsizetype size() const noexcept { return chars[1] ? 2 : 1; }
442 [[nodiscard]] constexpr const char16_t *begin() const noexcept { return chars; }
443 [[nodiscard]] constexpr const char16_t *end() const noexcept { return begin() + size(); }
444 };
445 return requiresSurrogates(c) ? R{{QChar::highSurrogate(c),
447 R{{char16_t(c), u'\0'}} ;
448}
449
451
452#endif /* QSTRINGVIEW_H */
NSData * m_data
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qchar.h:48
static constexpr auto fromUcs4(char32_t c) noexcept
static constexpr char16_t highSurrogate(char32_t ucs4) noexcept
Returns the high surrogate part of a UCS-4-encoded code point.
Definition qchar.h:518
static constexpr char16_t lowSurrogate(char32_t ucs4) noexcept
Returns the low surrogate part of a UCS-4-encoded code point.
Definition qchar.h:522
Definition qlist.h:74
\inmodule QtCore \reentrant
\inmodule QtCore \reentrant
\inmodule QtCore
Definition qstringview.h:76
const_iterator cend() const noexcept
Same as end().
friend bool operator!=(QStringView lhs, QStringView rhs) noexcept
bool startsWith(QChar c) const noexcept
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
qsizetype lastIndexOf(QStringView s, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Q_CORE_EXPORT double toDouble(bool *ok=nullptr) const
Returns the string view converted to a double value.
Definition qstring.cpp:7647
constexpr void truncate(qsizetype n) noexcept
Truncates this string view to length length.
bool isRightToLeft() const noexcept
const_iterator cbegin() const noexcept
Same as begin().
int compare(QChar c, Qt::CaseSensitivity cs) const noexcept
Q_CORE_EXPORT float toFloat(bool *ok=nullptr) const
Returns the string view converted to a float value.
Definition qstring.cpp:7693
value_type & reference
Alias for {value_type &}.
Definition qstringview.h:82
friend bool operator>=(QStringView lhs, QChar rhs) noexcept
friend bool operator!=(QChar lhs, QStringView rhs) noexcept
bool startsWith(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
bool startsWith(QChar c, Qt::CaseSensitivity cs) const noexcept
Returns true if this string view starts with.
friend bool operator<=(QChar lhs, QStringView rhs) noexcept
constexpr const storage_type * utf16() const noexcept
bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept
Returns true if this string view ends with.
qsizetype count(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
const QChar value_type
Alias for {const QChar}.
Definition qstringview.h:79
int localeAwareCompare(QStringView other) const
Definition qstring.h:1369
constexpr void chop(qsizetype n) noexcept
Truncates this string view by length characters.
constexpr auto tokenize(Needle &&needle, Flags...flags) const noexcept(noexcept(qTokenize(std::declval< const QStringView & >(), std::forward< Needle >(needle), flags...))) -> decltype(qTokenize(*this, std::forward< Needle >(needle), flags...))
constexpr bool isEmpty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
ushort toUShort(bool *ok=nullptr, int base=10) const
Returns the string view converted to an {unsigned short} using base base, which is 10 by default and ...
Definition qstring.h:1031
const_pointer const_iterator
This typedef provides an STL-style const iterator for QStringView.
Definition qstringview.h:88
QString arg(Args &&...args) const
const_reverse_iterator rbegin() const noexcept
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first character i...
constexpr qsizetype size() const noexcept
Returns the size of this string view, in UTF-16 code units (that is, surrogate pairs count as two for...
friend bool operator<(QStringView lhs, QStringView rhs) noexcept
friend bool operator==(QStringView lhs, QStringView rhs) noexcept
const_iterator constEnd() const noexcept
constexpr QStringView first(qsizetype n) const noexcept
constexpr QStringView chopped(qsizetype n) const noexcept
Returns the substring of length size() - length starting at the beginning of this object.
const_reverse_iterator crend() const noexcept
Same as rend().
value_type & const_reference
Alias for {value_type &}.
Definition qstringview.h:83
qsizetype count(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr Q_ALWAYS_INLINE QStringView(const Container &c) noexcept
constexpr QChar last() const
Returns the last character in the string view.
constexpr QStringView left(qsizetype n) const noexcept
const_pointer data() const noexcept
qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
const_iterator begin() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the st...
QList< uint > toUcs4() const
Returns a UCS-4/UTF-32 representation of the string view as a QList<uint>.
Definition qlist.h:1012
friend bool operator>(QStringView lhs, QStringView rhs) noexcept
QByteArray toLatin1() const
Returns a Latin-1 representation of the string as a QByteArray.
bool endsWith(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
pointer iterator
This typedef provides an STL-style const iterator for QStringView.
Definition qstringview.h:87
QByteArray toUtf8() const
Returns a UTF-8 representation of the string view as a QByteArray.
Q_CORE_EXPORT QList< QStringView > split(QStringView sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the view into substring views wherever sep occurs, and returns the list of those string views.
Definition qstring.cpp:7987
QByteArray toLocal8Bit() const
Returns a local 8-bit representation of the string as a QByteArray.
bool endsWith(QChar c) const noexcept
bool contains(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
const_reverse_iterator rend() const noexcept
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past the last character...
std::ptrdiff_t difference_type
Alias for {std::ptrdiff_t}.
Definition qstringview.h:80
QString toString() const
Returns a deep copy of this string view's data as a QString.
Definition qstring.h:1014
int toInt(bool *ok=nullptr, int base=10) const
Returns the string view converted to an int using base base, which is 10 by default and must be betwe...
Definition qstring.h:1025
qlonglong toLongLong(bool *ok=nullptr, int base=10) const
Returns the string view converted to a {long long} using base base, which is 10 by default and must b...
Definition qstring.h:1017
std::reverse_iterator< const_iterator > const_reverse_iterator
This typedef provides an STL-style const reverse iterator for QStringView.
Definition qstringview.h:90
constexpr qsizetype length() const noexcept
Same as size().
constexpr QStringView last(qsizetype n) const noexcept
constexpr QStringView() noexcept
Constructs a null string view.
constexpr QChar operator[](qsizetype n) const
Returns the character at position n in this string view.
friend bool operator<=(QStringView lhs, QChar rhs) noexcept
value_type * pointer
Alias for {value_type *}.
Definition qstringview.h:84
constexpr bool empty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
ulong toULong(bool *ok=nullptr, int base=10) const
Returns the string view converted to an {unsigned long} using base base, which is 10 by default and m...
Definition qstring.h:1023
constexpr QChar back() const
Returns the last character in the string view.
bool isValidUtf16() const noexcept
constexpr bool isNull() const noexcept
Returns whether this string view is null - that is, whether {data() == nullptr}.
int compare(QStringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
qulonglong toULongLong(bool *ok=nullptr, int base=10) const
Returns the string view converted to an {unsigned long long} using base base, which is 10 by default ...
Definition qstring.h:1019
short toShort(bool *ok=nullptr, int base=10) const
Returns the string view converted to a short using base base, which is 10 by default and must be betw...
Definition qstring.h:1029
constexpr QStringView right(qsizetype n) const noexcept
const_reverse_iterator crbegin() const noexcept
Same as rbegin().
constexpr QChar at(qsizetype n) const noexcept
Returns the character at position n in this string view.
char16_t storage_type
Alias for {char16_t}.
Definition qstringview.h:78
constexpr int compare(QChar c) const noexcept
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
qsizetype indexOf(QStringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QStringView sliced(qsizetype pos) const noexcept
friend bool operator==(QChar lhs, QStringView rhs) noexcept
friend bool operator==(QStringView lhs, QChar rhs) noexcept
static constexpr QStringView fromArray(const Char(&string)[Size]) noexcept
Constructs a string view on the full character string literal string, including any trailing {Char(0)...
value_type * const_pointer
Alias for {value_type *}.
Definition qstringview.h:85
QStringView trimmed() const noexcept
Strips leading and trailing whitespace and returns the result.
constexpr QChar front() const
friend bool operator>=(QStringView lhs, QStringView rhs) noexcept
Operators for comparing lhs to rhs.
const_iterator constBegin() const noexcept
friend bool operator!=(QStringView lhs, QChar rhs) noexcept
constexpr QStringView sliced(qsizetype pos, qsizetype n) const noexcept
const_iterator end() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary character after...
friend bool operator<=(QStringView lhs, QStringView rhs) noexcept
const_pointer constData() const noexcept
friend bool operator>=(QChar lhs, QStringView rhs) noexcept
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QStringView(std::nullptr_t) noexcept
Constructs a null string view.
uint toUInt(bool *ok=nullptr, int base=10) const
Returns the string view converted to an {unsigned int} using base base, which is 10 by default and mu...
Definition qstring.h:1027
constexpr QStringView(const Char *f, const Char *l)
Constructs a string view on first with length (last - first).
qsizetype lastIndexOf(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QStringView(const Char *str, qsizetype len)
Constructs a string view on str with length len.
qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
long toLong(bool *ok=nullptr, int base=10) const
Returns the string view converted to a long using base base, which is 10 by default and must be betwe...
Definition qstring.h:1021
std::reverse_iterator< iterator > reverse_iterator
This typedef provides an STL-style const reverse iterator for QStringView.
Definition qstringview.h:89
qsizetype toWCharArray(wchar_t *array) const
Definition qstring.h:1151
constexpr QStringView(const Pointer &str) noexcept
qsizetype size_type
Alias for qsizetype.
Definition qstringview.h:81
constexpr QChar first() const
Returns the first character in the string view.
QStringView(const String &str) noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:898
#define this
Definition dialogs.cpp:9
QString str
[2]
Combined button and popup list for selecting options.
\macro QT_NAMESPACE
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QByteArrayView haystack, QByteArrayView needle) noexcept
constexpr Q_ALWAYS_INLINE std::enable_if_t< sizeof(Char)==sizeof(char16_t), qsizetype > lengthHelperContainer(const Char(&str)[N])
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype qustrlen(const char16_t *str) noexcept
Definition qstring.cpp:686
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isValidUtf16(QStringView s) noexcept
Definition qstring.cpp:915
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QByteArrayView trimmed(QByteArrayView s) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QByteArrayView haystack, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QByteArrayView haystack, qsizetype from, QByteArrayView needle) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QByteArrayView haystack, QByteArrayView needle) noexcept
Q_CORE_EXPORT QByteArray convertToLocal8Bit(QStringView str)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool equalStrings(QStringView lhs, QStringView rhs) noexcept
Definition qstring.cpp:1405
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findString(QStringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
Definition qstring.cpp:9631
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isRightToLeft(QStringView string) noexcept
Q_CORE_EXPORT QByteArray convertToLatin1(QStringView str)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
qsizetype indexOf(const QList< V > &list, const U &u, qsizetype from) noexcept
Q_CORE_EXPORT QByteArray convertToUtf8(QStringView str)
CaseSensitivity
@ CaseSensitive
@ KeepEmptyParts
Definition qnamespace.h:126
#define Q_DECL_NS_RETURNS_AUTORELEASED
#define Q_DECL_CF_RETURNS_RETAINED
#define Q_ALWAYS_INLINE
#define Q_FORWARD_DECLARE_CF_TYPE(type)
#define Q_FORWARD_DECLARE_OBJC_CLASS(classname)
Flags
#define Size(name)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLuint end
GLenum GLenum GLsizei count
GLfloat GLfloat f
GLenum type
GLbitfield flags
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat n
const GLubyte * c
GLenum array
GLenum GLsizei len
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static constexpr QChar sep
constexpr auto qTokenize(Haystack &&h, Needle &&n, Flags...flags) noexcept(QtPrivate::Tok::is_nothrow_constructible_from< Haystack, Needle >::value) -> decltype(QtPrivate::Tok::TokenizerResult< Haystack, Needle >{std::forward< Haystack >(h), std::forward< Needle >(n), flags...})
QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept
char Char
@ Q_PRIMITIVE_TYPE
Definition qtypeinfo.h:144
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:163
unsigned long ulong
Definition qtypes.h:30
quint64 qulonglong
Definition qtypes.h:59
ptrdiff_t qsizetype
Definition qtypes.h:70
unsigned int uint
Definition qtypes.h:29
unsigned short ushort
Definition qtypes.h:28
qint64 qlonglong
Definition qtypes.h:58
QSharedPointer< T > other(t)
[5]
QJSValueList args