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
qstring.h
Go to the documentation of this file.
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// Qt-Security score:critical reason:data-parser
7
8#ifndef QSTRING_H
9#define QSTRING_H
10
11#if defined(QT_NO_CAST_FROM_ASCII) && defined(QT_RESTRICTED_CAST_FROM_ASCII)
12#error QT_NO_CAST_FROM_ASCII and QT_RESTRICTED_CAST_FROM_ASCII must not be defined at the same time
13#endif
14
15#include <QtCore/qchar.h>
16#include <QtCore/qcompare.h>
17#include <QtCore/qbytearray.h>
18#include <QtCore/qbytearrayview.h>
19#include <QtCore/qarraydata.h>
20#include <QtCore/qarraydatapointer.h>
21#include <QtCore/qlatin1stringview.h>
22#include <QtCore/qnamespace.h>
23#include <QtCore/qstringalgorithms.h>
24#include <QtCore/qanystringview.h>
25#include <QtCore/qstringtokenizer.h>
26
27#include <string>
28#include <iterator>
29#include <QtCore/q20memory.h>
30#include <string_view>
31#include <QtCore/q23type_traits.h>
32
33#include <stdarg.h>
34
35#ifdef truncate
36#error qstring.h must be included before any header file that defines truncate
37#endif
38
39#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
40Q_FORWARD_DECLARE_CF_TYPE(CFString);
41Q_FORWARD_DECLARE_OBJC_CLASS(NSString);
42#endif
43
44class tst_QString;
45
46QT_BEGIN_NAMESPACE
47
48class qfloat16;
49class QRegularExpression;
50class QRegularExpressionMatch;
51class QString;
52
53namespace QtPrivate {
54template <bool...B> class BoolList;
55
56template <typename Char>
58 std::is_same<Char, char32_t>;
59template <typename Char>
62
63// hack to work around ushort/uchar etc being treated as both characters and
64// integers, depending on which Qt API you look at:
65template <typename T> struct treat_as_integral_arg : std::false_type {};
66template <> struct treat_as_integral_arg<unsigned short> : std::true_type {};
67template <> struct treat_as_integral_arg< signed short> : std::true_type {};
68template <> struct treat_as_integral_arg<unsigned char> : std::true_type {};
69template <> struct treat_as_integral_arg< signed char> : std::true_type {};
70}
71
72// Qt 4.x compatibility
73
74//
75// QLatin1StringView inline implementations
76//
77constexpr bool QtPrivate::isLatin1(QLatin1StringView) noexcept
78{ return true; }
79
80//
81// QStringView members that require QLatin1StringView:
82//
83int QStringView::compare(QLatin1StringView s, Qt::CaseSensitivity cs) const noexcept
84{
85#if (!defined(Q_CC_GNU_ONLY) || Q_CC_GNU_ONLY >= 1700) && __has_builtin(__builtin_constant_p)
86 if (__builtin_constant_p(s.m_size) && s.size() == 1)
87 return compare(s.front(), cs);
88#endif
89 return QtPrivate::compareStrings(*this, s, cs);
90}
91bool QStringView::startsWith(QLatin1StringView s, Qt::CaseSensitivity cs) const noexcept
92{
93#if (!defined(Q_CC_GNU_ONLY) || Q_CC_GNU_ONLY >= 1700) && __has_builtin(__builtin_constant_p)
94 if (__builtin_constant_p(s.m_size) && s.size() == 1)
95 return startsWith(s.front(), cs);
96#endif
97 return QtPrivate::startsWith(*this, s, cs);
98}
99bool QStringView::endsWith(QLatin1StringView s, Qt::CaseSensitivity cs) const noexcept
100{
101#if (!defined(Q_CC_GNU_ONLY) || Q_CC_GNU_ONLY >= 1700) && __has_builtin(__builtin_constant_p)
102 if (__builtin_constant_p(s.m_size) && s.size() == 1)
103 return endsWith(s.front(), cs);
104#endif
105 return QtPrivate::endsWith(*this, s, cs);
106}
107qsizetype QStringView::indexOf(QLatin1StringView s, qsizetype from, Qt::CaseSensitivity cs) const noexcept
108{
109#if (!defined(Q_CC_GNU_ONLY) || Q_CC_GNU_ONLY >= 1700) && __has_builtin(__builtin_constant_p)
110 if (__builtin_constant_p(s.m_size) && s.size() == 1)
111 return indexOf(s.front(), from, cs);
112#endif
113 return QtPrivate::findString(*this, from, s, cs);
114}
115bool QStringView::contains(QLatin1StringView s, Qt::CaseSensitivity cs) const noexcept
116{ return indexOf(s, 0, cs) != qsizetype(-1); }
117qsizetype QStringView::lastIndexOf(QLatin1StringView s, Qt::CaseSensitivity cs) const noexcept
118{ return lastIndexOf(s, size(), cs); }
119qsizetype QStringView::lastIndexOf(QLatin1StringView s, qsizetype from, Qt::CaseSensitivity cs) const noexcept
120{
121#if (!defined(Q_CC_GNU_ONLY) || Q_CC_GNU_ONLY >= 1700) && __has_builtin(__builtin_constant_p)
122 if (__builtin_constant_p(s.m_size) && s.size() == 1)
123 return lastIndexOf(s.front(), from, cs);
124#endif
125 return QtPrivate::lastIndexOf(*this, from, s, cs);
126}
127qsizetype QStringView::count(QLatin1StringView s, Qt::CaseSensitivity cs) const
128{
129#if (!defined(Q_CC_GNU_ONLY) || Q_CC_GNU_ONLY >= 1700) && __has_builtin(__builtin_constant_p)
130 if (__builtin_constant_p(s.m_size) && s.size() == 1)
131 return count(s.front(), cs);
132#endif
133 return QtPrivate::count(*this, s, cs);
134}
135
136//
137// QAnyStringView members that require QLatin1StringView
138//
139
140constexpr QAnyStringView::QAnyStringView(QLatin1StringView str) noexcept
141 : m_data{str.data()}, m_size{size_t(str.size() << SizeShift) | Tag::Latin1} {}
142
143constexpr QLatin1StringView QAnyStringView::asLatin1StringView() const
144{
145 Q_ASSERT(isLatin1());
146 return {m_data_utf8, size()};
147}
148
149
150template <typename Visitor>
151constexpr decltype(auto) QAnyStringView::visit(Visitor &&v) const
152{
153 if (isUtf16())
154 return std::forward<Visitor>(v)(asStringView());
155 else if (isLatin1())
156 return std::forward<Visitor>(v)(asLatin1StringView());
157 else
158 return std::forward<Visitor>(v)(asUtf8StringView());
159}
160
161//
162// QAnyStringView members that require QAnyStringView::visit()
163//
164
165constexpr QChar QAnyStringView::front() const
166{
167 return visit([] (auto that) { return QAnyStringView::toQChar(that.front()); });
168}
169constexpr QChar QAnyStringView::back() const
170{
171 return visit([] (auto that) { return QAnyStringView::toQChar(that.back()); });
172}
173
174using QStringPrivate = QArrayDataPointer<char16_t>;
175
176class Q_CORE_EXPORT QString
177{
178 typedef QTypedArrayData<char16_t> Data;
179
180 friend class ::tst_QString;
181
182 template <typename Iterator>
183 static constexpr bool is_contiguous_iterator_v =
184 // Can't use contiguous_iterator_tag here, as STL impls can't agree on feature macro.
185 // To avoid differences in C++20 and C++17 builds, treat only pointers as contiguous
186 // for now:
187 // std::contiguous_iterator<Iterator>;
188 std::is_pointer_v<Iterator>;
189
190 template <typename Char>
191 using is_compatible_char_helper = std::disjunction<
192 QtPrivate::IsCompatibleCharType<Char>,
193 QtPrivate::IsCompatibleChar32Type<Char>,
194 QtPrivate::IsCompatibleChar8Type<Char>,
195 std::is_same<Char, QLatin1Char> // special case
196 >;
197
198 template <typename T>
199 using is_string_like = std::conjunction<
200 std::negation<QtPrivate::treat_as_integral_arg<std::remove_cv_t<T>>>, // used to be integral, so keep
201 std::is_convertible<T, QAnyStringView>
202 >;
203
204 template <typename T>
205 using if_string_like = std::enable_if_t<is_string_like<T>::value, bool>;
206
207 template <typename T>
208 using is_floating_point_like = std::disjunction<
209 #if QFLOAT16_IS_NATIVE
210 std::is_same<q20::remove_cvref_t<T>, QtPrivate::NativeFloat16Type>,
211 #endif
212 std::is_same<q20::remove_cvref_t<T>, qfloat16>,
213 std::is_floating_point<T>
214 >;
215
216 template <typename T>
217 using if_floating_point = std::enable_if_t<is_floating_point_like<T>::value, bool>;
218
219 template <typename T>
220 using if_integral_non_char = std::enable_if_t<std::conjunction_v<
221 std::disjunction<
222 std::is_integral<T>,
223 std::conjunction<
224 std::is_enum<T>, // (unscoped) enums yes,
225 std::negation<q23::is_scoped_enum<T>> // but not scoped ones
226 >
227 >,
228 std::negation<is_floating_point_like<T>>, // has its own overload
229 std::negation<is_string_like<T>> // ditto
230 >, bool>;
231
232 template <typename Iterator>
233 static constexpr bool is_compatible_iterator_v = std::conjunction_v<
234 std::is_convertible<
235 typename std::iterator_traits<Iterator>::iterator_category,
236 std::input_iterator_tag
237 >,
238 is_compatible_char_helper<typename std::iterator_traits<Iterator>::value_type>
239 >;
240
241 template <typename Iterator>
242 using if_compatible_iterator = std::enable_if_t<is_compatible_iterator_v<Iterator>, bool>;
243
244public:
245 typedef QStringPrivate DataPointer;
246
247 constexpr QString() noexcept = default;
248 explicit QString(const QChar *unicode, qsizetype size = -1);
249 QString(QChar c);
250 QString(qsizetype size, QChar c);
251 inline QString(QLatin1StringView latin1);
252 explicit QString(QStringView sv) : QString(sv.data(), sv.size()) {}
253#if defined(__cpp_char8_t) || defined(Q_QDOC)
254 Q_WEAK_OVERLOAD
255 inline QString(const char8_t *str)
256 : QString(fromUtf8(str))
257 {}
258#endif
259 Q_DECL_CONSTEXPR_DTOR QString(const QString &other) noexcept : d(other.d) {}
260#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED)
261 Q_DECL_CONSTEXPR_DTOR ~QString() = default;
262#endif
263 QString &operator=(QChar c);
264 QT_CORE_CONSTEXPR_DTOR_INLINE_SINCE(6, 13)
265 QString &operator=(const QString &) noexcept;
266 QString &operator=(QLatin1StringView latin1);
267 Q_DECL_CONSTEXPR_DTOR QString(QString &&other) noexcept = default;
268 Q_DECL_CONSTEXPR_DTOR
269 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QString)
270 constexpr void swap(QString &other) noexcept { d.swap(other.d); }
271
272 static constexpr qsizetype maxSize() noexcept
273 {
274 // -1 to deal with the NUL terminator
275 return Data::maxSize() - 1;
276 }
277 constexpr qsizetype size() const noexcept
278 {
279 constexpr size_t MaxSize = maxSize();
280 Q_PRESUME(size_t(d.size) <= MaxSize);
281 return d.size;
282 }
283#if QT_DEPRECATED_SINCE(6, 4)
284 QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.")
285 constexpr qsizetype count() const { return size(); }
286#endif
287 constexpr qsizetype length() const noexcept { return size(); }
288 constexpr bool isEmpty() const noexcept { return size() == 0; }
289 void resize(qsizetype size);
290 void resize(qsizetype size, QChar fillChar);
291 void resizeForOverwrite(qsizetype size);
292
293 QString &fill(QChar ch);
294 QString &fill(QChar c, qsizetype size);
295 void truncate(qsizetype pos);
296 void chop(qsizetype n);
297
298 QString &slice(qsizetype pos)
299 { verify(pos, 0); return remove(0, pos); }
300 QString &slice(qsizetype pos, qsizetype n)
301 {
302 verify(pos, n);
303 if (isNull())
304 return *this;
305 resize(pos + n);
306 return remove(0, pos);
307 }
308
309 inline qsizetype capacity() const;
310 inline void reserve(qsizetype size);
311 inline void squeeze();
312
313 inline const QChar *unicode() const;
314 inline QChar *data();
315 inline const QChar *data() const;
316 inline const QChar *constData() const;
317
318 inline void detach();
319 inline bool isDetached() const;
320 inline bool isSharedWith(const QString &other) const { return d.isSharedWith(other.d); }
321 Q_DECL_CONSTEXPR_DTOR void clear();
322
323 constexpr inline const QChar at(qsizetype i) const;
324 constexpr inline const QChar operator[](qsizetype i) const;
325 [[nodiscard]] inline QChar &operator[](qsizetype i);
326
327 [[nodiscard]] constexpr inline QChar front() const { return at(0); }
328 [[nodiscard]] inline QChar &front();
329 [[nodiscard]] constexpr inline QChar back() const { return at(size() - 1); }
330 [[nodiscard]] inline QChar &back();
331
332#if QT_CORE_REMOVED_SINCE(6, 9)
333 [[nodiscard]] QString arg(qlonglong a, int fieldwidth=0, int base=10,
334 QChar fillChar = u' ') const;
335 [[nodiscard]] QString arg(qulonglong a, int fieldwidth=0, int base=10,
336 QChar fillChar = u' ') const;
337 [[nodiscard]] inline QString arg(long a, int fieldwidth=0, int base=10,
338 QChar fillChar = u' ') const;
339 [[nodiscard]] inline QString arg(ulong a, int fieldwidth=0, int base=10,
340 QChar fillChar = u' ') const;
341 [[nodiscard]] inline QString arg(int a, int fieldWidth = 0, int base = 10,
342 QChar fillChar = u' ') const;
343 [[nodiscard]] inline QString arg(uint a, int fieldWidth = 0, int base = 10,
344 QChar fillChar = u' ') const;
345 [[nodiscard]] inline QString arg(short a, int fieldWidth = 0, int base = 10,
346 QChar fillChar = u' ') const;
347 [[nodiscard]] inline QString arg(ushort a, int fieldWidth = 0, int base = 10,
348 QChar fillChar = u' ') const;
349 [[nodiscard]] QString arg(double a, int fieldWidth = 0, char format = 'g', int precision = -1,
350 QChar fillChar = u' ') const;
351 [[nodiscard]] QString arg(char a, int fieldWidth = 0,
352 QChar fillChar = u' ') const;
353 [[nodiscard]] QString arg(QChar a, int fieldWidth = 0,
354 QChar fillChar = u' ') const;
355 [[nodiscard]] QString arg(const QString &a, int fieldWidth = 0,
356 QChar fillChar = u' ') const;
357 [[nodiscard]] QString arg(QStringView a, int fieldWidth = 0,
358 QChar fillChar = u' ') const;
359 [[nodiscard]] QString arg(QLatin1StringView a, int fieldWidth = 0,
360 QChar fillChar = u' ') const;
361#endif
362
363 template <typename T, if_integral_non_char<T> = true>
364 [[nodiscard]] QString arg(T a, int fieldWidth = 0, int base = 10,
365 QChar fillChar = u' ') const
366 {
367 using U = typename std::conditional<
368 // underlying_type_t<non-enum> is UB in C++17/SFINAE in C++20, so wrap:
369 std::is_enum_v<T>, std::underlying_type<T>,
370 q20::type_identity<T>
371 >::type::type;
372 if constexpr (std::is_signed_v<U>)
373 return arg_impl(qlonglong(a), fieldWidth, base, fillChar);
374 else
375 return arg_impl(qulonglong(a), fieldWidth, base, fillChar);
376 }
377
378 template <typename T, if_floating_point<T> = true>
379 [[nodiscard]] QString arg(T a, int fieldWidth = 0, char format = 'g', int precision = -1,
380 QChar fillChar = u' ') const
381 { return arg_impl(double(a), fieldWidth, format, precision, fillChar); }
382
383 template <typename T, if_string_like<T> = true>
384 [[nodiscard]] QString arg(const T &a, int fieldWidth = 0, QChar fillChar = u' ') const
385 { return arg_impl(QAnyStringView(a), fieldWidth, fillChar); }
386
387private:
388 QString arg_impl(qlonglong a, int fieldwidth, int base, QChar fillChar) const;
389 QString arg_impl(qulonglong a, int fieldwidth, int base, QChar fillChar) const;
390 QString arg_impl(double a, int fieldWidth, char format, int precision, QChar fillChar) const;
391 QString arg_impl(QAnyStringView a, int fieldWidth, QChar fillChar) const;
392
393public:
394 template <typename...Args>
395 [[nodiscard]]
396#ifdef Q_QDOC
397 QString
398#else
399 typename std::enable_if<
400 sizeof...(Args) >= 2 && std::conjunction_v<is_string_like<Args>...>,
401 QString
402 >::type
403#endif
404 arg(Args &&...args) const
405 { return qToStringViewIgnoringNull(*this).arg(std::forward<Args>(args)...); }
406
407 static QString vasprintf(const char *format, va_list ap) Q_ATTRIBUTE_FORMAT_PRINTF(1, 0);
408 static QString asprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(1, 2);
409
410 [[nodiscard]] QT_CORE_INLINE_SINCE(6, 8)
411 qsizetype indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
412 [[nodiscard]] QT_CORE_INLINE_SINCE(6, 12)
413 qsizetype indexOf(QLatin1StringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
414 [[nodiscard]] QT_CORE_INLINE_SINCE(6, 12)
415 qsizetype indexOf(const QString &s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
416 [[nodiscard]] qsizetype indexOf(QStringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
417 { return QStringView(begin(), size()).indexOf(s, from, cs); }
418 [[nodiscard]] qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
419 { return lastIndexOf(c, -1, cs); }
420 [[nodiscard]] QT_CORE_INLINE_SINCE(6, 8)
421 qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
422 [[nodiscard]] qsizetype lastIndexOf(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
423 { return lastIndexOf(s, size(), cs); }
424 [[nodiscard]] QT_CORE_INLINE_SINCE(6, 12)
425 qsizetype lastIndexOf(QLatin1StringView s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
426 [[nodiscard]] qsizetype lastIndexOf(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
427 { return lastIndexOf(s, size(), cs); }
428 [[nodiscard]] QT_CORE_INLINE_SINCE(6, 12)
429 qsizetype lastIndexOf(const QString &s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
430
431 [[nodiscard]] qsizetype lastIndexOf(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
432 { return lastIndexOf(s, size(), cs); }
433 [[nodiscard]] qsizetype lastIndexOf(QStringView s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
434 { return QStringView(begin(), size()).lastIndexOf(s, from, cs); }
435
436 [[nodiscard]] inline bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
437 [[nodiscard]] inline bool contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
438 [[nodiscard]] inline bool contains(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
439 [[nodiscard]] inline bool contains(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
440 [[nodiscard]] qsizetype count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
441 [[nodiscard]] qsizetype count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
442 [[nodiscard]] qsizetype count(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
443 [[nodiscard]] qsizetype count(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
444 { return QStringView{*this}.count(s, cs); }
445
446#if QT_CONFIG(regularexpression)
447 [[nodiscard]] qsizetype indexOf(const QRegularExpression &re, qsizetype from = 0,
448 QRegularExpressionMatch *rmatch = nullptr) const;
449#ifdef Q_QDOC
450 [[nodiscard]] qsizetype lastIndexOf(const QRegularExpression &re, QRegularExpressionMatch *rmatch = nullptr) const;
451#else
452 // prevent an ambiguity when called like this: lastIndexOf(re, 0)
453 template <typename T = QRegularExpressionMatch, std::enable_if_t<std::is_same_v<T, QRegularExpressionMatch>, bool> = false>
454 [[nodiscard]] qsizetype lastIndexOf(const QRegularExpression &re, T *rmatch = nullptr) const
455 { return lastIndexOf(re, size(), rmatch); }
456#endif
457 [[nodiscard]] qsizetype lastIndexOf(const QRegularExpression &re, qsizetype from,
458 QRegularExpressionMatch *rmatch = nullptr) const;
459 [[nodiscard]] bool contains(const QRegularExpression &re, QRegularExpressionMatch *rmatch = nullptr) const;
460 [[nodiscard]] qsizetype count(const QRegularExpression &re) const;
461#endif
462
463 enum SectionFlag {
464 SectionDefault = 0x00,
465 SectionSkipEmpty = 0x01,
466 SectionIncludeLeadingSep = 0x02,
467 SectionIncludeTrailingSep = 0x04,
468 SectionCaseInsensitiveSeps = 0x08
469 };
470 Q_DECLARE_FLAGS(SectionFlags, SectionFlag)
471
472 [[nodiscard]] inline QString section(QChar sep, qsizetype start, qsizetype end = -1, SectionFlags flags = SectionDefault) const;
473 [[nodiscard]] QString section(const QString &in_sep, qsizetype start, qsizetype end = -1, SectionFlags flags = SectionDefault) const;
474#if QT_CONFIG(regularexpression)
475 [[nodiscard]] QString section(const QRegularExpression &re, qsizetype start, qsizetype end = -1, SectionFlags flags = SectionDefault) const;
476#endif
477
478#if QT_CORE_REMOVED_SINCE(6, 7)
479 QString left(qsizetype n) const;
480 QString right(qsizetype n) const;
481 QString mid(qsizetype position, qsizetype n = -1) const;
482
483 QString first(qsizetype n) const;
484 QString last(qsizetype n) const;
485 QString sliced(qsizetype pos) const;
486 QString sliced(qsizetype pos, qsizetype n) const;
487 QString chopped(qsizetype n) const;
488#else
489 [[nodiscard]] QString left(qsizetype n) const &
490 {
491 if (size_t(n) >= size_t(size()))
492 return *this;
493 return first(n);
494 }
495 [[nodiscard]] QString left(qsizetype n) &&
496 {
497 if (size_t(n) >= size_t(size()))
498 return std::move(*this);
499 return std::move(*this).first(n);
500 }
501 [[nodiscard]] QString right(qsizetype n) const &
502 {
503 if (size_t(n) >= size_t(size()))
504 return *this;
505 return last(n);
506 }
507 [[nodiscard]] QString right(qsizetype n) &&
508 {
509 if (size_t(n) >= size_t(size()))
510 return std::move(*this);
511 return std::move(*this).last(n);
512 }
513 [[nodiscard]] QString mid(qsizetype position, qsizetype n = -1) const &;
514 [[nodiscard]] QString mid(qsizetype position, qsizetype n = -1) &&;
515
516 [[nodiscard]] QString first(qsizetype n) const &
517 { verify(0, n); return sliced(0, n); }
518 [[nodiscard]] QString last(qsizetype n) const &
519 { verify(0, n); return sliced(size() - n, n); }
520 [[nodiscard]] QString sliced(qsizetype pos) const &
521 { verify(pos, 0); return sliced(pos, size() - pos); }
522 [[nodiscard]] QString sliced(qsizetype pos, qsizetype n) const &
523 { verify(pos, n); return QString(begin() + pos, n); }
524 [[nodiscard]] QString chopped(qsizetype n) const &
525 { verify(0, n); return sliced(0, size() - n); }
526
527 [[nodiscard]] QString first(qsizetype n) &&
528 {
529 verify(0, n);
530 resize(n); // may detach and allocate memory
531 return std::move(*this);
532 }
533 [[nodiscard]] QString last(qsizetype n) &&
534 { verify(0, n); return sliced_helper(*this, size() - n, n); }
535 [[nodiscard]] QString sliced(qsizetype pos) &&
536 { verify(pos, 0); return sliced_helper(*this, pos, size() - pos); }
537 [[nodiscard]] QString sliced(qsizetype pos, qsizetype n) &&
538 { verify(pos, n); return sliced_helper(*this, pos, n); }
539 [[nodiscard]] QString chopped(qsizetype n) &&
540 { verify(0, n); chop(n); return std::move(*this); }
541#endif
542 bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
543 [[nodiscard]] bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
544 { return QStringView(begin(), size()).startsWith(s, cs); }
545 bool startsWith(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
546 bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
547
548 bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
549 [[nodiscard]] bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
550 { return QStringView(begin(), size()).endsWith(s, cs); }
551 bool endsWith(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
552 bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
553
554 bool isUpper() const;
555 bool isLower() const;
556
557 [[nodiscard]] QString leftJustified(qsizetype width, QChar fill = u' ', bool trunc = false) const;
558 [[nodiscard]] QString rightJustified(qsizetype width, QChar fill = u' ', bool trunc = false) const;
559
560#if !defined(Q_QDOC)
561 [[nodiscard]] QString toLower() const &
562 { return toLower_helper(*this); }
563 [[nodiscard]] QString toLower() &&
564 { return toLower_helper(*this); }
565 [[nodiscard]] QString toUpper() const &
566 { return toUpper_helper(*this); }
567 [[nodiscard]] QString toUpper() &&
568 { return toUpper_helper(*this); }
569 [[nodiscard]] QString toCaseFolded() const &
570 { return toCaseFolded_helper(*this); }
571 [[nodiscard]] QString toCaseFolded() &&
572 { return toCaseFolded_helper(*this); }
573 [[nodiscard]] QString trimmed() const &
574 { return trimmed_helper(*this); }
575 [[nodiscard]] QString trimmed() &&
576 { return trimmed_helper(*this); }
577 [[nodiscard]] QString simplified() const &
578 { return simplified_helper(*this); }
579 [[nodiscard]] QString simplified() &&
580 { return simplified_helper(*this); }
581#else
582 [[nodiscard]] QString toLower() const;
583 [[nodiscard]] QString toUpper() const;
584 [[nodiscard]] QString toCaseFolded() const;
585 [[nodiscard]] QString trimmed() const;
586 [[nodiscard]] QString simplified() const;
587#endif
588 [[nodiscard]] QString toHtmlEscaped() const;
589
590 QString &insert(qsizetype i, QChar c);
591 QString &insert(qsizetype i, const QChar *uc, qsizetype len);
592 inline QString &insert(qsizetype i, const QString &s) { return insert(i, s.constData(), s.size()); }
593 inline QString &insert(qsizetype i, QStringView v) { return insert(i, v.data(), v.size()); }
594 QString &insert(qsizetype i, QLatin1StringView s);
595 QString &insert(qsizetype i, QUtf8StringView s);
596
597 QString &append(QChar c);
598 QString &append(const QChar *uc, qsizetype len);
599 QString &append(const QString &s);
600 inline QString &append(QStringView v) { return append(v.data(), v.size()); }
601 QString &append(QLatin1StringView s);
602 QString &append(QUtf8StringView s);
603
604 inline QString &prepend(QChar c) { return insert(0, c); }
605 inline QString &prepend(const QChar *uc, qsizetype len) { return insert(0, uc, len); }
606 inline QString &prepend(const QString &s) { return insert(0, s); }
607 inline QString &prepend(QStringView v) { return prepend(v.data(), v.size()); }
608 inline QString &prepend(QLatin1StringView s) { return insert(0, s); }
609 QString &prepend(QUtf8StringView s) { return insert(0, s); }
610
611 QString &assign(QAnyStringView s);
612 inline QString &assign(qsizetype n, QChar c)
613 {
614 Q_PRE(n >= 0);
615 resizeForOverwrite(n);
616 return fill(c);
617 }
618 template <typename InputIterator, if_compatible_iterator<InputIterator> = true>
619 QString &assign(InputIterator first, InputIterator last)
620 {
621 using V = typename std::iterator_traits<InputIterator>::value_type;
622 constexpr bool IsL1C = std::is_same_v<std::remove_cv_t<V>, QLatin1Char>;
623 constexpr bool IsFwdIt = std::is_convertible_v<
624 typename std::iterator_traits<InputIterator>::iterator_category,
625 std::forward_iterator_tag
626 >;
627
628 if constexpr (is_contiguous_iterator_v<InputIterator>) {
629 const auto p = q20::to_address(first);
630 const auto len = qsizetype(last - first);
631 Q_PRE(len >= 0); // cheap, so check
632 if constexpr (IsL1C)
633 return assign(QLatin1StringView(reinterpret_cast<const char*>(p), len));
634 else if constexpr (sizeof(V) == 4)
635 return assign_helper(p, len);
636 else
637 return assign(QAnyStringView(p, len));
638 } else if constexpr (sizeof(V) == 4) { // non-contiguous iterator, feed data piecemeal
639 resize(0);
640 if constexpr (IsFwdIt) {
641 // This can't overflow for [first, last) a valid range:
642 // distance() < [addressable memory] / sizeof(V) - some ε (e.g.: this code)
643 const qsizetype requiredCapacity = 2 * std::distance(first, last);
644 reserve(requiredCapacity);
645 }
646 while (first != last) {
647 append(QChar::fromUcs4(*first));
648 ++first;
649 }
650 return *this;
651 } else if constexpr (QtPrivate::IsCompatibleChar8Type<V>::value) {
652 assign_helper_char8(first, last);
653 if (d.isMutable())
654 d.data()[d.size] = u'\0';
655 return *this;
656 } else {
657 d->assign(first, last, [](QChar ch) noexcept -> char16_t { return ch.unicode(); });
658 if (d.isMutable())
659 d.data()[d.size] = u'\0';
660 return *this;
661 }
662 }
663
664 inline QString &operator+=(QChar c) { return append(c); }
665
666 inline QString &operator+=(const QString &s) { return append(s); }
667 inline QString &operator+=(QStringView v) { return append(v); }
668 inline QString &operator+=(QLatin1StringView s) { return append(s); }
669 QString &operator+=(QUtf8StringView s) { return append(s); }
670
671#if defined(QT_RESTRICTED_CAST_FROM_ASCII)
672 template <qsizetype N>
673 QString &insert(qsizetype i, const char (&ch)[N]) { return insert(i, QUtf8StringView(ch)); }
674 template <qsizetype N>
675 QString &append(const char (&ch)[N]) { return append(QUtf8StringView(ch)); }
676 template <qsizetype N>
677 QString &prepend(const char (&ch)[N]) { return prepend(QUtf8StringView(ch)); }
678 template <qsizetype N>
679 QString &operator+=(const char (&ch)[N]) { return append(QUtf8StringView(ch)); }
680#endif
681
682 QString &remove(qsizetype i, qsizetype len);
683 QString &remove(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive);
684 QString &remove(QLatin1StringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive);
685 QString &remove(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive);
686
687 QString &removeAt(qsizetype pos)
688 { return size_t(pos) < size_t(size()) ? remove(pos, 1) : *this; }
689 QString &removeFirst() { return !isEmpty() ? remove(0, 1) : *this; }
690 QString &removeLast() { return !isEmpty() ? remove(size() - 1, 1) : *this; }
691
692 template <typename Predicate>
693 QString &removeIf(Predicate pred)
694 {
695 QtPrivate::q_string_like_container_erase_if(*this, pred);
696 return *this;
697 }
698
699 QString &replace(qsizetype i, qsizetype len, QChar after);
700 QString &replace(qsizetype i, qsizetype len, const QChar *s, qsizetype slen);
701 QString &replace(qsizetype i, qsizetype len, const QString &after);
702 QString &replace(QChar before, QChar after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
703 QString &replace(const QChar *before, qsizetype blen, const QChar *after, qsizetype alen, Qt::CaseSensitivity cs = Qt::CaseSensitive);
704 QString &replace(QLatin1StringView before, QLatin1StringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
705 QString &replace(QLatin1StringView before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
706 QString &replace(const QString &before, QLatin1StringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
707 QString &replace(const QString &before, const QString &after,
708 Qt::CaseSensitivity cs = Qt::CaseSensitive);
709 QString &replace(QChar c, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
710 QString &replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
711#if QT_CONFIG(regularexpression)
712 QString &replace(const QRegularExpression &re, const QString &after);
713 inline QString &remove(const QRegularExpression &re)
714 { return replace(re, QString()); }
715#endif
716
717public:
718 [[nodiscard]]
719 QStringList split(const QString &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts,
720 Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
721 [[nodiscard]]
722 QStringList split(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts,
723 Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
724#ifndef QT_NO_REGULAREXPRESSION
725 [[nodiscard]]
726 QStringList split(const QRegularExpression &sep,
727 Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const;
728#endif
729
730 template <typename Needle, typename...Flags>
731 [[nodiscard]] inline auto tokenize(Needle &&needle, Flags...flags) const &
732 noexcept(noexcept(qTokenize(std::declval<const QString &>(), std::forward<Needle>(needle), flags...)))
733 -> decltype(qTokenize(*this, std::forward<Needle>(needle), flags...))
734 { return qTokenize(qToStringViewIgnoringNull(*this), std::forward<Needle>(needle), flags...); }
735
736 template <typename Needle, typename...Flags>
737 [[nodiscard]] inline auto tokenize(Needle &&needle, Flags...flags) const &&
738 noexcept(noexcept(qTokenize(std::declval<const QString>(), std::forward<Needle>(needle), flags...)))
739 -> decltype(qTokenize(std::move(*this), std::forward<Needle>(needle), flags...))
740 { return qTokenize(std::move(*this), std::forward<Needle>(needle), flags...); }
741
742 template <typename Needle, typename...Flags>
743 [[nodiscard]] inline auto tokenize(Needle &&needle, Flags...flags) &&
744 noexcept(noexcept(qTokenize(std::declval<QString>(), std::forward<Needle>(needle), flags...)))
745 -> decltype(qTokenize(std::move(*this), std::forward<Needle>(needle), flags...))
746 { return qTokenize(std::move(*this), std::forward<Needle>(needle), flags...); }
747
748
749 enum NormalizationForm {
750 NormalizationForm_D,
751 NormalizationForm_C,
752 NormalizationForm_KD,
753 NormalizationForm_KC
754 };
755 [[nodiscard]] QString normalized(NormalizationForm mode, QChar::UnicodeVersion version = QChar::Unicode_Unassigned) const;
756
757 [[nodiscard]] QString repeated(qsizetype times) const;
758
759 const ushort *utf16() const; // ### Qt 7 char16_t
760 [[nodiscard]] QString nullTerminated() const &;
761 [[nodiscard]] QString nullTerminated() &&;
762 QString &nullTerminate();
763
764#if !defined(Q_QDOC)
765 [[nodiscard]] QByteArray toLatin1() const &
766 { return toLatin1_helper(*this); }
767 [[nodiscard]] QByteArray toLatin1() &&
768 { return toLatin1_helper_inplace(*this); }
769 [[nodiscard]] QByteArray toUtf8() const &
770 { return toUtf8_helper(*this); }
771 [[nodiscard]] QByteArray toUtf8() &&
772 { return toUtf8_helper(*this); }
773 [[nodiscard]] QByteArray toLocal8Bit() const &
774 { return toLocal8Bit_helper(isNull() ? nullptr : constData(), size()); }
775 [[nodiscard]] QByteArray toLocal8Bit() &&
776 { return toLocal8Bit_helper(isNull() ? nullptr : constData(), size()); }
777#else
778 [[nodiscard]] QByteArray toLatin1() const;
779 [[nodiscard]] QByteArray toUtf8() const;
780 [[nodiscard]] QByteArray toLocal8Bit() const;
781#endif
782 [[nodiscard]] QList<uint> toUcs4() const; // ### Qt 7 char32_t
783
784 // note - this are all inline so we can benefit from strlen() compile time optimizations
785 static QString fromLatin1(QByteArrayView ba);
786 Q_WEAK_OVERLOAD
787 static inline QString fromLatin1(const QByteArray &ba) { return fromLatin1(QByteArrayView(ba)); }
788 static inline QString fromLatin1(const char *str, qsizetype size)
789 {
790 return fromLatin1(QByteArrayView(str, !str || size < 0 ? qstrlen(str) : size));
791 }
792 static QString fromUtf8(QByteArrayView utf8);
793 Q_WEAK_OVERLOAD
794 static inline QString fromUtf8(const QByteArray &ba) { return fromUtf8(QByteArrayView(ba)); }
795 static inline QString fromUtf8(const char *utf8, qsizetype size)
796 {
797 return fromUtf8(QByteArrayView(utf8, !utf8 || size < 0 ? qstrlen(utf8) : size));
798 }
799#if defined(__cpp_char8_t) || defined(Q_QDOC)
800 Q_WEAK_OVERLOAD
801 static inline QString fromUtf8(const char8_t *str)
802 { return fromUtf8(reinterpret_cast<const char *>(str)); }
803 Q_WEAK_OVERLOAD
804 static inline QString fromUtf8(const char8_t *str, qsizetype size)
805 { return fromUtf8(reinterpret_cast<const char *>(str), size); }
806#endif
807 static QString fromLocal8Bit(QByteArrayView ba);
808 Q_WEAK_OVERLOAD
809 static inline QString fromLocal8Bit(const QByteArray &ba) { return fromLocal8Bit(QByteArrayView(ba)); }
810 static inline QString fromLocal8Bit(const char *str, qsizetype size)
811 {
812 return fromLocal8Bit(QByteArrayView(str, !str || size < 0 ? qstrlen(str) : size));
813 }
814 static QString fromUtf16(const char16_t *, qsizetype size = -1);
815 static QString fromUcs4(const char32_t *, qsizetype size = -1);
816 static QString fromRawData(const char16_t *unicode, qsizetype size)
817 {
818 return QString(DataPointer::fromRawData(unicode, size));
819 }
820 QT_CORE_INLINE_SINCE(6, 10)
821 static QString fromRawData(const QChar *, qsizetype size);
822
823#if QT_DEPRECATED_SINCE(6, 0)
824 QT_DEPRECATED_VERSION_X_6_0("Use char16_t* overload.")
825 static QString fromUtf16(const ushort *str, qsizetype size = -1)
826 { return fromUtf16(reinterpret_cast<const char16_t *>(str), size); }
827 QT_DEPRECATED_VERSION_X_6_0("Use char32_t* overload.")
828 static QString fromUcs4(const uint *str, qsizetype size = -1)
829 { return fromUcs4(reinterpret_cast<const char32_t *>(str), size); }
830#endif
831
832 inline qsizetype toWCharArray(wchar_t *array) const;
833 [[nodiscard]] static inline QString fromWCharArray(const wchar_t *string, qsizetype size = -1);
834
835 QString &setRawData(const QChar *unicode, qsizetype size);
836 QString &setUnicode(const QChar *unicode, qsizetype size);
837 Q_WEAK_OVERLOAD
838 QString &setUnicode(const char16_t *utf16, qsizetype size)
839 { return setUnicode(reinterpret_cast<const QChar *>(utf16), size); }
840 QString &setUtf16(const char16_t *utf16, qsizetype size)
841 { return setUnicode(reinterpret_cast<const QChar *>(utf16), size); }
842
843#if !QT_CORE_REMOVED_SINCE(6, 9)
844 Q_WEAK_OVERLOAD
845#endif
846 QString &setUtf16(const ushort *autf16, qsizetype asize)
847 { return setUnicode(reinterpret_cast<const QChar *>(autf16), asize); }
848
849 int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
850 int compare(QLatin1StringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
851 inline int compare(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
852 int compare(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
853 { return compare(QStringView{&ch, 1}, cs); }
854
855 static inline int compare(const QString &s1, const QString &s2,
856 Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept
857 { return s1.compare(s2, cs); }
858
859 static inline int compare(const QString &s1, QLatin1StringView s2,
860 Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept
861 { return s1.compare(s2, cs); }
862 static inline int compare(QLatin1StringView s1, const QString &s2,
863 Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept
864 { return -s2.compare(s1, cs); }
865 static int compare(const QString &s1, QStringView s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept
866 { return s1.compare(s2, cs); }
867 static int compare(QStringView s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept
868 { return -s2.compare(s1, cs); }
869
870 int localeAwareCompare(const QString& s) const;
871 inline int localeAwareCompare(QStringView s) const;
872 static int localeAwareCompare(const QString& s1, const QString& s2)
873 { return s1.localeAwareCompare(s2); }
874
875 static inline int localeAwareCompare(QStringView s1, QStringView s2);
876
877 short toShort(bool *ok=nullptr, int base=10) const
878 { return toIntegral_helper<short>(*this, ok, base); }
879 ushort toUShort(bool *ok=nullptr, int base=10) const
880 { return toIntegral_helper<ushort>(*this, ok, base); }
881 int toInt(bool *ok=nullptr, int base=10) const
882 { return toIntegral_helper<int>(*this, ok, base); }
883 uint toUInt(bool *ok=nullptr, int base=10) const
884 { return toIntegral_helper<uint>(*this, ok, base); }
885 long toLong(bool *ok=nullptr, int base=10) const
886 { return toIntegral_helper<long>(*this, ok, base); }
887 ulong toULong(bool *ok=nullptr, int base=10) const
888 { return toIntegral_helper<ulong>(*this, ok, base); }
889 QT_CORE_INLINE_SINCE(6, 5)
890 qlonglong toLongLong(bool *ok=nullptr, int base=10) const;
891 QT_CORE_INLINE_SINCE(6, 5)
892 qulonglong toULongLong(bool *ok=nullptr, int base=10) const;
893 float toFloat(bool *ok=nullptr) const;
894 double toDouble(bool *ok=nullptr) const;
895
896 inline QString &setNum(short, int base=10);
897 inline QString &setNum(ushort, int base=10);
898 inline QString &setNum(int, int base=10);
899 inline QString &setNum(uint, int base=10);
900 inline QString &setNum(long, int base=10);
901 inline QString &setNum(ulong, int base=10);
902 QString &setNum(qlonglong, int base=10);
903 QString &setNum(qulonglong, int base=10);
904 inline QString &setNum(float, char format='g', int precision=6);
905 QString &setNum(double, char format='g', int precision=6);
906
907 static QString number(int, int base=10);
908 static QString number(uint, int base=10);
909 static QString number(long, int base=10);
910 static QString number(ulong, int base=10);
911 static QString number(qlonglong, int base=10);
912 static QString number(qulonglong, int base=10);
913 static QString number(double, char format='g', int precision=6);
914
915 friend bool comparesEqual(const QString &s1, const QString &s2) noexcept
916 { return comparesEqual(QStringView(s1), QStringView(s2)); }
917 friend Qt::strong_ordering compareThreeWay(const QString &s1, const QString &s2) noexcept
918 { return compareThreeWay(QStringView(s1), QStringView(s2)); }
919 Q_DECLARE_STRONGLY_ORDERED(QString)
920
921 Q_WEAK_OVERLOAD
922 friend bool comparesEqual(const QString &s1, QUtf8StringView s2) noexcept
923 { return QtPrivate::equalStrings(s1, s2); }
924 Q_WEAK_OVERLOAD
925 friend Qt::strong_ordering compareThreeWay(const QString &s1, QUtf8StringView s2) noexcept
926 {
927 const int res = QtPrivate::compareStrings(s1, s2, Qt::CaseSensitive);
928 return Qt::compareThreeWay(res, 0);
929 }
930 Q_DECLARE_STRONGLY_ORDERED(QString, QUtf8StringView, Q_WEAK_OVERLOAD)
931
932#ifdef __cpp_char8_t
933 friend bool comparesEqual(const QString &s1, const char8_t *s2) noexcept
934 { return comparesEqual(s1, QUtf8StringView(s2)); }
935 friend Qt::strong_ordering compareThreeWay(const QString &s1, const char8_t *s2) noexcept
936 { return compareThreeWay(s1, QUtf8StringView(s2)); }
937 Q_DECLARE_STRONGLY_ORDERED(QString, const char8_t *)
938#endif // __cpp_char8_t
939
940 friend bool comparesEqual(const QString &s1, QLatin1StringView s2) noexcept
941 { return (s1.size() == s2.size()) && QtPrivate::equalStrings(s1, s2); }
942 friend Qt::strong_ordering
943 compareThreeWay(const QString &s1, QLatin1StringView s2) noexcept
944 {
945 const int res = QtPrivate::compareStrings(s1, s2, Qt::CaseSensitive);
946 return Qt::compareThreeWay(res, 0);
947 }
948 Q_DECLARE_STRONGLY_ORDERED(QString, QLatin1StringView)
949
950 // Check isEmpty() instead of isNull() for backwards compatibility.
951 friend bool comparesEqual(const QString &s1, std::nullptr_t) noexcept
952 { return s1.isEmpty(); }
953 friend Qt::strong_ordering compareThreeWay(const QString &s1, std::nullptr_t) noexcept
954 { return s1.isEmpty() ? Qt::strong_ordering::equivalent : Qt::strong_ordering::greater; }
955 Q_DECLARE_STRONGLY_ORDERED(QString, std::nullptr_t)
956
957 friend bool comparesEqual(const QString &s1, const char16_t *s2) noexcept
958 { return comparesEqual(s1, QStringView(s2)); }
959 friend Qt::strong_ordering compareThreeWay(const QString &s1, const char16_t *s2) noexcept
960 { return compareThreeWay(s1, QStringView(s2)); }
961 Q_DECLARE_STRONGLY_ORDERED(QString, const char16_t *)
962
963 // QChar <> QString
964 friend bool comparesEqual(const QString &lhs, QChar rhs) noexcept
965 { return lhs.size() == 1 && rhs == lhs.front(); }
966 friend Qt::strong_ordering compareThreeWay(const QString &lhs, QChar rhs) noexcept
967 {
968 const int res = compare_helper(lhs.data(), lhs.size(), &rhs, 1);
969 return Qt::compareThreeWay(res, 0);
970 }
971 Q_DECLARE_STRONGLY_ORDERED(QString, QChar)
972
973 // ASCII compatibility
974#if defined(QT_RESTRICTED_CAST_FROM_ASCII)
975 template <qsizetype N>
976 inline QString(const char (&ch)[N])
977 : QString(fromUtf8(ch))
978 {}
979 template <qsizetype N>
980 QString(char (&)[N]) = delete;
981 template <qsizetype N>
982 inline QString &operator=(const char (&ch)[N])
983 { return (*this = fromUtf8(ch, N - 1)); }
984 template <qsizetype N>
985 QString &operator=(char (&)[N]) = delete;
986#endif
987#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
988 QT_ASCII_CAST_WARN inline QString(const char *ch)
989 : QString(fromUtf8(ch))
990 {}
991 QT_ASCII_CAST_WARN inline QString(const QByteArray &a)
992 : QString(fromUtf8(a))
993 {}
994 QT_ASCII_CAST_WARN inline QString &operator=(const char *ch)
995 {
996 if (!ch) {
997 clear();
998 return *this;
999 }
1000 return assign(ch);
1001 }
1002 QT_ASCII_CAST_WARN inline QString &operator=(const QByteArray &a)
1003 {
1004 if (a.isNull()) {
1005 clear();
1006 return *this;
1007 }
1008 return assign(a);
1009 }
1010 // these are needed, so it compiles with STL support enabled
1011 QT_ASCII_CAST_WARN inline QString &prepend(const char *s)
1012 { return prepend(QUtf8StringView(s)); }
1013 QT_ASCII_CAST_WARN inline QString &prepend(const QByteArray &s)
1014 { return prepend(QUtf8StringView(s)); }
1015 QT_ASCII_CAST_WARN inline QString &append(const char *s)
1016 { return append(QUtf8StringView(s)); }
1017 QT_ASCII_CAST_WARN inline QString &append(const QByteArray &s)
1018 { return append(QUtf8StringView(s)); }
1019 QT_ASCII_CAST_WARN inline QString &insert(qsizetype i, const char *s)
1020 { return insert(i, QUtf8StringView(s)); }
1021 QT_ASCII_CAST_WARN inline QString &insert(qsizetype i, const QByteArray &s)
1022 { return insert(i, QUtf8StringView(s)); }
1023 QT_ASCII_CAST_WARN inline QString &operator+=(const char *s)
1024 { return append(QUtf8StringView(s)); }
1025 QT_ASCII_CAST_WARN inline QString &operator+=(const QByteArray &s)
1026 { return append(QUtf8StringView(s)); }
1027
1028#if QT_CORE_REMOVED_SINCE(6, 8)
1029 QT_ASCII_CAST_WARN inline bool operator==(const char *s) const;
1030 QT_ASCII_CAST_WARN inline bool operator!=(const char *s) const;
1031 QT_ASCII_CAST_WARN inline bool operator<(const char *s) const;
1032 QT_ASCII_CAST_WARN inline bool operator<=(const char *s) const;
1033 QT_ASCII_CAST_WARN inline bool operator>(const char *s) const;
1034 QT_ASCII_CAST_WARN inline bool operator>=(const char *s) const;
1035
1036 QT_ASCII_CAST_WARN inline bool operator==(const QByteArray &s) const;
1037 QT_ASCII_CAST_WARN inline bool operator!=(const QByteArray &s) const;
1038 QT_ASCII_CAST_WARN inline bool operator<(const QByteArray &s) const;
1039 QT_ASCII_CAST_WARN inline bool operator>(const QByteArray &s) const;
1040 QT_ASCII_CAST_WARN inline bool operator<=(const QByteArray &s) const;
1041 QT_ASCII_CAST_WARN inline bool operator>=(const QByteArray &s) const;
1042#else
1043 friend bool comparesEqual(const QString &lhs, QByteArrayView rhs) noexcept
1044 {
1045 return QString::compare_helper(lhs.constData(), lhs.size(),
1046 rhs.constData(), rhs.size()) == 0;
1047 }
1048 friend Qt::strong_ordering
1049 compareThreeWay(const QString &lhs, QByteArrayView rhs) noexcept
1050 {
1051 const int res = QString::compare_helper(lhs.constData(), lhs.size(),
1052 rhs.constData(), rhs.size());
1053 return Qt::compareThreeWay(res, 0);
1054 }
1055 Q_DECLARE_STRONGLY_ORDERED(QString, QByteArrayView, QT_ASCII_CAST_WARN)
1056
1057 friend bool comparesEqual(const QString &lhs, const QByteArray &rhs) noexcept
1058 { return comparesEqual(lhs, QByteArrayView(rhs)); }
1059 friend Qt::strong_ordering
1060 compareThreeWay(const QString &lhs, const QByteArray &rhs) noexcept
1061 {
1062 return compareThreeWay(lhs, QByteArrayView(rhs));
1063 }
1064 Q_DECLARE_STRONGLY_ORDERED(QString, QByteArray, QT_ASCII_CAST_WARN)
1065
1066 friend bool comparesEqual(const QString &lhs, const char *rhs) noexcept
1067 { return comparesEqual(lhs, QByteArrayView(rhs)); }
1068 friend Qt::strong_ordering
1069 compareThreeWay(const QString &lhs, const char *rhs) noexcept
1070 {
1071 return compareThreeWay(lhs, QByteArrayView(rhs));
1072 }
1073 Q_DECLARE_STRONGLY_ORDERED(QString, const char *, QT_ASCII_CAST_WARN)
1074#endif // QT_CORE_REMOVED_SINCE(6, 8)
1075
1076#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
1077
1078 typedef QChar *iterator;
1079 typedef const QChar *const_iterator;
1080 typedef iterator Iterator;
1081 typedef const_iterator ConstIterator;
1082 typedef std::reverse_iterator<iterator> reverse_iterator;
1083 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
1084 inline iterator begin();
1085 inline const_iterator begin() const;
1086 inline const_iterator cbegin() const;
1087 inline const_iterator constBegin() const;
1088 inline iterator end();
1089 inline const_iterator end() const;
1090 inline const_iterator cend() const;
1091 inline const_iterator constEnd() const;
1092 reverse_iterator rbegin() { return reverse_iterator(end()); }
1093 reverse_iterator rend() { return reverse_iterator(begin()); }
1094 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
1095 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
1096 const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); }
1097 const_reverse_iterator crend() const { return const_reverse_iterator(begin()); }
1098
1099 // STL compatibility
1100 typedef qsizetype size_type;
1101 typedef qptrdiff difference_type;
1102 typedef const QChar & const_reference;
1103 typedef QChar & reference;
1104 typedef QChar *pointer;
1105 typedef const QChar *const_pointer;
1106 typedef QChar value_type;
1107 inline void push_back(QChar c) { append(c); }
1108 inline void push_back(const QString &s) { append(s); }
1109 inline void push_front(QChar c) { prepend(c); }
1110 inline void push_front(const QString &s) { prepend(s); }
1111 void shrink_to_fit() { squeeze(); }
1112 iterator erase(const_iterator first, const_iterator last);
1113 inline iterator erase(const_iterator it) { return erase(it, it + 1); }
1114 constexpr qsizetype max_size() const noexcept
1115 {
1116 return maxSize();
1117 }
1118
1119 static inline QString fromStdString(const std::string &s);
1120 std::string toStdString() const;
1121 static inline QString fromStdWString(const std::wstring &s);
1122 inline std::wstring toStdWString() const;
1123
1124 static inline QString fromStdU16String(const std::u16string &s);
1125 inline std::u16string toStdU16String() const;
1126 static inline QString fromStdU32String(const std::u32string &s);
1127 inline std::u32string toStdU32String() const;
1128
1129 constexpr Q_IMPLICIT inline operator std::u16string_view() const noexcept;
1130
1131#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
1132 static QString fromCFString(CFStringRef string);
1133 CFStringRef toCFString() const Q_DECL_CF_RETURNS_RETAINED;
1134 static QString fromNSString(const NSString *string);
1135 NSString *toNSString() const Q_DECL_NS_RETURNS_AUTORELEASED;
1136#endif
1137
1138#if defined(Q_OS_WASM) || defined(Q_QDOC)
1139 static QString fromEcmaString(emscripten::val jsString);
1140 emscripten::val toEcmaString() const;
1141#endif
1142
1143 constexpr bool isNull() const { return d.isNull(); }
1144
1145 bool isRightToLeft() const;
1146 [[nodiscard]] bool isValidUtf16() const noexcept
1147 { return QStringView(*this).isValidUtf16(); }
1148
1149 QString(qsizetype size, Qt::Initialization);
1150 Q_DECL_CONSTEXPR_DTOR
1151 explicit QString(DataPointer &&dd) : d(std::move(dd)) {}
1152
1153private:
1154#if defined(QT_NO_CAST_FROM_ASCII)
1155#define QSTRING_DECL_DELETED_ASCII_OP Q_DECL_EQ_DELETE_X("This function is not available under QT_NO_CAST_FROM_ASCII")
1156 QString &operator+=(const char *s) QSTRING_DECL_DELETED_ASCII_OP;
1157 QString &operator+=(const QByteArray &s) QSTRING_DECL_DELETED_ASCII_OP;
1158 QString(const char *ch) QSTRING_DECL_DELETED_ASCII_OP;
1159 QString(const QByteArray &a) QSTRING_DECL_DELETED_ASCII_OP;
1160 QString &operator=(const char *ch) QSTRING_DECL_DELETED_ASCII_OP;
1161 QString &operator=(const QByteArray &a) QSTRING_DECL_DELETED_ASCII_OP;
1162#undef QSTRING_DECL_DELETED_ASCII_OP
1163#endif
1164
1165 DataPointer d;
1166 static const char16_t _empty;
1167
1168 void reallocData(qsizetype alloc, QArrayData::AllocationOption option);
1169 void reallocGrowData(qsizetype n);
1170 // ### remove once QAnyStringView supports UTF-32:
1171 QString &assign_helper(const char32_t *data, qsizetype len);
1172 // Defined in qstringconverter.h
1173 template <typename InputIterator>
1174 void assign_helper_char8(InputIterator first, InputIterator last);
1175 static int compare_helper(const QChar *data1, qsizetype length1,
1176 const QChar *data2, qsizetype length2,
1177 Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept;
1178 static int compare_helper(const QChar *data1, qsizetype length1,
1179 const char *data2, qsizetype length2,
1180 Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept;
1181 static int localeAwareCompare_helper(const QChar *data1, qsizetype length1,
1182 const QChar *data2, qsizetype length2);
1183 static QString sliced_helper(QString &str, qsizetype pos, qsizetype n);
1184 static QString toLower_helper(const QString &str);
1185 static QString toLower_helper(QString &str);
1186 static QString toUpper_helper(const QString &str);
1187 static QString toUpper_helper(QString &str);
1188 static QString toCaseFolded_helper(const QString &str);
1189 static QString toCaseFolded_helper(QString &str);
1190 static QString trimmed_helper(const QString &str);
1191 static QString trimmed_helper(QString &str);
1192 static QString simplified_helper(const QString &str);
1193 static QString simplified_helper(QString &str);
1194 static QByteArray toLatin1_helper(const QString &);
1195 static QByteArray toLatin1_helper_inplace(QString &);
1196 static QByteArray toUtf8_helper(const QString &);
1197 static QByteArray toLocal8Bit_helper(const QChar *data, qsizetype size);
1198#if QT_CORE_REMOVED_SINCE(6, 6)
1199 static qsizetype toUcs4_helper(const ushort *uc, qsizetype length, uint *out);
1200#endif
1201 static qsizetype toUcs4_helper(const char16_t *uc, qsizetype length, char32_t *out);
1202 static qlonglong toIntegral_helper(QStringView string, bool *ok, int base);
1203 static qulonglong toIntegral_helper(QStringView string, bool *ok, uint base);
1204
1205 friend class QStringView;
1206 friend class QByteArray;
1207 friend struct QAbstractConcatenable;
1208 template <typename T> friend qsizetype erase(QString &s, const T &t);
1209 template <typename Predicate> friend qsizetype erase_if(QString &s, Predicate pred);
1210
1211 template <typename T> static
1212 T toIntegral_helper(QStringView string, bool *ok, int base)
1213 {
1214 using Int64 = typename std::conditional<std::is_unsigned<T>::value, qulonglong, qlonglong>::type;
1215 using Int32 = typename std::conditional<std::is_unsigned<T>::value, uint, int>::type;
1216
1217 // we select the right overload by casting base to int or uint
1218 Int64 val = toIntegral_helper(string, ok, Int32(base));
1219 if (T(val) != val) {
1220 if (ok)
1221 *ok = false;
1222 val = 0;
1223 }
1224 return T(val);
1225 }
1226
1227 Q_ALWAYS_INLINE constexpr void verify([[maybe_unused]] qsizetype pos = 0,
1228 [[maybe_unused]] qsizetype n = 1) const
1229 {
1230 Q_ASSERT(pos >= 0);
1231 Q_ASSERT(pos <= d.size);
1232 Q_ASSERT(n >= 0);
1233 Q_ASSERT(n <= d.size - pos);
1234 }
1235
1236public:
1237 inline DataPointer &data_ptr() { return d; }
1238 inline const DataPointer &data_ptr() const { return d; }
1239};
1240
1241//
1242// QLatin1StringView inline members that require QUtf8StringView:
1243//
1244
1245int QLatin1StringView::compare(QUtf8StringView other, Qt::CaseSensitivity cs) const noexcept
1246{ return QtPrivate::compareStrings(*this, other, cs); }
1247
1248//
1249// QLatin1StringView inline members that require QString:
1250//
1251
1252QString QLatin1StringView::toString() const { return *this; }
1253
1254//
1255// QStringView inline members that require QUtf8StringView:
1256//
1257
1258int QStringView::compare(QUtf8StringView other, Qt::CaseSensitivity cs) const noexcept
1259{ return QtPrivate::compareStrings(*this, other, cs); }
1260
1261//
1262// QStringView inline members that require QString:
1263//
1264
1265QString QStringView::toString() const
1266{ return QString(*this); }
1267
1268qint64 QStringView::toLongLong(bool *ok, int base) const
1269{ return QString::toIntegral_helper<qint64>(*this, ok, base); }
1270quint64 QStringView::toULongLong(bool *ok, int base) const
1271{ return QString::toIntegral_helper<quint64>(*this, ok, base); }
1272long QStringView::toLong(bool *ok, int base) const
1273{ return QString::toIntegral_helper<long>(*this, ok, base); }
1274ulong QStringView::toULong(bool *ok, int base) const
1275{ return QString::toIntegral_helper<ulong>(*this, ok, base); }
1276int QStringView::toInt(bool *ok, int base) const
1277{ return QString::toIntegral_helper<int>(*this, ok, base); }
1278uint QStringView::toUInt(bool *ok, int base) const
1279{ return QString::toIntegral_helper<uint>(*this, ok, base); }
1280short QStringView::toShort(bool *ok, int base) const
1281{ return QString::toIntegral_helper<short>(*this, ok, base); }
1282ushort QStringView::toUShort(bool *ok, int base) const
1283{ return QString::toIntegral_helper<ushort>(*this, ok, base); }
1284
1285//
1286// QUtf8StringView inline members that require QStringView:
1287//
1288
1289template <bool UseChar8T>
1290int QBasicUtf8StringView<UseChar8T>::compare(QChar other, Qt::CaseSensitivity cs) const noexcept
1291{
1292 return QtPrivate::compareStrings(*this, QStringView(&other, 1), cs);
1293}
1294
1295template <bool UseChar8T>
1296int QBasicUtf8StringView<UseChar8T>::compare(QStringView other, Qt::CaseSensitivity cs) const noexcept
1297{
1298 return QtPrivate::compareStrings(*this, other, cs);
1299}
1300
1301template <bool UseChar8T>
1302[[nodiscard]] bool QBasicUtf8StringView<UseChar8T>::equal(QChar other) const noexcept
1303{
1304 return QtPrivate::equalStrings(*this, QStringView(&other, 1));
1305}
1306
1307template <bool UseChar8T>
1308[[nodiscard]] bool QBasicUtf8StringView<UseChar8T>::equal(QStringView other) const noexcept
1309{
1310 return QtPrivate::equalStrings(*this, other);
1311}
1312
1313//
1314// QUtf8StringView inline members that require QString, QL1SV or QBA:
1315//
1316
1317template <bool UseChar8T>
1318QString QBasicUtf8StringView<UseChar8T>::toString() const
1319{
1320 return QString::fromUtf8(data(), size());
1321}
1322
1323template<bool UseChar8T>
1324[[nodiscard]] int QBasicUtf8StringView<UseChar8T>::compare(QLatin1StringView other,
1325 Qt::CaseSensitivity cs) const noexcept
1326{
1327 return QtPrivate::compareStrings(*this, other, cs);
1328}
1329
1330template<bool UseChar8T>
1331[[nodiscard]] int QBasicUtf8StringView<UseChar8T>::compare(const QByteArray &other,
1332 Qt::CaseSensitivity cs) const noexcept
1333{
1334 return QtPrivate::compareStrings(*this,
1335 QBasicUtf8StringView<UseChar8T>(other.data(), other.size()),
1336 cs);
1337}
1338
1339template <bool UseChar8T>
1340[[nodiscard]] bool QBasicUtf8StringView<UseChar8T>::equal(QLatin1StringView other) const noexcept
1341{
1342 return QtPrivate::equalStrings(*this, other);
1343}
1344
1345template <bool UseChar8T>
1346[[nodiscard]] bool QBasicUtf8StringView<UseChar8T>::equal(const QByteArray &other) const noexcept
1347{
1348 return size() == other.size()
1349 && QtPrivate::equalStrings(*this, QBasicUtf8StringView<UseChar8T>(other.data(),
1350 other.size()));
1351}
1352
1353//
1354// QAnyStringView inline members that require QString:
1355//
1356
1357QAnyStringView::QAnyStringView(const QByteArray &str) noexcept
1358 : QAnyStringView{str.begin(), str.size()} {}
1359QAnyStringView::QAnyStringView(const QString &str) noexcept
1360 : QAnyStringView{str.begin(), str.size()} {}
1361
1362QString QAnyStringView::toString() const
1363{ return QtPrivate::convertToQString(*this); }
1364
1365//
1366// QString inline members
1367//
1368QString::QString(QLatin1StringView latin1)
1369 : QString{QString::fromLatin1(latin1.data(), latin1.size())} {}
1370constexpr const QChar QString::at(qsizetype i) const
1371{ verify(i, 1); return QChar(d.data()[i]); }
1372constexpr const QChar QString::operator[](qsizetype i) const
1373{ verify(i, 1); return QChar(d.data()[i]); }
1374const QChar *QString::unicode() const
1375{ return data(); }
1376const QChar *QString::data() const
1377{
1378#if QT5_NULL_STRINGS == 1
1379 return reinterpret_cast<const QChar *>(d.data() ? d.data() : &_empty);
1380#else
1381 return reinterpret_cast<const QChar *>(d.data());
1382#endif
1383}
1384QChar *QString::data()
1385{
1386 detach();
1387 Q_ASSERT(d.data());
1388 return reinterpret_cast<QChar *>(d.data());
1389}
1390const QChar *QString::constData() const
1391{ return data(); }
1392void QString::detach()
1393{ if (d.needsDetach()) reallocData(d.size, QArrayData::KeepSize); }
1394bool QString::isDetached() const
1395{ return !d.isShared(); }
1396Q_DECL_CONSTEXPR_DTOR
1397void QString::clear()
1398{ *this = QString(); }
1399#if QT_CORE_INLINE_IMPL_SINCE(6, 13)
1400QT_CORE_CONSTEXPR_DTOR_INLINE_SINCE(6, 13)
1401QString &QString::operator=(const QString &other) noexcept
1402{
1403 d = other.d;
1404 return *this;
1405}
1406#endif // QT_CORE_INLINE_IMPL_SINCE(6, 13)
1407qsizetype QString::capacity() const { return qsizetype(d.constAllocatedCapacity()); }
1408QString &QString::setNum(short n, int base)
1409{ return setNum(qlonglong(n), base); }
1410QString &QString::setNum(ushort n, int base)
1411{ return setNum(qulonglong(n), base); }
1412QString &QString::setNum(int n, int base)
1413{ return setNum(qlonglong(n), base); }
1414QString &QString::setNum(uint n, int base)
1415{ return setNum(qulonglong(n), base); }
1416QString &QString::setNum(long n, int base)
1417{ return setNum(qlonglong(n), base); }
1418QString &QString::setNum(ulong n, int base)
1419{ return setNum(qulonglong(n), base); }
1420QString &QString::setNum(float n, char f, int prec)
1421{ return setNum(double(n),f,prec); }
1422#if QT_CORE_REMOVED_SINCE(6, 9)
1423QString QString::arg(int a, int fieldWidth, int base, QChar fillChar) const
1424{ return arg(qlonglong(a), fieldWidth, base, fillChar); }
1425QString QString::arg(uint a, int fieldWidth, int base, QChar fillChar) const
1426{ return arg(qulonglong(a), fieldWidth, base, fillChar); }
1427QString QString::arg(long a, int fieldWidth, int base, QChar fillChar) const
1428{ return arg(qlonglong(a), fieldWidth, base, fillChar); }
1429QString QString::arg(ulong a, int fieldWidth, int base, QChar fillChar) const
1430{ return arg(qulonglong(a), fieldWidth, base, fillChar); }
1431QString QString::arg(short a, int fieldWidth, int base, QChar fillChar) const
1432{ return arg(qlonglong(a), fieldWidth, base, fillChar); }
1433QString QString::arg(ushort a, int fieldWidth, int base, QChar fillChar) const
1434{ return arg(qulonglong(a), fieldWidth, base, fillChar); }
1435#endif // QT_CORE_REMOVED_SINCE
1436
1437QString QString::section(QChar asep, qsizetype astart, qsizetype aend, SectionFlags aflags) const
1438{ return section(QString(asep), astart, aend, aflags); }
1439
1440QT_WARNING_PUSH
1441QT_WARNING_DISABLE_MSVC(4127) // "conditional expression is constant"
1442QT_WARNING_DISABLE_INTEL(111) // "statement is unreachable"
1443
1444qsizetype QString::toWCharArray(wchar_t *array) const
1445{
1446 return qToStringViewIgnoringNull(*this).toWCharArray(array);
1447}
1448
1449qsizetype QStringView::toWCharArray(wchar_t *array) const
1450{
1451 if (sizeof(wchar_t) == sizeof(QChar)) {
1452 if (auto src = data())
1453 memcpy(array, src, sizeof(QChar) * size());
1454 return size();
1455 } else {
1456 return QString::toUcs4_helper(utf16(), size(), reinterpret_cast<char32_t *>(array));
1457 }
1458}
1459
1461
1462QString QString::fromWCharArray(const wchar_t *string, qsizetype size)
1463{
1464 if constexpr (sizeof(wchar_t) == sizeof(QChar)) {
1465 return QString(reinterpret_cast<const QChar *>(string), size);
1466 } else {
1467#ifdef QT_BOOTSTRAPPED
1468 Q_UNREACHABLE_RETURN(QString());
1469#else
1470 return fromUcs4(reinterpret_cast<const char32_t *>(string), size);
1471#endif
1472 }
1473}
1474
1475void QString::reserve(qsizetype asize)
1476{
1477 if (d.needsDetach() || asize >= capacity() - d.freeSpaceAtBegin())
1478 reallocData(qMax(asize, size()), QArrayData::KeepSize);
1479 if (d.constAllocatedCapacity())
1480 d.setFlag(Data::CapacityReserved);
1481}
1482
1483void QString::squeeze()
1484{
1485 if (!d.isMutable())
1486 return;
1487 if (d.needsDetach() || size() < capacity())
1488 reallocData(d.size, QArrayData::KeepSize);
1489 if (d.constAllocatedCapacity())
1490 d.clearFlag(Data::CapacityReserved);
1491}
1492
1493QChar &QString::operator[](qsizetype i)
1494{ verify(i, 1); return data()[i]; }
1495QChar &QString::front() { return operator[](0); }
1496QChar &QString::back() { return operator[](size() - 1); }
1497QString::iterator QString::begin()
1498{ detach(); return reinterpret_cast<QChar*>(d.data()); }
1499QString::const_iterator QString::begin() const
1500{ return reinterpret_cast<const QChar*>(d.data()); }
1501QString::const_iterator QString::cbegin() const
1502{ return reinterpret_cast<const QChar*>(d.data()); }
1503QString::const_iterator QString::constBegin() const
1504{ return reinterpret_cast<const QChar*>(d.data()); }
1505QString::iterator QString::end()
1506{ detach(); return reinterpret_cast<QChar*>(d.data() + d.size); }
1507QString::const_iterator QString::end() const
1508{ return reinterpret_cast<const QChar*>(d.data() + d.size); }
1509QString::const_iterator QString::cend() const
1510{ return reinterpret_cast<const QChar*>(d.data() + d.size); }
1511QString::const_iterator QString::constEnd() const
1512{ return reinterpret_cast<const QChar*>(d.data() + d.size); }
1513bool QString::contains(const QString &s, Qt::CaseSensitivity cs) const
1514{ return indexOf(s, 0, cs) != -1; }
1515bool QString::contains(QLatin1StringView s, Qt::CaseSensitivity cs) const
1516{ return indexOf(s, 0, cs) != -1; }
1517bool QString::contains(QChar c, Qt::CaseSensitivity cs) const
1518{ return indexOf(c, 0, cs) != -1; }
1519bool QString::contains(QStringView s, Qt::CaseSensitivity cs) const noexcept
1520{ return indexOf(s, 0, cs) != -1; }
1521
1522#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
1523#if QT_CORE_REMOVED_SINCE(6, 8)
1524bool QString::operator==(const char *s) const
1525{ return QString::compare_helper(constData(), size(), s, -1) == 0; }
1526bool QString::operator!=(const char *s) const
1527{ return QString::compare_helper(constData(), size(), s, -1) != 0; }
1528bool QString::operator<(const char *s) const
1529{ return QString::compare_helper(constData(), size(), s, -1) < 0; }
1530bool QString::operator>(const char *s) const
1531{ return QString::compare_helper(constData(), size(), s, -1) > 0; }
1532bool QString::operator<=(const char *s) const
1533{ return QString::compare_helper(constData(), size(), s, -1) <= 0; }
1534bool QString::operator>=(const char *s) const
1535{ return QString::compare_helper(constData(), size(), s, -1) >= 0; }
1536
1537QT_ASCII_CAST_WARN bool QString::operator==(const QByteArray &s) const
1538{ return QString::compare_helper(constData(), size(), s.constData(), s.size()) == 0; }
1539QT_ASCII_CAST_WARN bool QString::operator!=(const QByteArray &s) const
1540{ return QString::compare_helper(constData(), size(), s.constData(), s.size()) != 0; }
1541QT_ASCII_CAST_WARN bool QString::operator<(const QByteArray &s) const
1542{ return QString::compare_helper(constData(), size(), s.constData(), s.size()) < 0; }
1543QT_ASCII_CAST_WARN bool QString::operator>(const QByteArray &s) const
1544{ return QString::compare_helper(constData(), size(), s.constData(), s.size()) > 0; }
1545QT_ASCII_CAST_WARN bool QString::operator<=(const QByteArray &s) const
1546{ return QString::compare_helper(constData(), size(), s.constData(), s.size()) <= 0; }
1547QT_ASCII_CAST_WARN bool QString::operator>=(const QByteArray &s) const
1548{ return QString::compare_helper(constData(), size(), s.constData(), s.size()) >= 0; }
1549
1550bool QByteArray::operator==(const QString &s) const
1551{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) == 0; }
1552bool QByteArray::operator!=(const QString &s) const
1553{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) != 0; }
1554bool QByteArray::operator<(const QString &s) const
1555{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) > 0; }
1556bool QByteArray::operator>(const QString &s) const
1557{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) < 0; }
1558bool QByteArray::operator<=(const QString &s) const
1559{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) >= 0; }
1560bool QByteArray::operator>=(const QString &s) const
1561{ return QString::compare_helper(s.constData(), s.size(), constData(), size()) <= 0; }
1562#endif // QT_CORE_REMOVED_SINCE(6, 8)
1563#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
1564
1565#if !defined(QT_USE_FAST_OPERATOR_PLUS) && !defined(QT_USE_QSTRINGBUILDER)
1566// QString + QString
1567inline QString operator+(const QString &s1, const QString &s2)
1568{ QString t(s1); t += s2; return t; }
1569inline QString operator+(QString &&lhs, const QString &rhs)
1570{ return std::move(lhs += rhs); }
1571inline QString operator+(const QString &s1, QChar s2)
1572{ QString t(s1); t += s2; return t; }
1573inline QString operator+(QString &&lhs, QChar rhs)
1574{ return std::move(lhs += rhs); }
1575inline QString operator+(QChar s1, const QString &s2)
1576{ QString t(s1); t += s2; return t; }
1577inline QString operator+(const QString &lhs, QStringView rhs)
1578{
1579 QString ret{lhs.size() + rhs.size(), Qt::Uninitialized};
1580 return ret.assign(lhs).append(rhs);
1581}
1582inline QString operator+(QStringView lhs, const QString &rhs)
1583{
1584 QString ret{lhs.size() + rhs.size(), Qt::Uninitialized};
1585 return ret.assign(lhs).append(rhs);
1586}
1587
1588# if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
1589QT_ASCII_CAST_WARN inline QString operator+(const QString &s1, const char *s2)
1590{ QString t(s1); t += QUtf8StringView(s2); return t; }
1591QT_ASCII_CAST_WARN inline QString operator+(QString &&lhs, const char *rhs)
1592{ QT_IGNORE_DEPRECATIONS(return std::move(lhs += rhs);) }
1593QT_ASCII_CAST_WARN inline QString operator+(const char *s1, const QString &s2)
1594{ QString t = QString::fromUtf8(s1); t += s2; return t; }
1595QT_ASCII_CAST_WARN inline QString operator+(const QByteArray &ba, const QString &s)
1596{ QString t = QString::fromUtf8(ba); t += s; return t; }
1597QT_ASCII_CAST_WARN inline QString operator+(const QString &s, const QByteArray &ba)
1598{ QString t(s); t += QUtf8StringView(ba); return t; }
1599QT_ASCII_CAST_WARN inline QString operator+(QString &&lhs, const QByteArray &rhs)
1600{ QT_IGNORE_DEPRECATIONS(return std::move(lhs += rhs);) }
1601# endif // QT_NO_CAST_FROM_ASCII
1602#endif // QT_USE_QSTRINGBUILDER
1603
1604QString QString::fromStdString(const std::string &s)
1605{ return fromUtf8(s.data(), qsizetype(s.size())); }
1606
1607std::wstring QString::toStdWString() const
1608{
1609 std::wstring str;
1610 str.resize(size());
1611 str.resize(toWCharArray(str.data()));
1612 return str;
1613}
1614
1615QString QString::fromStdWString(const std::wstring &s)
1616{ return fromWCharArray(s.data(), qsizetype(s.size())); }
1617
1618QString QString::fromStdU16String(const std::u16string &s)
1619{ return fromUtf16(s.data(), qsizetype(s.size())); }
1620
1621std::u16string QString::toStdU16String() const
1622{ return std::u16string(reinterpret_cast<const char16_t*>(data()), size()); }
1623
1624QString QString::fromStdU32String(const std::u32string &s)
1625{ return fromUcs4(s.data(), qsizetype(s.size())); }
1626
1627std::u32string QString::toStdU32String() const
1628{
1629 std::u32string u32str(size(), char32_t(0));
1630 const qsizetype len = toUcs4_helper(reinterpret_cast<const char16_t *>(data()),
1631 size(), u32str.data());
1632 u32str.resize(len);
1633 return u32str;
1634}
1635
1636constexpr QString::operator std::u16string_view() const noexcept
1637{
1638 return std::u16string_view(d.data(), size_t(d.size));
1639}
1640
1641#if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED)
1642Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QString &);
1643Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QString &);
1644#endif
1645
1647Q_DECLARE_OPERATORS_FOR_FLAGS(QString::SectionFlags)
1648
1649int QString::compare(QStringView s, Qt::CaseSensitivity cs) const noexcept
1650{ return -s.compare(*this, cs); }
1651
1652int QString::localeAwareCompare(QStringView s) const
1653{ return localeAwareCompare_helper(constData(), size(), s.constData(), s.size()); }
1654int QString::localeAwareCompare(QStringView s1, QStringView s2)
1655{ return localeAwareCompare_helper(s1.constData(), s1.size(), s2.constData(), s2.size()); }
1656int QStringView::localeAwareCompare(QStringView other) const
1657{ return QString::localeAwareCompare(*this, other); }
1658
1659#if QT_CORE_INLINE_IMPL_SINCE(6, 5)
1660qint64 QString::toLongLong(bool *ok, int base) const
1661{
1662 return toIntegral_helper<qlonglong>(*this, ok, base);
1663}
1664
1665quint64 QString::toULongLong(bool *ok, int base) const
1666{
1667 return toIntegral_helper<qulonglong>(*this, ok, base);
1668}
1669#endif
1670#if QT_CORE_INLINE_IMPL_SINCE(6, 8)
1671qsizetype QString::indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const
1672{
1673 return qToStringViewIgnoringNull(*this).indexOf(ch, from, cs);
1674}
1675qsizetype QString::lastIndexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const
1676{
1677 return qToStringViewIgnoringNull(*this).lastIndexOf(ch, from, cs);
1678}
1679#endif
1680#if QT_CORE_INLINE_IMPL_SINCE(6, 10)
1681QString QString::fromRawData(const QChar *unicode, qsizetype size)
1682{
1683 return fromRawData(reinterpret_cast<const char16_t *>(unicode), size);
1684}
1685#endif
1686#if QT_CORE_INLINE_IMPL_SINCE(6, 12)
1687qsizetype QString::indexOf(const QString &str, qsizetype from, Qt::CaseSensitivity cs) const
1688{
1689 return indexOf(QStringView(str.begin(), str.size()), from, cs);
1690}
1691qsizetype QString::indexOf(QLatin1StringView str, qsizetype from, Qt::CaseSensitivity cs) const
1692{
1693 return QStringView(begin(), size()).indexOf(str, from, cs);
1694}
1695qsizetype QString::lastIndexOf(const QString &str, qsizetype from, Qt::CaseSensitivity cs) const
1696{
1697 return lastIndexOf(QStringView(str.begin(), str.size()), from, cs);
1698}
1699qsizetype QString::lastIndexOf(QLatin1StringView str, qsizetype from, Qt::CaseSensitivity cs) const
1700{
1701 return QStringView(begin(), size()).lastIndexOf(str, from, cs);
1702}
1703#endif
1704
1705namespace QtPrivate {
1706// used by qPrintable() and qUtf8Printable() macros
1707inline const QString &asString(const QString &s) { return s; }
1708inline QString &&asString(QString &&s) { return std::move(s); }
1709}
1710
1711#ifndef qPrintable
1712# define qPrintable(string) QtPrivate::asString(string).toLocal8Bit().constData()
1713#endif
1714
1715#ifndef qUtf8Printable
1716# define qUtf8Printable(string) QtPrivate::asString(string).toUtf8().constData()
1717#endif
1718
1719/*
1720 Wrap QString::constData() with enough casts to allow passing it
1721 to QString::asprintf("%ls") without warnings.
1722*/
1723#ifndef qUtf16Printable
1724# define qUtf16Printable(string)
1725 static_cast<const wchar_t *>(
1726 static_cast<const void *>(QtPrivate::asString(string).nullTerminated().constData()))
1727#endif
1728
1729//
1730// QStringView::arg() implementation
1731//
1732
1733namespace QtPrivate {
1734
1735struct ArgBase {
1736 enum Tag : uchar { L1, Any, U16 } tag;
1737};
1738
1741 QStringViewArg() = default;
1742 constexpr explicit QStringViewArg(QStringView v) noexcept : ArgBase{U16}, string{v} {}
1743};
1744
1747 QLatin1StringArg() = default;
1748 constexpr explicit QLatin1StringArg(QLatin1StringView v) noexcept : ArgBase{L1}, string{v} {}
1749};
1750
1753 QAnyStringArg() = default;
1754 constexpr explicit QAnyStringArg(QAnyStringView v) noexcept : ArgBase{Any}, string{v} {}
1755};
1756
1757#if QT_CORE_REMOVED_SINCE(6, 9)
1760#endif
1761[[nodiscard]] Q_CORE_EXPORT QString argToQString(QAnyStringView pattern, size_t n, const ArgBase **args);
1762
1763template <typename...Args>
1764[[nodiscard]] Q_ALWAYS_INLINE QString argToQStringDispatch(QAnyStringView pattern, const Args &...args)
1765{
1766 const ArgBase *argBases[] = {&args..., /* avoid zero-sized array */ nullptr};
1767 return QtPrivate::argToQString(pattern, sizeof...(Args), argBases);
1768}
1769
1770constexpr inline QAnyStringArg qStringLikeToArg(QAnyStringView s) noexcept { return QAnyStringArg{s}; }
1771
1772} // namespace QtPrivate
1773
1774template <typename...Args>
1776QString QStringView::arg(Args &&...args) const
1777{
1778 return QtPrivate::argToQStringDispatch(*this, QtPrivate::qStringLikeToArg(args)...);
1779}
1780
1781template <typename...Args>
1783QString QLatin1StringView::arg(Args &&...args) const
1784{
1785 return QtPrivate::argToQStringDispatch(*this, QtPrivate::qStringLikeToArg(args)...);
1786}
1787
1788template <bool HasChar8T>
1789template <typename...Args>
1790QString QBasicUtf8StringView<HasChar8T>::arg(Args &&...args) const
1791{
1792 return QtPrivate::argToQStringDispatch(*this, QtPrivate::qStringLikeToArg(args)...);
1793}
1794
1795template <typename...Args>
1796QString QAnyStringView::arg(Args &&...args) const
1797{
1798 return QtPrivate::argToQStringDispatch(*this, QtPrivate::qStringLikeToArg(args)...);
1799}
1800
1801template <typename T>
1802qsizetype erase(QString &s, const T &t)
1803{
1804 return QtPrivate::q_string_like_container_erase_if(s, [&t](const auto &e) { return t == e; });
1805}
1806
1807template <typename Predicate>
1808qsizetype erase_if(QString &s, Predicate pred)
1809{
1810 return QtPrivate::q_string_like_container_erase_if(s, pred);
1811}
1812
1813namespace Qt {
1814inline namespace Literals {
1815inline namespace StringLiterals {
1816Q_DECL_CONSTEXPR_DTOR QString operator""_s(const char16_t *str, size_t size) noexcept
1817{
1818 return QString(QStringPrivate(nullptr, const_cast<char16_t *>(str), qsizetype(size)));
1819}
1820
1821} // StringLiterals
1822} // Literals
1823} // Qt
1824
1825inline namespace QtLiterals {
1826#if QT_DEPRECATED_SINCE(6, 8)
1827
1828QT_DEPRECATED_VERSION_X_6_8("Use _s from Qt::StringLiterals namespace instead.")
1829inline QString operator""_qs(const char16_t *str, size_t size) noexcept
1830{
1831 return Qt::StringLiterals::operator""_s(str, size);
1832}
1833
1834#endif // QT_DEPRECATED_SINCE(6, 8)
1835} // QtLiterals
1836
1837// all our supported compilers support Unicode string literals,
1838// even if their Q_COMPILER_UNICODE_STRING has been revoked due
1839// to lacking stdlib support. But QStringLiteral only needs the
1840// core language feature, so just use u"" here unconditionally:
1841
1842#define QT_UNICODE_LITERAL(str) u"" str
1843
1844namespace QtPrivate {
1845template <qsizetype N>
1846#if __cpp_constexpr >= 201907L
1847consteval
1848#else
1849Q_ALWAYS_INLINE
1850#endif
1851static QStringPrivate qMakeStringPrivate(const char16_t (&literal)[N])
1852{
1853 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
1854 auto str = const_cast<char16_t *>(literal);
1855 return { nullptr, str, N - 1 };
1856}
1857} // namespace QtPrivate
1858
1859#define QStringLiteral(str) (QString(QtPrivate::qMakeStringPrivate(QT_UNICODE_LITERAL(str)))) /**/
1860
1861QT_END_NAMESPACE
1862
1863#include <QtCore/qstringbuilder.h>
1864#include <QtCore/qstringconverter.h>
1865
1866#ifdef Q_L1S_VIEW_IS_PRIMARY
1867# undef Q_L1S_VIEW_IS_PRIMARY
1868#endif
1869
1870#endif // QSTRING_H
Definition moc.h:234
void parse()
Definition moc.cpp:775
bool requireCompleteTypes
Definition moc.h:246
ModuleUnitKind moduleUnitKind
Definition moc.h:258
void generate(FILE *out, FILE *jsonOutput)
Definition moc.cpp:1343
bool noInclude
Definition moc.h:244
QByteArray resolveIncludeNext(const QByteArray &filename, qsizetype startIndex, qsizetype *foundIndex=nullptr)
void setDebugIncludes(bool value)
void parseDefineArguments(Macro *m)
void skipUntilEndif()
Symbols preprocessed(const QByteArray &filename, QFile *device)
void substituteUntilNewline(Symbols &substituted)
QList< QByteArray > frameworks
QHash< QByteArray, IncludeResolution > nonlocalIncludePathResolutionCache
static bool preprocessOnly
QByteArray resolveInclude(const QByteArray &filename, const QByteArray &relativeTo, qsizetype *foundIndex=nullptr)
static Symbols macroExpandIdentifier(Preprocessor *that, SymbolStack &symbols, int lineNum, QByteArray *macroName)
static Symbols tokenize(const QByteArray &input, int lineNum=1, TokenizeMode mode=TokenizeCpp)
static void macroExpand(Symbols *into, Preprocessor *that, const Symbols &toExpand, qsizetype &index, int lineNum, bool one, const QSet< QByteArray > &excludeSymbols=QSet< QByteArray >())
@ PreparePreprocessorStatement
@ TokenizePreprocessorStatement
The QCommandLineOption class defines a possible command-line option. \inmodule QtCore.
The QCommandLineParser class provides a means for handling the command line options.
\inmodule QtCore\reentrant
Definition qdatastream.h:50
Definition qlist.h:82
\inmodule QtSql
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:177
QByteArray unquotedLexem()
Definition symbols.h:105
const Symbol & symbol() const
Definition symbols.h:102
Token token()
Definition symbols.h:103
bool dontReplaceSymbol(const QByteArray &name) const
Definition symbols.h:125
bool hasNext()
Definition symbols.h:89
QByteArray lexem() const
Definition symbols.h:104
Token next()
Definition symbols.h:94
const SafeSymbols & constTop() const
Definition symbols.h:88
bool test(Token)
Definition symbols.h:111
ModuleUnitKind
Definition moc.h:225
std::conditional_t< std::is_same_v< HashKey, q20::remove_cvref_t< KeyArgument > >, KeyArgument, HashKey > HeterogenousConstructProxy
Definition qhash.h:834
Combined button and popup list for selecting options.
QString && asString(QString &&s)
Definition qstring.h:1708
constexpr QAnyStringArg qStringLikeToArg(QAnyStringView s) noexcept
Definition qstring.h:1770
const QString & asString(const QString &s)
Definition qstring.h:1707
std::is_same< Char, char32_t > IsCompatibleChar32TypeHelper
Definition qstring.h:57
constexpr bool isLatin1(QLatin1StringView s) noexcept
Definition qstring.h:77
Definition qcompare.h:111
QHash< MacroName, Macro > Macros
SubArray MacroName
#define __has_builtin(x)
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_CREF(Class)
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH(Class, Arguments)
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_VALUE(Class)
#define QT_MK_QHASH_COMPAT(X)
QString operator+(const QString &s1, QChar s2)
Definition qstring.h:1571
QString operator+(QString &&lhs, const QString &rhs)
Definition qstring.h:1569
qsizetype erase_if(QString &s, Predicate pred)
Definition qstring.h:1808
#define QT_UNICODE_LITERAL(str)
Definition qstring.h:1842
#define qPrintable(string)
Definition qstring.h:1712
QString operator+(QString &&lhs, QChar rhs)
Definition qstring.h:1573
QString operator+(QChar s1, const QString &s2)
Definition qstring.h:1575
#define QStringLiteral(str)
Definition qstring.h:1859
QString operator+(const QString &s1, const QString &s2)
Definition qstring.h:1567
qsizetype erase(QString &s, const T &t)
Definition qstring.h:1802
static QByteArray combinePath(const QString &infile, const QString &outfile)
Definition main.cpp:40
static bool hasNext(const Symbols &symbols, int i)
Definition main.cpp:78
static const Symbol & next(const Symbols &symbols, int &i)
Definition main.cpp:81
int runMoc(int argc, char **argv)
Definition main.cpp:170
static auto openFileForWriting(const QString &name)
Definition main.cpp:62
void error(const char *msg="Invalid argument")
Definition main.cpp:56
static QStringList argumentsFromCommandLineAndFile(const QStringList &arguments, bool &hasOptionFiles)
Definition main.cpp:138
QByteArray composePreprocessorOutput(const Symbols &symbols)
Definition main.cpp:85
int main(int argc, char *argv[])
[ctor_close]
qsizetype foundIndex
Simple structure used by the Doc and DocParser classes.
Symbols symbols
bool isVariadic
bool isFunction
Symbols arguments
constexpr QAnyStringArg(QAnyStringView v) noexcept
Definition qstring.h:1754
QAnyStringView string
Definition qstring.h:1752
QLatin1StringView string
Definition qstring.h:1746
constexpr QLatin1StringArg(QLatin1StringView v) noexcept
Definition qstring.h:1748
constexpr QStringViewArg(QStringView v) noexcept
Definition qstring.h:1742
qsizetype index
Definition symbols.h:81
Symbols symbols
Definition symbols.h:78
QByteArray expandedMacro
Definition symbols.h:79
QByteArray array
Definition symbols.h:26
SubArray(const char *s)
Definition symbols.h:21
qsizetype len
Definition symbols.h:28
bool operator==(const SubArray &other) const
Definition symbols.h:29
qsizetype from
Definition symbols.h:27
SubArray()=default
SubArray(const QByteArray &a)
Definition symbols.h:20
SubArray(const QByteArray &a, qsizetype from, qsizetype len)
Definition symbols.h:22
qsizetype from
Definition symbols.h:70
QByteArrayView unquotedLexemView() const
Definition symbols.h:62
Symbol(int lineNum, Token token)
Definition symbols.h:48
operator SubArray() const
Definition symbols.h:64
QByteArrayView lexemView() const
Definition symbols.h:61
Token token
Definition symbols.h:58
void mergeStringLiteral(const Symbol &next)
bool operator==(const Symbol &o) const
Definition symbols.h:65
int lineNum
Definition symbols.h:57
Symbol()=default
Symbol(int lineNum, Token token, const QByteArray &lexem, qsizetype from, qsizetype len)
Definition symbols.h:53
QByteArray lexem() const
Definition symbols.h:59
QByteArray lex
Definition symbols.h:69
QByteArray unquotedLexem() const
Definition symbols.h:60
qsizetype len
Definition symbols.h:71
Symbol(int lineNum, Token token, const QByteArray &lexem)
Definition symbols.h:49
size_t qHash(const SubArray &key, size_t seed=0)
Definition symbols.h:39
Q_DECLARE_TYPEINFO(Symbol, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(SafeSymbols, Q_RELOCATABLE_TYPE)
QList< Symbol > Symbols
Definition symbols.h:75
#define FOR_ALL_TOKENS(F)
Definition token.h:11
Token PP_Token
Definition token.h:254