Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
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/qcompare.h>
9#include <QtCore/qcontainerfwd.h>
10#include <QtCore/qbytearray.h>
11#include <QtCore/qstringliteral.h>
12#include <QtCore/qstringalgorithms.h>
13
14#include <string>
15#include <string_view>
16#include <QtCore/q20type_traits.h>
17
18#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
19Q_FORWARD_DECLARE_CF_TYPE(CFString);
20Q_FORWARD_DECLARE_OBJC_CLASS(NSString);
21#endif
22
23QT_BEGIN_NAMESPACE
24
25class QString;
26class QStringView;
27class QRegularExpression;
28class QRegularExpressionMatch;
29#ifdef Q_QDOC
30class QUtf8StringView;
31#endif
32
33namespace QtPrivate {
34template <typename Char>
36 : std::integral_constant<bool,
39 std::is_same<Char, char16_t>::value ||
40 (std::is_same<Char, wchar_t>::value && sizeof(wchar_t) == sizeof(QChar))> {};
41template <typename Char>
44
45template <typename Pointer>
47template <typename Char>
50template <typename Pointer>
53
54template <typename T, typename Enable = void>
56
57template <typename T>
59 // lacking concepts and ranges, we accept any T whose std::data yields a suitable pointer ...
60 IsCompatiblePointer<decltype( std::data(std::declval<const T &>()) )>,
61 // ... and that has a suitable size ...
62 std::is_convertible<decltype( std::size(std::declval<const T &>()) ), qsizetype>,
63 // ... and it's a range as it defines an iterator-like API
64 IsCompatibleCharType<typename std::iterator_traits<decltype( std::begin(std::declval<const T &>()) )>::value_type>,
66 decltype( std::begin(std::declval<const T &>()) != std::end(std::declval<const T &>()) ),
67 bool>,
68
69 // These need to be treated specially due to the empty vs null distinction
71
72 // Don't make an accidental copy constructor
74 >>> : std::true_type {};
75
76} // namespace QtPrivate
77
79{
80public:
81 typedef char16_t storage_type;
82 typedef const QChar value_type;
83 typedef std::ptrdiff_t difference_type;
89
92 typedef std::reverse_iterator<iterator> reverse_iterator;
93 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
94
95private:
96 template <typename Char>
97 using if_compatible_char = typename std::enable_if<QtPrivate::IsCompatibleCharType<Char>::value, bool>::type;
98
99 template <typename Pointer>
100 using if_compatible_pointer = typename std::enable_if<QtPrivate::IsCompatiblePointer<Pointer>::value, bool>::type;
101
102 template <typename T>
103 using if_compatible_qstring_like = typename std::enable_if<std::is_same<T, QString>::value, bool>::type;
104
105 template <typename T>
107
108 template <typename Char>
109 static constexpr qsizetype lengthHelperPointer(const Char *str) noexcept
110 {
111 if (q20::is_constant_evaluated())
112 return QtPrivate::lengthHelperPointer(str);
113 return QtPrivate::qustrlen(reinterpret_cast<const char16_t *>(str));
114 }
115 static qsizetype lengthHelperPointer(const QChar *str) noexcept
116 {
117 return QtPrivate::qustrlen(reinterpret_cast<const char16_t *>(str));
118 }
119
120 template <typename Char>
121 static const storage_type *castHelper(const Char *str) noexcept
122 { return reinterpret_cast<const storage_type*>(str); }
123 static constexpr const storage_type *castHelper(const storage_type *str) noexcept
124 { return str; }
125
126public:
127 constexpr QStringView() noexcept {}
128 constexpr QStringView(std::nullptr_t) noexcept
129 : QStringView() {}
130
131 template <typename Char, if_compatible_char<Char> = true>
132 constexpr QStringView(const Char *str, qsizetype len)
133#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED)
135 m_size((Q_ASSERT(len >= 0), Q_ASSERT(str || !len), len))
136#else
137 : m_size((Q_ASSERT(len >= 0), Q_ASSERT(str || !len), len)),
138 m_data(castHelper(str))
139#endif
140 {}
141
142 template <typename Char, if_compatible_char<Char> = true>
143 constexpr QStringView(const Char *f, const Char *l)
144 : QStringView(f, l - f) {}
145
146#ifdef Q_QDOC
147 template <typename Char, size_t N>
148 constexpr QStringView(const Char (&array)[N]) noexcept;
149
150 template <typename Char>
151 constexpr QStringView(const Char *str) noexcept;
152#else
153
154 template <typename Pointer, if_compatible_pointer<Pointer> = true>
155 constexpr QStringView(const Pointer &str) noexcept
156 : QStringView(str, str ? lengthHelperPointer(str) : 0) {}
157#endif
158
159#ifdef Q_QDOC
160 QStringView(const QString &str) noexcept;
161#else
162 template <typename String, if_compatible_qstring_like<String> = true>
163 QStringView(const String &str) noexcept
164 : QStringView{str.begin(), str.size()} {}
165#endif
166
167 template <typename Container, if_compatible_container<Container> = true>
170
171 template <typename Char, size_t Size, if_compatible_char<Char> = true>
172 [[nodiscard]] constexpr static QStringView fromArray(const Char (&string)[Size]) noexcept
173 { return QStringView(string, Size); }
174
175 [[nodiscard]] inline QString toString() const; // defined in qstring.h
176#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
177 // defined in qcore_foundation.mm
180#endif
181
182 [[nodiscard]] constexpr qsizetype size() const noexcept { return m_size; }
183 [[nodiscard]] const_pointer data() const noexcept { return reinterpret_cast<const_pointer>(m_data); }
184 [[nodiscard]] const_pointer constData() const noexcept { return data(); }
185 [[nodiscard]] constexpr const storage_type *utf16() const noexcept { return m_data; }
186
187 [[nodiscard]] constexpr QChar operator[](qsizetype n) const
188 { verify(n, 1); return QChar(m_data[n]); }
189
190 //
191 // QString API
192 //
193
194 template <typename...Args>
195 [[nodiscard]] inline QString arg(Args &&...args) const; // defined in qstring.h
196
197 [[nodiscard]] QByteArray toLatin1() const { return QtPrivate::convertToLatin1(*this); }
198 [[nodiscard]] QByteArray toUtf8() const { return QtPrivate::convertToUtf8(*this); }
199 [[nodiscard]] QByteArray toLocal8Bit() const { return QtPrivate::convertToLocal8Bit(*this); }
200 [[nodiscard]] inline QList<uint> toUcs4() const; // defined in qlist.h ### Qt 7 char32_t
201
202 [[nodiscard]] constexpr QChar at(qsizetype n) const noexcept { return (*this)[n]; }
203
204 [[nodiscard]] constexpr QStringView mid(qsizetype pos, qsizetype n = -1) const noexcept
205 {
206 using namespace QtPrivate;
207 auto result = QContainerImplHelper::mid(size(), &pos, &n);
208 return result == QContainerImplHelper::Null ? QStringView() : QStringView(m_data + pos, n);
209 }
210 [[nodiscard]] constexpr QStringView left(qsizetype n) const noexcept
211 {
212 if (size_t(n) >= size_t(size()))
213 n = size();
214 return QStringView(m_data, n);
215 }
216 [[nodiscard]] constexpr QStringView right(qsizetype n) const noexcept
217 {
218 if (size_t(n) >= size_t(size()))
219 n = size();
220 return QStringView(m_data + m_size - n, n);
221 }
222
223 [[nodiscard]] constexpr QStringView first(qsizetype n) const noexcept
224 { verify(0, n); return sliced(0, n); }
225 [[nodiscard]] constexpr QStringView last(qsizetype n) const noexcept
226 { verify(0, n); return sliced(size() - n, n); }
227 [[nodiscard]] constexpr QStringView sliced(qsizetype pos) const noexcept
228 { verify(pos, 0); return QStringView(m_data + pos, size() - pos); }
229 [[nodiscard]] constexpr QStringView sliced(qsizetype pos, qsizetype n) const noexcept
230 { verify(pos, n); return QStringView(m_data + pos, n); }
231 [[nodiscard]] constexpr QStringView chopped(qsizetype n) const noexcept
232 { verify(0, n); return sliced(0, m_size - n); }
233
234 constexpr void truncate(qsizetype n) noexcept
235 { verify(0, n); ; m_size = n; }
236 constexpr void chop(qsizetype n) noexcept
237 { verify(0, n); m_size -= n; }
238
239 [[nodiscard]] QStringView trimmed() const noexcept { return QtPrivate::trimmed(*this); }
240
241 constexpr QStringView &slice(qsizetype pos)
242 { *this = sliced(pos); return *this; }
243 constexpr QStringView &slice(qsizetype pos, qsizetype n)
244 { *this = sliced(pos, n); return *this; }
245
246 template <typename Needle, typename...Flags>
247 [[nodiscard]] constexpr inline auto tokenize(Needle &&needle, Flags...flags) const
248 noexcept(noexcept(qTokenize(std::declval<const QStringView&>(), std::forward<Needle>(needle), flags...)))
249 -> decltype(qTokenize(*this, std::forward<Needle>(needle), flags...))
250 { return qTokenize(*this, std::forward<Needle>(needle), flags...); }
251
252 [[nodiscard]] int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
253 { return QtPrivate::compareStrings(*this, other, cs); }
254 [[nodiscard]] inline int compare(QLatin1StringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
255 [[nodiscard]] inline int compare(QUtf8StringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
256 [[nodiscard]] constexpr int compare(QChar c) const noexcept
257 { return size() >= 1 ? compare_single_char_helper(*utf16() - c.unicode()) : -1; }
258 [[nodiscard]] int compare(QChar c, Qt::CaseSensitivity cs) const noexcept
259 { return QtPrivate::compareStrings(*this, QStringView(&c, 1), cs); }
260
261 [[nodiscard]] inline int localeAwareCompare(QStringView other) const;
262
263 [[nodiscard]] bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
264 { return QtPrivate::startsWith(*this, s, cs); }
265 [[nodiscard]] inline bool startsWith(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
266 [[nodiscard]] bool startsWith(QChar c) const noexcept
267 { return !empty() && front() == c; }
268 [[nodiscard]] bool startsWith(QChar c, Qt::CaseSensitivity cs) const noexcept
269 { return QtPrivate::startsWith(*this, QStringView(&c, 1), cs); }
270
271 [[nodiscard]] bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
272 { return QtPrivate::endsWith(*this, s, cs); }
273 [[nodiscard]] inline bool endsWith(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
274 [[nodiscard]] bool endsWith(QChar c) const noexcept
275 { return !empty() && back() == c; }
276 [[nodiscard]] bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept
277 { return QtPrivate::endsWith(*this, QStringView(&c, 1), cs); }
278
279 [[nodiscard]] qsizetype indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
280 { return QtPrivate::findString(*this, from, c.unicode(), cs); }
281 [[nodiscard]] qsizetype indexOf(QStringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
282 { return QtPrivate::findString(*this, from, s, cs); }
283 [[nodiscard]] inline qsizetype indexOf(QLatin1StringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
284
285 [[nodiscard]] bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
286 { return indexOf(QStringView(&c, 1), 0, cs) != qsizetype(-1); }
287 [[nodiscard]] bool contains(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
288 { return indexOf(s, 0, cs) != qsizetype(-1); }
289 [[nodiscard]] inline bool contains(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
290
291 [[nodiscard]] qsizetype count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
292 { return QtPrivate::count(*this, c, cs); }
293 [[nodiscard]] qsizetype count(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
294 { return QtPrivate::count(*this, s, cs); }
295 [[nodiscard]] inline qsizetype count(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
296
297 [[nodiscard]] qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
298 { return lastIndexOf(c, -1, cs); }
299 [[nodiscard]] qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
300 { return QtPrivate::lastIndexOf(*this, from, c.unicode(), cs); }
301 [[nodiscard]] qsizetype lastIndexOf(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
302 { return lastIndexOf(s, size(), cs); }
303 [[nodiscard]] qsizetype lastIndexOf(QStringView s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
304 { return QtPrivate::lastIndexOf(*this, from, s, cs); }
305 [[nodiscard]] inline qsizetype lastIndexOf(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
306 [[nodiscard]] inline qsizetype lastIndexOf(QLatin1StringView s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
307
308#if QT_CONFIG(regularexpression)
310 {
311 return QtPrivate::indexOf(*this, re, from, rmatch);
312 }
313#ifdef Q_QDOC
315#else
316 // prevent an ambiguity when called like this: lastIndexOf(re, 0)
317 template <typename T = QRegularExpressionMatch, std::enable_if_t<std::is_same_v<T, QRegularExpressionMatch>, bool> = false>
318 [[nodiscard]] qsizetype lastIndexOf(const QRegularExpression &re, T *rmatch = nullptr) const
319 {
320 return QtPrivate::lastIndexOf(*this, re, size(), rmatch);
321 }
322#endif
324 {
325 return QtPrivate::lastIndexOf(*this, re, from, rmatch);
326 }
327 [[nodiscard]] bool contains(const QRegularExpression &re, QRegularExpressionMatch *rmatch = nullptr) const
328 {
329 return QtPrivate::contains(*this, re, rmatch);
330 }
332 {
333 return QtPrivate::count(*this, re);
334 }
335#endif
336
337 [[nodiscard]] bool isRightToLeft() const noexcept
338 { return QtPrivate::isRightToLeft(*this); }
339 [[nodiscard]] bool isValidUtf16() const noexcept
340 { return QtPrivate::isValidUtf16(*this); }
341
342 [[nodiscard]] bool isUpper() const noexcept
343 { return QtPrivate::isUpper(*this); }
344 [[nodiscard]] bool isLower() const noexcept
345 { return QtPrivate::isLower(*this); }
346
347 [[nodiscard]] inline short toShort(bool *ok = nullptr, int base = 10) const;
348 [[nodiscard]] inline ushort toUShort(bool *ok = nullptr, int base = 10) const;
349 [[nodiscard]] inline int toInt(bool *ok = nullptr, int base = 10) const;
350 [[nodiscard]] inline uint toUInt(bool *ok = nullptr, int base = 10) const;
351 [[nodiscard]] inline long toLong(bool *ok = nullptr, int base = 10) const;
352 [[nodiscard]] inline ulong toULong(bool *ok = nullptr, int base = 10) const;
353 [[nodiscard]] inline qlonglong toLongLong(bool *ok = nullptr, int base = 10) const;
354 [[nodiscard]] inline qulonglong toULongLong(bool *ok = nullptr, int base = 10) const;
355 [[nodiscard]] Q_CORE_EXPORT float toFloat(bool *ok = nullptr) const;
356 [[nodiscard]] Q_CORE_EXPORT double toDouble(bool *ok = nullptr) const;
357
358 [[nodiscard]] inline qsizetype toWCharArray(wchar_t *array) const; // defined in qstring.h
359
360
361 [[nodiscard]] Q_CORE_EXPORT
368
369#if QT_CONFIG(regularexpression)
373#endif
374
375 // QStringView <> QStringView
376 friend bool comparesEqual(const QStringView &lhs, const QStringView &rhs) noexcept
377 { return lhs.size() == rhs.size() && QtPrivate::equalStrings(lhs, rhs); }
378 friend Qt::strong_ordering
379 compareThreeWay(const QStringView &lhs, const QStringView &rhs) noexcept
380 {
381 const int res = QtPrivate::compareStrings(lhs, rhs);
382 return Qt::compareThreeWay(res, 0);
383 }
385
386 // QStringView <> QChar
387 friend bool comparesEqual(const QStringView &lhs, QChar rhs) noexcept
388 { return lhs.size() == 1 && lhs[0] == rhs; }
390 { return compareThreeWay(lhs, QStringView(&rhs, 1)); }
392
393 //
394 // STL compatibility API:
395 //
396 [[nodiscard]] const_iterator begin() const noexcept { return data(); }
397 [[nodiscard]] const_iterator end() const noexcept { return data() + size(); }
398 [[nodiscard]] const_iterator cbegin() const noexcept { return begin(); }
399 [[nodiscard]] const_iterator cend() const noexcept { return end(); }
402 [[nodiscard]] const_reverse_iterator crbegin() const noexcept { return rbegin(); }
403 [[nodiscard]] const_reverse_iterator crend() const noexcept { return rend(); }
404
405 [[nodiscard]] constexpr bool empty() const noexcept { return size() == 0; }
406 [[nodiscard]] constexpr QChar front() const { return Q_ASSERT(!empty()), QChar(m_data[0]); }
407 [[nodiscard]] constexpr QChar back() const { return Q_ASSERT(!empty()), QChar(m_data[m_size - 1]); }
408
411
412 [[nodiscard]] constexpr qsizetype max_size() const noexcept { return maxSize(); }
413
414 //
415 // Qt compatibility API:
416 //
417 [[nodiscard]] const_iterator constBegin() const noexcept { return begin(); }
418 [[nodiscard]] const_iterator constEnd() const noexcept { return end(); }
419 [[nodiscard]] constexpr bool isNull() const noexcept { return !m_data; }
420 [[nodiscard]] constexpr bool isEmpty() const noexcept { return empty(); }
421 [[nodiscard]] constexpr qsizetype length() const noexcept
422 { return size(); }
423 [[nodiscard]] constexpr QChar first() const { return front(); }
424 [[nodiscard]] constexpr QChar last() const { return back(); }
425
426 [[nodiscard]] static constexpr qsizetype maxSize() noexcept
427 {
428 // -1 to deal with the pointer one-past-the-end;
429 return QtPrivate::MaxAllocSize / sizeof(storage_type) - 1;
430 }
431private:
432#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED)
433 const storage_type *m_data = nullptr;
434 qsizetype m_size = 0;
435#else
436 qsizetype m_size = 0;
437 const storage_type *m_data = nullptr;
438#endif
439
440 Q_ALWAYS_INLINE constexpr void verify([[maybe_unused]] qsizetype pos = 0,
441 [[maybe_unused]] qsizetype n = 1) const
442 {
443 Q_ASSERT(pos >= 0);
444 Q_ASSERT(pos <= size());
445 Q_ASSERT(n >= 0);
446 Q_ASSERT(n <= size() - pos);
447 }
448
449 constexpr int compare_single_char_helper(int diff) const noexcept
450 { return diff ? diff : size() > 1 ? 1 : 0; }
451
452 Q_CORE_EXPORT static bool equal_helper(QStringView sv, const char *data, qsizetype len);
453 Q_CORE_EXPORT static int compare_helper(QStringView sv, const char *data, qsizetype len);
454
455#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
456 friend bool comparesEqual(const QStringView &lhs, const QByteArrayView &rhs) noexcept
457 { return equal_helper(lhs, rhs.data(), rhs.size()); }
458 friend Qt::strong_ordering
459 compareThreeWay(const QStringView &lhs, const QByteArrayView &rhs) noexcept
460 {
461 const int res = compare_helper(lhs, rhs.data(), rhs.size());
462 return Qt::compareThreeWay(res, 0);
463 }
464 Q_DECLARE_STRONGLY_ORDERED(QStringView, QByteArrayView, QT_ASCII_CAST_WARN)
467#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
468};
470
471template <typename QStringLike, typename std::enable_if<
472 std::is_same<QStringLike, QString>::value,
473 bool>::type = true>
474inline QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept
475{ return QStringView(s.begin(), s.size()); }
476
477// QChar inline functions:
478
479[[nodiscard]] constexpr auto QChar::fromUcs4(char32_t c) noexcept
480{
481 struct R {
482 char16_t chars[2];
483 [[nodiscard]] constexpr operator QStringView() const noexcept { return {begin(), end()}; }
484 [[nodiscard]] constexpr qsizetype size() const noexcept { return chars[1] ? 2 : 1; }
485 [[nodiscard]] constexpr const char16_t *begin() const noexcept { return chars; }
486 [[nodiscard]] constexpr const char16_t *end() const noexcept { return begin() + size(); }
487 };
488 return requiresSurrogates(c) ? R{{QChar::highSurrogate(c),
489 QChar::lowSurrogate(c)}} :
490 R{{char16_t(c), u'\0'}} ;
491}
492
493qsizetype QtPrivate::findString(QStringView str, qsizetype from, QChar ch, Qt::CaseSensitivity cs) noexcept
494{
495 if (from < -str.size()) // from < 0 && abs(from) > str.size(), avoiding overflow
496 return -1;
497 if (from < 0)
498 from = qMax(from + str.size(), qsizetype(0));
499 if (from < str.size()) {
500 const char16_t *s = str.utf16();
501 char16_t c = ch.unicode();
502 const char16_t *n = s + from;
503 const char16_t *e = s + str.size();
504 if (cs == Qt::CaseSensitive)
505 n = qustrchr(QStringView(n, e), c);
506 else
507 n = qustrcasechr(QStringView(n, e), c);
508 if (n != e)
509 return n - s;
510 }
511 return -1;
512}
513
514QT_END_NAMESPACE
515
516#endif /* QSTRINGVIEW_H */
\inmodule QtCore
Definition qstringview.h:79
QString arg(Args &&...args) const
bool isLower() const noexcept
bool startsWith(QChar c) const noexcept
const QChar value_type
Alias for {const QChar}.
Definition qstringview.h:82
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:7958
bool isRightToLeft() const noexcept
constexpr QStringView(std::nullptr_t) noexcept
Constructs a null string view.
Q_CORE_EXPORT float toFloat(bool *ok=nullptr) const
Returns the string view converted to a float value.
Definition qstring.cpp:8004
constexpr QStringView & slice(qsizetype pos)
bool startsWith(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QStringView() noexcept
Constructs a null string view.
qsizetype count(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
int localeAwareCompare(QStringView other) const
Definition qstring.h:1520
friend bool comparesEqual(const QStringView &lhs, const QStringView &rhs) noexcept
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:1147
constexpr int compare(QChar c) const noexcept
constexpr QStringView(const Char *str, qsizetype len)
constexpr const storage_type * utf16() const noexcept
qsizetype size_type
Alias for qsizetype.
Definition qstringview.h:84
value_type * const_pointer
Alias for {value_type *}.
Definition qstringview.h:88
value_type & const_reference
Alias for {value_type &}.
Definition qstringview.h:86
constexpr QStringView right(qsizetype n) const noexcept
qsizetype count(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QStringView & slice(qsizetype pos, qsizetype n)
value_type & reference
Alias for {value_type &}.
Definition qstringview.h:85
const_pointer data() const noexcept
qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
const_pointer constData() const 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)...
QList< uint > toUcs4() const
Returns a UCS-4/UTF-32 representation of the string view as a QList<uint>.
Definition qlist.h:1021
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
QByteArray toUtf8() const
Returns a UTF-8 representation of the string view as a QByteArray.
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
constexpr QStringView last(qsizetype n) const noexcept
constexpr void truncate(qsizetype n) noexcept
Truncates this string view to length length.
constexpr QStringView sliced(qsizetype pos, qsizetype n) const noexcept
value_type * pointer
Alias for {value_type *}.
Definition qstringview.h:87
QString toString() const
Returns a deep copy of this string view's data as a QString.
Definition qstring.h:1130
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:1141
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:1133
friend Qt::strong_ordering compareThreeWay(const QStringView &lhs, const QByteArrayView &rhs) noexcept
constexpr QStringView first(qsizetype n) const noexcept
pointer iterator
This typedef provides an STL-style const iterator for QStringView.
Definition qstringview.h:90
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:1139
bool isValidUtf16() const noexcept
constexpr QChar operator[](qsizetype n) const
Returns the character at position n in this string view.
int compare(QStringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
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...
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:1135
constexpr QStringView(const Char *f, const Char *l)
Constructs a string view on first with length (last - first).
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:1145
bool endsWith(QLatin1StringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition qstring.h:76
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...))
const_pointer const_iterator
This typedef provides an STL-style const iterator for QStringView.
Definition qstringview.h:91
constexpr QStringView left(qsizetype n) const noexcept
qsizetype indexOf(QStringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QStringView chopped(qsizetype n) const noexcept
Returns the substring of length size() - length starting at the beginning of this object.
bool isUpper() const noexcept
qsizetype toWCharArray(wchar_t *array) const
Definition qstring.h:1305
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
QStringView trimmed() const noexcept
Strips leading and trailing whitespace and returns the result.
std::reverse_iterator< const_iterator > const_reverse_iterator
This typedef provides an STL-style const reverse iterator for QStringView.
Definition qstringview.h:93
bool startsWith(QLatin1StringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition qstring.h:74
std::ptrdiff_t difference_type
Alias for {std::ptrdiff_t}.
Definition qstringview.h:83
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
friend bool comparesEqual(const QStringView &lhs, const QByteArrayView &rhs) noexcept
constexpr void chop(qsizetype n) noexcept
Truncates this string view by length characters.
constexpr QChar at(qsizetype n) const noexcept
Returns the character at position n in this 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:1143
qsizetype lastIndexOf(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr QStringView sliced(qsizetype pos) const noexcept
int compare(QLatin1StringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition qstring.h:72
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:1137
friend Qt::strong_ordering compareThreeWay(const QStringView &lhs, const QStringView &rhs) noexcept
constexpr QStringView(const Pointer &str) noexcept
char16_t storage_type
Alias for {char16_t}.
Definition qstringview.h:81
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
Definition qcompare.h:24
QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept
Q_DECLARE_TYPEINFO(QStringView, Q_PRIMITIVE_TYPE)