8#if QT_CONFIG(regularexpression)
9#include "qregularexpression.h"
12#include <private/qstringconverter_p.h>
13#include <private/qtools_p.h>
15#include "private/qsimd_p.h"
17#include <qdatastream.h>
31#include <private/qcore_mac_p.h>
34#include <private/qfunctions_p.h>
48#include <QtCore/private/qnumeric_p.h>
55# include <qt_windows.h>
56# if !defined(QT_BOOTSTRAPPED) && (defined(QT_NO_CAST_FROM_ASCII) || defined(QT_NO_CAST_TO_ASCII))
58# error "This file cannot be compiled with QT_NO_CAST_{TO,FROM}_ASCII, "
59 "otherwise some QString functions will not get exported."
68 if (sl_minus_1 < sizeof(sl_minus_1) * CHAR_BIT)
69 hashHaystack -= decltype(hashHaystack)(a) << sl_minus_1;
74using namespace Qt::StringLiterals;
75using namespace QtMiscUtils;
77const char16_t QString::_empty = 0;
83enum StringComparisonMode {
84 CompareStringsForEquality,
85 CompareStringsForOrdering
88template <
typename Pointer>
89char32_t foldCaseHelper(Pointer ch, Pointer start) =
delete;
92char32_t foldCaseHelper<
const QChar*>(
const QChar* ch,
const QChar* start)
94 return foldCase(
reinterpret_cast<
const char16_t*>(ch),
95 reinterpret_cast<
const char16_t*>(start));
99char32_t foldCaseHelper<
const char*>(
const char* ch,
const char*)
105char16_t valueTypeToUtf16(T t) =
delete;
108char16_t valueTypeToUtf16<QChar>(QChar t)
114char16_t valueTypeToUtf16<
char>(
char t)
116 return char16_t{uchar(t)};
120static inline bool foldAndCompare(
const T a,
const T b)
122 return foldCase(a) == b;
126
127
128
129
130
131
132
133template <
typename Haystack>
134static inline qsizetype qLastIndexOf(Haystack haystack, QChar needle,
135 qsizetype from, Qt::CaseSensitivity cs)
noexcept
137 if (haystack.size() == 0)
140 from += haystack.size();
141 else if (
std::size_t(from) >
std::size_t(haystack.size()))
142 from = haystack.size() - 1;
144 char16_t c = needle.unicode();
145 const auto b = haystack.data();
147 if (cs == Qt::CaseSensitive) {
149 if (valueTypeToUtf16(*n) == c)
154 if (foldCase(valueTypeToUtf16(*n)) == c)
161qLastIndexOf(QString, QChar, qsizetype, Qt::CaseSensitivity)
noexcept =
delete;
163template<
typename Haystack,
typename Needle>
164static qsizetype qLastIndexOf(Haystack haystack0, qsizetype from,
165 Needle needle0, Qt::CaseSensitivity cs)
noexcept
167 const qsizetype sl = needle0.size();
169 return qLastIndexOf(haystack0, needle0.front(), from, cs);
171 const qsizetype l = haystack0.size();
174 if (from == l && sl == 0)
176 const qsizetype delta = l - sl;
177 if (
std::size_t(from) >
std::size_t(l) || delta < 0)
182 auto sv = [sl](
const typename Haystack::value_type *v) {
return Haystack(v, sl); };
184 auto haystack = haystack0.data();
185 const auto needle = needle0.data();
186 const auto *end = haystack;
188 const qregisteruint sl_minus_1 = sl ? sl - 1 : 0;
189 const auto *n = needle + sl_minus_1;
190 const auto *h = haystack + sl_minus_1;
191 qregisteruint hashNeedle = 0, hashHaystack = 0;
193 if (cs == Qt::CaseSensitive) {
194 for (qsizetype idx = 0; idx < sl; ++idx) {
195 hashNeedle = (hashNeedle << 1) + valueTypeToUtf16(*(n - idx));
196 hashHaystack = (hashHaystack << 1) + valueTypeToUtf16(*(h - idx));
198 hashHaystack -= valueTypeToUtf16(*haystack);
200 while (haystack >= end) {
201 hashHaystack += valueTypeToUtf16(*haystack);
202 if (hashHaystack == hashNeedle
203 && QtPrivate::compareStrings(needle0, sv(haystack), Qt::CaseSensitive) == 0)
204 return haystack - end;
206 REHASH(valueTypeToUtf16(haystack[sl]));
209 for (qsizetype idx = 0; idx < sl; ++idx) {
210 hashNeedle = (hashNeedle << 1) + foldCaseHelper(n - idx, needle);
211 hashHaystack = (hashHaystack << 1) + foldCaseHelper(h - idx, end);
213 hashHaystack -= foldCaseHelper(haystack, end);
215 while (haystack >= end) {
216 hashHaystack += foldCaseHelper(haystack, end);
217 if (hashHaystack == hashNeedle
218 && QtPrivate::compareStrings(sv(haystack), needle0, Qt::CaseInsensitive) == 0)
219 return haystack - end;
221 REHASH(foldCaseHelper(haystack + sl, end));
227template <
typename Haystack,
typename Needle>
228bool qt_starts_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs)
noexcept
230 if (haystack.isNull())
231 return needle.isNull();
232 const auto haystackLen = haystack.size();
233 const auto needleLen = needle.size();
234 if (haystackLen == 0)
235 return needleLen == 0;
236 if (needleLen > haystackLen)
239 return QtPrivate::compareStrings(haystack.first(needleLen), needle, cs) == 0;
242template <
typename Haystack,
typename Needle>
243bool qt_ends_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs)
noexcept
245 if (haystack.isNull())
246 return needle.isNull();
247 const auto haystackLen = haystack.size();
248 const auto needleLen = needle.size();
249 if (haystackLen == 0)
250 return needleLen == 0;
251 if (haystackLen < needleLen)
254 return QtPrivate::compareStrings(haystack.last(needleLen), needle, cs) == 0;
258static void append_helper(QString &self, T view)
260 const auto strData = view.data();
261 const qsizetype strSize = view.size();
262 auto &d = self.data_ptr();
263 if (strData && strSize > 0) {
266 d.detachAndGrow(QArrayData::GrowsAtEnd, strSize,
nullptr,
nullptr);
267 Q_CHECK_PTR(d.data());
268 Q_ASSERT(strSize <= d.freeSpaceAtEnd());
270 auto dst =
std::next(d.data(), d.size);
271 if constexpr (std::is_same_v<T, QUtf8StringView>) {
272 dst = QUtf8::convertToUnicode(dst, view);
273 }
else if constexpr (std::is_same_v<T, QLatin1StringView>) {
274 QLatin1::convertToUnicode(dst, view);
278 "Can only operate on UTF-8 and Latin-1");
280 self.resize(
std::distance(d.begin(), dst));
281 }
else if (d.isNull() && !view.isNull()) {
282 self = QLatin1StringView(
"");
286template <uint MaxCount>
struct UnrollTailLoop
288 template <
typename RetType,
typename Functor1,
typename Functor2,
typename Number>
289 static inline RetType exec(Number count, RetType returnIfExited, Functor1 loopCheck, Functor2 returnIfFailed, Number i = 0)
292
293
294
295
296
297
300 return returnIfExited;
302 bool check = loopCheck(i);
304 return returnIfFailed(i);
306 return UnrollTailLoop<MaxCount - 1>::exec(count - 1, returnIfExited, loopCheck, returnIfFailed, i + 1);
309 template <
typename Functor,
typename Number>
310 static inline void exec(Number count, Functor code)
313
314
315
316 exec(count, 0, [=](Number i) ->
bool { code(i);
return false; }, [](Number) {
return 0; });
319template <>
template <
typename RetType,
typename Functor1,
typename Functor2,
typename Number>
320inline RetType UnrollTailLoop<0>::exec(Number, RetType returnIfExited, Functor1, Functor2, Number)
322 return returnIfExited;
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
356#if defined(__mips_dsp)
358extern "C" void qt_fromlatin1_mips_asm_unroll4 (
char16_t*,
const char*, uint);
359extern "C" void qt_fromlatin1_mips_asm_unroll8 (
char16_t*,
const char*, uint);
360extern "C" void qt_toLatin1_mips_dsp_asm(uchar *dst,
const char16_t *src,
int length);
363#if defined(__SSE2__
) && defined(Q_CC_GNU)
366# define ATTRIBUTE_NO_SANITIZE __attribute__((__no_sanitize_address__, __no_sanitize_thread__))
368# define ATTRIBUTE_NO_SANITIZE
372static constexpr bool UseSse4_1 =
bool(qCompilerCpuFeatures & CpuFeatureSSE4_1);
373static constexpr bool UseAvx2 = UseSse4_1 &&
374 (qCompilerCpuFeatures & CpuFeatureArchHaswell) == CpuFeatureArchHaswell;
377Q_ALWAYS_INLINE
static __m128i mm_load8_zero_extend(
const void *ptr)
379 const __m128i *dataptr =
static_cast<
const __m128i *>(ptr);
380 if constexpr (UseSse4_1) {
383 __m128i data = _mm_loadl_epi64(dataptr);
384 return _mm_cvtepu8_epi16(data);
388 __m128i data = _mm_loadl_epi64(dataptr);
389 return _mm_unpacklo_epi8(data, _mm_setzero_si128());
393static qsizetype qustrlen_sse2(
const char16_t *str)
noexcept
396 quintptr misalignment = quintptr(str) & 0xf;
397 Q_ASSERT((misalignment & 1) == 0);
398 const char16_t *ptr = str - (misalignment / 2);
402 const __m128i zeroes = _mm_setzero_si128();
403 __m128i data = _mm_load_si128(
reinterpret_cast<
const __m128i *>(ptr));
404 __m128i comparison = _mm_cmpeq_epi16(data, zeroes);
405 uint mask = _mm_movemask_epi8(comparison);
408 mask >>= misalignment;
413 return qCountTrailingZeroBits(mask) /
sizeof(
char16_t);
415 constexpr qsizetype Step =
sizeof(__m128i) /
sizeof(
char16_t);
416 qsizetype size = Step - misalignment /
sizeof(
char16_t);
421 data = _mm_load_si128(
reinterpret_cast<
const __m128i *>(str + size));
423 comparison = _mm_cmpeq_epi16(data, zeroes);
424 mask = _mm_movemask_epi8(comparison);
428 return size + qCountTrailingZeroBits(mask) /
sizeof(
char16_t);
435static qptrdiff simdTestMask(
const char16_t *ptr16, qsizetype len, quint32 maskval)
437 const char *ptr =
reinterpret_cast<
const char *>(ptr16);
439 const qptrdiff bytes = len * 2;
440 auto updatePtr = [&](uint result) {
442 uint idx = qCountTrailingZeroBits(~result);
443 return (offset + idx) / 2;
446 if constexpr (UseSse4_1) {
449 auto updatePtrSimd = [&](__m128i data) -> qptrdiff {
450 __m128i masked = _mm_and_si128(mask, data);
451 __m128i comparison = _mm_cmpeq_epi16(masked, _mm_setzero_si128());
452 uint result = _mm_movemask_epi8(comparison);
453 return updatePtr(result);
456 if constexpr (UseAvx2) {
458 const __m256i mask256 = _mm256_broadcastd_epi32(_mm_cvtsi32_si128(maskval));
459 while (offset + 32 <= bytes) {
460 __m256i data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(ptr + offset));
461 if (!_mm256_testz_si256(mask256, data)) {
463 __m256i masked256 = _mm256_and_si256(mask256, data);
464 __m256i comparison256 = _mm256_cmpeq_epi16(masked256, _mm256_setzero_si256());
465 return updatePtr(_mm256_movemask_epi8(comparison256));
470 mask = _mm256_castsi256_si128(mask256);
474 mask = _mm_set1_epi32(maskval);
475 while (offset + 32 <= bytes) {
476 __m128i data1 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr + offset));
477 __m128i data2 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr + offset + 16));
478 if (!_mm_testz_si128(mask, data1))
479 return updatePtrSimd(data1);
482 if (!_mm_testz_si128(mask, data2))
483 return updatePtrSimd(data2);
489 if (offset + 16 <= bytes) {
490 __m128i data1 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr + offset));
491 if (!_mm_testz_si128(mask, data1))
492 return updatePtrSimd(data1);
497 if (offset + 8 <= bytes) {
498 __m128i data1 = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr + offset));
499 if (!_mm_testz_si128(mask, data1))
500 return updatePtrSimd(data1);
509 const __m128i mask = _mm_set1_epi32(maskval);
510 while (offset + 16 <= bytes) {
511 __m128i data = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr + offset));
512 __m128i masked = _mm_and_si128(mask, data);
513 __m128i comparison = _mm_cmpeq_epi16(masked, _mm_setzero_si128());
514 quint16 result = _mm_movemask_epi8(comparison);
515 if (result != 0xffff)
516 return updatePtr(result);
521 if (offset + 8 <= bytes) {
522 __m128i data = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr + offset));
523 __m128i masked = _mm_and_si128(mask, data);
524 __m128i comparison = _mm_cmpeq_epi16(masked, _mm_setzero_si128());
525 quint8 result = _mm_movemask_epi8(comparison);
527 return updatePtr(result);
534template <StringComparisonMode Mode,
typename Char> [[maybe_unused]]
535static int ucstrncmp_sse2(
const char16_t *a,
const Char *b, size_t l)
537 static_assert(
std::is_unsigned_v<Char>);
541 static const auto codeUnitAt = [](
const auto *n, qptrdiff idx) ->
int {
542 constexpr int Stride = 2;
549 auto ptr =
reinterpret_cast<
const uchar *>(n);
550 ptr += idx / (Stride /
sizeof(*n));
551 return *
reinterpret_cast<
decltype(n)>(ptr);
553 auto difference = [a, b](uint mask, qptrdiff offset) {
554 if (Mode == CompareStringsForEquality)
556 uint idx = qCountTrailingZeroBits(mask);
557 return codeUnitAt(a + offset, idx) - codeUnitAt(b + offset, idx);
560 static const auto load8Chars = [](
const auto *ptr) {
561 if (
sizeof(*ptr) == 2)
562 return _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr));
563 __m128i chunk = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr));
564 return _mm_unpacklo_epi8(chunk, _mm_setzero_si128());
566 static const auto load4Chars = [](
const auto *ptr) {
567 if (
sizeof(*ptr) == 2)
568 return _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr));
569 __m128i chunk = _mm_cvtsi32_si128(qFromUnaligned<quint32>(ptr));
570 return _mm_unpacklo_epi8(chunk, _mm_setzero_si128());
574 auto processChunk16Chars = [a, b](qptrdiff offset) -> uint {
575 if constexpr (UseAvx2) {
576 __m256i a_data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(a + offset));
578 if (
sizeof(Char) == 1) {
580 __m128i chunk = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(b + offset));
581 b_data = _mm256_cvtepu8_epi16(chunk);
583 b_data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(b + offset));
585 __m256i result = _mm256_cmpeq_epi16(a_data, b_data);
586 return _mm256_movemask_epi8(result);
589 __m128i a_data1 = load8Chars(a + offset);
590 __m128i a_data2 = load8Chars(a + offset + 8);
591 __m128i b_data1, b_data2;
592 if (
sizeof(Char) == 1) {
594 __m128i b_data = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(b + offset));
595 b_data1 = _mm_unpacklo_epi8(b_data, _mm_setzero_si128());
596 b_data2 = _mm_unpackhi_epi8(b_data, _mm_setzero_si128());
598 b_data1 = load8Chars(b + offset);
599 b_data2 = load8Chars(b + offset + 8);
601 __m128i result1 = _mm_cmpeq_epi16(a_data1, b_data1);
602 __m128i result2 = _mm_cmpeq_epi16(a_data2, b_data2);
603 return _mm_movemask_epi8(result1) | _mm_movemask_epi8(result2) << 16;
606 if (l >=
sizeof(__m256i) /
sizeof(
char16_t)) {
608 for ( ; l >= offset +
sizeof(__m256i) /
sizeof(
char16_t); offset +=
sizeof(__m256i) /
sizeof(
char16_t)) {
609 uint mask = ~processChunk16Chars(offset);
611 return difference(mask, offset);
615 if (size_t(offset) < l) {
616 offset = l -
sizeof(__m256i) /
sizeof(
char16_t);
617 uint mask = ~processChunk16Chars(offset);
618 return mask ? difference(mask, offset) : 0;
621 __m128i a_data1, b_data1;
622 __m128i a_data2, b_data2;
626 a_data1 = load8Chars(a);
627 b_data1 = load8Chars(b);
628 a_data2 = load8Chars(a + l - width);
629 b_data2 = load8Chars(b + l - width);
633 a_data1 = load4Chars(a);
634 b_data1 = load4Chars(b);
635 a_data2 = load4Chars(a + l - width);
636 b_data2 = load4Chars(b + l - width);
639 __m128i result = _mm_cmpeq_epi16(a_data1, b_data1);
640 ushort mask = ~_mm_movemask_epi8(result);
642 return difference(mask, 0);
644 result = _mm_cmpeq_epi16(a_data2, b_data2);
645 mask = ~_mm_movemask_epi8(result);
647 return difference(mask, l - width);
652 const auto lambda = [=](size_t i) ->
int {
655 return UnrollTailLoop<3>::exec(l, 0, lambda, lambda);
662qsizetype QtPrivate::qustrlen(
const char16_t *str)
noexcept
664#if defined(__SSE2__
) && !(defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)) && !(defined(__SANITIZE_THREAD__) || __has_feature(thread_sanitizer))
665 return qustrlen_sse2(str);
668 if (
sizeof(
wchar_t) ==
sizeof(
char16_t))
669 return wcslen(
reinterpret_cast<
const wchar_t *>(str));
671 qsizetype result = 0;
677qsizetype
QtPrivate::qustrnlen(
const char16_t *str, qsizetype maxlen)
noexcept
679 return qustrchr({ str, maxlen }, u'\0') - str;
683
684
685
686
687
688
689
693 const char16_t *n = str.utf16();
694 const char16_t *e = n + str.size();
701 if constexpr (UseAvx2) {
703 __m256i mch256 = _mm256_set1_epi32(c | (c << 16));
704 for (
const char16_t *next = n + 16; next <= e; n = next, next += 16) {
705 __m256i data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(n));
706 __m256i result = _mm256_cmpeq_epi16(data, mch256);
707 uint mask = uint(_mm256_movemask_epi8(result));
709 uint idx = qCountTrailingZeroBits(mask);
714 mch = _mm256_castsi256_si128(mch256);
716 mch = _mm_set1_epi32(c | (c << 16));
719 auto hasMatch = [mch, &n](__m128i data, ushort validityMask) {
720 __m128i result = _mm_cmpeq_epi16(data, mch);
721 uint mask = uint(_mm_movemask_epi8(result));
722 if ((mask & validityMask) == 0)
724 uint idx = qCountTrailingZeroBits(mask);
730 for (
const char16_t *next = n + 8; next <= e; n = next, next += 8) {
731 __m128i data = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(n));
732 if (hasMatch(data, 0xffff))
741# if !defined(__OPTIMIZE_SIZE__)
744 __m128i data = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(n));
745 if (hasMatch(data, 0xff))
751 return UnrollTailLoop<3>::exec(e - n, e,
752 [=](qsizetype i) {
return n[i] == c; },
753 [=](qsizetype i) {
return n + i; });
755#elif defined(__ARM_NEON__)
756 const uint16x8_t vmask = qvsetq_n_u16(1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7);
757 const uint16x8_t ch_vec = vdupq_n_u16(c);
758 for (
const char16_t *next = n + 8; next <= e; n = next, next += 8) {
759 uint16x8_t data = vld1q_u16(
reinterpret_cast<
const uint16_t *>(n));
760 uint mask = vaddvq_u16(vandq_u16(vceqq_u16(data, ch_vec), vmask));
763 return n + qCountTrailingZeroBits(mask);
768 return std::find(n, e, c);
772
773
774
775
776
777
781 const QChar *n = str.begin();
782 const QChar *e = str.end();
784 auto it =
std::find_if(n, e, [c](
auto ch) {
return foldAndCompare(ch, QChar(c)); });
785 return reinterpret_cast<
const char16_t *>(it);
790 const char *
const ptr = s.begin();
791 const qsizetype len = s.size();
796 if constexpr (UseAvx2) {
797 while (offset + 32 <= len) {
798 __m256i data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(ptr + offset));
799 quint32 mask = _mm256_movemask_epi8(data);
807 while (offset + 16 <= len) {
808 __m128i data = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr + offset));
809 quint32 mask = _mm_movemask_epi8(data);
818 if (offset + 8 <= len) {
819 __m128i data = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr + offset));
820 quint8 mask = _mm_movemask_epi8(data);
827 while (offset + 4 <= len) {
828 quint32 data = qFromUnaligned<quint32>(ptr + offset);
829 if (data & 0x80808080U)
834 while (offset != len) {
835 if (quint8(ptr[offset]) & 0x80)
846 offset = simdTestMask(ptr, len, 0xff80ff80);
849 while (offset != len) {
850 if (ptr[offset] & 0xff80)
859 const char16_t *ptr = s.utf16();
861 return isAscii_helper(ptr, s.size()) < 0;
867 const char16_t *ptr = s.utf16();
868 const qsizetype len = s.size();
871 offset = simdTestMask(ptr, len, 0xff00ff00);
874 while (offset != len) {
875 if (ptr[offset++] > 0xff)
883 constexpr char32_t InvalidCodePoint = UINT_MAX;
887 const char32_t c = i
.next(InvalidCodePoint
);
888 if (c == InvalidCodePoint)
896Q_CORE_EXPORT
void qt_from_latin1(
char16_t *dst,
const char *str, size_t size)
noexcept
899
900
901
902
905 const __m128i nullMask = _mm_setzero_si128();
906 auto processOneChunk = [=](qptrdiff offset) {
907 const __m128i chunk = _mm_loadu_si128((
const __m128i*)(str + offset));
908 if constexpr (UseAvx2) {
910 const __m256i extended = _mm256_cvtepu8_epi16(chunk);
913 _mm256_storeu_si256((__m256i*)(dst + offset), extended);
916 const __m128i firstHalf = _mm_unpacklo_epi8(chunk, nullMask);
917 _mm_storeu_si128((__m128i*)(dst + offset), firstHalf);
920 const __m128i secondHalf = _mm_unpackhi_epi8 (chunk, nullMask);
921 _mm_storeu_si128((__m128i*)(dst + offset + 8), secondHalf);
925 const char *e = str + size;
926 if (size >=
sizeof(__m128i)) {
928 for ( ; str + offset +
sizeof(__m128i) <= e; offset +=
sizeof(__m128i))
929 processOneChunk(offset);
930 if (str + offset < e)
931 processOneChunk(size -
sizeof(__m128i));
935# if !defined(__OPTIMIZE_SIZE__)
939 const __m128i unpacked1 = mm_load8_zero_extend(str);
940 const __m128i unpacked2 = mm_load8_zero_extend(str + size - 8);
941 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst), unpacked1);
942 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst + size - 8), unpacked2);
944 const __m128i chunk1 = _mm_cvtsi32_si128(qFromUnaligned<quint32>(str));
945 const __m128i chunk2 = _mm_cvtsi32_si128(qFromUnaligned<quint32>(str + size - 4));
946 const __m128i unpacked1 = _mm_unpacklo_epi8(chunk1, nullMask);
947 const __m128i unpacked2 = _mm_unpacklo_epi8(chunk2, nullMask);
948 _mm_storel_epi64(
reinterpret_cast<__m128i *>(dst), unpacked1);
949 _mm_storel_epi64(
reinterpret_cast<__m128i *>(dst + size - 4), unpacked2);
954 return UnrollTailLoop<3>::exec(qsizetype(size), [=](qsizetype i) { dst[i] = uchar(str[i]); });
958#if defined(__mips_dsp)
959 static_assert(
sizeof(qsizetype) ==
sizeof(
int),
960 "oops, the assembler implementation needs to be called in a loop");
962 qt_fromlatin1_mips_asm_unroll8(dst, str, size);
964 qt_fromlatin1_mips_asm_unroll4(dst, str, size);
967 *dst++ = (uchar)*str++;
973 const qsizetype len = str.size();
975 QVarLengthArray<
char16_t> arr(len);
976 qt_from_latin1(arr.data(), str.data(), len);
980template <
bool Checked>
984 auto questionMark256 = []() {
985 if constexpr (UseAvx2)
986 return _mm256_broadcastw_epi16(_mm_cvtsi32_si128(
'?'));
990 auto outOfRange256 = []() {
991 if constexpr (UseAvx2)
992 return _mm256_broadcastw_epi16(_mm_cvtsi32_si128(0x100));
996 __m128i questionMark, outOfRange;
997 if constexpr (UseAvx2) {
998 questionMark = _mm256_castsi256_si128(questionMark256);
999 outOfRange = _mm256_castsi256_si128(outOfRange256);
1001 questionMark = _mm_set1_epi16(
'?');
1002 outOfRange = _mm_set1_epi16(0x100);
1005 auto mergeQuestionMarks = [=](__m128i chunk) {
1010 if constexpr (UseSse4_1) {
1012 chunk = _mm_min_epu16(chunk, outOfRange);
1013 const __m128i offLimitMask = _mm_cmpeq_epi16(chunk, outOfRange);
1014 chunk = _mm_blendv_epi8(chunk, questionMark, offLimitMask);
1018 const __m128i signedBitOffset = _mm_set1_epi16(
short(0x8000));
1019 const __m128i thresholdMask = _mm_set1_epi16(
short(0xff + 0x8000));
1021 const __m128i signedChunk = _mm_add_epi16(chunk, signedBitOffset);
1022 const __m128i offLimitMask = _mm_cmpgt_epi16(signedChunk, thresholdMask);
1026 const __m128i offLimitQuestionMark = _mm_and_si128(offLimitMask, questionMark);
1030 const __m128i correctBytes = _mm_andnot_si128(offLimitMask, chunk);
1033 chunk = _mm_or_si128(correctBytes, offLimitQuestionMark);
1035 Q_UNUSED(outOfRange);
1040 auto loadChunkAt = [=](qptrdiff offset) {
1041 __m128i chunk1, chunk2;
1042 if constexpr (UseAvx2) {
1043 __m256i chunk = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(src + offset));
1046 chunk = _mm256_min_epu16(chunk, outOfRange256);
1047 const __m256i offLimitMask = _mm256_cmpeq_epi16(chunk, outOfRange256);
1048 chunk = _mm256_blendv_epi8(chunk, questionMark256, offLimitMask);
1051 chunk2 = _mm256_extracti128_si256(chunk, 1);
1052 chunk1 = _mm256_castsi256_si128(chunk);
1054 chunk1 = _mm_loadu_si128((
const __m128i*)(src + offset));
1055 chunk1 = mergeQuestionMarks(chunk1);
1057 chunk2 = _mm_loadu_si128((
const __m128i*)(src + offset + 8));
1058 chunk2 = mergeQuestionMarks(chunk2);
1062 return _mm_packus_epi16(chunk1, chunk2);
1065 if (size_t(length) >=
sizeof(__m128i)) {
1067 qptrdiff offset = 0;
1068 for ( ; offset + 2 *
sizeof(__m128i) < size_t(length); offset +=
sizeof(__m128i))
1069 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst + offset), loadChunkAt(offset));
1072 __m128i last1 = loadChunkAt(offset);
1073 __m128i last2 = loadChunkAt(length -
sizeof(__m128i));
1074 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst + offset), last1);
1075 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst + length -
sizeof(__m128i)), last2);
1079# if !defined(__OPTIMIZE_SIZE__)
1084 __m128i chunk1 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(src));
1085 __m128i chunk2 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(src + length - 8));
1086 chunk1 = mergeQuestionMarks(chunk1);
1087 chunk2 = mergeQuestionMarks(chunk2);
1090 const __m128i result1 = _mm_packus_epi16(chunk1, chunk1);
1091 const __m128i result2 = _mm_packus_epi16(chunk2, chunk2);
1092 _mm_storel_epi64(
reinterpret_cast<__m128i *>(dst), result1);
1093 _mm_storel_epi64(
reinterpret_cast<__m128i *>(dst + length - 8), result2);
1095 __m128i chunk1 = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(src));
1096 __m128i chunk2 = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(src + length - 4));
1097 chunk1 = mergeQuestionMarks(chunk1);
1098 chunk2 = mergeQuestionMarks(chunk2);
1101 const __m128i result1 = _mm_packus_epi16(chunk1, chunk1);
1102 const __m128i result2 = _mm_packus_epi16(chunk2, chunk2);
1103 qToUnaligned(_mm_cvtsi128_si32(result1), dst);
1104 qToUnaligned(_mm_cvtsi128_si32(result2), dst + length - 4);
1109 length = length % 4;
1110 return UnrollTailLoop<3>::exec(length, [=](qsizetype i) {
1112 dst[i] = (src[i]>0xff) ?
'?' : (uchar) src[i];
1117 length = length % 16;
1119#elif defined(__ARM_NEON__)
1125 const qsizetype chunkCount = length >> 3;
1126 const uint16x8_t questionMark = vdupq_n_u16(
'?');
1127 const uint16x8_t thresholdMask = vdupq_n_u16(0xff);
1128 for (qsizetype i = 0; i < chunkCount; ++i) {
1129 uint16x8_t chunk = vld1q_u16((uint16_t *)src);
1133 const uint16x8_t offLimitMask = vcgtq_u16(chunk, thresholdMask);
1134 const uint16x8_t offLimitQuestionMark = vandq_u16(offLimitMask, questionMark);
1135 const uint16x8_t correctBytes = vbicq_u16(chunk, offLimitMask);
1136 chunk = vorrq_u16(correctBytes, offLimitQuestionMark);
1138 const uint8x8_t result = vmovn_u16(chunk);
1139 vst1_u8(dst, result);
1142 length = length % 8;
1145#if defined(__mips_dsp)
1146 static_assert(
sizeof(qsizetype) ==
sizeof(
int),
1147 "oops, the assembler implementation needs to be called in a loop");
1148 qt_toLatin1_mips_dsp_asm(dst, src, length);
1152 *dst++ = (*src>0xff) ?
'?' : (uchar) *src;
1162 qt_to_latin1_internal<
true>(dst, src, length);
1167 qt_to_latin1_internal<
false>(dst, src, length);
1172 Q_DECL_UNINITIALIZED
1173 QVarLengthArray<
char> s(str.size());
1174 qt_to_latin1_unchecked(
reinterpret_cast<uchar *>(s.data()), str.utf16(), str.size());
1182 return qt_lencmp(alen, blen);
1184 qsizetype l = qMin(alen, blen);
1186 for (i = 0; i < l; ++i) {
1190 int diff = foldCase(a + i, a) - foldCase(b + i, b);
1206 qsizetype l = qMin(alen, blen);
1208 for (i = 0; i < l; ++i) {
1209 int diff = foldCase(a[i]) -
foldCase(char16_t{uchar(b[i])}
);
1224 auto src1 =
reinterpret_cast<
const qchar8_t *>(utf8);
1225 auto end1 =
reinterpret_cast<
const qchar8_t *>(utf8end);
1229 char32_t uc1 = QChar::toCaseFolded(QUtf8Functions::nextUcs4FromUtf8(src1, end1));
1230 char32_t uc2 = QChar::toCaseFolded(src2.next());
1231 int diff = uc1 - uc2;
1240#if defined(__mips_dsp)
1242extern "C" int qt_ucstrncmp_mips_dsp_asm(
const char16_t *a,
1248template <StringComparisonMode Mode>
1249static int ucstrncmp(
const char16_t *a,
const char16_t *b, size_t l)
1255#ifndef __OPTIMIZE_SIZE__
1256# if defined(__mips_dsp)
1257 static_assert(
sizeof(uint) ==
sizeof(size_t));
1259 return qt_ucstrncmp_mips_dsp_asm(a, b, l);
1261# elif defined(__SSE2__
)
1262 return ucstrncmp_sse2<Mode>(a, b, l);
1263# elif defined(__ARM_NEON__)
1265 const char16_t *end = a + l;
1266 const uint16x8_t mask = qvsetq_n_u16( 1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7 );
1267 while (end - a > 7) {
1268 uint16x8_t da = vld1q_u16(
reinterpret_cast<
const uint16_t *>(a));
1269 uint16x8_t db = vld1q_u16(
reinterpret_cast<
const uint16_t *>(b));
1271 uint8_t r = ~(uint8_t)vaddvq_u16(vandq_u16(vceqq_u16(da, db), mask));
1274 if (Mode == CompareStringsForEquality)
1276 uint idx = qCountTrailingZeroBits(r);
1277 return a[idx] - b[idx];
1284 const auto lambda = [=](size_t i) ->
int {
1287 return UnrollTailLoop<7>::exec(l, 0, lambda, lambda);
1291 if (Mode == CompareStringsForEquality || QSysInfo::ByteOrder == QSysInfo::BigEndian)
1292 return memcmp(a, b, l *
sizeof(
char16_t));
1294 for (size_t i = 0; i < l; ++i) {
1295 if (
int diff = a[i] - b[i])
1301template <StringComparisonMode Mode>
1302static int ucstrncmp(
const char16_t *a,
const char *b, size_t l)
1304 const uchar *c =
reinterpret_cast<
const uchar *>(b);
1305 const char16_t *uc = a;
1306 const char16_t *e = uc + l;
1308#if defined(__SSE2__
) && !defined(__OPTIMIZE_SIZE__)
1309 return ucstrncmp_sse2<Mode>(uc, c, l);
1313 int diff = *uc - *c;
1323template <
typename Char2>
1324static bool ucstreq(
const char16_t *a, size_t alen,
const Char2 *b)
1326 return ucstrncmp<CompareStringsForEquality>(a, b, alen) == 0;
1330template <
typename Char2>
1331static int ucstrcmp(
const char16_t *a, size_t alen,
const Char2 *b, size_t blen)
1333 const size_t l = qMin(alen, blen);
1334 int cmp = ucstrncmp<CompareStringsForOrdering>(a, b, l);
1335 return cmp ? cmp : qt_lencmp(alen, blen);
1340static int latin1nicmp(
const char *lhsChar, qsizetype lSize,
const char *rhsChar, qsizetype rSize)
1343 Q_ASSERT(lSize >= 0 && rSize >= 0);
1345 return rSize ? -1 : 0;
1348 const qsizetype size =
std::min(lSize, rSize);
1350 Q_ASSERT(lhsChar && rhsChar);
1351 for (qsizetype i = 0; i < size; i++) {
1355 return qt_lencmp(lSize, rSize);
1360 Q_ASSERT(lhs.size() == rhs.size());
1361 return ucstreq(lhs.utf16(), lhs.size(), rhs.utf16());
1366 Q_ASSERT(lhs.size() == rhs.size());
1367 return ucstreq(lhs.utf16(), lhs.size(), rhs.latin1());
1372 return QtPrivate::equalStrings(rhs, lhs);
1377 Q_ASSERT(lhs.size() == rhs.size());
1378 return (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0);
1383 return QUtf8::compareUtf8(lhs, rhs) == 0;
1388 return QtPrivate::equalStrings(rhs, lhs);
1393 return QUtf8::compareUtf8(QByteArrayView(rhs), lhs) == 0;
1398 return QtPrivate::equalStrings(rhs, lhs);
1403#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
) || defined(QT_BOOTSTRAPPED) || defined(QT_STATIC)
1404 Q_ASSERT(lhs.size() == rhs.size());
1407 if (lhs.size() != rhs.size())
1410 return (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0);
1413bool QAnyStringView::equal(QAnyStringView lhs, QAnyStringView rhs)
noexcept
1415 if (lhs.size() != rhs.size() && lhs.isUtf8() == rhs.isUtf8())
1417 return lhs.visit([rhs](
auto lhs) {
1418 return rhs.visit([lhs](
auto rhs) {
1419 return QtPrivate::equalStrings(lhs, rhs);
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1441 if (cs == Qt::CaseSensitive)
1442 return ucstrcmp(lhs.utf16(), lhs.size(), rhs.utf16(), rhs.size());
1443 return ucstricmp(lhs.size(), lhs.utf16(), rhs.size(), rhs.utf16());
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1464 if (cs == Qt::CaseSensitive)
1465 return ucstrcmp(lhs.utf16(), lhs.size(), rhs.latin1(), rhs.size());
1466 return ucstricmp(lhs.size(), lhs.utf16(), rhs.size(), rhs.latin1());
1470
1471
1472
1473
1474
1477 return -compareStrings(rhs, lhs, cs);
1481
1482
1483
1484
1485
1488 return -compareStrings(rhs, lhs, cs);
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1510 return qt_lencmp(qsizetype(0), rhs.size());
1512 return qt_lencmp(lhs.size(), qsizetype(0));
1513 if (cs == Qt::CaseInsensitive)
1514 return latin1nicmp(lhs.data(), lhs.size(), rhs.data(), rhs.size());
1515 const auto l =
std::min(lhs.size(), rhs.size());
1516 int r = memcmp(lhs.data(), rhs.data(), l);
1517 return r ? r : qt_lencmp(lhs.size(), rhs.size());
1521
1522
1523
1524
1525
1528 return -QUtf8::compareUtf8(QByteArrayView(rhs), lhs, cs);
1532
1533
1534
1535
1536
1539 if (cs == Qt::CaseSensitive)
1540 return QUtf8::compareUtf8(lhs, rhs);
1541 return ucstricmp8(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1545
1546
1547
1548
1549
1552 return -compareStrings(rhs, lhs, cs);
1556
1557
1558
1559
1560
1563 return QUtf8::compareUtf8(QByteArrayView(lhs), QByteArrayView(rhs), cs);
1566int QAnyStringView::compare(QAnyStringView lhs, QAnyStringView rhs, Qt::CaseSensitivity cs)
noexcept
1568 return lhs.visit([rhs, cs](
auto lhs) {
1569 return rhs.visit([lhs, cs](
auto rhs) {
1570 return QtPrivate::compareStrings(lhs, rhs, cs);
1577#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
1578static bool supportUnicodeDigitValuesInArg()
1580 static const bool result = []() {
1581 static const char supportUnicodeDigitValuesEnvVar[]
1582 =
"QT_USE_UNICODE_DIGIT_VALUES_IN_STRING_ARG";
1584 if (qEnvironmentVariableIsSet(supportUnicodeDigitValuesEnvVar))
1585 return qEnvironmentVariableIntValue(supportUnicodeDigitValuesEnvVar) != 0;
1587#if QT_VERSION < QT_VERSION_CHECK(6
, 6
, 0
)
1600#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
1601 if (supportUnicodeDigitValuesInArg())
1602 return ch.digitValue();
1604 if (ch >= u'0' && ch <= u'9')
1605 return int(ch.unicode() - u'0');
1609#if QT_CONFIG(regularexpression)
1611static void qtWarnAboutInvalidRegularExpression(
const QRegularExpression &re,
const char *cls,
const char *method)
1613 extern void qtWarnAboutInvalidRegularExpression(
const QString &pattern,
const char *cls,
const char *method);
1614 qtWarnAboutInvalidRegularExpression(re.pattern(), cls, method);
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1650
1651
1652
1653
1654
1655
1656
1657
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2124
2125
2126
2129
2130
2131
2134
2135
2136
2139
2140
2141
2144
2145
2146
2147
2150
2151
2152
2153
2156
2157
2160
2161
2164
2165
2167
2168
2171
2172
2173
2174
2175
2177
2178
2179
2180
2181
2184
2185
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2201
2202
2203
2206
2207
2208
2209
2210
2211
2212
2213
2214
2217
2218
2219
2220
2221
2222
2223
2224
2227
2228
2229
2230
2231
2232
2233
2234
2237
2238
2239
2242
2243
2244
2245
2246
2247
2248
2249
2250
2253
2254
2255
2256
2257
2258
2259
2260
2263
2264
2265
2266
2267
2268
2269
2270
2271
2274
2275
2276
2279
2280
2281
2282
2283
2284
2285
2286
2287
2290
2291
2292
2293
2294
2295
2296
2297
2298
2301
2302
2303
2306
2307
2308
2309
2310
2311
2312
2313
2314
2317
2318
2319
2320
2321
2322
2325
2326
2327
2328
2329
2330
2331
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2354
2355
2356
2357
2358
2359
2360
2361
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2376
2377
2378
2379
2380
2383
2384
2385
2386
2387
2390
2391
2392
2393
2394
2395
2396
2397
2398
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2428qsizetype QString::toUcs4_helper(
const char16_t *uc, qsizetype length,
char32_t *out)
2430 qsizetype count = 0;
2432 QStringIterator i(QStringView(uc, length));
2434 out[count++] = i.next();
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486QString::QString(
const QChar *unicode, qsizetype size)
2492 size = QtPrivate::qustrlen(
reinterpret_cast<
const char16_t *>(unicode));
2494 d = DataPointer::fromRawData(&_empty, 0);
2496 d = DataPointer(size, size);
2497 Q_CHECK_PTR(d.data());
2498 memcpy(d.data(), unicode, size *
sizeof(QChar));
2499 d.data()[size] =
'\0';
2505
2506
2507
2508
2509
2510QString::QString(qsizetype size, QChar ch)
2513 d = DataPointer::fromRawData(&_empty, 0);
2515 d = DataPointer(size, size);
2516 Q_CHECK_PTR(d.data());
2517 d.data()[size] =
'\0';
2518 char16_t *b = d.data();
2519 char16_t *e = d.data() + size;
2520 const char16_t value = ch.unicode();
2521 std::fill(b, e, value);
2526
2527
2528
2529
2530QString::QString(qsizetype size, Qt::Initialization)
2533 d = DataPointer::fromRawData(&_empty, 0);
2535 d = DataPointer(size, size);
2536 Q_CHECK_PTR(d.data());
2537 d.data()[size] =
'\0';
2542
2543
2544
2545
2546
2549
2550
2551QString::QString(QChar ch)
2553 d = DataPointer(1, 1);
2554 Q_CHECK_PTR(d.data());
2555 d.data()[0] = ch.unicode();
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2577
2578
2581
2582
2585
2586
2589
2590
2591
2592
2596
2597
2598
2601
2602
2603
2604
2607
2608
2609
2612
2613
2614
2617
2618
2619
2620
2621
2625 const auto capacityAtEnd = str.capacity() - str.data_ptr().freeSpaceAtBegin();
2626 return newSize > capacityAtEnd;
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2660void QString::resize(qsizetype size)
2665 if (d.needsDetach() || needsReallocate(*
this, size))
2666 reallocData(size, QArrayData::Grow);
2669 d.data()[size] = u'\0';
2673
2674
2675
2676
2677
2678
2679
2680
2682void QString::resize(qsizetype newSize, QChar fillChar)
2684 const qsizetype oldSize = size();
2686 const qsizetype difference = size() - oldSize;
2688 std::fill_n(d.data() + oldSize, difference, fillChar.unicode());
2693
2694
2695
2696
2697
2698
2699
2700
2701
2703void QString::resizeForOverwrite(qsizetype size)
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2777void QString::reallocData(qsizetype alloc, QArrayData::AllocationOption option)
2780 d = DataPointer::fromRawData(&_empty, 0);
2786 const bool cannotUseReallocate = d.freeSpaceAtBegin() > 0;
2788 if (d.needsDetach() || cannotUseReallocate) {
2789 DataPointer dd(alloc, qMin(alloc, d.size), option);
2790 Q_CHECK_PTR(dd.data());
2792 ::memcpy(dd.data(), d.data(), dd.size *
sizeof(QChar));
2793 dd.data()[dd.size] = 0;
2796 d->reallocate(alloc, option);
2800void QString::reallocGrowData(qsizetype n)
2805 if (d.needsDetach()) {
2806 DataPointer dd(DataPointer::allocateGrow(d, n, QArrayData::GrowsAtEnd));
2807 Q_CHECK_PTR(dd.data());
2808 dd->copyAppend(d.data(), d.data() + d.size);
2809 dd.data()[dd.size] = 0;
2812 d->reallocate(d.constAllocatedCapacity() + n, QArrayData::Grow);
2817
2818
2819
2820
2821
2824
2825
2826
2827
2830
2831
2832
2833
2834
2835
2838
2839
2840
2841
2842
2843QString &QString::operator=(QLatin1StringView other)
2845 const qsizetype capacityAtEnd = capacity() - d.freeSpaceAtBegin();
2846 if (isDetached() && other.size() <= capacityAtEnd) {
2847 d.size = other.size();
2848 d.data()[other.size()] = 0;
2849 qt_from_latin1(d.data(), other.latin1(), other.size());
2851 *
this = fromLatin1(other.latin1(), other.size());
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2883
2884
2885
2886
2887QString &QString::operator=(QChar ch)
2889 return assign(1, ch);
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2912
2913
2914
2915
2916
2917
2918
2919
2920
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2953
2954
2955template <
typename T>
2958 auto &str_d = str.data_ptr();
2959 qsizetype difference = 0;
2960 if (Q_UNLIKELY(i > str_d.size))
2961 difference = i - str_d.size;
2962 const qsizetype oldSize = str_d.size;
2963 const qsizetype insert_size = toInsert.size();
2964 const qsizetype newSize = str_d.size + difference + insert_size;
2965 const auto side = i == 0 ? QArrayData::GrowsAtBeginning : QArrayData::GrowsAtEnd;
2967 if (str_d.needsDetach() || needsReallocate(str, newSize)) {
2968 const auto cbegin = str.cbegin();
2969 const auto cend = str.cend();
2970 const auto insert_start = difference == 0 ? std::next(cbegin, i) : cend;
2974 other.data_ptr().detachAndGrow(side, newSize,
nullptr,
nullptr);
2975 other.append(QStringView(cbegin, insert_start));
2976 other.resize(i, u' ');
2977 other.append(toInsert);
2978 other.append(QStringView(insert_start, cend));
2983 str_d.detachAndGrow(side, difference + insert_size,
nullptr,
nullptr);
2984 Q_CHECK_PTR(str_d.data());
2985 str.resize(newSize);
2987 auto begin = str_d.begin();
2988 auto old_end =
std::next(begin, oldSize);
2989 std::fill_n(old_end, difference, u' ');
2990 auto insert_start =
std::next(begin, i);
2991 if (difference == 0)
2992 std::move_backward(insert_start, old_end, str_d.end());
2994 using Char = std::remove_cv_t<
typename T::value_type>;
2995 if constexpr(std::is_same_v<Char, QChar>)
2996 std::copy_n(
reinterpret_cast<
const char16_t *>(toInsert.data()), insert_size, insert_start);
2997 else if constexpr (std::is_same_v<Char,
char16_t>)
2998 std::copy_n(toInsert.data(), insert_size, insert_start);
2999 else if constexpr (std::is_same_v<Char,
char>)
3000 qt_from_latin1(insert_start, toInsert.data(), insert_size);
3004
3005
3006
3007
3008
3009
3010
3011QString &QString::insert(qsizetype i, QLatin1StringView str)
3013 if (i < 0 || str.isEmpty())
3016 insert_helper(*
this, i, str);
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033QString &QString::insert(qsizetype i, QUtf8StringView s)
3035 auto insert_size = s.size();
3036 if (i < 0 || insert_size <= 0)
3039 qsizetype difference = 0;
3040 if (Q_UNLIKELY(i > d.size))
3041 difference = i - d.size;
3043 const qsizetype newSize = d.size + difference + insert_size;
3045 if (d.needsDetach() || needsReallocate(*
this, newSize)) {
3046 const auto cbegin =
this->cbegin();
3047 const auto insert_start = difference == 0 ? std::next(cbegin, i) : cend();
3049 other.reserve(newSize);
3050 other.append(QStringView(cbegin, insert_start));
3052 other.resize(i, u' ');
3054 other.append(QStringView(insert_start, cend()));
3060 d.detachAndGrow(QArrayData::GrowsAtEnd, difference + insert_size,
nullptr,
nullptr);
3061 Q_CHECK_PTR(d.data());
3070 QVarLengthArray<
char16_t> buffer(insert_size);
3071 char16_t *b = QUtf8::convertToUnicode(buffer.data(), s);
3072 insert_helper(*
this, i, QStringView(buffer.data(), b));
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090QString& QString::insert(qsizetype i,
const QChar *unicode, qsizetype size)
3092 if (i < 0 || size <= 0)
3096 if (!d.needsDetach() && QtPrivate::q_points_into_range(unicode, *
this)) {
3097 QVarLengthArray copy(unicode, unicode + size);
3098 insert(i, copy.data(), size);
3100 insert_helper(*
this, i, QStringView(unicode, size));
3107
3108
3109
3110
3111
3112
3113
3114
3115
3117QString& QString::insert(qsizetype i, QChar ch)
3121 return insert(i, &ch, 1);
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142QString &QString::append(
const QString &str)
3144 if (!str.isNull()) {
3146 if (Q_UNLIKELY(!str.d.isMutable()))
3150 }
else if (str.size()) {
3151 append(str.constData(), str.size());
3158
3159
3160
3161
3162
3163
3166
3167
3168
3169
3170
3171QString &QString::append(
const QChar *str, qsizetype len)
3173 if (str && len > 0) {
3174 static_assert(
sizeof(QChar) ==
sizeof(
char16_t),
"Unexpected difference in sizes");
3176 const char16_t *char16String =
reinterpret_cast<
const char16_t *>(str);
3177 d->growAppend(char16String, char16String + len);
3178 d.data()[d.size] = u'\0';
3184
3185
3186
3187
3188QString &QString::append(QLatin1StringView str)
3190 append_helper(*
this, str);
3195
3196
3197
3198
3199
3200QString &QString::append(QUtf8StringView str)
3202 append_helper(*
this, str);
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3233
3234
3235
3236
3237QString &QString::append(QChar ch)
3239 d.detachAndGrow(QArrayData::GrowsAtEnd, 1,
nullptr,
nullptr);
3240 d->copyAppend(1, ch.unicode());
3241 d.data()[d.size] =
'\0';
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3262
3263
3264
3265
3266
3269
3270
3271
3272
3273
3276
3277
3278
3279
3280
3281
3284
3285
3286
3287
3288
3289
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3318
3319
3320
3321
3322
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3391QString &QString::assign(QAnyStringView s)
3393 if (s.size() <= capacity() && isDetached()) {
3394 const auto offset = d.freeSpaceAtBegin();
3396 d.setBegin(d.begin() - offset);
3398 s.visit([
this](
auto input) {
3399 this->append(input);
3402 *
this = s.toString();
3407#ifndef QT_BOOTSTRAPPED
3408QString &QString::assign_helper(
const char32_t *data, qsizetype len)
3412 const auto requiredCapacity = len * 2;
3413 if (requiredCapacity <= capacity() && isDetached()) {
3414 const auto offset = d.freeSpaceAtBegin();
3416 d.setBegin(d.begin() - offset);
3417 auto begin =
reinterpret_cast<QChar *>(d.begin());
3418 auto ba = QByteArrayView(
reinterpret_cast<
const std::byte*>(data), len *
sizeof(
char32_t));
3419 QStringConverter::State state;
3420 const auto end = QUtf32::convertToUnicode(begin, ba, &state, DetectEndianness);
3421 d.size = end - begin;
3422 d.data()[d.size] = u'\0';
3424 *
this = QString::fromUcs4(data, len);
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452QString &QString::remove(qsizetype pos, qsizetype len)
3457 if (size_t(pos) >= size_t(size()) || len <= 0)
3460 len = std::min(len, size() - pos);
3462 QStringAlgorithms<QString>::remove_helper(*
this, pos, len);
3469 const auto needleSize = needle.size();
3474 qsizetype i = s.indexOf(needle, 0, cs);
3478 QString::DataPointer &dptr = s.data_ptr();
3479 auto begin = dptr.begin();
3480 auto end = dptr.end();
3482 auto copyFunc = [&](
auto &dst) {
3483 auto src = begin + i + needleSize;
3485 i = s.indexOf(needle, std::distance(begin, src), cs);
3486 auto hit = i == -1 ? end : begin + i;
3487 dst =
std::copy(src, hit, dst);
3488 src = hit + needleSize;
3493 if (!dptr.needsDetach()) {
3494 auto dst = begin + i;
3495 dst = copyFunc(dst);
3496 s.truncate(
std::distance(begin, dst));
3498 QString copy{s.size(), Qt::Uninitialized};
3499 auto copy_begin = copy.begin();
3500 auto dst =
std::copy(begin, begin + i, copy_begin);
3501 dst = copyFunc(dst);
3502 copy.resize(
std::distance(copy_begin, dst));
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519QString &QString::remove(
const QString &str, Qt::CaseSensitivity cs)
3521 const auto s = str.d.data();
3522 if (QtPrivate::q_points_into_range(s, d))
3523 removeStringImpl(*
this, QStringView{QVarLengthArray(s, s + str.size())}, cs);
3525 removeStringImpl(*
this, qToStringViewIgnoringNull(str), cs);
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544QString &QString::remove(QLatin1StringView str, Qt::CaseSensitivity cs)
3546 removeStringImpl(*
this, str, cs);
3551
3552
3553
3554
3555
3556
3557
3558
3559
3562
3563
3564
3565
3566
3567
3568
3569
3570
3573
3574
3575
3576
3577
3578
3579
3580
3581
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599QString &QString::remove(QChar ch, Qt::CaseSensitivity cs)
3601 const qsizetype idx = indexOf(ch, 0, cs);
3605 const bool isCase = cs == Qt::CaseSensitive;
3606 ch = isCase ? ch : ch.toCaseFolded();
3607 auto match = [ch, isCase](QChar x) {
3608 return ch == (isCase ? x : x.toCaseFolded());
3612 auto begin = d.begin();
3613 auto first_match = begin + idx;
3615 if (!d.isShared()) {
3616 auto it = std::remove_if(first_match, end, match);
3617 d->erase(it, std::distance(it, end));
3618 d.data()[d.size] = u'\0';
3623 QString copy{size(), Qt::Uninitialized};
3624 auto dst = copy.d.begin();
3625 auto it = std::copy(begin, first_match, dst);
3626 it = std::remove_copy_if(first_match + 1, end, it, match);
3627 copy.d.size = std::distance(dst, it);
3628 copy.d.data()[copy.d.size] = u'\0';
3629 *
this = std::move(copy);
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3649
3650
3651
3652
3653
3654
3655
3656
3658static void replace_helper(QString &str, QSpan<qsizetype> indices, qsizetype blen, QStringView after)
3660 const qsizetype oldSize = str.data_ptr().size;
3661 const qsizetype adjust = indices.size() * (after.size() - blen);
3662 const qsizetype newSize = oldSize + adjust;
3663 using A = QStringAlgorithms<QString>;
3664 if (str.data_ptr().needsDetach() || needsReallocate(str, newSize)) {
3665 A::replace_helper(str, blen, after, indices);
3669 if (QtPrivate::q_points_into_range(after.begin(), str)) {
3672 A::replace_helper(str, blen, QVarLengthArray(after.begin(), after.end()), indices);
3674 A::replace_helper(str, blen, after, indices);
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694QString &QString::replace(qsizetype pos, qsizetype len,
const QString &after)
3696 return replace(pos, len, after.constData(), after.size());
3700
3701
3702
3703
3704
3705
3706
3707
3708QString &QString::replace(qsizetype pos, qsizetype len,
const QChar *after, qsizetype alen)
3712 if (size_t(pos) > size_t(
this->size()))
3714 if (len >
this->size() - pos)
3715 len =
this->size() - pos;
3717 qsizetype indices[] = {pos};
3718 replace_helper(*
this, indices, len, QStringView{after, alen});
3723
3724
3725
3726
3727
3728
3729QString &QString::replace(qsizetype pos, qsizetype len, QChar after)
3731 return replace(pos, len, &after, 1);
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757QString &QString::replace(
const QString &before,
const QString &after, Qt::CaseSensitivity cs)
3759 return replace(before.constData(), before.size(), after.constData(), after.size(), cs);
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776QString &QString::replace(
const QChar *before, qsizetype blen,
3777 const QChar *after, qsizetype alen,
3778 Qt::CaseSensitivity cs)
3784 if (cs == Qt::CaseSensitive && before == after && blen == alen)
3787 if (alen == 0 && blen == 0)
3789 if (alen == 1 && blen == 1)
3790 return replace(*before, *after, cs);
3792 QStringMatcher matcher(before, blen, cs);
3794 qsizetype index = 0;
3796 QVarLengthArray<qsizetype> indices;
3797 while ((index = matcher.indexIn(*
this, index)) != -1) {
3798 indices.push_back(index);
3804 if (indices.isEmpty())
3807 replace_helper(*
this, indices, blen, QStringView{after, alen});
3812
3813
3814
3815
3816
3817
3818QString& QString::replace(QChar ch,
const QString &after, Qt::CaseSensitivity cs)
3820 if (after.size() == 0)
3821 return remove(ch, cs);
3823 if (after.size() == 1)
3824 return replace(ch, after.front(), cs);
3829 const char16_t cc = (cs == Qt::CaseSensitive ? ch.unicode() : ch.toCaseFolded().unicode());
3831 QVarLengthArray<qsizetype> indices;
3832 if (cs == Qt::CaseSensitive) {
3833 const char16_t *begin = d.begin();
3834 const char16_t *end = d.end();
3835 QStringView view(begin, end);
3836 const char16_t *hit =
nullptr;
3837 while ((hit = QtPrivate::qustrchr(view, cc)) != end) {
3838 indices.push_back(std::distance(begin, hit));
3839 view = QStringView(std::next(hit), end);
3842 for (qsizetype i = 0; i < d.size; ++i)
3843 if (QChar::toCaseFolded(d.data()[i]) == cc)
3844 indices.push_back(i);
3846 if (indices.isEmpty())
3849 replace_helper(*
this, indices, 1, after);
3854
3855
3856
3857
3858
3859
3860QString& QString::replace(QChar before, QChar after, Qt::CaseSensitivity cs)
3862 const qsizetype idx = indexOf(before, 0, cs);
3866 const char16_t achar = after.unicode();
3867 char16_t bchar = before.unicode();
3869 auto matchesCIS = [](
char16_t beforeChar) {
3870 return [beforeChar](
char16_t ch) {
return foldAndCompare(ch, beforeChar); };
3873 auto hit = d.begin() + idx;
3874 if (!d.needsDetach()) {
3876 if (cs == Qt::CaseSensitive) {
3877 std::replace(hit, d.end(), bchar, achar);
3879 bchar = foldCase(bchar);
3880 std::replace_if(hit, d.end(), matchesCIS(bchar), achar);
3883 QString other{ d.size, Qt::Uninitialized };
3884 auto dest = std::copy(d.begin(), hit, other.d.begin());
3887 if (cs == Qt::CaseSensitive) {
3888 std::replace_copy(hit, d.end(), dest, bchar, achar);
3890 bchar = foldCase(bchar);
3891 std::replace_copy_if(hit, d.end(), dest, matchesCIS(bchar), achar);
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913QString &QString::replace(QLatin1StringView before, QLatin1StringView after, Qt::CaseSensitivity cs)
3915 const qsizetype alen = after.size();
3916 const qsizetype blen = before.size();
3917 if (blen == 1 && alen == 1)
3918 return replace(before.front(), after.front(), cs);
3920 QVarLengthArray<
char16_t> a = qt_from_latin1_to_qvla(after);
3921 QVarLengthArray<
char16_t> b = qt_from_latin1_to_qvla(before);
3922 return replace((
const QChar *)b.data(), blen, (
const QChar *)a.data(), alen, cs);
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939QString &QString::replace(QLatin1StringView before,
const QString &after, Qt::CaseSensitivity cs)
3941 const qsizetype blen = before.size();
3942 if (blen == 1 && after.size() == 1)
3943 return replace(before.front(), after.front(), cs);
3945 QVarLengthArray<
char16_t> b = qt_from_latin1_to_qvla(before);
3946 return replace((
const QChar *)b.data(), blen, after.constData(), after.d.size, cs);
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962QString &QString::replace(
const QString &before, QLatin1StringView after, Qt::CaseSensitivity cs)
3964 const qsizetype alen = after.size();
3965 if (before.size() == 1 && alen == 1)
3966 return replace(before.front(), after.front(), cs);
3968 QVarLengthArray<
char16_t> a = qt_from_latin1_to_qvla(after);
3969 return replace(before.constData(), before.d.size, (
const QChar *)a.data(), alen, cs);
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity cs)
3985 const qsizetype alen = after.size();
3987 return replace(c, after.front(), cs);
3989 QVarLengthArray<
char16_t> a = qt_from_latin1_to_qvla(after);
3990 return replace(&c, 1, (
const QChar *)a.data(), alen, cs);
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4006
4007
4008
4009
4010
4011
4012
4015
4016
4017
4018
4019
4020
4021
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4051
4052
4053
4054
4055
4056
4057
4058
4059
4062
4063
4064
4065
4066
4067
4068
4071
4072
4073
4074
4075
4076
4077
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4109
4110
4111
4112
4113
4114
4117
4118
4119
4120
4121
4122
4123
4126
4127
4128
4129
4130
4131
4132
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4161
4162
4163
4164
4165
4166
4169
4170
4171
4172
4173
4174
4175
4178
4179
4180
4181
4182
4183
4184
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4213
4214
4215
4216
4217
4218
4221
4222
4223
4224
4225
4226
4227
4230
4231
4232
4233
4234
4235
4236
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4265
4266
4267
4268
4269
4270
4273
4274
4275
4276
4277
4278
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4437
4438
4439
4440
4441
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4530
4531
4532
4533
4534
4537
4538
4539
4540
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4578#if QT_CONFIG(regularexpression)
4579struct QStringCapture
4585Q_DECLARE_TYPEINFO(QStringCapture, Q_PRIMITIVE_TYPE);
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605QString &QString::replace(
const QRegularExpression &re,
const QString &after)
4607 if (!re.isValid()) {
4608 qtWarnAboutInvalidRegularExpression(re,
"QString",
"replace");
4612 const QString copy(*
this);
4613 QRegularExpressionMatchIterator iterator = re.globalMatch(copy);
4614 if (!iterator.hasNext())
4617 reallocData(d.size, QArrayData::KeepSize);
4619 qsizetype numCaptures = re.captureCount();
4623 QVarLengthArray<QStringCapture> backReferences;
4624 const qsizetype al = after.size();
4625 const QChar *ac = after.unicode();
4627 for (qsizetype i = 0; i < al - 1; i++) {
4628 if (ac[i] == u'\\') {
4629 int no = ac[i + 1].digitValue();
4630 if (no > 0 && no <= numCaptures) {
4631 QStringCapture backReference;
4632 backReference.pos = i;
4633 backReference.len = 2;
4636 int secondDigit = ac[i + 2].digitValue();
4637 if (secondDigit != -1 && ((no * 10) + secondDigit) <= numCaptures) {
4638 no = (no * 10) + secondDigit;
4639 ++backReference.len;
4643 backReference.no = no;
4644 backReferences.append(backReference);
4653 qsizetype newLength = 0;
4654 qsizetype lastEnd = 0;
4655 QVarLengthArray<QStringView> chunks;
4656 const QStringView copyView{ copy }, afterView{ after };
4657 while (iterator.hasNext()) {
4658 QRegularExpressionMatch match = iterator.next();
4661 len = match.capturedStart() - lastEnd;
4663 chunks << copyView.mid(lastEnd, len);
4669 for (
const QStringCapture &backReference : std::as_const(backReferences)) {
4671 len = backReference.pos - lastEnd;
4673 chunks << afterView.mid(lastEnd, len);
4678 len = match.capturedLength(backReference.no);
4680 chunks << copyView.mid(match.capturedStart(backReference.no), len);
4684 lastEnd = backReference.pos + backReference.len;
4688 len = afterView.size() - lastEnd;
4690 chunks << afterView.mid(lastEnd, len);
4694 lastEnd = match.capturedEnd();
4698 if (copyView.size() > lastEnd) {
4699 chunks << copyView.mid(lastEnd);
4700 newLength += copyView.size() - lastEnd;
4707 for (
const QStringView &chunk : std::as_const(chunks)) {
4708 qsizetype len = chunk.size();
4709 memcpy(uc + i, chunk.constData(), len *
sizeof(QChar));
4718
4719
4720
4721
4722
4723
4724
4726qsizetype QString::count(
const QString &str, Qt::CaseSensitivity cs)
const
4728 return QtPrivate::count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs);
4732
4733
4734
4735
4736
4737
4738
4739
4741qsizetype QString::count(QChar ch, Qt::CaseSensitivity cs)
const
4743 return QtPrivate::count(QStringView(unicode(), size()), ch, cs);
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756qsizetype QString::count(QStringView str, Qt::CaseSensitivity cs)
const
4758 return QtPrivate::count(*
this, str, cs);
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4788
4789
4790
4791
4792
4793
4794
4797
4798
4799
4800
4801
4802
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4816#if QT_CONFIG(regularexpression)
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832qsizetype QString::indexOf(
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
const
4834 return QtPrivate::indexOf(QStringView(*
this),
this, re, from, rmatch);
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868qsizetype QString::lastIndexOf(
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
const
4870 return QtPrivate::lastIndexOf(QStringView(*
this),
this, re, from, rmatch);
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4907bool QString::contains(
const QRegularExpression &re, QRegularExpressionMatch *rmatch)
const
4909 return QtPrivate::contains(QStringView(*
this),
this, re, rmatch);
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930qsizetype QString::count(
const QRegularExpression &re)
const
4932 return QtPrivate::count(QStringView(*
this), re);
4936#if QT_DEPRECATED_SINCE(6
, 4
)
4938
4939
4940
4941
4942
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
5001
5002
5003
5004
5005
5006
5007
5009QString QString::section(
const QString &sep, qsizetype start, qsizetype end, SectionFlags flags)
const
5011 const QList<QStringView> sections = QStringView{ *
this }.split(
5012 sep, Qt::KeepEmptyParts, (flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive : Qt::CaseSensitive);
5013 const qsizetype sectionsSize = sections.size();
5014 if (!(flags & SectionSkipEmpty)) {
5016 start += sectionsSize;
5018 end += sectionsSize;
5021 for (qsizetype k = 0; k < sectionsSize; ++k) {
5022 if (sections.at(k).isEmpty())
5026 start += sectionsSize - skip;
5028 end += sectionsSize - skip;
5030 if (start >= sectionsSize || end < 0 || start > end)
5034 qsizetype first_i = start, last_i = end;
5035 for (qsizetype x = 0, i = 0; x <= end && i < sectionsSize; ++i) {
5036 const QStringView §ion = sections.at(i);
5037 const bool empty = section.isEmpty();
5043 if (x > start && i > 0)
5047 if (!empty || !(flags & SectionSkipEmpty))
5050 if ((flags & SectionIncludeLeadingSep) && first_i > 0)
5052 if ((flags & SectionIncludeTrailingSep) && last_i < sectionsSize - 1)
5057#if QT_CONFIG(regularexpression)
5058struct qt_section_chunk
5063Q_DECLARE_TYPEINFO(qt_section_chunk, Q_RELOCATABLE_TYPE);
5065static QString extractSections(QSpan<qt_section_chunk> sections, qsizetype start, qsizetype end,
5066 QString::SectionFlags flags)
5068 const qsizetype sectionsSize = sections.size();
5070 if (!(flags & QString::SectionSkipEmpty)) {
5072 start += sectionsSize;
5074 end += sectionsSize;
5077 for (qsizetype k = 0; k < sectionsSize; ++k) {
5078 const qt_section_chunk §ion = sections[k];
5079 if (section.length == section.string.size())
5083 start += sectionsSize - skip;
5085 end += sectionsSize - skip;
5087 if (start >= sectionsSize || end < 0 || start > end)
5092 qsizetype first_i = start, last_i = end;
5093 for (qsizetype i = 0; x <= end && i < sectionsSize; ++i) {
5094 const qt_section_chunk §ion = sections[i];
5095 const bool empty = (section.length == section.string.size());
5102 ret += section.string;
5104 ret += section.string.mid(section.length);
5106 if (!empty || !(flags & QString::SectionSkipEmpty))
5110 if ((flags & QString::SectionIncludeLeadingSep) && first_i >= 0) {
5111 const qt_section_chunk §ion = sections[first_i];
5112 ret.prepend(section.string.left(section.length));
5115 if ((flags & QString::SectionIncludeTrailingSep)
5116 && last_i < sectionsSize - 1) {
5117 const qt_section_chunk §ion = sections[last_i + 1];
5118 ret += section.string.left(section.length);
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138QString QString::section(
const QRegularExpression &re, qsizetype start, qsizetype end, SectionFlags flags)
const
5140 if (!re.isValid()) {
5141 qtWarnAboutInvalidRegularExpression(re,
"QString",
"section");
5145 const QChar *uc = unicode();
5149 QRegularExpression sep(re);
5150 if (flags & SectionCaseInsensitiveSeps)
5151 sep.setPatternOptions(sep.patternOptions() | QRegularExpression::CaseInsensitiveOption);
5153 QVarLengthArray<qt_section_chunk> sections;
5154 qsizetype n = size(), m = 0, last_m = 0, last_len = 0;
5155 QRegularExpressionMatchIterator iterator = sep.globalMatch(*
this);
5156 while (iterator.hasNext()) {
5157 QRegularExpressionMatch match = iterator.next();
5158 m = match.capturedStart();
5159 sections.append(qt_section_chunk{last_len, QStringView{*
this}.sliced(last_m, m - last_m)});
5161 last_len = match.capturedLength();
5163 sections.append(qt_section_chunk{last_len, QStringView{*
this}.sliced(last_m, n - last_m)});
5165 return extractSections(sections, start, end, flags);
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221QString QString::mid(qsizetype position, qsizetype n)
const &
5223 qsizetype p = position;
5225 using namespace QtPrivate;
5226 switch (QContainerImplHelper::mid(size(), &p, &l)) {
5227 case QContainerImplHelper::Null:
5229 case QContainerImplHelper::Empty:
5230 return QString(DataPointer::fromRawData(&_empty, 0));
5231 case QContainerImplHelper::Full:
5233 case QContainerImplHelper::Subset:
5234 return sliced(p, l);
5236 Q_UNREACHABLE_RETURN(QString());
5239QString QString::mid(qsizetype position, qsizetype n) &&
5241 qsizetype p = position;
5243 using namespace QtPrivate;
5244 switch (QContainerImplHelper::mid(size(), &p, &l)) {
5245 case QContainerImplHelper::Null:
5247 case QContainerImplHelper::Empty:
5250 case QContainerImplHelper::Full:
5251 return std::move(*
this);
5252 case QContainerImplHelper::Subset:
5253 return std::move(*
this).sliced(p, l);
5255 Q_UNREACHABLE_RETURN(QString());
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304QString QString::sliced_helper(QString &str, qsizetype pos, qsizetype n)
5307 return QString(DataPointer::fromRawData(&_empty, 0));
5308 DataPointer d = std::move(str.d).sliced(pos, n);
5310 return QString(std::move(d));
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379bool QString::startsWith(
const QString& s, Qt::CaseSensitivity cs)
const
5381 return qt_starts_with_impl(QStringView(*
this), QStringView(s), cs);
5385
5386
5387bool QString::startsWith(QLatin1StringView s, Qt::CaseSensitivity cs)
const
5389 return qt_starts_with_impl(QStringView(*
this), s, cs);
5393
5394
5395
5396
5397
5398bool QString::startsWith(QChar c, Qt::CaseSensitivity cs)
const
5402 if (cs == Qt::CaseSensitive)
5404 return foldCase(at(0)) == foldCase(c);
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430bool QString::endsWith(
const QString &s, Qt::CaseSensitivity cs)
const
5432 return qt_ends_with_impl(QStringView(*
this), QStringView(s), cs);
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5448
5449
5450bool QString::endsWith(QLatin1StringView s, Qt::CaseSensitivity cs)
const
5452 return qt_ends_with_impl(QStringView(*
this), s, cs);
5456
5457
5458
5459
5460
5461bool QString::endsWith(QChar c, Qt::CaseSensitivity cs)
const
5465 if (cs == Qt::CaseSensitive)
5466 return at(size() - 1) == c;
5467 return foldCase(at(size() - 1)) == foldCase(c);
5474 const char32_t uc = it
.next();
5475 if (caseConversion(uc)[c].diff)
5483 return checkCase(s, QUnicodeTables::LowerCase);
5488 return checkCase(s, QUnicodeTables::UpperCase);
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504bool QString::isUpper()
const
5506 return QtPrivate::isUpper(qToStringViewIgnoringNull(*
this));
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522bool QString::isLower()
const
5524 return QtPrivate::isLower(qToStringViewIgnoringNull(*
this));
5529QByteArray QString::toLatin1_helper(
const QString &string)
5531 return qt_convert_to_latin1(string);
5535
5536
5537
5538
5539
5540
5541
5542
5543
5546 return string.visit([] (
auto string) {
return string.toString(); });
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5563 return qt_convert_to_latin1(string);
5567static QByteArray qt_convert_to_latin1(QStringView string)
5569 if (Q_UNLIKELY(string.isNull()))
5570 return QByteArray();
5572 QByteArray ba(string.size(), Qt::Uninitialized);
5576 qt_to_latin1(
reinterpret_cast<uchar *>(
const_cast<
char *>(ba.constData())),
5577 string.utf16(), string.size());
5581QByteArray QString::toLatin1_helper_inplace(QString &s)
5583 if (!s.isDetached())
5584 return qt_convert_to_latin1(s);
5592 qsizetype length = s.size();
5593 char16_t *sdata = s.d.data();
5594 Q_ASSERT(sdata[length] == u'\0');
5595 qt_to_latin1(
reinterpret_cast<uchar *>(sdata), sdata, length + 1);
5599 auto ba_d = std::move(s.d).reinterpreted<
char>();
5602 Q_ASSERT(ba_d.d->allocatedCapacity() >= ba_d.size);
5603 Q_ASSERT(s.isNull());
5604 Q_ASSERT(s.isEmpty());
5605 Q_ASSERT(s.constData() == QString().constData());
5607 return QByteArray(std::move(ba_d));
5611
5612
5613
5614
5615
5616
5620 if (Q_UNLIKELY(string.isNull()))
5625 if (qMulOverflow<2>(string.size(), &required))
5626 required = (std::numeric_limits<qsizetype>::max)();
5627 ba.resizeForOverwrite(required);
5628 const qsizetype sz = QUtf8::convertFromLatin1(ba.data(), string) - ba.data();
5635char16_t *QLatin1::convertToUnicode(
char16_t *out, QLatin1StringView in)
noexcept
5637 const qsizetype len = in.size();
5638 qt_from_latin1(out, in.data(), len);
5639 return std::next(out, len);
5642char *QLatin1::convertFromUnicode(
char *out, QStringView in)
noexcept
5644 const qsizetype len = in.size();
5645 qt_to_latin1(
reinterpret_cast<uchar *>(out), in.utf16(), len);
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5678QByteArray QString::toLocal8Bit_helper(
const QChar *data, qsizetype size)
5680 return qt_convert_to_local_8bit(QStringView(data, size));
5685 if (string.isNull())
5686 return QByteArray();
5687 QStringEncoder fromUtf16(QStringEncoder::System, QStringEncoder::Flag::Stateless);
5688 return fromUtf16(string);
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5708 return qt_convert_to_local_8bit(string);
5714
5715
5716
5717
5718
5719
5720
5721
5722
5724QByteArray QString::toUtf8_helper(
const QString &str)
5726 return qt_convert_to_utf8(str);
5732 return QByteArray();
5734 return QUtf8::convertFromUnicode(str);
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5751 return qt_convert_to_utf8(string);
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771QList<uint> QString::toUcs4()
const
5773 return qt_convert_to_ucs4(*
this);
5778 QList<uint> v(string.size());
5779 uint *a =
const_cast<uint*>(v.constData());
5783 v.resize(a - v.constData());
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5806 return qt_convert_to_ucs4(string);
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819QString QString::fromLatin1(QByteArrayView ba)
5824 }
else if (ba.size() == 0) {
5825 d = DataPointer::fromRawData(&_empty, 0);
5827 d = DataPointer(ba.size(), ba.size());
5828 Q_CHECK_PTR(d.data());
5829 d.data()[ba.size()] =
'\0';
5830 char16_t *dst = d.data();
5832 qt_from_latin1(dst, ba.data(), size_t(ba.size()));
5834 return QString(std::move(d));
5838
5839
5840
5841
5842
5843
5844
5845
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897QString QString::fromLocal8Bit(QByteArrayView ba)
5902 return QString(DataPointer::fromRawData(&_empty, 0));
5903 QStringDecoder toUtf16(QStringDecoder::System, QStringDecoder::Flag::Stateless);
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5929
5930
5931
5932
5933
5934
5937
5938
5939
5940
5941
5942
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966QString QString::fromUtf8(QByteArrayView ba)
5971 return QString(DataPointer::fromRawData(&_empty, 0));
5972 return QUtf8::convertToUnicode(ba);
5975#ifndef QT_BOOTSTRAPPED
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993QString QString::fromUtf16(
const char16_t *unicode, qsizetype size)
5998 size = QtPrivate::qustrlen(unicode);
5999 QStringDecoder toUtf16(QStringDecoder::Utf16, QStringDecoder::Flag::Stateless);
6000 return toUtf16(QByteArrayView(
reinterpret_cast<
const char *>(unicode), size * 2));
6004
6005
6006
6009
6010
6011
6012
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025QString QString::fromUcs4(
const char32_t *unicode, qsizetype size)
6030 if constexpr (
sizeof(
char32_t) ==
sizeof(
wchar_t))
6031 size = wcslen(
reinterpret_cast<
const wchar_t *>(unicode));
6033 size = std::char_traits<
char32_t>::length(unicode);
6035 QStringDecoder toUtf16(QStringDecoder::Utf32, QStringDecoder::Flag::Stateless);
6036 return toUtf16(QByteArrayView(
reinterpret_cast<
const char *>(unicode), size * 4));
6041
6042
6043
6044
6045
6046
6047
6048
6049QString& QString::setUnicode(
const QChar *unicode, qsizetype size)
6052 if (unicode && size)
6053 memcpy(d.data(), unicode, size *
sizeof(QChar));
6058
6059
6060
6061
6062
6063
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6082
6083
6084
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103QString QString::simplified_helper(
const QString &str)
6105 return QStringAlgorithms<
const QString>::simplified_helper(str);
6108QString QString::simplified_helper(QString &str)
6110 return QStringAlgorithms<QString>::simplified_helper(str);
6114 template <
typename StringView>
6115 StringView qt_trimmed(StringView s)
noexcept
6117 const auto [begin, end] = QStringAlgorithms<
const StringView>::trimmed_helper_positions(s);
6118 return StringView{begin, end};
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6139 return qt_trimmed(s);
6142QLatin1StringView
QtPrivate::trimmed(QLatin1StringView s)
noexcept
6144 return qt_trimmed(s);
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165QString QString::trimmed_helper(
const QString &str)
6167 return QStringAlgorithms<
const QString>::trimmed_helper(str);
6170QString QString::trimmed_helper(QString &str)
6172 return QStringAlgorithms<QString>::trimmed_helper(str);
6176
6177
6178
6179
6180
6181
6182
6183
6184
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6200
6201
6202
6203
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6283void QString::truncate(qsizetype pos)
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304void QString::chop(qsizetype n)
6313
6314
6315
6316
6317
6318
6319
6320
6321QString& QString::fill(QChar ch)
6323 QChar *ptr = begin();
6324 std::fill_n(ptr, size(), ch.unicode());
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6341QString& QString::fill(QChar ch, qsizetype size)
6344 resizeForOverwrite(size);
6349
6350
6351
6352
6353
6354
6355
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6371
6372
6373
6374
6375
6376
6377
6378
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6426
6427
6428
6429
6430
6433
6434
6435
6436
6437
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6468
6469
6470
6471
6472
6475
6476
6477
6478
6479
6482
6483
6484
6485
6486
6487
6488
6489
6490
6493
6494
6495
6496
6497
6498
6499
6500
6503
6504
6505
6506
6507
6508
6509
6510
6513
6514
6515
6516
6517
6518
6519
6520
6523
6524
6525
6526
6527
6528
6529
6532
6533
6534
6535
6536
6537
6538
6539
6542
6543
6544
6545
6546
6547
6548
6551
6552
6553
6554
6555
6556
6557
6558
6559
6562
6563
6564
6565
6566
6567
6568
6569
6570
6573
6574
6575
6576
6577
6578
6579
6580
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6608
6609
6610
6611
6612
6613
6614
6617
6618
6619
6620
6621
6622
6623
6624
6627
6628
6629
6630
6631
6632
6633
6634
6637
6638
6639
6640
6641
6642
6643
6644
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656int QString::compare(
const QString &other, Qt::CaseSensitivity cs)
const noexcept
6658 return QtPrivate::compareStrings(*
this, other, cs);
6662
6663
6664
6665int QString::compare_helper(
const QChar *data1, qsizetype length1,
const QChar *data2, qsizetype length2,
6666 Qt::CaseSensitivity cs)
noexcept
6668 Q_ASSERT(length1 >= 0);
6669 Q_ASSERT(length2 >= 0);
6670 Q_ASSERT(data1 || length1 == 0);
6671 Q_ASSERT(data2 || length2 == 0);
6672 return QtPrivate::compareStrings(QStringView(data1, length1), QStringView(data2, length2), cs);
6676
6677
6678
6679
6680
6681int QString::compare(QLatin1StringView other, Qt::CaseSensitivity cs)
const noexcept
6683 return QtPrivate::compareStrings(*
this, other, cs);
6687
6688
6689
6690int QString::compare_helper(
const QChar *data1, qsizetype length1,
const char *data2, qsizetype length2,
6691 Qt::CaseSensitivity cs)
noexcept
6693 Q_ASSERT(length1 >= 0);
6694 Q_ASSERT(data1 || length1 == 0);
6696 return qt_lencmp(length1, 0);
6697 if (Q_UNLIKELY(length2 < 0))
6698 length2 = qsizetype(strlen(data2));
6699 return QtPrivate::compareStrings(QStringView(data1, length1),
6700 QUtf8StringView(data2, length2), cs);
6704
6705
6706
6709
6710
6711
6715 return QtPrivate::equalStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6720 const int res = QtPrivate::compareStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6721 return Qt::compareThreeWay(res, 0);
6726 return QtPrivate::equalStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6731 const int res = QtPrivate::compareStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6732 return Qt::compareThreeWay(res, 0);
6737 return QtPrivate::equalStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6742 const int res = QtPrivate::compareStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6743 return Qt::compareThreeWay(res, 0);
6748 return QtPrivate::equalStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6753 const int res = QtPrivate::compareStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6754 return Qt::compareThreeWay(res, 0);
6758
6759
6760
6761bool QT_FASTCALL QChar::equal_helper(QChar lhs,
const char *rhs)
noexcept
6763 return QtPrivate::equalStrings(QStringView(&lhs, 1), QUtf8StringView(rhs));
6766int QT_FASTCALL QChar::compare_helper(QChar lhs,
const char *rhs)
noexcept
6768 return QtPrivate::compareStrings(QStringView(&lhs, 1), QUtf8StringView(rhs));
6772
6773
6774
6775bool QStringView::equal_helper(QStringView sv,
const char *data, qsizetype len)
6778 Q_ASSERT(data || len == 0);
6779 return QtPrivate::equalStrings(sv, QUtf8StringView(data, len));
6783
6784
6785
6786int QStringView::compare_helper(QStringView sv,
const char *data, qsizetype len)
6789 Q_ASSERT(data || len == 0);
6790 return QtPrivate::compareStrings(sv, QUtf8StringView(data, len));
6794
6795
6796
6797bool QLatin1StringView::equal_helper(QLatin1StringView s1,
const char *s2, qsizetype len)
noexcept
6801 Q_ASSERT(s2 || len == 0);
6802 return QtPrivate::equalStrings(s1, QUtf8StringView(s2, len));
6806
6807
6808
6809int QLatin1StringView::compare_helper(
const QLatin1StringView &s1,
const char *s2, qsizetype len)
noexcept
6813 Q_ASSERT(s2 || len == 0);
6814 return QtPrivate::compareStrings(s1, QUtf8StringView(s2, len));
6818
6819
6820
6821int QLatin1StringView::compare_helper(
const QChar *data1, qsizetype length1, QLatin1StringView s2,
6822 Qt::CaseSensitivity cs)
noexcept
6824 Q_ASSERT(length1 >= 0);
6825 Q_ASSERT(data1 || length1 == 0);
6826 return QtPrivate::compareStrings(QStringView(data1, length1), s2, cs);
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6878#if !defined(CSTR_LESS_THAN)
6879#define CSTR_LESS_THAN 1
6881#define CSTR_GREATER_THAN 3
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899int QString::localeAwareCompare(
const QString &other)
const
6901 return localeAwareCompare_helper(constData(), size(), other.constData(), other.size());
6905
6906
6907
6908int QString::localeAwareCompare_helper(
const QChar *data1, qsizetype length1,
6909 const QChar *data2, qsizetype length2)
6911 Q_ASSERT(length1 >= 0);
6912 Q_ASSERT(data1 || length1 == 0);
6913 Q_ASSERT(length2 >= 0);
6914 Q_ASSERT(data2 || length2 == 0);
6917 if (length1 == 0 || length2 == 0)
6918 return QtPrivate::compareStrings(QStringView(data1, length1), QStringView(data2, length2),
6921#if QT_CONFIG(icu) || defined(Q_OS_ANDROID)
6922 return QCollator::defaultCompare(QStringView(data1, length1), QStringView(data2, length2));
6924 const QString lhs = QString::fromRawData(data1, length1).normalized(QString::NormalizationForm_C);
6925 const QString rhs = QString::fromRawData(data2, length2).normalized(QString::NormalizationForm_C);
6926# if defined(Q_OS_WIN)
6927 int res = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, (LPWSTR)lhs.constData(), lhs.length(), (LPWSTR)rhs.constData(), rhs.length(), NULL, NULL, 0);
6930 case CSTR_LESS_THAN:
6932 case CSTR_GREATER_THAN:
6937# elif defined (Q_OS_DARWIN)
6942 const CFStringRef thisString =
6943 CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault,
6944 reinterpret_cast<
const UniChar *>(lhs.constData()), lhs.length(), kCFAllocatorNull);
6945 const CFStringRef otherString =
6946 CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault,
6947 reinterpret_cast<
const UniChar *>(rhs.constData()), rhs.length(), kCFAllocatorNull);
6949 const int result = CFStringCompare(thisString, otherString, kCFCompareLocalized);
6950 CFRelease(thisString);
6951 CFRelease(otherString);
6953# elif defined(Q_OS_UNIX)
6955 return strcoll(lhs.toLocal8Bit().constData(), rhs.toLocal8Bit().constData());
6957# error "This case shouldn't happen"
6958 return QtPrivate::compareStrings(lhs, rhs, Qt::CaseSensitive);
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6988const ushort *QString::utf16()
const
6990 if (!d.isMutable()) {
6992 const_cast<QString*>(
this)->reallocData(d.size, QArrayData::KeepSize);
6994 return reinterpret_cast<
const ushort *>(d.data());
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011QString &QString::nullTerminate()
7015 *
this = QString{constData(), size()};
7020
7021
7022
7023
7024
7025
7026
7027
7028QString QString::nullTerminated()
const &
7032 return QString{constData(), size()};
7036QString QString::nullTerminated() &&
7039 return std::move(*
this);
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7060QString QString::leftJustified(qsizetype width, QChar fill,
bool truncate)
const
7062 return QStringAlgorithms<QString>::aligned(*
this, width, fill, Qt::AlignLeft, truncate);
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7083QString QString::rightJustified(qsizetype width, QChar fill,
bool truncate)
const
7085 return QStringAlgorithms<QString>::aligned(*
this, width, fill, Qt::AlignRight, truncate);
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127template <
typename T>
7163template <
typename T>
7166 const QChar *p = str.constBegin();
7167 const QChar *e = p + str.size();
7170 while (e != p && e[-1].isHighSurrogate())
7175 const char32_t uc = it
.next();
7176 if (caseConversion(uc)[which].diff) {
7178 return detachAndConvertCase(str, it, which);
7181 return std::move(str);
7185QString QString::toLower_helper(
const QString &str)
7187 return QUnicodeTables::convertCase(str, QUnicodeTables::LowerCase);
7190QString QString::toLower_helper(QString &str)
7192 return QUnicodeTables::convertCase(str, QUnicodeTables::LowerCase);
7196
7197
7198
7199
7200
7202QString QString::toCaseFolded_helper(
const QString &str)
7204 return QUnicodeTables::convertCase(str, QUnicodeTables::CaseFold);
7207QString QString::toCaseFolded_helper(QString &str)
7209 return QUnicodeTables::convertCase(str, QUnicodeTables::CaseFold);
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7234QString QString::toUpper_helper(
const QString &str)
7236 return QUnicodeTables::convertCase(str, QUnicodeTables::UpperCase);
7239QString QString::toUpper_helper(QString &str)
7241 return QUnicodeTables::convertCase(str, QUnicodeTables::UpperCase);
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7278QString QString::asprintf(
const char *cformat, ...)
7281 va_start(ap, cformat);
7282 QString s = vasprintf(cformat, ap);
7301 default:
return flags;
7309 Q_ASSERT(isAsciiDigit(*c));
7310 const char *
const stop = c + size;
7314 auto [result, used] = qstrntoull(c, size, 10);
7319 while (c < stop && isAsciiDigit(*c))
7321 return result < qulonglong(
std::numeric_limits<
int>::max()) ?
int(result) : 0;
7340 case 'L':
return lm_L;
7341 case 'j':
return lm_j;
7343 case 'Z':
return lm_z;
7344 case 't':
return lm_t;
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7364QString QString::vasprintf(
const char *cformat, va_list ap)
7366 if (!cformat || !*cformat) {
7368 return fromLatin1(
"");
7374 const char *c = cformat;
7375 const char *formatEnd = cformat + qstrlen(cformat);
7379 while (*c !=
'\0' && *c !=
'%')
7381 result.append(QUtf8StringView{cb, c - cb});
7387 const char *escape_start = c;
7391 result.append(u'%');
7395 result.append(u'%');
7400 uint flags = parse_flag_characters(c);
7403 result.append(QLatin1StringView(escape_start));
7409 if (isAsciiDigit(*c)) {
7410 width = parse_field_width(c, formatEnd - c);
7411 }
else if (*c ==
'*') {
7412 width = va_arg(ap,
int);
7419 result.append(QLatin1StringView(escape_start));
7428 if (isAsciiDigit(*c)) {
7429 precision = parse_field_width(c, formatEnd - c);
7430 }
else if (*c ==
'*') {
7431 precision = va_arg(ap,
int);
7439 result.append(QLatin1StringView(escape_start));
7443 const LengthMod length_mod = parse_length_modifier(c);
7446 result.append(QLatin1StringView(escape_start));
7456 switch (length_mod) {
7457 case lm_none: i = va_arg(ap,
int);
break;
7458 case lm_hh: i = qint8(va_arg(ap,
int));
break;
7459 case lm_h: i =
short(va_arg(ap,
int));
break;
7460 case lm_l: i = va_arg(ap,
long int);
break;
7461 case lm_ll: i = va_arg(ap, qint64);
break;
7462 case lm_j: i = qint64{va_arg(ap, intmax_t)};
break;
7465 case lm_z: i = va_arg(ap, qsizetype);
break;
7466 case lm_t: i = va_arg(ap, qsizetype);
break;
7467 default: i = 0;
break;
7469 subst = QLocaleData::c()->longLongToString(i, precision, 10, width, flags);
7478 switch (length_mod) {
7479 case lm_none: u = va_arg(ap, uint);
break;
7480 case lm_hh: u = uchar(va_arg(ap, uint));
break;
7481 case lm_h: u = ushort(va_arg(ap, uint));
break;
7482 case lm_l: u = va_arg(ap, ulong);
break;
7483 case lm_ll: u = va_arg(ap, quint64);
break;
7484 case lm_j: u = quint64{va_arg(ap, uintmax_t)};
break;
7485 case lm_t: u = va_arg(ap, size_t);
break;
7486 case lm_z: u = va_arg(ap, size_t);
break;
7487 default: u = 0;
break;
7490 if (isAsciiUpper(*c))
7491 flags |= QLocaleData::CapitalEorX;
7494 switch (QtMiscUtils::toAsciiLower(*c)) {
7503 subst = QLocaleData::c()->unsLongLongToString(u, precision, base, width, flags);
7516 if (length_mod == lm_L)
7517 d = va_arg(ap,
long double);
7519 d = va_arg(ap,
double);
7521 if (isAsciiUpper(*c))
7522 flags |= QLocaleData::CapitalEorX;
7524 QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
7525 switch (QtMiscUtils::toAsciiLower(*c)) {
7526 case 'e': form = QLocaleData::DFExponent;
break;
7528 case 'f': form = QLocaleData::DFDecimal;
break;
7529 case 'g': form = QLocaleData::DFSignificantDigits;
break;
7532 subst = QLocaleData::c()->doubleToString(d, precision, form, width, flags);
7537 if (length_mod == lm_l)
7538 subst = QChar::fromUcs2(va_arg(ap,
int));
7540 subst = QLatin1Char((uchar) va_arg(ap,
int));
7545 if (length_mod == lm_l) {
7546 const char16_t *buff = va_arg(ap,
const char16_t*);
7547 const auto *ch = buff;
7548 while (precision != 0 && *ch != 0) {
7552 subst.setUtf16(buff, ch - buff);
7553 }
else if (precision == -1) {
7554 subst = QString::fromUtf8(va_arg(ap,
const char*));
7556 const char *buff = va_arg(ap,
const char*);
7557 subst = QString::fromUtf8(buff, qstrnlen(buff, precision));
7563 void *arg = va_arg(ap,
void*);
7564 const quint64 i =
reinterpret_cast<quintptr>(arg);
7565 flags |= QLocaleData::ShowBase;
7566 subst = QLocaleData::c()->unsLongLongToString(i, precision, 16, width, flags);
7571 const auto lenSoFar = result.size();
7572 switch (length_mod) {
7573 #define CASE(mod, type) case lm_##mod:
7574 *va_arg(ap, type*) = static_cast<type>(lenSoFar);
7577 CASE(hh,
signed char);
7582 CASE(j, std::intmax_t);
7583 CASE(z, std::make_signed_t<size_t>);
7584 CASE(t, std::ptrdiff_t);
7588 (
void)va_arg(ap,
void*);
7589 qWarning(
"QString::asprintf(): L modifier is invalid for %%n!");
7595 for (
const char *cc = escape_start; cc != c; ++cc)
7596 result.append(QLatin1Char(*cc));
7600 if (flags & QLocaleData::LeftAdjusted)
7601 result.append(subst.leftJustified(width));
7603 result.append(subst.rightJustified(width));
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7638template <
typename Int>
7641#if defined(QT_CHECK_RANGE)
7642 if (base != 0 && (base < 2 || base > 36)) {
7643 qWarning(
"QString::toIntegral: Invalid base (%d)", base);
7648 QVarLengthArray<uchar> latin1(string.size());
7649 qt_to_latin1(latin1.data(), string.utf16(), string.size());
7650 QSimpleParsedNumber<Int> r;
7651 if constexpr (
std::is_signed_v<Int>)
7652 r = QLocaleData::bytearrayToLongLong(latin1, base);
7654 r = QLocaleData::bytearrayToUnsLongLong(latin1, base);
7660qlonglong QString::toIntegral_helper(QStringView string,
bool *ok,
int base)
7662 return toIntegral<qlonglong>(string, ok, base);
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7694qulonglong QString::toIntegral_helper(QStringView string,
bool *ok, uint base)
7696 return toIntegral<qulonglong>(string, ok, base);
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7905double QString::toDouble(
bool *ok)
const
7907 return QStringView(*
this).toDouble(ok);
7910double QStringView::toDouble(
bool *ok)
const
7912 QStringView string = qt_trimmed(*
this);
7913 QVarLengthArray<uchar> latin1(string.size());
7914 qt_to_latin1(latin1.data(), string.utf16(), string.size());
7915 auto r = qt_asciiToDouble(
reinterpret_cast<
const char *>(latin1.data()), string.size());
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7951float QString::toFloat(
bool *ok)
const
7953 return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
7956float QStringView::toFloat(
bool *ok)
const
7958 return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7978
7979
7980
7983
7984
7985
7988
7989
7990
7993
7994
7995QString &QString::setNum(qlonglong n,
int base)
7997 return *
this = number(n, base);
8001
8002
8003QString &QString::setNum(qulonglong n,
int base)
8005 return *
this = number(n, base);
8009
8010
8011
8014
8015
8016
8019
8020
8021
8022
8023
8024
8025
8027QString &QString::setNum(
double n,
char format,
int precision)
8029 return *
this = number(n, format, precision);
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8067QString QString::number(
long n,
int base)
8069 return number(qlonglong(n), base);
8073
8074
8075
8076
8077QString QString::number(ulong n,
int base)
8079 return number(qulonglong(n), base);
8083
8084
8085QString QString::number(
int n,
int base)
8087 return number(qlonglong(n), base);
8091
8092
8093QString QString::number(uint n,
int base)
8095 return number(qulonglong(n), base);
8099
8100
8101QString QString::number(qlonglong n,
int base)
8103#if defined(QT_CHECK_RANGE)
8104 if (base < 2 || base > 36) {
8105 qWarning(
"QString::setNum: Invalid base (%d)", base);
8109 bool negative = n < 0;
8111
8112
8113
8114 return qulltoBasicLatin(negative ? 1u + qulonglong(-(n + 1)) : qulonglong(n), base, negative);
8118
8119
8120QString QString::number(qulonglong n,
int base)
8122#if defined(QT_CHECK_RANGE)
8123 if (base < 2 || base > 36) {
8124 qWarning(
"QString::setNum: Invalid base (%d)", base);
8128 return qulltoBasicLatin(n, base,
false);
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143QString QString::number(
double n,
char format,
int precision)
8145 QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
8147 switch (QtMiscUtils::toAsciiLower(format)) {
8149 form = QLocaleData::DFDecimal;
8152 form = QLocaleData::DFExponent;
8155 form = QLocaleData::DFSignificantDigits;
8158#if defined(QT_CHECK_RANGE)
8159 qWarning(
"QString::setNum: Invalid format char '%c'", format);
8164 return qdtoBasicLatin(n, form, precision, isAsciiUpper(format));
8168template<
class ResultList,
class StringSource>
8169static ResultList splitString(
const StringSource &source, QStringView sep,
8170 Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
8173 typename StringSource::size_type start = 0;
8174 typename StringSource::size_type end;
8175 typename StringSource::size_type extra = 0;
8176 while ((end = QtPrivate::findString(QStringView(source.constData(), source.size()), start + extra, sep, cs)) != -1) {
8177 if (start != end || behavior == Qt::KeepEmptyParts)
8178 list.append(source.sliced(start, end - start));
8179 start = end + sep.size();
8180 extra = (sep.size() == 0 ? 1 : 0);
8182 if (start != source.size() || behavior == Qt::KeepEmptyParts)
8183 list.append(source.sliced(start));
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219QStringList QString::split(
const QString &sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
const
8221 return splitString<QStringList>(*
this, sep, behavior, cs);
8225
8226
8227
8228QStringList QString::split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
const
8230 return splitString<QStringList>(*
this, QStringView(&sep, 1), behavior, cs);
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250QList<QStringView> QStringView::split(QStringView sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
const
8252 return splitString<QList<QStringView>>(QStringView(*
this), sep, behavior, cs);
8255QList<QStringView> QStringView::split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
const
8257 return split(QStringView(&sep, 1), behavior, cs);
8260#if QT_CONFIG(regularexpression)
8262template<
class ResultList,
typename String,
typename MatchingFunction>
8263static ResultList splitString(
const String &source,
const QRegularExpression &re,
8264 MatchingFunction matchingFunction,
8265 Qt::SplitBehavior behavior)
8268 if (!re.isValid()) {
8269 qtWarnAboutInvalidRegularExpression(re,
"QString",
"split");
8273 qsizetype start = 0;
8275 QRegularExpressionMatchIterator iterator = (re.*matchingFunction)(source, 0, QRegularExpression::NormalMatch, QRegularExpression::NoMatchOption);
8276 while (iterator.hasNext()) {
8277 QRegularExpressionMatch match = iterator.next();
8278 end = match.capturedStart();
8279 if (start != end || behavior == Qt::KeepEmptyParts)
8280 list.append(source.sliced(start, end - start));
8281 start = match.capturedEnd();
8284 if (start != source.size() || behavior == Qt::KeepEmptyParts)
8285 list.append(source.sliced(start));
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318QStringList QString::split(
const QRegularExpression &re, Qt::SplitBehavior behavior)
const
8320#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
8321 const auto matchingFunction = qOverload<
const QString &, qsizetype, QRegularExpression::MatchType, QRegularExpression::MatchOptions>(&QRegularExpression::globalMatch);
8323 const auto matchingFunction = &QRegularExpression::globalMatch;
8325 return splitString<QStringList>(*
this,
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344QList<QStringView> QStringView::split(
const QRegularExpression &re, Qt::SplitBehavior behavior)
const
8346 return splitString<QList<QStringView>>(*
this, re, &QRegularExpression::globalMatchView, behavior);
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376QString QString::repeated(qsizetype times)
const
8387 const qsizetype resultSize = [&] {
8389 if (mul_overflow(r, d.size, &r))
8395 result.reserve(resultSize);
8396 if (result.capacity() != resultSize)
8399 memcpy(result.d.data(), d.data(), d.size *
sizeof(QChar));
8401 qsizetype sizeSoFar = d.size;
8402 char16_t *end = result.d.data() + sizeSoFar;
8404 const qsizetype halfResultSize = resultSize >> 1;
8405 while (sizeSoFar <= halfResultSize) {
8406 memcpy(end, result.d.data(), sizeSoFar *
sizeof(QChar));
8410 memcpy(end, result.d.data(), (resultSize - sizeSoFar) *
sizeof(QChar));
8411 result.d.data()[resultSize] =
'\0';
8412 result.d.size = resultSize;
8416static void normalize(QString *data, QString::NormalizationForm mode,
8417 QChar::UnicodeVersion version, qsizetype from)
8421 auto start =
reinterpret_cast<
const char16_t *>(data->constData());
8422 qsizetype offset = isAscii_helper(start + from, data->size() - from);
8429 if (version == QChar::Unicode_Unassigned) {
8430 version = QChar::currentUnicodeVersion();
8432 const QString &s = *data;
8436 qsizetype pos = from;
8437 if (QChar::requiresSurrogates(n.ucs4)) {
8438 char16_t ucs4High = QChar::highSurrogate(n.ucs4);
8439 char16_t ucs4Low = QChar::lowSurrogate(n.ucs4);
8442 for ( ; pos < s.size() - 1; ++pos) {
8443 if (s.at(pos).unicode() == ucs4High && s.at(pos + 1).unicode() == ucs4Low)
8446 if (pos == s.size())
8452 if (QChar::requiresSurrogates(n.old_mapping)) {
8454 char16_t oldHigh = QChar::highSurrogate(n.old_mapping);
8455 char16_t oldLow = QChar::lowSurrogate(n.old_mapping);
8456 while (pos < s.size() - 1) {
8457 if (s.at(pos).unicode() == ucs4High && s.at(pos + 1).unicode() == ucs4Low) {
8458 d[pos] = QChar(oldHigh);
8459 d[++pos] = QChar(oldLow);
8466 qsizetype outpos = pos;
8467 for ( ; pos < s.size(); ++outpos, ++pos) {
8468 if (pos < s.size() - 1 && s.at(pos).unicode() == ucs4High
8469 && s.at(pos + 1).unicode() == ucs4Low) {
8470 d[outpos] = QChar(old);
8474 data->truncate(outpos);
8478 Q_ASSERT(!QChar::requiresSurrogates(n.old_mapping));
8479 while (pos < s.size()) {
8480 if (s.at(pos).unicode() == n
.ucs4) {
8483 d[pos] = QChar(n.old_mapping);
8492 if (normalizationQuickCheckHelper(data, mode, from, &from))
8495 decomposeHelper(data, mode < QString::NormalizationForm_KD, version, from);
8497 canonicalOrderHelper(data, version, from);
8499 if (mode == QString::NormalizationForm_D || mode == QString::NormalizationForm_KD)
8502 composeHelper(data, version, from);
8506
8507
8508
8509QString QString::normalized(QString::NormalizationForm mode, QChar::UnicodeVersion version)
const
8511 QString copy = *
this;
8512 normalize(©, mode, version, 0);
8516#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
8517static void checkArgEscape(QStringView s)
8522 if (!supportUnicodeDigitValuesInArg())
8525 const auto isNonAsciiDigit = [](QChar c) {
8526 return c.unicode() < u'0' || c.unicode() > u'9';
8529 if (std::any_of(s.begin(), s.end(), isNonAsciiDigit)) {
8530 const auto accumulateDigit = [](
int partial, QChar digit) {
8531 return partial * 10 + digit.digitValue();
8533 const int parsedNumber = std::accumulate(s.begin(), s.end(), 0, accumulateDigit);
8535 qWarning(
"QString::arg(): the replacement \"%%%ls\" contains non-ASCII digits;\n"
8536 " it is currently being interpreted as the %d-th substitution.\n"
8537 " This is deprecated; support for non-ASCII digits will be dropped\n"
8538 " in a future version of Qt.",
8539 qUtf16Printable(s.toString()),
8556 const QChar *uc_begin = s.begin();
8557 const QChar *uc_end = s.end();
8564 d.locale_occurrences = 0;
8566 const QChar *c = uc_begin;
8567 while (c != uc_end) {
8568 while (c != uc_end && c->unicode() !=
'%')
8573 const QChar *escape_start = c;
8577 bool locale_arg =
false;
8578 if (c->unicode() ==
'L') {
8584 int escape = qArgDigitValue(*c);
8590#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
8591 const QChar *escapeBegin = c;
8592 const QChar *escapeEnd = escapeBegin + 1;
8598 const int next_escape = qArgDigitValue(*c);
8599 if (next_escape != -1) {
8600 escape = (10 * escape) + next_escape;
8602#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
8608#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
8609 checkArgEscape(QStringView(escapeBegin, escapeEnd));
8619 d.locale_occurrences = 0;
8624 ++d.locale_occurrences;
8625 d.escape_len += c - escape_start;
8631 QStringView arg, QStringView larg, QChar fillChar)
8634 const qsizetype abs_field_width = qAbs(field_width);
8635 const qsizetype result_len = [&] {
8636 using S = QString::size_type;
8637 auto accu = s.size() - d.escape_len;
8638 const struct { S num, size; } summands[] = {
8639 { d.occurrences - d.locale_occurrences, (
std::max)(abs_field_width, arg.size()) },
8640 { d.locale_occurrences, (
std::max)(abs_field_width, larg.size()) },
8642 for (
auto e : summands) {
8643 if (S tmp; mul_overflow(e.num, e.size, &tmp) || add_overflow(accu, tmp, &accu))
8649 QString result(result_len, Qt::Uninitialized);
8650 QChar *rc =
const_cast<QChar *>(result.unicode());
8651 QChar *
const result_end = rc + result_len;
8652 qsizetype repl_cnt = 0;
8654 const QChar *c = s.begin();
8655 const QChar *
const uc_end = s.end();
8656 while (c != uc_end) {
8657 Q_ASSERT(d.occurrences > repl_cnt);
8659
8660
8662 const QChar *text_start = c;
8663 while (c->unicode() !=
'%')
8666 const QChar *escape_start = c++;
8667 const bool localize = c->unicode() ==
'L';
8671 int escape = qArgDigitValue(*c);
8672 if (escape != -1 && c + 1 != uc_end) {
8673 const int digit = qArgDigitValue(c[1]);
8676 escape = 10 * escape + digit;
8681 memcpy(rc, text_start, (c - text_start) *
sizeof(QChar));
8682 rc += c - text_start;
8686 memcpy(rc, text_start, (escape_start - text_start) *
sizeof(QChar));
8687 rc += escape_start - text_start;
8689 const QStringView use = localize ? larg : arg;
8690 const qsizetype pad_chars = abs_field_width - use.size();
8693 if (field_width > 0) {
8694 rc =
std::fill_n(rc, pad_chars, fillChar);
8698 memcpy(rc, use.data(), use.size() *
sizeof(QChar));
8701 if (field_width < 0) {
8702 rc =
std::fill_n(rc, pad_chars, fillChar);
8705 if (++repl_cnt == d.occurrences) {
8706 memcpy(rc, c, (uc_end - c) *
sizeof(QChar));
8708 Q_ASSERT(rc == result_end);
8713 Q_ASSERT(rc == result_end);
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755QString QString::arg_impl(QAnyStringView a,
int fieldWidth, QChar fillChar)
const
8757 ArgEscapeData d = findArgEscapes(*
this);
8759 if (Q_UNLIKELY(d.occurrences == 0)) {
8760 qWarning(
"QString::arg: Argument missing: \"%ls\", \"%ls\"",
qUtf16Printable(*
this),
8765 QVarLengthArray<
char16_t> out;
8766 QStringView operator()(QStringView in)
noexcept {
return in; }
8767 QStringView operator()(QLatin1StringView in)
8769 out.resize(in.size());
8770 qt_from_latin1(out.data(), in.data(), size_t(in.size()));
8773 QStringView operator()(QUtf8StringView in)
8775 out.resize(in.size());
8776 return QStringView{out.data(), QUtf8::convertToUnicode(out.data(), in)};
8780 QStringView sv = a.visit(std::ref(convert));
8781 return replaceArgEscapes(*
this, d, fieldWidth, sv, sv, fillChar);
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819QString QString::arg_impl(qlonglong a,
int fieldWidth,
int base, QChar fillChar)
const
8821 ArgEscapeData d = findArgEscapes(*
this);
8823 if (d.occurrences == 0) {
8824 qWarning(
"QString::arg: Argument missing: \"%ls\", %llu",
qUtf16Printable(*
this), a);
8828 unsigned flags = QLocaleData::NoFlags;
8830 if (fillChar == u'0')
8831 flags = QLocaleData::ZeroPadded;
8834 if (d.occurrences > d.locale_occurrences) {
8835 arg = QLocaleData::c()->longLongToString(a, -1, base, fieldWidth, flags);
8836 Q_ASSERT(fillChar != u'0' || fieldWidth <= arg.size());
8840 if (d.locale_occurrences > 0) {
8842 if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
8843 flags |= QLocaleData::GroupDigits;
8844 localeArg = locale.d->m_data->longLongToString(a, -1, base, fieldWidth, flags);
8845 Q_ASSERT(fillChar != u'0' || fieldWidth <= localeArg.size());
8848 return replaceArgEscapes(*
this, d, fieldWidth, arg, localeArg, fillChar);
8851QString QString::arg_impl(qulonglong a,
int fieldWidth,
int base, QChar fillChar)
const
8853 ArgEscapeData d = findArgEscapes(*
this);
8855 if (d.occurrences == 0) {
8856 qWarning(
"QString::arg: Argument missing: \"%ls\", %lld",
qUtf16Printable(*
this), a);
8860 unsigned flags = QLocaleData::NoFlags;
8862 if (fillChar == u'0')
8863 flags = QLocaleData::ZeroPadded;
8866 if (d.occurrences > d.locale_occurrences) {
8867 arg = QLocaleData::c()->unsLongLongToString(a, -1, base, fieldWidth, flags);
8868 Q_ASSERT(fillChar != u'0' || fieldWidth <= arg.size());
8872 if (d.locale_occurrences > 0) {
8874 if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
8875 flags |= QLocaleData::GroupDigits;
8876 localeArg = locale.d->m_data->unsLongLongToString(a, -1, base, fieldWidth, flags);
8877 Q_ASSERT(fillChar != u'0' || fieldWidth <= localeArg.size());
8880 return replaceArgEscapes(*
this, d, fieldWidth, arg, localeArg, fillChar);
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905QString QString::arg_impl(
double a,
int fieldWidth,
char format,
int precision, QChar fillChar)
const
8907 ArgEscapeData d = findArgEscapes(*
this);
8909 if (d.occurrences == 0) {
8910 qWarning(
"QString::arg: Argument missing: \"%ls\", %g",
qUtf16Printable(*
this), a);
8914 unsigned flags = QLocaleData::NoFlags;
8916 if (fillChar == u'0')
8917 flags |= QLocaleData::ZeroPadded;
8919 if (isAsciiUpper(format))
8920 flags |= QLocaleData::CapitalEorX;
8922 QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
8923 switch (QtMiscUtils::toAsciiLower(format)) {
8925 form = QLocaleData::DFDecimal;
8928 form = QLocaleData::DFExponent;
8931 form = QLocaleData::DFSignificantDigits;
8934#if defined(QT_CHECK_RANGE)
8935 qWarning(
"QString::arg: Invalid format char '%c'", format);
8941 if (d.occurrences > d.locale_occurrences) {
8942 arg = QLocaleData::c()->doubleToString(a, precision, form, fieldWidth,
8943 flags | QLocaleData::ZeroPadExponent);
8944 Q_ASSERT(fillChar != u'0' || !qt_is_finite(a)
8945 || fieldWidth <= arg.size());
8949 if (d.locale_occurrences > 0) {
8952 const QLocale::NumberOptions numberOptions = locale.numberOptions();
8953 if (!(numberOptions & QLocale::OmitGroupSeparator))
8954 flags |= QLocaleData::GroupDigits;
8955 if (!(numberOptions & QLocale::OmitLeadingZeroInExponent))
8956 flags |= QLocaleData::ZeroPadExponent;
8957 if (numberOptions & QLocale::IncludeTrailingZeroesAfterDot)
8958 flags |= QLocaleData::AddTrailingZeroes;
8959 localeArg = locale.d->m_data->doubleToString(a, precision, form, fieldWidth, flags);
8960 Q_ASSERT(fillChar != u'0' || !qt_is_finite(a)
8961 || fieldWidth <= localeArg.size());
8964 return replaceArgEscapes(*
this, d, fieldWidth, arg, localeArg, fillChar);
8967static inline char16_t to_unicode(
const QChar c) {
return c.unicode(); }
8970template <
typename Char>
8971static int getEscape(
const Char *uc, qsizetype *pos, qsizetype len)
8975 if (i < len && uc[i] == u'L')
8978 int escape = to_unicode(uc[i]) -
'0';
8979 if (uint(escape) >= 10U)
8984 int digit = to_unicode(uc[i]) -
'0';
8985 if (uint(digit) < 10U) {
8986 escape = (escape * 10) + digit;
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9034 constexpr Part(QAnyStringView s,
int num = -1)
9035 : string{s}, number{num} {}
9037 void reset(QAnyStringView s)
noexcept { *
this = {s, number}; }
9039 QAnyStringView string;
9048enum { ExpectedParts = 32 };
9051typedef QVarLengthArray<
int, ExpectedParts/2> ArgIndexToPlaceholderMap;
9053template <
typename StringView>
9054static ParseResult parseMultiArgFormatString_impl(StringView s)
9058 const auto uc = s.data();
9059 const auto len = s.size();
9060 const auto end = len - 1;
9065 if (uc[i] == u'%') {
9066 qsizetype percent = i;
9067 int number = getEscape(uc, &i, len);
9069 if (last != percent)
9070 result.push_back(Part{s.sliced(last, percent - last)});
9071 result.push_back(Part{s.sliced(percent, i - percent), number});
9080 result.push_back(Part{s.sliced(last, len - last)});
9085static ParseResult parseMultiArgFormatString(QAnyStringView s)
9087 return s.visit([] (
auto s) {
return parseMultiArgFormatString_impl(s); });
9090static ArgIndexToPlaceholderMap makeArgIndexToPlaceholderMap(
const ParseResult &parts)
9092 ArgIndexToPlaceholderMap result;
9094 for (
const Part &part : parts) {
9095 if (part.number >= 0)
9096 result.push_back(part.number);
9099 std::sort(result.begin(), result.end());
9100 result.erase(
std::unique(result.begin(), result.end()),
9106static qsizetype resolveStringRefsAndReturnTotalSize(ParseResult &parts,
const ArgIndexToPlaceholderMap &argIndexToPlaceholderMap,
const QtPrivate::
ArgBase *args[])
9109 qsizetype totalSize = 0;
9110 for (Part &part : parts) {
9111 if (part.number != -1) {
9112 const auto it = std::find(argIndexToPlaceholderMap.begin(), argIndexToPlaceholderMap.end(), part.number);
9113 if (it != argIndexToPlaceholderMap.end()) {
9114 const auto &arg = *args[it - argIndexToPlaceholderMap.begin()];
9117 part.reset(
static_cast<
const QLatin1StringArg&>(arg).string);
9120 part.reset(
static_cast<
const QAnyStringArg&>(arg).string);
9123 part.reset(
static_cast<
const QStringViewArg&>(arg).string);
9128 if (add_overflow(totalSize, part.string.size(), &totalSize))
9139 ParseResult parts = parseMultiArgFormatString(pattern);
9142 ArgIndexToPlaceholderMap argIndexToPlaceholderMap = makeArgIndexToPlaceholderMap(parts);
9144 if (
static_cast<size_t>(argIndexToPlaceholderMap.size()) > numArgs)
9145 argIndexToPlaceholderMap.resize(qsizetype(numArgs));
9146 else if (Q_UNLIKELY(
static_cast<size_t>(argIndexToPlaceholderMap.size()) < numArgs))
9147 qWarning(
"QString::arg: %d argument(s) missing in %ls",
9148 int(numArgs - argIndexToPlaceholderMap.size()),
qUtf16Printable(pattern.toString()));
9151 const qsizetype totalSize = resolveStringRefsAndReturnTotalSize(parts, argIndexToPlaceholderMap, args);
9154 QString result(totalSize, Qt::Uninitialized);
9155 auto out =
const_cast<QChar*>(result.constData());
9157 struct Concatenate {
9159 QChar *operator()(QLatin1String part)
noexcept
9162 qt_from_latin1(
reinterpret_cast<
char16_t*>(out),
9163 part.data(), part.size());
9165 return out + part.size();
9167 QChar *operator()(QUtf8StringView part)
noexcept
9169 return QUtf8::convertToUnicode(out, part);
9171 QChar *operator()(QStringView part)
noexcept
9174 memcpy(out, part.data(), part.size() *
sizeof(QChar));
9175 return out + part.size();
9179 for (
const Part &part : parts)
9180 out = part.string.visit(Concatenate{out});
9183 result.truncate(out - result.cbegin());
9189
9190
9191
9192
9193
9194bool QString::isRightToLeft()
const
9196 return QtPrivate::isRightToLeft(QStringView(*
this));
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9235
9236
9237
9238
9239
9240
9241
9242
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9259
9260
9261
9262
9263
9264
9265
9268
9269
9270
9271
9272
9275
9276
9277
9278
9279
9280
9281
9284
9285
9286
9287
9288
9291
9292
9293
9294
9295
9296
9297
9298QString::iterator QString::erase(QString::const_iterator first, QString::const_iterator last)
9300 const auto start = std::distance(cbegin(), first);
9301 const auto len = std::distance(first, last);
9303 return begin() + start;
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9323
9324
9325
9326
9327
9328
9329
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343std::string QString::toStdString()
const
9349 auto writeToBuffer = [
this](
char *out, size_t) {
9350 char *last = QUtf8::convertFromUnicode(out, *
this);
9353 const size_t maxSize = size() * size_t{3};
9354#ifdef __cpp_lib_string_resize_and_overwrite
9356 result.resize_and_overwrite(maxSize, writeToBuffer);
9358 result.resize(maxSize);
9359 result.resize(writeToBuffer(result.data(), result.size()));
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9395
9396
9397
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413QString &QString::setRawData(
const QChar *unicode, qsizetype size)
9415 if (!unicode || !size) {
9418 *
this = fromRawData(unicode, size);
9423
9424
9425
9426
9427
9428
9431
9432
9433
9434
9435
9436
9437
9438
9439
9442
9443
9444
9445
9446
9447
9450
9451
9452
9453
9454
9455
9456
9457
9458
9460#if !defined(QT_NO_DATASTREAM)
9462
9463
9464
9465
9466
9467
9468
9470QDataStream &operator<<(QDataStream &out,
const QString &str)
9472 if (out.version() == 1) {
9473 out << str.toLatin1();
9475 if (!str.isNull() || out.version() < 3) {
9476 if ((out.byteOrder() == QDataStream::BigEndian) == (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
9477 out.writeBytes(
reinterpret_cast<
const char *>(str.unicode()),
9478 static_cast<qsizetype>(
sizeof(QChar) * str.size()));
9480 QVarLengthArray<
char16_t> buffer(str.size());
9481 qbswap<
sizeof(
char16_t)>(str.constData(), str.size(), buffer.data());
9482 out.writeBytes(
reinterpret_cast<
const char *>(buffer.data()),
9483 static_cast<qsizetype>(
sizeof(
char16_t) * buffer.size()));
9486 QDataStream::writeQSizeType(out, -1);
9493
9494
9495
9496
9497
9498
9499
9503 if (in.version() == 1) {
9506 str = QString::fromLatin1(l);
9508 qint64 size = QDataStream::readQSizeType(in);
9509 if (in.status() != QDataStream::Ok) {
9514 qsizetype bytes = size;
9515 if (size != bytes || size < -1) {
9517 in.setStatus(QDataStream::SizeLimitExceeded);
9522 }
else if (bytes > 0) {
9525 in.setStatus(QDataStream::ReadCorruptData);
9529 const qsizetype Step = 1024 * 1024;
9530 qsizetype len = bytes / 2;
9531 qsizetype allocated = 0;
9533 while (allocated < len) {
9534 int blockSize = qMin(Step, len - allocated);
9535 str.resize(allocated + blockSize);
9536 if (in.readRawData(
reinterpret_cast<
char *>(str.data()) + allocated * 2,
9537 blockSize * 2) != blockSize * 2) {
9539 in.setStatus(QDataStream::ReadPastEnd);
9542 allocated += blockSize;
9545 if ((in.byteOrder() == QDataStream::BigEndian)
9546 != (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
9547 char16_t *data =
reinterpret_cast<
char16_t *>(str.data());
9548 qbswap<
sizeof(*data)>(data, len, data);
9551 str = QString(QLatin1StringView(
""));
9559
9560
9561
9564
9565
9566
9569
9570
9571
9574
9575
9576
9577
9578
9579
9580
9581
9584 int isolateLevel = 0;
9589 switch (QChar::direction(c)) {
9630template <
typename Haystack,
typename Needle>
9633 using Matcher = std::conditional_t<std::is_same_v<Needle, QLatin1StringView>,
9634 QLatin1StringMatcher, QStringMatcher>;
9638 Matcher matcher(needle, cs);
9639 while ((i = matcher.indexIn(haystack, i + 1)) != -1)
9644template <
typename String>
9649 static_assert(
noexcept(QtPrivate::findString(haystack, i + 1, needle, cs)));
9650 while ((i = QtPrivate::findString(haystack, i + 1, needle, cs)) != -1)
9655template <
typename Haystack,
typename Needle>
9658 static_assert(!std::is_same_v<Haystack, QUtf8StringView>,
"assumptions not implemented");
9659 static_assert(!std::is_same_v<Needle, QUtf8StringView>,
"assumptions not implemented");
9660 constexpr int NeedleThreshold =
sizeof(needle[0]) == 1 ? 13 : 5;
9661 constexpr int HaystackThreshold = 500;
9663 if (haystack.size() < needle.size())
9666 if (haystack.size() > HaystackThreshold && needle.size() > NeedleThreshold)
9667 return qt_count_with_matcher(haystack, needle, cs);
9669 if constexpr (
sizeof(haystack[0]) <
sizeof(needle[0])) {
9671 static_assert(
sizeof(haystack[0]) * 0,
"Not reached, see count(QL1SV, QSV) below");
9672 }
else if constexpr (
sizeof(haystack[0]) >
sizeof(needle[0])) {
9676 Q_DECL_UNINITIALIZED
9677 char16_t buf[HaystackThreshold];
9678 Q_ASSERT(needle.size() <= HaystackThreshold);
9679 qt_from_latin1(buf, needle.data(), needle.size());
9680 return qt_count_with_findstring(haystack, QStringView(buf, needle.size()), cs);
9682 return qt_count_with_findstring(haystack, needle, cs);
9686qsizetype
QtPrivate::count(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs)
noexcept
9688 return qt_count_impl(haystack, needle, cs);
9691qsizetype
QtPrivate::count(QStringView haystack, QChar needle, Qt::CaseSensitivity cs)
noexcept
9693 if (cs == Qt::CaseSensitive)
9694 return std::count(haystack.cbegin(), haystack.cend(), needle);
9696 needle = foldCase(needle);
9697 return std::count_if(haystack.cbegin(), haystack.cend(),
9698 [needle](
const QChar c) {
return foldAndCompare(c, needle); });
9701qsizetype
QtPrivate::count(QLatin1StringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
9703 return qt_count_impl(haystack, needle, cs);
9706qsizetype
QtPrivate::count(QLatin1StringView haystack, QStringView needle, Qt::CaseSensitivity cs)
9712 if (haystack.size() < needle.size())
9715 if (!QtPrivate::isLatin1(needle))
9718 Q_DECL_UNINITIALIZED
9719 QVarLengthArray<
char> n = qt_to_latin1_unchecked_to_qvla(needle);
9720 return qt_count_impl(haystack, QLatin1StringView(n), cs);
9723qsizetype
QtPrivate::count(QStringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
9725 return qt_count_impl(haystack, needle, cs);
9728qsizetype
QtPrivate::count(QLatin1StringView haystack, QChar needle, Qt::CaseSensitivity cs)
noexcept
9731 if (needle.unicode() > 0xff)
9734 if (cs == Qt::CaseSensitive) {
9735 return std::count(haystack.cbegin(), haystack.cend(), needle.toLatin1());
9737 return std::count_if(haystack.cbegin(), haystack.cend(),
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9764 return qt_starts_with_impl(haystack, needle, cs);
9769 return qt_starts_with_impl(haystack, needle, cs);
9774 return qt_starts_with_impl(haystack, needle, cs);
9777bool QtPrivate::
startsWith(QLatin1StringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
9779 return qt_starts_with_impl(haystack, needle, cs);
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9804 return qt_ends_with_impl(haystack, needle, cs);
9807bool QtPrivate::
endsWith(QStringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
9809 return qt_ends_with_impl(haystack, needle, cs);
9812bool QtPrivate::
endsWith(QLatin1StringView haystack, QStringView needle, Qt::CaseSensitivity cs)
noexcept
9814 return qt_ends_with_impl(haystack, needle, cs);
9817bool QtPrivate::
endsWith(QLatin1StringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
9819 return qt_ends_with_impl(haystack, needle, cs);
9824 const qsizetype l = haystack0.size();
9825 const qsizetype sl = needle0.size();
9827 return findString(haystack0, from, needle0[0], cs);
9830 if (
std::size_t(sl + from) >
std::size_t(l))
9838
9839
9840
9841
9842 if (l > 500 && sl > 5)
9843 return qFindStringBoyerMoore(haystack0, from, needle0, cs);
9845 auto sv = [sl](
const char16_t *v) {
return QStringView(v, sl); };
9847
9848
9849
9850
9851
9852 const char16_t *needle = needle0.utf16();
9853 const char16_t *haystack = haystack0.utf16() + from;
9854 const char16_t *end = haystack0.utf16() + (l - sl);
9855 const qregisteruint sl_minus_1 = sl - 1;
9856 qregisteruint hashNeedle = 0, hashHaystack = 0;
9859 if (cs == Qt::CaseSensitive) {
9860 for (idx = 0; idx < sl; ++idx) {
9861 hashNeedle = ((hashNeedle<<1) + needle[idx]);
9862 hashHaystack = ((hashHaystack<<1) + haystack[idx]);
9864 hashHaystack -= haystack[sl_minus_1];
9866 while (haystack <= end) {
9867 hashHaystack += haystack[sl_minus_1];
9868 if (hashHaystack == hashNeedle
9869 && QtPrivate::compareStrings(needle0, sv(haystack), Qt::CaseSensitive) == 0)
9870 return haystack - haystack0.utf16();
9876 const char16_t *haystack_start = haystack0.utf16();
9877 for (idx = 0; idx < sl; ++idx) {
9878 hashNeedle = (hashNeedle<<1) + foldCase(needle + idx, needle);
9879 hashHaystack = (hashHaystack<<1) + foldCase(haystack + idx, haystack_start);
9881 hashHaystack -= foldCase(haystack + sl_minus_1, haystack_start);
9883 while (haystack <= end) {
9884 hashHaystack += foldCase(haystack + sl_minus_1, haystack_start);
9885 if (hashHaystack == hashNeedle
9886 && QtPrivate::compareStrings(needle0, sv(haystack), Qt::CaseInsensitive) == 0)
9887 return haystack - haystack0.utf16();
9889 REHASH(foldCase(haystack, haystack_start));
9898 if (haystack.size() < needle.size())
9901 QVarLengthArray<
char16_t> s = qt_from_latin1_to_qvla(needle);
9902 return QtPrivate::findString(haystack, from, QStringView(
reinterpret_cast<
const QChar*>(s.constData()), s.size()), cs);
9907 if (haystack.size() < needle.size())
9910 if (!QtPrivate::isLatin1(needle))
9913 if (needle.size() == 1) {
9914 const char n = needle.front().toLatin1();
9915 return QtPrivate::findString(haystack, from, QLatin1StringView(&n, 1), cs);
9918 Q_DECL_UNINITIALIZED
9919 QVarLengthArray<
char> s = qt_to_latin1_unchecked_to_qvla(needle);
9920 return QtPrivate::findString(haystack, from, QLatin1StringView(s.data(), s.size()), cs);
9926 from += haystack.size();
9929 qsizetype adjustedSize = haystack.size() - from;
9930 if (adjustedSize < needle.size())
9932 if (needle.size() == 0)
9935 if (cs == Qt::CaseSensitive) {
9937 if (needle.size() == 1) {
9938 Q_ASSERT(haystack.data() !=
nullptr);
9939 if (
auto it = memchr(haystack.data() + from, needle.front().toLatin1(), adjustedSize))
9940 return static_cast<
const char *>(it) - haystack.data();
9945 return matcher.indexIn(haystack, from);
9958 const qsizetype threshold = 1;
9960 const qsizetype threshold = 13;
9962 if (needle.size() <= threshold) {
9963 const auto begin = haystack.begin();
9964 const auto end = haystack.end() - needle.size() + 1;
9966 const qsizetype nlen1 = needle.size() - 1;
9967 for (
auto it =
std::find_if(begin + from, end, ciMatch); it != end;
9968 it =
std::find_if(it + 1, end, ciMatch)) {
9970 if (!nlen1 || QLatin1StringView(it + 1, nlen1).compare(needle.sliced(1), cs) == 0)
9971 return std::distance(begin, it);
9977 return matcher.indexIn(haystack, from);
9980qsizetype
QtPrivate::lastIndexOf(QStringView haystack, qsizetype from,
char16_t needle, Qt::CaseSensitivity cs)
noexcept
9982 return qLastIndexOf(haystack, QChar(needle), from, cs);
9985qsizetype
QtPrivate::lastIndexOf(QStringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs)
noexcept
9987 return qLastIndexOf(haystack, from, needle, cs);
9990qsizetype
QtPrivate::lastIndexOf(QStringView haystack, qsizetype from, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
9992 return qLastIndexOf(haystack, from, needle, cs);
9995qsizetype
QtPrivate::lastIndexOf(QLatin1StringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs)
noexcept
9997 return qLastIndexOf(haystack, from, needle, cs);
10000qsizetype
QtPrivate::lastIndexOf(QLatin1StringView haystack, qsizetype from, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
10002 return qLastIndexOf(haystack, from, needle, cs);
10005#if QT_CONFIG(regularexpression)
10006qsizetype QtPrivate::indexOf(QStringView viewHaystack,
const QString *stringHaystack,
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
10008 if (!re.isValid()) {
10009 qtWarnAboutInvalidRegularExpression(re,
"QString(View)",
"indexOf");
10013 QRegularExpressionMatch match = stringHaystack
10014 ? re.match(*stringHaystack, from)
10015 : re.matchView(viewHaystack, from);
10016 if (match.hasMatch()) {
10017 const qsizetype ret = match.capturedStart();
10019 *rmatch = std::move(match);
10026qsizetype QtPrivate::indexOf(QStringView haystack,
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
10028 return indexOf(haystack,
nullptr, re, from, rmatch);
10031qsizetype QtPrivate::lastIndexOf(QStringView viewHaystack,
const QString *stringHaystack,
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
10033 if (!re.isValid()) {
10034 qtWarnAboutInvalidRegularExpression(re,
"QString(View)",
"lastIndexOf");
10038 qsizetype endpos = (from < 0) ? (viewHaystack.size() + from + 1) : (from + 1);
10039 QRegularExpressionMatchIterator iterator = stringHaystack
10040 ? re.globalMatch(*stringHaystack)
10041 : re.globalMatchView(viewHaystack);
10042 qsizetype lastIndex = -1;
10043 while (iterator.hasNext()) {
10044 QRegularExpressionMatch match = iterator.next();
10045 qsizetype start = match.capturedStart();
10046 if (start < endpos) {
10049 *rmatch = std::move(match);
10058qsizetype QtPrivate::lastIndexOf(QStringView haystack,
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
10060 return lastIndexOf(haystack,
nullptr, re, from, rmatch);
10063bool QtPrivate::contains(QStringView viewHaystack,
const QString *stringHaystack,
const QRegularExpression &re, QRegularExpressionMatch *rmatch)
10065 if (!re.isValid()) {
10066 qtWarnAboutInvalidRegularExpression(re,
"QString(View)",
"contains");
10069 QRegularExpressionMatch m = stringHaystack
10070 ? re.match(*stringHaystack)
10071 : re.matchView(viewHaystack);
10072 bool hasMatch = m.hasMatch();
10073 if (hasMatch && rmatch)
10074 *rmatch = std::move(m);
10078bool QtPrivate::contains(QStringView haystack,
const QRegularExpression &re, QRegularExpressionMatch *rmatch)
10080 return contains(haystack,
nullptr, re, rmatch);
10083qsizetype QtPrivate::count(QStringView haystack,
const QRegularExpression &re)
10085 if (!re.isValid()) {
10086 qtWarnAboutInvalidRegularExpression(re,
"QString(View)",
"count");
10089 qsizetype count = 0;
10090 qsizetype index = -1;
10091 qsizetype len = haystack.size();
10092 while (index <= len - 1) {
10093 QRegularExpressionMatch match = re.matchView(haystack, index + 1);
10094 if (!match.hasMatch())
10101 index = match.capturedStart();
10102 if (index < len && haystack[index].isHighSurrogate())
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121QString QString::toHtmlEscaped()
const
10123 const auto pos = std::u16string_view(*
this).find_first_of(u"<>&\"");
10124 if (pos == std::u16string_view::npos)
10127 rich.reserve(qsizetype(size() * 1.1));
10128 rich += qToStringViewIgnoringNull(*
this).first(pos);
10129 for (
auto ch : qToStringViewIgnoringNull(*
this).sliced(pos)) {
10132 else if (ch == u'>')
10134 else if (ch == u'&')
10135 rich +=
"&"_L1;
10136 else if (ch == u'"')
10137 rich +=
"""_L1;
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10192#if QT_DEPRECATED_SINCE(6
, 8
)
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10244
10245
10246void QAbstractConcatenable::appendLatin1To(QLatin1StringView in, QChar *out)
noexcept
10248 qt_from_latin1(
reinterpret_cast<
char16_t *>(out), in.data(), size_t(in.size()));
10252
10253
10254
10255
10256
10257
10258
10259
10260
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
QString convertToQString(QAnyStringView string)
char32_t next(char32_t invalidAs=QChar::ReplacementCharacter)
QList< uint > convertToUcs4(QStringView string)
QByteArray convertToUtf8(QStringView string)
QByteArray convertToLocal8Bit(QStringView string)
QByteArray convertToLatin1(QStringView string)
Combined button and popup list for selecting options.
@ NormalizationCorrectionsVersionMax
static QString convertCase(T &str, QUnicodeTables::Case which)
static constexpr NormalizationCorrection uc_normalization_corrections[]
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isLower(QStringView s) noexcept
const QString & asString(const QString &s)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isValidUtf16(QStringView s) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool equalStrings(QStringView lhs, QStringView rhs) noexcept
qsizetype findString(QStringView str, qsizetype from, QChar needle, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isRightToLeft(QStringView string) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isAscii(QLatin1StringView s) noexcept
constexpr bool isLatin1(QLatin1StringView s) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION const char16_t * qustrcasechr(QStringView str, char16_t ch) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isUpper(QStringView s) noexcept
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION const char16_t * qustrchr(QStringView str, char16_t ch) noexcept
void qt_to_latin1_unchecked(uchar *dst, const char16_t *uc, qsizetype len)
static char16_t foldCase(char16_t ch) noexcept
uint QT_FASTCALL fetch1Pixel< QPixelLayout::BPP1LSB >(const uchar *src, int index)
bool comparesEqual(const QFileInfo &lhs, const QFileInfo &rhs)
static Int toIntegral(QStringView string, bool *ok, int base)
void qt_to_latin1(uchar *dst, const char16_t *src, qsizetype length)
Qt::strong_ordering compareThreeWay(const QByteArray &lhs, const QChar &rhs) noexcept
#define ATTRIBUTE_NO_SANITIZE
static bool checkCase(QStringView s, QUnicodeTables::Case c) noexcept
static void replace_helper(QString &str, QSpan< qsizetype > indices, qsizetype blen, QStringView after)
Q_CORE_EXPORT void qt_from_latin1(char16_t *dst, const char *str, size_t size) noexcept
static int ucstrcmp(const char16_t *a, size_t alen, const Char2 *b, size_t blen)
bool comparesEqual(const QByteArray &lhs, char16_t rhs) noexcept
Q_DECLARE_TYPEINFO(Part, Q_PRIMITIVE_TYPE)
static void removeStringImpl(QString &s, const T &needle, Qt::CaseSensitivity cs)
static bool needsReallocate(const QString &str, qsizetype newSize)
static int qArgDigitValue(QChar ch) noexcept
bool comparesEqual(const QByteArray &lhs, const QChar &rhs) noexcept
bool comparesEqual(const QByteArrayView &lhs, char16_t rhs) noexcept
static int ucstrncmp(const char16_t *a, const char16_t *b, size_t l)
static Q_NEVER_INLINE int ucstricmp(qsizetype alen, const char16_t *a, qsizetype blen, const char *b)
static QVarLengthArray< char > qt_to_latin1_unchecked_to_qvla(QStringView str)
static QByteArray qt_convert_to_latin1(QStringView string)
static bool ucstreq(const char16_t *a, size_t alen, const Char2 *b)
static QList< uint > qt_convert_to_ucs4(QStringView string)
qsizetype qFindStringBoyerMoore(QStringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs)
static QByteArray qt_convert_to_local_8bit(QStringView string)
static LengthMod parse_length_modifier(const char *&c) noexcept
static ArgEscapeData findArgEscapes(QStringView s)
static QByteArray qt_convert_to_utf8(QStringView str)
static void qt_to_latin1_internal(uchar *dst, const char16_t *src, qsizetype length)
QtPrivate::QCaseInsensitiveLatin1Hash CaseInsensitiveL1
qsizetype qt_count_with_matcher(Haystack haystack, Needle needle, Qt::CaseSensitivity cs) noexcept
static qptrdiff isAscii_helper(const char16_t *ptr, qsizetype len)
static void insert_helper(QString &str, qsizetype i, const T &toInsert)
static int latin1nicmp(const char *lhsChar, qsizetype lSize, const char *rhsChar, qsizetype rSize)
Qt::strong_ordering compareThreeWay(const QByteArrayView &lhs, const QChar &rhs) noexcept
static char16_t to_unicode(const char c)
Qt::strong_ordering compareThreeWay(const QByteArray &lhs, char16_t rhs) noexcept
static QString replaceArgEscapes(QStringView s, const ArgEscapeData &d, qsizetype field_width, QStringView arg, QStringView larg, QChar fillChar)
static QVarLengthArray< char16_t > qt_from_latin1_to_qvla(QLatin1StringView str)
static Q_NEVER_INLINE int ucstricmp8(const char *utf8, const char *utf8end, const QChar *utf16, const QChar *utf16end)
static void normalize(QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, qsizetype from)
static uint parse_flag_characters(const char *&c) noexcept
qsizetype qt_count_with_findstring(String haystack, String needle, Qt::CaseSensitivity cs) noexcept
static Q_NEVER_INLINE int ucstricmp(qsizetype alen, const char16_t *a, qsizetype blen, const char16_t *b)
static char16_t to_unicode(const QChar c)
QDataStream & operator>>(QDataStream &in, QString &str)
static int getEscape(const Char *uc, qsizetype *pos, qsizetype len)
static int ucstrncmp(const char16_t *a, const char *b, size_t l)
static bool can_consume(const char *&c, char ch) noexcept
qsizetype qt_count_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs)
static int parse_field_width(const char *&c, qsizetype size)
Qt::strong_ordering compareThreeWay(const QByteArrayView &lhs, char16_t rhs) noexcept
#define qUtf16Printable(string)
qsizetype locale_occurrences
\inmodule QtCore \reentrant
constexpr char16_t unicode() const noexcept
Converts a Latin-1 character to an 16-bit-encoded Unicode representation of the character.
constexpr QLatin1Char(char c) noexcept
Constructs a Latin-1 character for c.
static auto matcher(char ch)
static int difference(char lhs, char rhs)