7#if QT_CONFIG(regularexpression)
8#include "qregularexpression.h"
11#include <private/qstringconverter_p.h>
12#include <private/qtools_p.h>
14#include "private/qsimd_p.h"
16#include <qdatastream.h>
30#include <private/qcore_mac_p.h>
33#include <private/qfunctions_p.h>
53# include <qt_windows.h>
54# if !defined(QT_BOOTSTRAPPED) && (defined(QT_NO_CAST_FROM_ASCII) || defined(QT_NO_CAST_TO_ASCII))
56# error "This file cannot be compiled with QT_NO_CAST_{TO,FROM}_ASCII, "
57 "otherwise some QString functions will not get exported."
66 if (sl_minus_1 < sizeof(sl_minus_1) * CHAR_BIT)
67 hashHaystack -= decltype(hashHaystack)(a) << sl_minus_1;
72using namespace Qt::StringLiterals;
73using namespace QtMiscUtils;
75const char16_t QString::_empty = 0;
81enum StringComparisonMode {
82 CompareStringsForEquality,
83 CompareStringsForOrdering
86template <
typename Pointer>
87char32_t foldCaseHelper(Pointer ch, Pointer start) =
delete;
90char32_t foldCaseHelper<
const QChar*>(
const QChar* ch,
const QChar* start)
92 return foldCase(
reinterpret_cast<
const char16_t*>(ch),
93 reinterpret_cast<
const char16_t*>(start));
97char32_t foldCaseHelper<
const char*>(
const char* ch,
const char*)
103char16_t valueTypeToUtf16(T t) =
delete;
106char16_t valueTypeToUtf16<QChar>(QChar t)
112char16_t valueTypeToUtf16<
char>(
char t)
114 return char16_t{uchar(t)};
118static inline bool foldAndCompare(
const T a,
const T b)
120 return foldCase(a) == b;
124
125
126
127
128
129
130
131template <
typename Haystack>
132static inline qsizetype qLastIndexOf(Haystack haystack, QChar needle,
133 qsizetype from, Qt::CaseSensitivity cs)
noexcept
135 if (haystack.size() == 0)
138 from += haystack.size();
139 else if (
std::size_t(from) >
std::size_t(haystack.size()))
140 from = haystack.size() - 1;
142 char16_t c = needle.unicode();
143 const auto b = haystack.data();
145 if (cs == Qt::CaseSensitive) {
147 if (valueTypeToUtf16(*n) == c)
152 if (foldCase(valueTypeToUtf16(*n)) == c)
159qLastIndexOf(QString, QChar, qsizetype, Qt::CaseSensitivity)
noexcept =
delete;
161template<
typename Haystack,
typename Needle>
162static qsizetype qLastIndexOf(Haystack haystack0, qsizetype from,
163 Needle needle0, Qt::CaseSensitivity cs)
noexcept
165 const qsizetype sl = needle0.size();
167 return qLastIndexOf(haystack0, needle0.front(), from, cs);
169 const qsizetype l = haystack0.size();
172 if (from == l && sl == 0)
174 const qsizetype delta = l - sl;
175 if (
std::size_t(from) >
std::size_t(l) || delta < 0)
180 auto sv = [sl](
const typename Haystack::value_type *v) {
return Haystack(v, sl); };
182 auto haystack = haystack0.data();
183 const auto needle = needle0.data();
184 const auto *end = haystack;
186 const qregisteruint sl_minus_1 = sl ? sl - 1 : 0;
187 const auto *n = needle + sl_minus_1;
188 const auto *h = haystack + sl_minus_1;
189 qregisteruint hashNeedle = 0, hashHaystack = 0;
191 if (cs == Qt::CaseSensitive) {
192 for (qsizetype idx = 0; idx < sl; ++idx) {
193 hashNeedle = (hashNeedle << 1) + valueTypeToUtf16(*(n - idx));
194 hashHaystack = (hashHaystack << 1) + valueTypeToUtf16(*(h - idx));
196 hashHaystack -= valueTypeToUtf16(*haystack);
198 while (haystack >= end) {
199 hashHaystack += valueTypeToUtf16(*haystack);
200 if (hashHaystack == hashNeedle
201 && QtPrivate::compareStrings(needle0, sv(haystack), Qt::CaseSensitive) == 0)
202 return haystack - end;
204 REHASH(valueTypeToUtf16(haystack[sl]));
207 for (qsizetype idx = 0; idx < sl; ++idx) {
208 hashNeedle = (hashNeedle << 1) + foldCaseHelper(n - idx, needle);
209 hashHaystack = (hashHaystack << 1) + foldCaseHelper(h - idx, end);
211 hashHaystack -= foldCaseHelper(haystack, end);
213 while (haystack >= end) {
214 hashHaystack += foldCaseHelper(haystack, end);
215 if (hashHaystack == hashNeedle
216 && QtPrivate::compareStrings(sv(haystack), needle0, Qt::CaseInsensitive) == 0)
217 return haystack - end;
219 REHASH(foldCaseHelper(haystack + sl, end));
225template <
typename Haystack,
typename Needle>
226bool qt_starts_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs)
noexcept
228 if (haystack.isNull())
229 return needle.isNull();
230 const auto haystackLen = haystack.size();
231 const auto needleLen = needle.size();
232 if (haystackLen == 0)
233 return needleLen == 0;
234 if (needleLen > haystackLen)
237 return QtPrivate::compareStrings(haystack.first(needleLen), needle, cs) == 0;
240template <
typename Haystack,
typename Needle>
241bool qt_ends_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs)
noexcept
243 if (haystack.isNull())
244 return needle.isNull();
245 const auto haystackLen = haystack.size();
246 const auto needleLen = needle.size();
247 if (haystackLen == 0)
248 return needleLen == 0;
249 if (haystackLen < needleLen)
252 return QtPrivate::compareStrings(haystack.last(needleLen), needle, cs) == 0;
256static void append_helper(QString &self, T view)
258 const auto strData = view.data();
259 const qsizetype strSize = view.size();
260 auto &d = self.data_ptr();
261 if (strData && strSize > 0) {
264 d.detachAndGrow(QArrayData::GrowsAtEnd, strSize,
nullptr,
nullptr);
265 Q_CHECK_PTR(d.data());
266 Q_ASSERT(strSize <= d.freeSpaceAtEnd());
268 auto dst =
std::next(d.data(), d.size);
269 if constexpr (std::is_same_v<T, QUtf8StringView>) {
270 dst = QUtf8::convertToUnicode(dst, view);
271 }
else if constexpr (std::is_same_v<T, QLatin1StringView>) {
272 QLatin1::convertToUnicode(dst, view);
276 "Can only operate on UTF-8 and Latin-1");
278 self.resize(
std::distance(d.begin(), dst));
279 }
else if (d.isNull() && !view.isNull()) {
280 self = QLatin1StringView(
"");
284template <uint MaxCount>
struct UnrollTailLoop
286 template <
typename RetType,
typename Functor1,
typename Functor2,
typename Number>
287 static inline RetType exec(Number count, RetType returnIfExited, Functor1 loopCheck, Functor2 returnIfFailed, Number i = 0)
290
291
292
293
294
295
298 return returnIfExited;
300 bool check = loopCheck(i);
302 return returnIfFailed(i);
304 return UnrollTailLoop<MaxCount - 1>::exec(count - 1, returnIfExited, loopCheck, returnIfFailed, i + 1);
307 template <
typename Functor,
typename Number>
308 static inline void exec(Number count, Functor code)
311
312
313
314 exec(count, 0, [=](Number i) ->
bool { code(i);
return false; }, [](Number) {
return 0; });
317template <>
template <
typename RetType,
typename Functor1,
typename Functor2,
typename Number>
318inline RetType UnrollTailLoop<0>::exec(Number, RetType returnIfExited, Functor1, Functor2, Number)
320 return returnIfExited;
325
326
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
354#if defined(__mips_dsp)
356extern "C" void qt_fromlatin1_mips_asm_unroll4 (
char16_t*,
const char*, uint);
357extern "C" void qt_fromlatin1_mips_asm_unroll8 (
char16_t*,
const char*, uint);
358extern "C" void qt_toLatin1_mips_dsp_asm(uchar *dst,
const char16_t *src,
int length);
361#if defined(__SSE2__
) && defined(Q_CC_GNU)
364# define ATTRIBUTE_NO_SANITIZE __attribute__((__no_sanitize_address__, __no_sanitize_thread__))
366# define ATTRIBUTE_NO_SANITIZE
370static constexpr bool UseSse4_1 =
bool(qCompilerCpuFeatures & CpuFeatureSSE4_1);
371static constexpr bool UseAvx2 = UseSse4_1 &&
372 (qCompilerCpuFeatures & CpuFeatureArchHaswell) == CpuFeatureArchHaswell;
375static Q_ALWAYS_INLINE __m128i mm_load8_zero_extend(
const void *ptr)
377 const __m128i *dataptr =
static_cast<
const __m128i *>(ptr);
378 if constexpr (UseSse4_1) {
381 __m128i data = _mm_loadl_epi64(dataptr);
382 return _mm_cvtepu8_epi16(data);
386 __m128i data = _mm_loadl_epi64(dataptr);
387 return _mm_unpacklo_epi8(data, _mm_setzero_si128());
391static qsizetype qustrlen_sse2(
const char16_t *str)
noexcept
394 quintptr misalignment = quintptr(str) & 0xf;
395 Q_ASSERT((misalignment & 1) == 0);
396 const char16_t *ptr = str - (misalignment / 2);
400 const __m128i zeroes = _mm_setzero_si128();
401 __m128i data = _mm_load_si128(
reinterpret_cast<
const __m128i *>(ptr));
402 __m128i comparison = _mm_cmpeq_epi16(data, zeroes);
403 uint mask = _mm_movemask_epi8(comparison);
406 mask >>= misalignment;
411 return qCountTrailingZeroBits(mask) /
sizeof(
char16_t);
413 constexpr qsizetype Step =
sizeof(__m128i) /
sizeof(
char16_t);
414 qsizetype size = Step - misalignment /
sizeof(
char16_t);
419 data = _mm_load_si128(
reinterpret_cast<
const __m128i *>(str + size));
421 comparison = _mm_cmpeq_epi16(data, zeroes);
422 mask = _mm_movemask_epi8(comparison);
426 return size + qCountTrailingZeroBits(mask) /
sizeof(
char16_t);
433static bool simdTestMask(
const char *&ptr,
const char *end, quint32 maskval)
435 auto updatePtr = [&](uint result) {
437 uint idx = qCountTrailingZeroBits(~result);
442 if constexpr (UseSse4_1) {
445 auto updatePtrSimd = [&](__m128i data) ->
bool {
446 __m128i masked = _mm_and_si128(mask, data);
447 __m128i comparison = _mm_cmpeq_epi16(masked, _mm_setzero_si128());
448 uint result = _mm_movemask_epi8(comparison);
449 return updatePtr(result);
452 if constexpr (UseAvx2) {
454 const __m256i mask256 = _mm256_broadcastd_epi32(_mm_cvtsi32_si128(maskval));
455 while (ptr + 32 <= end) {
456 __m256i data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(ptr));
457 if (!_mm256_testz_si256(mask256, data)) {
459 __m256i masked256 = _mm256_and_si256(mask256, data);
460 __m256i comparison256 = _mm256_cmpeq_epi16(masked256, _mm256_setzero_si256());
461 return updatePtr(_mm256_movemask_epi8(comparison256));
466 mask = _mm256_castsi256_si128(mask256);
470 mask = _mm_set1_epi32(maskval);
471 while (ptr + 32 <= end) {
472 __m128i data1 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr));
473 __m128i data2 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr + 16));
474 if (!_mm_testz_si128(mask, data1))
475 return updatePtrSimd(data1);
478 if (!_mm_testz_si128(mask, data2))
479 return updatePtrSimd(data2);
485 if (ptr + 16 <= end) {
486 __m128i data1 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr));
487 if (!_mm_testz_si128(mask, data1))
488 return updatePtrSimd(data1);
493 if (ptr + 8 <= end) {
494 __m128i data1 = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr));
495 if (!_mm_testz_si128(mask, data1))
496 return updatePtrSimd(data1);
505 const __m128i mask = _mm_set1_epi32(maskval);
506 while (ptr + 16 <= end) {
507 __m128i data = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr));
508 __m128i masked = _mm_and_si128(mask, data);
509 __m128i comparison = _mm_cmpeq_epi16(masked, _mm_setzero_si128());
510 quint16 result = _mm_movemask_epi8(comparison);
511 if (result != 0xffff)
512 return updatePtr(result);
517 if (ptr + 8 <= end) {
518 __m128i data = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr));
519 __m128i masked = _mm_and_si128(mask, data);
520 __m128i comparison = _mm_cmpeq_epi16(masked, _mm_setzero_si128());
521 quint8 result = _mm_movemask_epi8(comparison);
523 return updatePtr(result);
530template <StringComparisonMode Mode,
typename Char> [[maybe_unused]]
531static int ucstrncmp_sse2(
const char16_t *a,
const Char *b, size_t l)
533 static_assert(
std::is_unsigned_v<Char>);
537 static const auto codeUnitAt = [](
const auto *n, qptrdiff idx) ->
int {
538 constexpr int Stride = 2;
545 auto ptr =
reinterpret_cast<
const uchar *>(n);
546 ptr += idx / (Stride /
sizeof(*n));
547 return *
reinterpret_cast<
decltype(n)>(ptr);
549 auto difference = [a, b](uint mask, qptrdiff offset) {
550 if (Mode == CompareStringsForEquality)
552 uint idx = qCountTrailingZeroBits(mask);
553 return codeUnitAt(a + offset, idx) - codeUnitAt(b + offset, idx);
556 static const auto load8Chars = [](
const auto *ptr) {
557 if (
sizeof(*ptr) == 2)
558 return _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr));
559 __m128i chunk = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr));
560 return _mm_unpacklo_epi8(chunk, _mm_setzero_si128());
562 static const auto load4Chars = [](
const auto *ptr) {
563 if (
sizeof(*ptr) == 2)
564 return _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr));
565 __m128i chunk = _mm_cvtsi32_si128(qFromUnaligned<quint32>(ptr));
566 return _mm_unpacklo_epi8(chunk, _mm_setzero_si128());
570 auto processChunk16Chars = [a, b](qptrdiff offset) -> uint {
571 if constexpr (UseAvx2) {
572 __m256i a_data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(a + offset));
574 if (
sizeof(Char) == 1) {
576 __m128i chunk = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(b + offset));
577 b_data = _mm256_cvtepu8_epi16(chunk);
579 b_data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(b + offset));
581 __m256i result = _mm256_cmpeq_epi16(a_data, b_data);
582 return _mm256_movemask_epi8(result);
585 __m128i a_data1 = load8Chars(a + offset);
586 __m128i a_data2 = load8Chars(a + offset + 8);
587 __m128i b_data1, b_data2;
588 if (
sizeof(Char) == 1) {
590 __m128i b_data = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(b + offset));
591 b_data1 = _mm_unpacklo_epi8(b_data, _mm_setzero_si128());
592 b_data2 = _mm_unpackhi_epi8(b_data, _mm_setzero_si128());
594 b_data1 = load8Chars(b + offset);
595 b_data2 = load8Chars(b + offset + 8);
597 __m128i result1 = _mm_cmpeq_epi16(a_data1, b_data1);
598 __m128i result2 = _mm_cmpeq_epi16(a_data2, b_data2);
599 return _mm_movemask_epi8(result1) | _mm_movemask_epi8(result2) << 16;
602 if (l >=
sizeof(__m256i) /
sizeof(
char16_t)) {
604 for ( ; l >= offset +
sizeof(__m256i) /
sizeof(
char16_t); offset +=
sizeof(__m256i) /
sizeof(
char16_t)) {
605 uint mask = ~processChunk16Chars(offset);
607 return difference(mask, offset);
611 if (size_t(offset) < l) {
612 offset = l -
sizeof(__m256i) /
sizeof(
char16_t);
613 uint mask = ~processChunk16Chars(offset);
614 return mask ? difference(mask, offset) : 0;
617 __m128i a_data1, b_data1;
618 __m128i a_data2, b_data2;
622 a_data1 = load8Chars(a);
623 b_data1 = load8Chars(b);
624 a_data2 = load8Chars(a + l - width);
625 b_data2 = load8Chars(b + l - width);
629 a_data1 = load4Chars(a);
630 b_data1 = load4Chars(b);
631 a_data2 = load4Chars(a + l - width);
632 b_data2 = load4Chars(b + l - width);
635 __m128i result = _mm_cmpeq_epi16(a_data1, b_data1);
636 ushort mask = ~_mm_movemask_epi8(result);
638 return difference(mask, 0);
640 result = _mm_cmpeq_epi16(a_data2, b_data2);
641 mask = ~_mm_movemask_epi8(result);
643 return difference(mask, l - width);
648 const auto lambda = [=](size_t i) ->
int {
651 return UnrollTailLoop<3>::exec(l, 0, lambda, lambda);
658qsizetype QtPrivate::qustrlen(
const char16_t *str)
noexcept
660#if defined(__SSE2__
) && !(defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)) && !(defined(__SANITIZE_THREAD__) || __has_feature(thread_sanitizer))
661 return qustrlen_sse2(str);
664 if (
sizeof(
wchar_t) ==
sizeof(
char16_t))
665 return wcslen(
reinterpret_cast<
const wchar_t *>(str));
667 qsizetype result = 0;
673qsizetype
QtPrivate::qustrnlen(
const char16_t *str, qsizetype maxlen)
noexcept
675 return qustrchr({ str, maxlen }, u'\0') - str;
679
680
681
682
683
684
685
689 const char16_t *n = str.utf16();
690 const char16_t *e = n + str.size();
697 if constexpr (UseAvx2) {
699 __m256i mch256 = _mm256_set1_epi32(c | (c << 16));
700 for (
const char16_t *next = n + 16; next <= e; n = next, next += 16) {
701 __m256i data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(n));
702 __m256i result = _mm256_cmpeq_epi16(data, mch256);
703 uint mask = uint(_mm256_movemask_epi8(result));
705 uint idx = qCountTrailingZeroBits(mask);
710 mch = _mm256_castsi256_si128(mch256);
712 mch = _mm_set1_epi32(c | (c << 16));
715 auto hasMatch = [mch, &n](__m128i data, ushort validityMask) {
716 __m128i result = _mm_cmpeq_epi16(data, mch);
717 uint mask = uint(_mm_movemask_epi8(result));
718 if ((mask & validityMask) == 0)
720 uint idx = qCountTrailingZeroBits(mask);
726 for (
const char16_t *next = n + 8; next <= e; n = next, next += 8) {
727 __m128i data = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(n));
728 if (hasMatch(data, 0xffff))
737# if !defined(__OPTIMIZE_SIZE__)
740 __m128i data = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(n));
741 if (hasMatch(data, 0xff))
747 return UnrollTailLoop<3>::exec(e - n, e,
748 [=](qsizetype i) {
return n[i] == c; },
749 [=](qsizetype i) {
return n + i; });
751#elif defined(__ARM_NEON__)
752 const uint16x8_t vmask = qvsetq_n_u16(1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7);
753 const uint16x8_t ch_vec = vdupq_n_u16(c);
754 for (
const char16_t *next = n + 8; next <= e; n = next, next += 8) {
755 uint16x8_t data = vld1q_u16(
reinterpret_cast<
const uint16_t *>(n));
756 uint mask = vaddvq_u16(vandq_u16(vceqq_u16(data, ch_vec), vmask));
759 return n + qCountTrailingZeroBits(mask);
764 return std::find(n, e, c);
768
769
770
771
772
773
777 const QChar *n = str.begin();
778 const QChar *e = str.end();
780 auto it =
std::find_if(n, e, [c](
auto ch) {
return foldAndCompare(ch, QChar(c)); });
781 return reinterpret_cast<
const char16_t *>(it);
791 if constexpr (UseAvx2) {
792 while (ptr + 32 <= end) {
793 __m256i data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(ptr));
794 quint32 mask = _mm256_movemask_epi8(data);
796 uint idx = qCountTrailingZeroBits(mask);
805 while (ptr + 16 <= end) {
806 __m128i data = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr));
807 quint32 mask = _mm_movemask_epi8(data);
809 uint idx = qCountTrailingZeroBits(mask);
818 if (ptr + 8 <= end) {
819 __m128i data = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr));
820 quint8 mask = _mm_movemask_epi8(data);
822 uint idx = qCountTrailingZeroBits(mask);
830 while (ptr + 4 <= end) {
831 quint32 data = qFromUnaligned<quint32>(ptr);
832 if (data &= 0x80808080U) {
833 uint idx = QSysInfo::ByteOrder == QSysInfo::BigEndian
834 ? qCountLeadingZeroBits(data)
835 : qCountTrailingZeroBits(data);
843 if (quint8(*ptr) & 0x80)
852 const char *ptr = s.begin();
853 const char *end = s.end();
861 const char *ptr8 =
reinterpret_cast<
const char *>(ptr);
862 const char *end8 =
reinterpret_cast<
const char *>(end);
863 bool ok = simdTestMask(ptr8, end8, 0xff80ff80);
864 ptr =
reinterpret_cast<
const char16_t *>(ptr8);
879 const char16_t *ptr = s.utf16();
880 const char16_t *end = ptr + s.size();
887 const char16_t *ptr = s.utf16();
888 const char16_t *end = ptr + s.size();
891 const char *ptr8 =
reinterpret_cast<
const char *>(ptr);
892 const char *end8 =
reinterpret_cast<
const char *>(end);
893 if (!simdTestMask(ptr8, end8, 0xff00ff00))
895 ptr =
reinterpret_cast<
const char16_t *>(ptr8);
907 constexpr char32_t InvalidCodePoint = UINT_MAX;
911 const char32_t c = i
.next(InvalidCodePoint
);
912 if (c == InvalidCodePoint)
920Q_CORE_EXPORT
void qt_from_latin1(
char16_t *dst,
const char *str, size_t size)
noexcept
923
924
925
926
929 const __m128i nullMask = _mm_setzero_si128();
930 auto processOneChunk = [=](qptrdiff offset) {
931 const __m128i chunk = _mm_loadu_si128((
const __m128i*)(str + offset));
932 if constexpr (UseAvx2) {
934 const __m256i extended = _mm256_cvtepu8_epi16(chunk);
937 _mm256_storeu_si256((__m256i*)(dst + offset), extended);
940 const __m128i firstHalf = _mm_unpacklo_epi8(chunk, nullMask);
941 _mm_storeu_si128((__m128i*)(dst + offset), firstHalf);
944 const __m128i secondHalf = _mm_unpackhi_epi8 (chunk, nullMask);
945 _mm_storeu_si128((__m128i*)(dst + offset + 8), secondHalf);
949 const char *e = str + size;
950 if (size >=
sizeof(__m128i)) {
952 for ( ; str + offset +
sizeof(__m128i) <= e; offset +=
sizeof(__m128i))
953 processOneChunk(offset);
954 if (str + offset < e)
955 processOneChunk(size -
sizeof(__m128i));
959# if !defined(__OPTIMIZE_SIZE__)
963 const __m128i unpacked1 = mm_load8_zero_extend(str);
964 const __m128i unpacked2 = mm_load8_zero_extend(str + size - 8);
965 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst), unpacked1);
966 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst + size - 8), unpacked2);
968 const __m128i chunk1 = _mm_cvtsi32_si128(qFromUnaligned<quint32>(str));
969 const __m128i chunk2 = _mm_cvtsi32_si128(qFromUnaligned<quint32>(str + size - 4));
970 const __m128i unpacked1 = _mm_unpacklo_epi8(chunk1, nullMask);
971 const __m128i unpacked2 = _mm_unpacklo_epi8(chunk2, nullMask);
972 _mm_storel_epi64(
reinterpret_cast<__m128i *>(dst), unpacked1);
973 _mm_storel_epi64(
reinterpret_cast<__m128i *>(dst + size - 4), unpacked2);
978 return UnrollTailLoop<3>::exec(qsizetype(size), [=](qsizetype i) { dst[i] = uchar(str[i]); });
982#if defined(__mips_dsp)
983 static_assert(
sizeof(qsizetype) ==
sizeof(
int),
984 "oops, the assembler implementation needs to be called in a loop");
986 qt_fromlatin1_mips_asm_unroll8(dst, str, size);
988 qt_fromlatin1_mips_asm_unroll4(dst, str, size);
991 *dst++ = (uchar)*str++;
997 const qsizetype len = str.size();
998 QVarLengthArray<
char16_t> arr(len);
999 qt_from_latin1(arr.data(), str.data(), len);
1003template <
bool Checked>
1006#if defined(__SSE2__
)
1007 auto questionMark256 = []() {
1008 if constexpr (UseAvx2)
1009 return _mm256_broadcastw_epi16(_mm_cvtsi32_si128(
'?'));
1013 auto outOfRange256 = []() {
1014 if constexpr (UseAvx2)
1015 return _mm256_broadcastw_epi16(_mm_cvtsi32_si128(0x100));
1019 __m128i questionMark, outOfRange;
1020 if constexpr (UseAvx2) {
1021 questionMark = _mm256_castsi256_si128(questionMark256);
1022 outOfRange = _mm256_castsi256_si128(outOfRange256);
1024 questionMark = _mm_set1_epi16(
'?');
1025 outOfRange = _mm_set1_epi16(0x100);
1028 auto mergeQuestionMarks = [=](__m128i chunk) {
1033 if constexpr (UseSse4_1) {
1035 chunk = _mm_min_epu16(chunk, outOfRange);
1036 const __m128i offLimitMask = _mm_cmpeq_epi16(chunk, outOfRange);
1037 chunk = _mm_blendv_epi8(chunk, questionMark, offLimitMask);
1041 const __m128i signedBitOffset = _mm_set1_epi16(
short(0x8000));
1042 const __m128i thresholdMask = _mm_set1_epi16(
short(0xff + 0x8000));
1044 const __m128i signedChunk = _mm_add_epi16(chunk, signedBitOffset);
1045 const __m128i offLimitMask = _mm_cmpgt_epi16(signedChunk, thresholdMask);
1049 const __m128i offLimitQuestionMark = _mm_and_si128(offLimitMask, questionMark);
1053 const __m128i correctBytes = _mm_andnot_si128(offLimitMask, chunk);
1056 chunk = _mm_or_si128(correctBytes, offLimitQuestionMark);
1058 Q_UNUSED(outOfRange);
1063 auto loadChunkAt = [=](qptrdiff offset) {
1064 __m128i chunk1, chunk2;
1065 if constexpr (UseAvx2) {
1066 __m256i chunk = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(src + offset));
1069 chunk = _mm256_min_epu16(chunk, outOfRange256);
1070 const __m256i offLimitMask = _mm256_cmpeq_epi16(chunk, outOfRange256);
1071 chunk = _mm256_blendv_epi8(chunk, questionMark256, offLimitMask);
1074 chunk2 = _mm256_extracti128_si256(chunk, 1);
1075 chunk1 = _mm256_castsi256_si128(chunk);
1077 chunk1 = _mm_loadu_si128((
const __m128i*)(src + offset));
1078 chunk1 = mergeQuestionMarks(chunk1);
1080 chunk2 = _mm_loadu_si128((
const __m128i*)(src + offset + 8));
1081 chunk2 = mergeQuestionMarks(chunk2);
1085 return _mm_packus_epi16(chunk1, chunk2);
1088 if (size_t(length) >=
sizeof(__m128i)) {
1090 qptrdiff offset = 0;
1091 for ( ; offset + 2 *
sizeof(__m128i) < size_t(length); offset +=
sizeof(__m128i))
1092 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst + offset), loadChunkAt(offset));
1095 __m128i last1 = loadChunkAt(offset);
1096 __m128i last2 = loadChunkAt(length -
sizeof(__m128i));
1097 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst + offset), last1);
1098 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst + length -
sizeof(__m128i)), last2);
1102# if !defined(__OPTIMIZE_SIZE__)
1107 __m128i chunk1 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(src));
1108 __m128i chunk2 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(src + length - 8));
1109 chunk1 = mergeQuestionMarks(chunk1);
1110 chunk2 = mergeQuestionMarks(chunk2);
1113 const __m128i result1 = _mm_packus_epi16(chunk1, chunk1);
1114 const __m128i result2 = _mm_packus_epi16(chunk2, chunk2);
1115 _mm_storel_epi64(
reinterpret_cast<__m128i *>(dst), result1);
1116 _mm_storel_epi64(
reinterpret_cast<__m128i *>(dst + length - 8), result2);
1118 __m128i chunk1 = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(src));
1119 __m128i chunk2 = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(src + length - 4));
1120 chunk1 = mergeQuestionMarks(chunk1);
1121 chunk2 = mergeQuestionMarks(chunk2);
1124 const __m128i result1 = _mm_packus_epi16(chunk1, chunk1);
1125 const __m128i result2 = _mm_packus_epi16(chunk2, chunk2);
1126 qToUnaligned(_mm_cvtsi128_si32(result1), dst);
1127 qToUnaligned(_mm_cvtsi128_si32(result2), dst + length - 4);
1132 length = length % 4;
1133 return UnrollTailLoop<3>::exec(length, [=](qsizetype i) {
1135 dst[i] = (src[i]>0xff) ?
'?' : (uchar) src[i];
1140 length = length % 16;
1142#elif defined(__ARM_NEON__)
1148 const qsizetype chunkCount = length >> 3;
1149 const uint16x8_t questionMark = vdupq_n_u16(
'?');
1150 const uint16x8_t thresholdMask = vdupq_n_u16(0xff);
1151 for (qsizetype i = 0; i < chunkCount; ++i) {
1152 uint16x8_t chunk = vld1q_u16((uint16_t *)src);
1156 const uint16x8_t offLimitMask = vcgtq_u16(chunk, thresholdMask);
1157 const uint16x8_t offLimitQuestionMark = vandq_u16(offLimitMask, questionMark);
1158 const uint16x8_t correctBytes = vbicq_u16(chunk, offLimitMask);
1159 chunk = vorrq_u16(correctBytes, offLimitQuestionMark);
1161 const uint8x8_t result = vmovn_u16(chunk);
1162 vst1_u8(dst, result);
1165 length = length % 8;
1168#if defined(__mips_dsp)
1169 static_assert(
sizeof(qsizetype) ==
sizeof(
int),
1170 "oops, the assembler implementation needs to be called in a loop");
1171 qt_toLatin1_mips_dsp_asm(dst, src, length);
1175 *dst++ = (*src>0xff) ?
'?' : (uchar) *src;
1185 qt_to_latin1_internal<
true>(dst, src, length);
1190 qt_to_latin1_internal<
false>(dst, src, length);
1197 return qt_lencmp(alen, blen);
1201 qsizetype l = qMin(alen, blen);
1203 for (i = 0; i < l; ++i) {
1207 int diff = foldCase(a[i], alast) - foldCase(b[i], blast);
1223 qsizetype l = qMin(alen, blen);
1225 for (i = 0; i < l; ++i) {
1226 int diff = foldCase(a[i]) - foldCase(
char16_t{uchar(b[i])});
1241 auto src1 =
reinterpret_cast<
const uchar *>(utf8);
1242 auto end1 =
reinterpret_cast<
const uchar *>(utf8end);
1246 char32_t decoded[1];
1247 char32_t *output = decoded;
1248 char32_t &uc1 = decoded[0];
1250 const qsizetype res = QUtf8Functions::fromUtf8<QUtf8BaseTraits>(b, output, src1, end1);
1253 uc1 = QChar::ReplacementCharacter;
1255 uc1 = QChar::toCaseFolded(uc1);
1258 char32_t uc2 = QChar::toCaseFolded(src2.next());
1259 int diff = uc1 - uc2;
1268#if defined(__mips_dsp)
1270extern "C" int qt_ucstrncmp_mips_dsp_asm(
const char16_t *a,
1276template <StringComparisonMode Mode>
1277static int ucstrncmp(
const char16_t *a,
const char16_t *b, size_t l)
1283#ifndef __OPTIMIZE_SIZE__
1284# if defined(__mips_dsp)
1285 static_assert(
sizeof(uint) ==
sizeof(size_t));
1287 return qt_ucstrncmp_mips_dsp_asm(a, b, l);
1289# elif defined(__SSE2__
)
1290 return ucstrncmp_sse2<Mode>(a, b, l);
1291# elif defined(__ARM_NEON__)
1293 const char16_t *end = a + l;
1294 const uint16x8_t mask = qvsetq_n_u16( 1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7 );
1295 while (end - a > 7) {
1296 uint16x8_t da = vld1q_u16(
reinterpret_cast<
const uint16_t *>(a));
1297 uint16x8_t db = vld1q_u16(
reinterpret_cast<
const uint16_t *>(b));
1299 uint8_t r = ~(uint8_t)vaddvq_u16(vandq_u16(vceqq_u16(da, db), mask));
1302 if (Mode == CompareStringsForEquality)
1304 uint idx = qCountTrailingZeroBits(r);
1305 return a[idx] - b[idx];
1312 const auto lambda = [=](size_t i) ->
int {
1315 return UnrollTailLoop<7>::exec(l, 0, lambda, lambda);
1319 if (Mode == CompareStringsForEquality || QSysInfo::ByteOrder == QSysInfo::BigEndian)
1320 return memcmp(a, b, l *
sizeof(
char16_t));
1322 for (size_t i = 0; i < l; ++i) {
1323 if (
int diff = a[i] - b[i])
1329template <StringComparisonMode Mode>
1330static int ucstrncmp(
const char16_t *a,
const char *b, size_t l)
1332 const uchar *c =
reinterpret_cast<
const uchar *>(b);
1333 const char16_t *uc = a;
1334 const char16_t *e = uc + l;
1336#if defined(__SSE2__
) && !defined(__OPTIMIZE_SIZE__)
1337 return ucstrncmp_sse2<Mode>(uc, c, l);
1341 int diff = *uc - *c;
1351template <
typename Char2>
1352static bool ucstreq(
const char16_t *a, size_t alen,
const Char2 *b)
1354 return ucstrncmp<CompareStringsForEquality>(a, b, alen) == 0;
1358template <
typename Char2>
1359static int ucstrcmp(
const char16_t *a, size_t alen,
const Char2 *b, size_t blen)
1361 const size_t l = qMin(alen, blen);
1362 int cmp = ucstrncmp<CompareStringsForOrdering>(a, b, l);
1363 return cmp ? cmp : qt_lencmp(alen, blen);
1368static int latin1nicmp(
const char *lhsChar, qsizetype lSize,
const char *rhsChar, qsizetype rSize)
1371 Q_ASSERT(lSize >= 0 && rSize >= 0);
1373 return rSize ? -1 : 0;
1376 const qsizetype size =
std::min(lSize, rSize);
1378 Q_ASSERT(lhsChar && rhsChar);
1379 for (qsizetype i = 0; i < size; i++) {
1383 return qt_lencmp(lSize, rSize);
1388 Q_ASSERT(lhs.size() == rhs.size());
1389 return ucstreq(lhs.utf16(), lhs.size(), rhs.utf16());
1394 Q_ASSERT(lhs.size() == rhs.size());
1395 return ucstreq(lhs.utf16(), lhs.size(), rhs.latin1());
1400 return QtPrivate::equalStrings(rhs, lhs);
1405 Q_ASSERT(lhs.size() == rhs.size());
1406 return (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0);
1411 return QUtf8::compareUtf8(lhs, rhs) == 0;
1416 return QtPrivate::equalStrings(rhs, lhs);
1421 return QUtf8::compareUtf8(QByteArrayView(rhs), lhs) == 0;
1426 return QtPrivate::equalStrings(rhs, lhs);
1431#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
) || defined(QT_BOOTSTRAPPED) || defined(QT_STATIC)
1432 Q_ASSERT(lhs.size() == rhs.size());
1435 if (lhs.size() != rhs.size())
1438 return (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0);
1441bool QAnyStringView::equal(QAnyStringView lhs, QAnyStringView rhs)
noexcept
1443 if (lhs.size() != rhs.size() && lhs.isUtf8() == rhs.isUtf8())
1445 return lhs.visit([rhs](
auto lhs) {
1446 return rhs.visit([lhs](
auto rhs) {
1447 return QtPrivate::equalStrings(lhs, rhs);
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1469 if (cs == Qt::CaseSensitive)
1470 return ucstrcmp(lhs.utf16(), lhs.size(), rhs.utf16(), rhs.size());
1471 return ucstricmp(lhs.size(), lhs.utf16(), rhs.size(), rhs.utf16());
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1492 if (cs == Qt::CaseSensitive)
1493 return ucstrcmp(lhs.utf16(), lhs.size(), rhs.latin1(), rhs.size());
1494 return ucstricmp(lhs.size(), lhs.utf16(), rhs.size(), rhs.latin1());
1498
1499
1500
1501
1502
1505 return -compareStrings(rhs, lhs, cs);
1509
1510
1511
1512
1513
1516 return -compareStrings(rhs, lhs, cs);
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1538 return qt_lencmp(qsizetype(0), rhs.size());
1540 return qt_lencmp(lhs.size(), qsizetype(0));
1541 if (cs == Qt::CaseInsensitive)
1542 return latin1nicmp(lhs.data(), lhs.size(), rhs.data(), rhs.size());
1543 const auto l =
std::min(lhs.size(), rhs.size());
1544 int r = memcmp(lhs.data(), rhs.data(), l);
1545 return r ? r : qt_lencmp(lhs.size(), rhs.size());
1549
1550
1551
1552
1553
1556 return -QUtf8::compareUtf8(QByteArrayView(rhs), lhs, cs);
1560
1561
1562
1563
1564
1567 if (cs == Qt::CaseSensitive)
1568 return QUtf8::compareUtf8(lhs, rhs);
1569 return ucstricmp8(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1573
1574
1575
1576
1577
1580 return -compareStrings(rhs, lhs, cs);
1584
1585
1586
1587
1588
1591 return QUtf8::compareUtf8(QByteArrayView(lhs), QByteArrayView(rhs), cs);
1594int QAnyStringView::compare(QAnyStringView lhs, QAnyStringView rhs, Qt::CaseSensitivity cs)
noexcept
1596 return lhs.visit([rhs, cs](
auto lhs) {
1597 return rhs.visit([lhs, cs](
auto rhs) {
1598 return QtPrivate::compareStrings(lhs, rhs, cs);
1605#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
1606static bool supportUnicodeDigitValuesInArg()
1608 static const bool result = []() {
1609 static const char supportUnicodeDigitValuesEnvVar[]
1610 =
"QT_USE_UNICODE_DIGIT_VALUES_IN_STRING_ARG";
1612 if (qEnvironmentVariableIsSet(supportUnicodeDigitValuesEnvVar))
1613 return qEnvironmentVariableIntValue(supportUnicodeDigitValuesEnvVar) != 0;
1615#if QT_VERSION < QT_VERSION_CHECK(6
, 6
, 0
)
1628#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
1629 if (supportUnicodeDigitValuesInArg())
1630 return ch.digitValue();
1632 if (ch >= u'0' && ch <= u'9')
1633 return int(ch.unicode() - u'0');
1637#if QT_CONFIG(regularexpression)
1639void qtWarnAboutInvalidRegularExpression(
const QString &pattern,
const char *where);
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1674
1675
1676
1677
1678
1679
1680
1681
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
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
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2137
2138
2139
2142
2143
2144
2147
2148
2149
2152
2153
2154
2157
2158
2159
2160
2163
2164
2165
2166
2169
2170
2173
2174
2177
2178
2180
2181
2184
2185
2186
2187
2188
2190
2191
2192
2193
2194
2197
2198
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2214
2215
2216
2219
2220
2221
2222
2223
2224
2225
2226
2227
2230
2231
2232
2233
2234
2235
2236
2237
2240
2241
2242
2243
2244
2245
2246
2247
2250
2251
2252
2255
2256
2257
2258
2259
2260
2261
2262
2263
2266
2267
2268
2269
2270
2271
2272
2273
2276
2277
2278
2279
2280
2281
2282
2283
2284
2287
2288
2289
2292
2293
2294
2295
2296
2297
2298
2299
2300
2303
2304
2305
2306
2307
2308
2309
2310
2311
2314
2315
2316
2319
2320
2321
2322
2323
2324
2325
2326
2327
2330
2331
2332
2333
2334
2335
2338
2339
2340
2341
2342
2343
2344
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2367
2368
2369
2370
2371
2372
2373
2374
2377
2378
2379
2380
2381
2384
2385
2386
2387
2388
2391
2392
2393
2394
2395
2396
2397
2398
2399
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2429qsizetype QString::toUcs4_helper(
const char16_t *uc, qsizetype length,
char32_t *out)
2431 qsizetype count = 0;
2433 QStringIterator i(QStringView(uc, length));
2435 out[count++] = i.next();
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487QString::QString(
const QChar *unicode, qsizetype size)
2493 size = QtPrivate::qustrlen(
reinterpret_cast<
const char16_t *>(unicode));
2495 d = DataPointer::fromRawData(&_empty, 0);
2497 d = DataPointer(size, size);
2498 Q_CHECK_PTR(d.data());
2499 memcpy(d.data(), unicode, size *
sizeof(QChar));
2500 d.data()[size] =
'\0';
2506
2507
2508
2509
2510
2511QString::QString(qsizetype size, QChar ch)
2514 d = DataPointer::fromRawData(&_empty, 0);
2516 d = DataPointer(size, size);
2517 Q_CHECK_PTR(d.data());
2518 d.data()[size] =
'\0';
2519 char16_t *b = d.data();
2520 char16_t *e = d.data() + size;
2521 const char16_t value = ch.unicode();
2522 std::fill(b, e, value);
2527
2528
2529
2530
2531
2532QString::QString(qsizetype size, Qt::Initialization)
2535 d = DataPointer::fromRawData(&_empty, 0);
2537 d = DataPointer(size, size);
2538 Q_CHECK_PTR(d.data());
2539 d.data()[size] =
'\0';
2544
2545
2546
2547
2548
2551
2552
2553QString::QString(QChar ch)
2555 d = DataPointer(1, 1);
2556 Q_CHECK_PTR(d.data());
2557 d.data()[0] = ch.unicode();
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2579
2580
2583
2584
2587
2588
2591
2592
2593
2594
2598
2599
2600
2603
2604
2605
2608
2609
2610
2613
2614
2615
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);
2668 if (d->allocatedCapacity())
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
2829QString &QString::operator=(
const QString &other)
noexcept
2836
2837
2838
2839
2840
2841
2844
2845
2846
2847
2848
2849QString &QString::operator=(QLatin1StringView other)
2851 const qsizetype capacityAtEnd = capacity() - d.freeSpaceAtBegin();
2852 if (isDetached() && other.size() <= capacityAtEnd) {
2853 d.size = other.size();
2854 d.data()[other.size()] = 0;
2855 qt_from_latin1(d.data(), other.latin1(), other.size());
2857 *
this = fromLatin1(other.latin1(), other.size());
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2889
2890
2891
2892
2893QString &QString::operator=(QChar ch)
2895 return assign(1, ch);
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2918
2919
2920
2921
2922
2923
2924
2925
2926
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2959
2960
2961template <
typename T>
2964 auto &str_d = str.data_ptr();
2965 qsizetype difference = 0;
2966 if (Q_UNLIKELY(i > str_d.size))
2967 difference = i - str_d.size;
2968 const qsizetype oldSize = str_d.size;
2969 const qsizetype insert_size = toInsert.size();
2970 const qsizetype newSize = str_d.size + difference + insert_size;
2971 const auto side = i == 0 ? QArrayData::GrowsAtBeginning : QArrayData::GrowsAtEnd;
2973 if (str_d.needsDetach() || needsReallocate(str, newSize)) {
2974 const auto cbegin = str.cbegin();
2975 const auto cend = str.cend();
2976 const auto insert_start = difference == 0 ? std::next(cbegin, i) : cend;
2980 other.data_ptr().detachAndGrow(side, newSize,
nullptr,
nullptr);
2981 other.append(QStringView(cbegin, insert_start));
2982 other.resize(i, u' ');
2983 other.append(toInsert);
2984 other.append(QStringView(insert_start, cend));
2989 str_d.detachAndGrow(side, difference + insert_size,
nullptr,
nullptr);
2990 Q_CHECK_PTR(str_d.data());
2991 str.resize(newSize);
2993 auto begin = str_d.begin();
2994 auto old_end =
std::next(begin, oldSize);
2995 std::fill_n(old_end, difference, u' ');
2996 auto insert_start =
std::next(begin, i);
2997 if (difference == 0)
2998 std::move_backward(insert_start, old_end, str_d.end());
3000 using Char = std::remove_cv_t<
typename T::value_type>;
3001 if constexpr(std::is_same_v<Char, QChar>)
3002 std::copy_n(
reinterpret_cast<
const char16_t *>(toInsert.data()), insert_size, insert_start);
3003 else if constexpr (std::is_same_v<Char,
char16_t>)
3004 std::copy_n(toInsert.data(), insert_size, insert_start);
3005 else if constexpr (std::is_same_v<Char,
char>)
3006 qt_from_latin1(insert_start, toInsert.data(), insert_size);
3010
3011
3012
3013
3014
3015
3016
3017QString &QString::insert(qsizetype i, QLatin1StringView str)
3019 const char *s = str.latin1();
3020 if (i < 0 || !s || !(*s))
3023 insert_helper(*
this, i, str);
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040QString &QString::insert(qsizetype i, QUtf8StringView s)
3042 auto insert_size = s.size();
3043 if (i < 0 || insert_size <= 0)
3046 qsizetype difference = 0;
3047 if (Q_UNLIKELY(i > d.size))
3048 difference = i - d.size;
3050 const qsizetype newSize = d.size + difference + insert_size;
3052 if (d.needsDetach() || needsReallocate(*
this, newSize)) {
3053 const auto cbegin =
this->cbegin();
3054 const auto insert_start = difference == 0 ? std::next(cbegin, i) : cend();
3056 other.reserve(newSize);
3057 other.append(QStringView(cbegin, insert_start));
3059 other.resize(i, u' ');
3061 other.append(QStringView(insert_start, cend()));
3067 d.detachAndGrow(QArrayData::GrowsAtEnd, difference + insert_size,
nullptr,
nullptr);
3068 Q_CHECK_PTR(d.data());
3077 QVarLengthArray<
char16_t> buffer(insert_size);
3078 char16_t *b = QUtf8::convertToUnicode(buffer.data(), s);
3079 insert_helper(*
this, i, QStringView(buffer.data(), b));
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097QString& QString::insert(qsizetype i,
const QChar *unicode, qsizetype size)
3099 if (i < 0 || size <= 0)
3103 if (!d->needsDetach() && QtPrivate::q_points_into_range(unicode, *
this)) {
3104 QVarLengthArray copy(unicode, unicode + size);
3105 insert(i, copy.data(), size);
3107 insert_helper(*
this, i, QStringView(unicode, size));
3114
3115
3116
3117
3118
3119
3120
3121
3122
3124QString& QString::insert(qsizetype i, QChar ch)
3128 return insert(i, &ch, 1);
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149QString &QString::append(
const QString &str)
3151 if (!str.isNull()) {
3153 if (Q_UNLIKELY(!str.d.isMutable()))
3157 }
else if (str.size()) {
3158 append(str.constData(), str.size());
3165
3166
3167
3168
3169
3170
3173
3174
3175
3176
3177
3178QString &QString::append(
const QChar *str, qsizetype len)
3180 if (str && len > 0) {
3181 static_assert(
sizeof(QChar) ==
sizeof(
char16_t),
"Unexpected difference in sizes");
3183 const char16_t *char16String =
reinterpret_cast<
const char16_t *>(str);
3184 d->growAppend(char16String, char16String + len);
3185 d.data()[d.size] = u'\0';
3191
3192
3193
3194
3195QString &QString::append(QLatin1StringView str)
3197 append_helper(*
this, str);
3202
3203
3204
3205
3206
3207QString &QString::append(QUtf8StringView str)
3209 append_helper(*
this, str);
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3240
3241
3242
3243
3244QString &QString::append(QChar ch)
3246 d.detachAndGrow(QArrayData::GrowsAtEnd, 1,
nullptr,
nullptr);
3247 d->copyAppend(1, ch.unicode());
3248 d.data()[d.size] =
'\0';
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3269
3270
3271
3272
3273
3276
3277
3278
3279
3280
3283
3284
3285
3286
3287
3288
3291
3292
3293
3294
3295
3296
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3325
3326
3327
3328
3329
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
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
3390
3391
3392
3393
3394
3395
3396
3398QString &QString::assign(QAnyStringView s)
3400 if (s.size() <= capacity() && isDetached()) {
3401 const auto offset = d.freeSpaceAtBegin();
3403 d.setBegin(d.begin() - offset);
3405 s.visit([
this](
auto input) {
3406 this->append(input);
3409 *
this = s.toString();
3414#ifndef QT_BOOTSTRAPPED
3415QString &QString::assign_helper(
const char32_t *data, qsizetype len)
3418 const auto requiredCapacity = len * 2;
3419 if (requiredCapacity <= capacity() && isDetached()) {
3420 const auto offset = d.freeSpaceAtBegin();
3422 d.setBegin(d.begin() - offset);
3423 auto begin =
reinterpret_cast<QChar *>(d.begin());
3424 auto ba = QByteArrayView(
reinterpret_cast<
const std::byte*>(data), len *
sizeof(
char32_t));
3425 QStringConverter::State state;
3426 const auto end = QUtf32::convertToUnicode(begin, ba, &state, DetectEndianness);
3427 d.size = end - begin;
3428 d.data()[d.size] = u'\0';
3430 *
this = QString::fromUcs4(data, len);
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458QString &QString::remove(qsizetype pos, qsizetype len)
3463 if (size_t(pos) >= size_t(size()) || len <= 0)
3466 len = std::min(len, size() - pos);
3468 if (!d->isShared()) {
3469 d->erase(d.begin() + pos, len);
3470 d.data()[d.size] = u'\0';
3475 const qsizetype sz = size() - len;
3476 QString copy{sz, Qt::Uninitialized};
3477 auto begin = d.begin();
3478 auto toRemove_start = d.begin() + pos;
3479 copy.d->copyRanges({{begin, toRemove_start},
3480 {toRemove_start + len, d.end()}});
3489 const auto needleSize = needle.size();
3494 qsizetype i = s.indexOf(needle, 0, cs);
3498 QString::DataPointer &dptr = s.data_ptr();
3499 auto begin = dptr.begin();
3500 auto end = dptr.end();
3502 auto copyFunc = [&](
auto &dst) {
3503 auto src = begin + i + needleSize;
3505 i = s.indexOf(needle, std::distance(begin, src), cs);
3506 auto hit = i == -1 ? end : begin + i;
3507 dst =
std::copy(src, hit, dst);
3508 src = hit + needleSize;
3513 if (!dptr->needsDetach()) {
3514 auto dst = begin + i;
3515 dst = copyFunc(dst);
3516 s.truncate(
std::distance(begin, dst));
3518 QString copy{s.size(), Qt::Uninitialized};
3519 auto copy_begin = copy.begin();
3520 auto dst = std::copy(begin, begin + i, copy_begin);
3521 dst = copyFunc(dst);
3522 copy.resize(
std::distance(copy_begin, dst));
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539QString &QString::remove(
const QString &str, Qt::CaseSensitivity cs)
3541 const auto s = str.d.data();
3542 if (QtPrivate::q_points_into_range(s, d))
3543 removeStringImpl(*
this, QStringView{QVarLengthArray(s, s + str.size())}, cs);
3545 removeStringImpl(*
this, qToStringViewIgnoringNull(str), cs);
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564QString &QString::remove(QLatin1StringView str, Qt::CaseSensitivity cs)
3566 removeStringImpl(*
this, str, cs);
3571
3572
3573
3574
3575
3576
3577
3578
3579
3582
3583
3584
3585
3586
3587
3588
3589
3590
3593
3594
3595
3596
3597
3598
3599
3600
3601
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619QString &QString::remove(QChar ch, Qt::CaseSensitivity cs)
3621 const qsizetype idx = indexOf(ch, 0, cs);
3625 const bool isCase = cs == Qt::CaseSensitive;
3626 ch = isCase ? ch : ch.toCaseFolded();
3627 auto match = [ch, isCase](QChar x) {
3628 return ch == (isCase ? x : x.toCaseFolded());
3632 auto begin = d.begin();
3633 auto first_match = begin + idx;
3635 if (!d->isShared()) {
3636 auto it = std::remove_if(first_match, end, match);
3637 d->erase(it, std::distance(it, end));
3638 d.data()[d.size] = u'\0';
3643 QString copy{size(), Qt::Uninitialized};
3644 auto dst = copy.d.begin();
3645 auto it = std::copy(begin, first_match, dst);
3646 it = std::remove_copy_if(first_match + 1, end, it, match);
3647 copy.d.size = std::distance(dst, it);
3648 copy.d.data()[copy.d.size] = u'\0';
3649 *
this = std::move(copy);
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3669
3670
3671
3672
3673
3674
3675
3676
3680
3681
3682
3683
3687 const qsizetype alen = after.size();
3688 const char16_t *after_b = after.utf16();
3690 const QString::DataPointer &str_d = str.data_ptr();
3691 auto src_start = str_d.begin();
3692 const qsizetype newSize = str_d.size + indices.size() * (alen - blen);
3693 QString copy{ newSize, Qt::Uninitialized };
3694 QString::DataPointer ©_d = copy.data_ptr();
3695 auto dst = copy_d.begin();
3696 for (size_t index : indices) {
3697 auto hit = str_d.begin() + index;
3698 dst = std::copy(src_start, hit, dst);
3699 dst = std::copy_n(after_b, alen, dst);
3700 src_start = hit + blen;
3702 dst =
std::copy(src_start, str_d.end(), dst);
3708 qsizetype blen, QStringView after)
3710 const qsizetype alen = after.size();
3711 const char16_t *after_b = after.utf16();
3712 const char16_t *after_e = after.utf16() + after.size();
3715 for (size_t index : indices)
3716 std::copy_n(after_b, alen, str.data_ptr().begin() + index);
3717 }
else if (blen > alen) {
3718 char16_t *begin = str.data_ptr().begin();
3719 char16_t *hit = begin + indices.front();
3721 to =
std::copy_n(after_b, alen, to);
3722 char16_t *movestart = hit + blen;
3723 for (size_t index : indices.sliced(1)) {
3724 hit = begin + index;
3725 to = std::move(movestart, hit, to);
3726 to = std::copy_n(after_b, alen, to);
3727 movestart = hit + blen;
3729 to =
std::move(movestart, str.data_ptr().end(), to);
3730 str.resize(
std::distance(begin, to));
3732 const qsizetype oldSize = str.data_ptr().size;
3733 const qsizetype adjust = indices.size() * (alen - blen);
3734 const qsizetype newSize = oldSize + adjust;
3736 str.resize(newSize);
3737 char16_t *begin = str.data_ptr().begin();
3738 char16_t *moveend = begin + oldSize;
3739 char16_t *to = str.data_ptr().end();
3741 for (
auto it = indices.rbegin(), end = indices.rend(); it != end; ++it) {
3742 char16_t *hit = begin + *it;
3743 char16_t *movestart = hit + blen;
3744 to =
std::move_backward(movestart, moveend, to);
3745 to =
std::copy_backward(after_b, after_e, to);
3751static void replace_helper(QString &str, QSpan<size_t> indices, qsizetype blen, QStringView after)
3753 const qsizetype oldSize = str.data_ptr().size;
3754 const qsizetype adjust = indices.size() * (after.size() - blen);
3755 const qsizetype newSize = oldSize + adjust;
3756 if (str.data_ptr().needsDetach() || needsReallocate(str, newSize)) {
3757 replace_with_copy(str, indices, blen, after);
3761 if (QtPrivate::q_points_into_range(after.begin(), str))
3764 replace_in_place(str, indices, blen,
QVarLengthArray(after.begin(), after.end()));
3766 replace_in_place(str, indices, blen, after);
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785QString &QString::replace(qsizetype pos, qsizetype len,
const QString &after)
3787 return replace(pos, len, after.constData(), after.size());
3791
3792
3793
3794
3795
3796
3797QString &QString::replace(qsizetype pos, qsizetype len,
const QChar *after, qsizetype alen)
3799 if (size_t(pos) > size_t(
this->size()))
3801 if (len >
this->size() - pos)
3802 len =
this->size() - pos;
3805 replace_helper(*
this, QSpan(&index, 1), len, QStringView{after, alen});
3810
3811
3812
3813
3814
3815
3816QString &QString::replace(qsizetype pos, qsizetype len, QChar after)
3818 return replace(pos, len, &after, 1);
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844QString &QString::replace(
const QString &before,
const QString &after, Qt::CaseSensitivity cs)
3846 return replace(before.constData(), before.size(), after.constData(), after.size(), cs);
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863QString &QString::replace(
const QChar *before, qsizetype blen,
3864 const QChar *after, qsizetype alen,
3865 Qt::CaseSensitivity cs)
3871 if (cs == Qt::CaseSensitive && before == after && blen == alen)
3874 if (alen == 0 && blen == 0)
3876 if (alen == 1 && blen == 1)
3877 return replace(*before, *after, cs);
3879 QStringMatcher matcher(before, blen, cs);
3881 qsizetype index = 0;
3883 QVarLengthArray<size_t> indices;
3884 while ((index = matcher.indexIn(*
this, index)) != -1) {
3885 indices.push_back(index);
3891 if (indices.isEmpty())
3894 replace_helper(*
this, indices, blen, QStringView{after, alen});
3899
3900
3901
3902
3903
3904
3905QString& QString::replace(QChar ch,
const QString &after, Qt::CaseSensitivity cs)
3907 if (after.size() == 0)
3908 return remove(ch, cs);
3910 if (after.size() == 1)
3911 return replace(ch, after.front(), cs);
3916 const char16_t cc = (cs == Qt::CaseSensitive ? ch.unicode() : ch.toCaseFolded().unicode());
3918 QVarLengthArray<size_t> indices;
3919 if (cs == Qt::CaseSensitive) {
3920 const char16_t *begin = d.begin();
3921 const char16_t *end = d.end();
3922 QStringView view(begin, end);
3923 const char16_t *hit =
nullptr;
3924 while ((hit = QtPrivate::qustrchr(view, cc)) != end) {
3925 indices.push_back(std::distance(begin, hit));
3926 view = QStringView(std::next(hit), end);
3929 for (qsizetype i = 0; i < d.size; ++i)
3930 if (QChar::toCaseFolded(d.data()[i]) == cc)
3931 indices.push_back(i);
3933 if (indices.isEmpty())
3936 replace_helper(*
this, indices, 1, after);
3941
3942
3943
3944
3945
3946
3947QString& QString::replace(QChar before, QChar after, Qt::CaseSensitivity cs)
3949 const qsizetype idx = indexOf(before, 0, cs);
3953 const char16_t achar = after.unicode();
3954 char16_t bchar = before.unicode();
3956 auto matchesCIS = [](
char16_t beforeChar) {
3957 return [beforeChar](
char16_t ch) {
return foldAndCompare(ch, beforeChar); };
3960 auto hit = d.begin() + idx;
3961 if (!d.needsDetach()) {
3963 if (cs == Qt::CaseSensitive) {
3964 std::replace(hit, d.end(), bchar, achar);
3966 bchar = foldCase(bchar);
3967 std::replace_if(hit, d.end(), matchesCIS(bchar), achar);
3970 QString other{ d.size, Qt::Uninitialized };
3971 auto dest = std::copy(d.begin(), hit, other.d.begin());
3974 if (cs == Qt::CaseSensitive) {
3975 std::replace_copy(hit, d.end(), dest, bchar, achar);
3977 bchar = foldCase(bchar);
3978 std::replace_copy_if(hit, d.end(), dest, matchesCIS(bchar), achar);
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000QString &QString::replace(QLatin1StringView before, QLatin1StringView after, Qt::CaseSensitivity cs)
4002 const qsizetype alen = after.size();
4003 const qsizetype blen = before.size();
4004 if (blen == 1 && alen == 1)
4005 return replace(before.front(), after.front(), cs);
4007 QVarLengthArray<
char16_t> a = qt_from_latin1_to_qvla(after);
4008 QVarLengthArray<
char16_t> b = qt_from_latin1_to_qvla(before);
4009 return replace((
const QChar *)b.data(), blen, (
const QChar *)a.data(), alen, cs);
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026QString &QString::replace(QLatin1StringView before,
const QString &after, Qt::CaseSensitivity cs)
4028 const qsizetype blen = before.size();
4029 if (blen == 1 && after.size() == 1)
4030 return replace(before.front(), after.front(), cs);
4032 QVarLengthArray<
char16_t> b = qt_from_latin1_to_qvla(before);
4033 return replace((
const QChar *)b.data(), blen, after.constData(), after.d.size, cs);
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049QString &QString::replace(
const QString &before, QLatin1StringView after, Qt::CaseSensitivity cs)
4051 const qsizetype alen = after.size();
4052 if (before.size() == 1 && alen == 1)
4053 return replace(before.front(), after.front(), cs);
4055 QVarLengthArray<
char16_t> a = qt_from_latin1_to_qvla(after);
4056 return replace(before.constData(), before.d.size, (
const QChar *)a.data(), alen, cs);
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity cs)
4072 const qsizetype alen = after.size();
4074 return replace(c, after.front(), cs);
4076 QVarLengthArray<
char16_t> a = qt_from_latin1_to_qvla(after);
4077 return replace(&c, 1, (
const QChar *)a.data(), alen, cs);
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4093
4094
4095
4096
4097
4098
4099
4102
4103
4104
4105
4106
4107
4108
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4138
4139
4140
4141
4142
4143
4144
4145
4146
4149
4150
4151
4152
4153
4154
4155
4158
4159
4160
4161
4162
4163
4164
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4196
4197
4198
4199
4200
4201
4204
4205
4206
4207
4208
4209
4210
4213
4214
4215
4216
4217
4218
4219
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4248
4249
4250
4251
4252
4253
4256
4257
4258
4259
4260
4261
4262
4265
4266
4267
4268
4269
4270
4271
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4300
4301
4302
4303
4304
4305
4308
4309
4310
4311
4312
4313
4314
4317
4318
4319
4320
4321
4322
4323
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4352
4353
4354
4355
4356
4357
4360
4361
4362
4363
4364
4365
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490qsizetype QString::indexOf(
const QString &str, qsizetype from, Qt::CaseSensitivity cs)
const
4492 return QtPrivate::findString(QStringView(unicode(), size()), from, QStringView(str.unicode(), str.size()), cs);
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4525qsizetype QString::indexOf(QLatin1StringView str, qsizetype from, Qt::CaseSensitivity cs)
const
4527 return QtPrivate::findString(QStringView(unicode(), size()), from, str, cs);
4531
4532
4533
4534
4535
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559qsizetype QString::lastIndexOf(
const QString &str, qsizetype from, Qt::CaseSensitivity cs)
const
4561 return QtPrivate::lastIndexOf(QStringView(*
this), from, str, cs);
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607qsizetype QString::lastIndexOf(QLatin1StringView str, qsizetype from, Qt::CaseSensitivity cs)
const
4609 return QtPrivate::lastIndexOf(*
this, from, str, cs);
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4630
4631
4632
4633
4634
4637
4638
4639
4640
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4678#if QT_CONFIG(regularexpression)
4679struct QStringCapture
4685Q_DECLARE_TYPEINFO(QStringCapture, Q_PRIMITIVE_TYPE);
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705QString &QString::replace(
const QRegularExpression &re,
const QString &after)
4707 if (!re.isValid()) {
4708 qtWarnAboutInvalidRegularExpression(re.pattern(),
"QString::replace");
4712 const QString copy(*
this);
4713 QRegularExpressionMatchIterator iterator = re.globalMatch(copy);
4714 if (!iterator.hasNext())
4717 reallocData(d.size, QArrayData::KeepSize);
4719 qsizetype numCaptures = re.captureCount();
4723 QVarLengthArray<QStringCapture> backReferences;
4724 const qsizetype al = after.size();
4725 const QChar *ac = after.unicode();
4727 for (qsizetype i = 0; i < al - 1; i++) {
4728 if (ac[i] == u'\\') {
4729 int no = ac[i + 1].digitValue();
4730 if (no > 0 && no <= numCaptures) {
4731 QStringCapture backReference;
4732 backReference.pos = i;
4733 backReference.len = 2;
4736 int secondDigit = ac[i + 2].digitValue();
4737 if (secondDigit != -1 && ((no * 10) + secondDigit) <= numCaptures) {
4738 no = (no * 10) + secondDigit;
4739 ++backReference.len;
4743 backReference.no = no;
4744 backReferences.append(backReference);
4753 qsizetype newLength = 0;
4754 qsizetype lastEnd = 0;
4755 QVarLengthArray<QStringView> chunks;
4756 const QStringView copyView{ copy }, afterView{ after };
4757 while (iterator.hasNext()) {
4758 QRegularExpressionMatch match = iterator.next();
4761 len = match.capturedStart() - lastEnd;
4763 chunks << copyView.mid(lastEnd, len);
4769 for (
const QStringCapture &backReference : std::as_const(backReferences)) {
4771 len = backReference.pos - lastEnd;
4773 chunks << afterView.mid(lastEnd, len);
4778 len = match.capturedLength(backReference.no);
4780 chunks << copyView.mid(match.capturedStart(backReference.no), len);
4784 lastEnd = backReference.pos + backReference.len;
4788 len = afterView.size() - lastEnd;
4790 chunks << afterView.mid(lastEnd, len);
4794 lastEnd = match.capturedEnd();
4798 if (copyView.size() > lastEnd) {
4799 chunks << copyView.mid(lastEnd);
4800 newLength += copyView.size() - lastEnd;
4807 for (
const QStringView &chunk : std::as_const(chunks)) {
4808 qsizetype len = chunk.size();
4809 memcpy(uc + i, chunk.constData(), len *
sizeof(QChar));
4818
4819
4820
4821
4822
4823
4824
4826qsizetype QString::count(
const QString &str, Qt::CaseSensitivity cs)
const
4828 return QtPrivate::count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs);
4832
4833
4834
4835
4836
4837
4838
4839
4841qsizetype QString::count(QChar ch, Qt::CaseSensitivity cs)
const
4843 return QtPrivate::count(QStringView(unicode(), size()), ch, cs);
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856qsizetype QString::count(QStringView str, Qt::CaseSensitivity cs)
const
4858 return QtPrivate::count(*
this, str, cs);
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4875
4876
4877
4878
4879
4880
4881
4884
4885
4886
4887
4888
4889
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4903#if QT_CONFIG(regularexpression)
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919qsizetype QString::indexOf(
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
const
4921 return QtPrivate::indexOf(QStringView(*
this),
this, re, from, rmatch);
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955qsizetype QString::lastIndexOf(
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
const
4957 return QtPrivate::lastIndexOf(QStringView(*
this),
this, re, from, rmatch);
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4994bool QString::contains(
const QRegularExpression &re, QRegularExpressionMatch *rmatch)
const
4996 return QtPrivate::contains(QStringView(*
this),
this, re, rmatch);
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017qsizetype QString::count(
const QRegularExpression &re)
const
5019 return QtPrivate::count(QStringView(*
this), re);
5023#if QT_DEPRECATED_SINCE(6
, 4
)
5025
5026
5027
5028
5029
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5088
5089
5090
5091
5092
5093
5094
5096QString QString::section(
const QString &sep, qsizetype start, qsizetype end, SectionFlags flags)
const
5098 const QList<QStringView> sections = QStringView{ *
this }.split(
5099 sep, Qt::KeepEmptyParts, (flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive : Qt::CaseSensitive);
5100 const qsizetype sectionsSize = sections.size();
5101 if (!(flags & SectionSkipEmpty)) {
5103 start += sectionsSize;
5105 end += sectionsSize;
5108 for (qsizetype k = 0; k < sectionsSize; ++k) {
5109 if (sections.at(k).isEmpty())
5113 start += sectionsSize - skip;
5115 end += sectionsSize - skip;
5117 if (start >= sectionsSize || end < 0 || start > end)
5121 qsizetype first_i = start, last_i = end;
5122 for (qsizetype x = 0, i = 0; x <= end && i < sectionsSize; ++i) {
5123 const QStringView §ion = sections.at(i);
5124 const bool empty = section.isEmpty();
5130 if (x > start && i > 0)
5134 if (!empty || !(flags & SectionSkipEmpty))
5137 if ((flags & SectionIncludeLeadingSep) && first_i > 0)
5139 if ((flags & SectionIncludeTrailingSep) && last_i < sectionsSize - 1)
5144#if QT_CONFIG(regularexpression)
5145class qt_section_chunk {
5147 qt_section_chunk() {}
5148 qt_section_chunk(qsizetype l, QStringView s) : length(l), string(std::move(s)) {}
5152Q_DECLARE_TYPEINFO(qt_section_chunk, Q_RELOCATABLE_TYPE);
5154static QString extractSections(QSpan<qt_section_chunk> sections, qsizetype start, qsizetype end,
5155 QString::SectionFlags flags)
5157 const qsizetype sectionsSize = sections.size();
5159 if (!(flags & QString::SectionSkipEmpty)) {
5161 start += sectionsSize;
5163 end += sectionsSize;
5166 for (qsizetype k = 0; k < sectionsSize; ++k) {
5167 const qt_section_chunk §ion = sections[k];
5168 if (section.length == section.string.size())
5172 start += sectionsSize - skip;
5174 end += sectionsSize - skip;
5176 if (start >= sectionsSize || end < 0 || start > end)
5181 qsizetype first_i = start, last_i = end;
5182 for (qsizetype i = 0; x <= end && i < sectionsSize; ++i) {
5183 const qt_section_chunk §ion = sections[i];
5184 const bool empty = (section.length == section.string.size());
5191 ret += section.string;
5193 ret += section.string.mid(section.length);
5195 if (!empty || !(flags & QString::SectionSkipEmpty))
5199 if ((flags & QString::SectionIncludeLeadingSep) && first_i >= 0) {
5200 const qt_section_chunk §ion = sections[first_i];
5201 ret.prepend(section.string.left(section.length));
5204 if ((flags & QString::SectionIncludeTrailingSep)
5205 && last_i < sectionsSize - 1) {
5206 const qt_section_chunk §ion = sections[last_i + 1];
5207 ret += section.string.left(section.length);
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227QString QString::section(
const QRegularExpression &re, qsizetype start, qsizetype end, SectionFlags flags)
const
5229 if (!re.isValid()) {
5230 qtWarnAboutInvalidRegularExpression(re.pattern(),
"QString::section");
5234 const QChar *uc = unicode();
5238 QRegularExpression sep(re);
5239 if (flags & SectionCaseInsensitiveSeps)
5240 sep.setPatternOptions(sep.patternOptions() | QRegularExpression::CaseInsensitiveOption);
5242 QVarLengthArray<qt_section_chunk> sections;
5243 qsizetype n = size(), m = 0, last_m = 0, last_len = 0;
5244 QRegularExpressionMatchIterator iterator = sep.globalMatch(*
this);
5245 while (iterator.hasNext()) {
5246 QRegularExpressionMatch match = iterator.next();
5247 m = match.capturedStart();
5248 sections.append(qt_section_chunk(last_len, QStringView{ *
this }.sliced(last_m, m - last_m)));
5250 last_len = match.capturedLength();
5252 sections.append(qt_section_chunk(last_len, QStringView{ *
this }.sliced(last_m, n - last_m)));
5254 return extractSections(sections, start, end, flags);
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310QString QString::mid(qsizetype position, qsizetype n)
const &
5312 qsizetype p = position;
5314 using namespace QtPrivate;
5315 switch (QContainerImplHelper::mid(size(), &p, &l)) {
5316 case QContainerImplHelper::Null:
5318 case QContainerImplHelper::Empty:
5319 return QString(DataPointer::fromRawData(&_empty, 0));
5320 case QContainerImplHelper::Full:
5322 case QContainerImplHelper::Subset:
5323 return sliced(p, l);
5325 Q_UNREACHABLE_RETURN(QString());
5328QString QString::mid(qsizetype position, qsizetype n) &&
5330 qsizetype p = position;
5332 using namespace QtPrivate;
5333 switch (QContainerImplHelper::mid(size(), &p, &l)) {
5334 case QContainerImplHelper::Null:
5336 case QContainerImplHelper::Empty:
5339 case QContainerImplHelper::Full:
5340 return std::move(*
this);
5341 case QContainerImplHelper::Subset:
5342 return std::move(*
this).sliced(p, l);
5344 Q_UNREACHABLE_RETURN(QString());
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393QString QString::sliced_helper(QString &str, qsizetype pos, qsizetype n)
5396 return QString(DataPointer::fromRawData(&_empty, 0));
5397 DataPointer d = std::move(str.d).sliced(pos, n);
5399 return QString(std::move(d));
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468bool QString::startsWith(
const QString& s, Qt::CaseSensitivity cs)
const
5470 return qt_starts_with_impl(QStringView(*
this), QStringView(s), cs);
5474
5475
5476bool QString::startsWith(QLatin1StringView s, Qt::CaseSensitivity cs)
const
5478 return qt_starts_with_impl(QStringView(*
this), s, cs);
5482
5483
5484
5485
5486
5487bool QString::startsWith(QChar c, Qt::CaseSensitivity cs)
const
5491 if (cs == Qt::CaseSensitive)
5493 return foldCase(at(0)) == foldCase(c);
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519bool QString::endsWith(
const QString &s, Qt::CaseSensitivity cs)
const
5521 return qt_ends_with_impl(QStringView(*
this), QStringView(s), cs);
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5537
5538
5539bool QString::endsWith(QLatin1StringView s, Qt::CaseSensitivity cs)
const
5541 return qt_ends_with_impl(QStringView(*
this), s, cs);
5545
5546
5547
5548
5549
5550bool QString::endsWith(QChar c, Qt::CaseSensitivity cs)
const
5554 if (cs == Qt::CaseSensitive)
5555 return at(size() - 1) == c;
5556 return foldCase(at(size() - 1)) == foldCase(c);
5563 const char32_t uc = it
.next();
5564 if (qGetProp(uc)->cases[c].diff)
5572 return checkCase(s, QUnicodeTables::LowerCase);
5577 return checkCase(s, QUnicodeTables::UpperCase);
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593bool QString::isUpper()
const
5595 return QtPrivate::isUpper(qToStringViewIgnoringNull(*
this));
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611bool QString::isLower()
const
5613 return QtPrivate::isLower(qToStringViewIgnoringNull(*
this));
5618QByteArray QString::toLatin1_helper(
const QString &string)
5620 return qt_convert_to_latin1(string);
5624
5625
5626
5627
5628
5629
5630
5631
5632
5635 return string.visit([] (
auto string) {
return string.toString(); });
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5652 return qt_convert_to_latin1(string);
5656static QByteArray qt_convert_to_latin1(QStringView string)
5658 if (Q_UNLIKELY(string.isNull()))
5659 return QByteArray();
5661 QByteArray ba(string.size(), Qt::Uninitialized);
5665 qt_to_latin1(
reinterpret_cast<uchar *>(
const_cast<
char *>(ba.constData())),
5666 string.utf16(), string.size());
5670QByteArray QString::toLatin1_helper_inplace(QString &s)
5672 if (!s.isDetached())
5673 return qt_convert_to_latin1(s);
5681 qsizetype length = s.size();
5682 char16_t *sdata = s.d->data();
5683 Q_ASSERT(sdata[length] == u'\0');
5684 qt_to_latin1(
reinterpret_cast<uchar *>(sdata), sdata, length + 1);
5688 auto ba_d = std::move(s.d).reinterpreted<
char>();
5691 Q_ASSERT(ba_d.d->allocatedCapacity() >= ba_d.size);
5692 Q_ASSERT(s.isNull());
5693 Q_ASSERT(s.isEmpty());
5694 Q_ASSERT(s.constData() == QString().constData());
5696 return QByteArray(std::move(ba_d));
5700
5701
5702
5703
5704
5705
5708 if (Q_UNLIKELY(string.isNull()))
5709 return QByteArray();
5712 QByteArray ba(string.size() * 2, Qt::Uninitialized);
5713 const qsizetype sz = QUtf8::convertFromLatin1(ba.data(), string) - ba.data();
5720char16_t *QLatin1::convertToUnicode(
char16_t *out, QLatin1StringView in)
noexcept
5722 const qsizetype len = in.size();
5723 qt_from_latin1(out, in.data(), len);
5724 return std::next(out, len);
5727char *QLatin1::convertFromUnicode(
char *out, QStringView in)
noexcept
5729 const qsizetype len = in.size();
5730 qt_to_latin1(
reinterpret_cast<uchar *>(out), in.utf16(), len);
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5763QByteArray QString::toLocal8Bit_helper(
const QChar *data, qsizetype size)
5765 return qt_convert_to_local_8bit(QStringView(data, size));
5770 if (string.isNull())
5771 return QByteArray();
5772 QStringEncoder fromUtf16(QStringEncoder::System, QStringEncoder::Flag::Stateless);
5773 return fromUtf16(string);
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5793 return qt_convert_to_local_8bit(string);
5799
5800
5801
5802
5803
5804
5805
5806
5807
5809QByteArray QString::toUtf8_helper(
const QString &str)
5811 return qt_convert_to_utf8(str);
5817 return QByteArray();
5819 return QUtf8::convertFromUnicode(str);
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5836 return qt_convert_to_utf8(string);
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856QList<uint> QString::toUcs4()
const
5858 return qt_convert_to_ucs4(*
this);
5863 QList<uint> v(string.size());
5864 uint *a =
const_cast<uint*>(v.constData());
5868 v.resize(a - v.constData());
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5891 return qt_convert_to_ucs4(string);
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904QString QString::fromLatin1(QByteArrayView ba)
5909 }
else if (ba.size() == 0) {
5910 d = DataPointer::fromRawData(&_empty, 0);
5912 d = DataPointer(ba.size(), ba.size());
5913 Q_CHECK_PTR(d.data());
5914 d.data()[ba.size()] =
'\0';
5915 char16_t *dst = d.data();
5917 qt_from_latin1(dst, ba.data(), size_t(ba.size()));
5919 return QString(std::move(d));
5923
5924
5925
5926
5927
5928
5929
5930
5933
5934
5935
5936
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
5966
5967
5968
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982QString QString::fromLocal8Bit(QByteArrayView ba)
5987 return QString(DataPointer::fromRawData(&_empty, 0));
5988 QStringDecoder toUtf16(QStringDecoder::System, QStringDecoder::Flag::Stateless);
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6014
6015
6016
6017
6018
6019
6022
6023
6024
6025
6026
6027
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051QString QString::fromUtf8(QByteArrayView ba)
6056 return QString(DataPointer::fromRawData(&_empty, 0));
6057 return QUtf8::convertToUnicode(ba);
6060#ifndef QT_BOOTSTRAPPED
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078QString QString::fromUtf16(
const char16_t *unicode, qsizetype size)
6083 size = QtPrivate::qustrlen(unicode);
6084 QStringDecoder toUtf16(QStringDecoder::Utf16, QStringDecoder::Flag::Stateless);
6085 return toUtf16(QByteArrayView(
reinterpret_cast<
const char *>(unicode), size * 2));
6089
6090
6091
6094
6095
6096
6097
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110QString QString::fromUcs4(
const char32_t *unicode, qsizetype size)
6115 if constexpr (
sizeof(
char32_t) ==
sizeof(
wchar_t))
6116 size = wcslen(
reinterpret_cast<
const wchar_t *>(unicode));
6118 size = std::char_traits<
char32_t>::length(unicode);
6120 QStringDecoder toUtf16(QStringDecoder::Utf32, QStringDecoder::Flag::Stateless);
6121 return toUtf16(QByteArrayView(
reinterpret_cast<
const char *>(unicode), size * 4));
6126
6127
6128
6129
6130
6131
6132
6133
6134QString& QString::setUnicode(
const QChar *unicode, qsizetype size)
6137 if (unicode && size)
6138 memcpy(d.data(), unicode, size *
sizeof(QChar));
6143
6144
6145
6146
6147
6148
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6167
6168
6169
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188QString QString::simplified_helper(
const QString &str)
6190 return QStringAlgorithms<
const QString>::simplified_helper(str);
6193QString QString::simplified_helper(QString &str)
6195 return QStringAlgorithms<QString>::simplified_helper(str);
6199 template <
typename StringView>
6200 StringView qt_trimmed(StringView s)
noexcept
6202 const auto [begin, end] = QStringAlgorithms<
const StringView>::trimmed_helper_positions(s);
6203 return StringView{begin, end};
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6224 return qt_trimmed(s);
6227QLatin1StringView
QtPrivate::trimmed(QLatin1StringView s)
noexcept
6229 return qt_trimmed(s);
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250QString QString::trimmed_helper(
const QString &str)
6252 return QStringAlgorithms<
const QString>::trimmed_helper(str);
6255QString QString::trimmed_helper(QString &str)
6257 return QStringAlgorithms<QString>::trimmed_helper(str);
6261
6262
6263
6264
6265
6266
6267
6268
6269
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6285
6286
6287
6288
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6368void QString::truncate(qsizetype pos)
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389void QString::chop(qsizetype n)
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6407QString& QString::fill(QChar ch, qsizetype size)
6409 resize(size < 0 ? d.size : size);
6411 std::fill(d.data(), d.data() + d.size, ch.unicode());
6416
6417
6418
6419
6420
6421
6422
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6438
6439
6440
6441
6442
6443
6444
6445
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6493
6494
6495
6496
6497
6500
6501
6502
6503
6504
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6535
6536
6537
6538
6539
6542
6543
6544
6545
6546
6549
6550
6551
6552
6553
6554
6555
6556
6557
6560
6561
6562
6563
6564
6565
6566
6567
6570
6571
6572
6573
6574
6575
6576
6577
6580
6581
6582
6583
6584
6585
6586
6587
6590
6591
6592
6593
6594
6595
6596
6599
6600
6601
6602
6603
6604
6605
6606
6609
6610
6611
6612
6613
6614
6615
6618
6619
6620
6621
6622
6623
6624
6625
6626
6629
6630
6631
6632
6633
6634
6635
6636
6637
6640
6641
6642
6643
6644
6645
6646
6647
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6675
6676
6677
6678
6679
6680
6681
6684
6685
6686
6687
6688
6689
6690
6691
6694
6695
6696
6697
6698
6699
6700
6701
6704
6705
6706
6707
6708
6709
6710
6711
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723int QString::compare(
const QString &other, Qt::CaseSensitivity cs)
const noexcept
6725 return QtPrivate::compareStrings(*
this, other, cs);
6729
6730
6731
6732int QString::compare_helper(
const QChar *data1, qsizetype length1,
const QChar *data2, qsizetype length2,
6733 Qt::CaseSensitivity cs)
noexcept
6735 Q_ASSERT(length1 >= 0);
6736 Q_ASSERT(length2 >= 0);
6737 Q_ASSERT(data1 || length1 == 0);
6738 Q_ASSERT(data2 || length2 == 0);
6739 return QtPrivate::compareStrings(QStringView(data1, length1), QStringView(data2, length2), cs);
6743
6744
6745
6746
6747
6748int QString::compare(QLatin1StringView other, Qt::CaseSensitivity cs)
const noexcept
6750 return QtPrivate::compareStrings(*
this, other, cs);
6754
6755
6756
6757int QString::compare_helper(
const QChar *data1, qsizetype length1,
const char *data2, qsizetype length2,
6758 Qt::CaseSensitivity cs)
noexcept
6760 Q_ASSERT(length1 >= 0);
6761 Q_ASSERT(data1 || length1 == 0);
6763 return qt_lencmp(length1, 0);
6764 if (Q_UNLIKELY(length2 < 0))
6765 length2 = qsizetype(strlen(data2));
6766 return QtPrivate::compareStrings(QStringView(data1, length1),
6767 QUtf8StringView(data2, length2), cs);
6771
6772
6773
6776
6777
6778
6782 return QtPrivate::equalStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6787 const int res = QtPrivate::compareStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6788 return Qt::compareThreeWay(res, 0);
6793 return QtPrivate::equalStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6798 const int res = QtPrivate::compareStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6799 return Qt::compareThreeWay(res, 0);
6804 return QtPrivate::equalStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6809 const int res = QtPrivate::compareStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6810 return Qt::compareThreeWay(res, 0);
6815 return QtPrivate::equalStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6820 const int res = QtPrivate::compareStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6821 return Qt::compareThreeWay(res, 0);
6825
6826
6827
6828bool QT_FASTCALL QChar::equal_helper(QChar lhs,
const char *rhs)
noexcept
6830 return QtPrivate::equalStrings(QStringView(&lhs, 1), QUtf8StringView(rhs));
6833int QT_FASTCALL QChar::compare_helper(QChar lhs,
const char *rhs)
noexcept
6835 return QtPrivate::compareStrings(QStringView(&lhs, 1), QUtf8StringView(rhs));
6839
6840
6841
6842bool QStringView::equal_helper(QStringView sv,
const char *data, qsizetype len)
6845 Q_ASSERT(data || len == 0);
6846 return QtPrivate::equalStrings(sv, QUtf8StringView(data, len));
6850
6851
6852
6853int QStringView::compare_helper(QStringView sv,
const char *data, qsizetype len)
6856 Q_ASSERT(data || len == 0);
6857 return QtPrivate::compareStrings(sv, QUtf8StringView(data, len));
6861
6862
6863
6864bool QLatin1StringView::equal_helper(QLatin1StringView s1,
const char *s2, qsizetype len)
noexcept
6868 Q_ASSERT(s2 || len == 0);
6869 return QtPrivate::equalStrings(s1, QUtf8StringView(s2, len));
6873
6874
6875
6876int QLatin1StringView::compare_helper(
const QLatin1StringView &s1,
const char *s2, qsizetype len)
noexcept
6880 Q_ASSERT(s2 || len == 0);
6881 return QtPrivate::compareStrings(s1, QUtf8StringView(s2, len));
6885
6886
6887
6888int QLatin1StringView::compare_helper(
const QChar *data1, qsizetype length1, QLatin1StringView s2,
6889 Qt::CaseSensitivity cs)
noexcept
6891 Q_ASSERT(length1 >= 0);
6892 Q_ASSERT(data1 || length1 == 0);
6893 return QtPrivate::compareStrings(QStringView(data1, length1), s2, cs);
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6945#if !defined(CSTR_LESS_THAN)
6946#define CSTR_LESS_THAN 1
6948#define CSTR_GREATER_THAN 3
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966int QString::localeAwareCompare(
const QString &other)
const
6968 return localeAwareCompare_helper(constData(), size(), other.constData(), other.size());
6972
6973
6974
6975int QString::localeAwareCompare_helper(
const QChar *data1, qsizetype length1,
6976 const QChar *data2, qsizetype length2)
6978 Q_ASSERT(length1 >= 0);
6979 Q_ASSERT(data1 || length1 == 0);
6980 Q_ASSERT(length2 >= 0);
6981 Q_ASSERT(data2 || length2 == 0);
6984 if (length1 == 0 || length2 == 0)
6985 return QtPrivate::compareStrings(QStringView(data1, length1), QStringView(data2, length2),
6989 return QCollator::defaultCompare(QStringView(data1, length1), QStringView(data2, length2));
6991 const QString lhs = QString::fromRawData(data1, length1).normalized(QString::NormalizationForm_C);
6992 const QString rhs = QString::fromRawData(data2, length2).normalized(QString::NormalizationForm_C);
6993# if defined(Q_OS_WIN)
6994 int res = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, (LPWSTR)lhs.constData(), lhs.length(), (LPWSTR)rhs.constData(), rhs.length(), NULL, NULL, 0);
6997 case CSTR_LESS_THAN:
6999 case CSTR_GREATER_THAN:
7004# elif defined (Q_OS_DARWIN)
7009 const CFStringRef thisString =
7010 CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault,
7011 reinterpret_cast<
const UniChar *>(lhs.constData()), lhs.length(), kCFAllocatorNull);
7012 const CFStringRef otherString =
7013 CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault,
7014 reinterpret_cast<
const UniChar *>(rhs.constData()), rhs.length(), kCFAllocatorNull);
7016 const int result = CFStringCompare(thisString, otherString, kCFCompareLocalized);
7017 CFRelease(thisString);
7018 CFRelease(otherString);
7020# elif defined(Q_OS_UNIX)
7022 return strcoll(lhs.toLocal8Bit().constData(), rhs.toLocal8Bit().constData());
7024# error "This case shouldn't happen"
7025 return QtPrivate::compareStrings(lhs, rhs, Qt::CaseSensitive);
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7044
7045
7046
7047
7048
7049
7050
7051
7052
7054const ushort *QString::utf16()
const
7056 if (!d->isMutable()) {
7058 const_cast<QString*>(
this)->reallocData(d.size, QArrayData::KeepSize);
7060 return reinterpret_cast<
const ushort *>(d.data());
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7079
7080
7081
7082
7083
7084
7085
7086
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7106QString QString::leftJustified(qsizetype width, QChar fill,
bool truncate)
const
7109 qsizetype len = size();
7110 qsizetype padlen = width - len;
7112 result.resize(len+padlen);
7114 memcpy(result.d.data(), d.data(),
sizeof(QChar)*len);
7115 QChar *uc = (QChar*)result.d.data() + len;
7120 result = left(width);
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7145QString QString::rightJustified(qsizetype width, QChar fill,
bool truncate)
const
7148 qsizetype len = size();
7149 qsizetype padlen = width - len;
7151 result.resize(len+padlen);
7152 QChar *uc = (QChar*)result.d.data();
7156 memcpy(
static_cast<
void *>(uc),
static_cast<
const void *>(d.data()),
sizeof(QChar)*len);
7159 result = left(width);
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205template <
typename T>
7241template <
typename T>
7244 const QChar *p = str.constBegin();
7245 const QChar *e = p + str.size();
7248 while (e != p && e[-1].isHighSurrogate())
7253 const char32_t uc = it
.next();
7254 if (qGetProp(uc)->cases[which].diff) {
7256 return detachAndConvertCase(str, it, which);
7259 return std::move(str);
7263QString QString::toLower_helper(
const QString &str)
7265 return QUnicodeTables::convertCase(str, QUnicodeTables::LowerCase);
7268QString QString::toLower_helper(QString &str)
7270 return QUnicodeTables::convertCase(str, QUnicodeTables::LowerCase);
7274
7275
7276
7277
7278
7280QString QString::toCaseFolded_helper(
const QString &str)
7282 return QUnicodeTables::convertCase(str, QUnicodeTables::CaseFold);
7285QString QString::toCaseFolded_helper(QString &str)
7287 return QUnicodeTables::convertCase(str, QUnicodeTables::CaseFold);
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7306QString QString::toUpper_helper(
const QString &str)
7308 return QUnicodeTables::convertCase(str, QUnicodeTables::UpperCase);
7311QString QString::toUpper_helper(QString &str)
7313 return QUnicodeTables::convertCase(str, QUnicodeTables::UpperCase);
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7350QString QString::asprintf(
const char *cformat, ...)
7353 va_start(ap, cformat);
7354 const QString s = vasprintf(cformat, ap);
7361 const qsizetype oldSize = qs.size();
7362 qs.resize(oldSize + len);
7363 const QChar *newEnd = QUtf8::convertToUnicode(qs.data() + oldSize, QByteArrayView(cs, len));
7364 qs.resize(newEnd - qs.constData());
7381 default:
return flags;
7389 Q_ASSERT(isAsciiDigit(*c));
7390 const char *
const stop = c + size;
7394 auto [result, used] = qstrntoull(c, size, 10);
7399 while (c < stop && isAsciiDigit(*c))
7401 return result < qulonglong(
std::numeric_limits<
int>::max()) ?
int(result) : 0;
7420 case 'L':
return lm_L;
7421 case 'j':
return lm_j;
7423 case 'Z':
return lm_z;
7424 case 't':
return lm_t;
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7444QString QString::vasprintf(
const char *cformat, va_list ap)
7446 if (!cformat || !*cformat) {
7448 return fromLatin1(
"");
7454 const char *c = cformat;
7455 const char *formatEnd = cformat + qstrlen(cformat);
7459 while (*c !=
'\0' && *c !=
'%')
7461 append_utf8(result, cb, qsizetype(c - cb));
7467 const char *escape_start = c;
7471 result.append(u'%');
7475 result.append(u'%');
7480 uint flags = parse_flag_characters(c);
7483 result.append(QLatin1StringView(escape_start));
7489 if (isAsciiDigit(*c)) {
7490 width = parse_field_width(c, formatEnd - c);
7491 }
else if (*c ==
'*') {
7492 width = va_arg(ap,
int);
7499 result.append(QLatin1StringView(escape_start));
7508 if (isAsciiDigit(*c)) {
7509 precision = parse_field_width(c, formatEnd - c);
7510 }
else if (*c ==
'*') {
7511 precision = va_arg(ap,
int);
7519 result.append(QLatin1StringView(escape_start));
7523 const LengthMod length_mod = parse_length_modifier(c);
7526 result.append(QLatin1StringView(escape_start));
7536 switch (length_mod) {
7537 case lm_none: i = va_arg(ap,
int);
break;
7538 case lm_hh: i = va_arg(ap,
int);
break;
7539 case lm_h: i = va_arg(ap,
int);
break;
7540 case lm_l: i = va_arg(ap,
long int);
break;
7541 case lm_ll: i = va_arg(ap, qint64);
break;
7542 case lm_j: i = va_arg(ap,
long int);
break;
7545 case lm_z: i = va_arg(ap, qsizetype);
break;
7546 case lm_t: i = va_arg(ap, qsizetype);
break;
7547 default: i = 0;
break;
7549 subst = QLocaleData::c()->longLongToString(i, precision, 10, width, flags);
7558 switch (length_mod) {
7559 case lm_none: u = va_arg(ap, uint);
break;
7560 case lm_hh: u = va_arg(ap, uint);
break;
7561 case lm_h: u = va_arg(ap, uint);
break;
7562 case lm_l: u = va_arg(ap, ulong);
break;
7563 case lm_ll: u = va_arg(ap, quint64);
break;
7564 case lm_t: u = va_arg(ap, size_t);
break;
7565 case lm_z: u = va_arg(ap, size_t);
break;
7566 default: u = 0;
break;
7569 if (isAsciiUpper(*c))
7570 flags |= QLocaleData::CapitalEorX;
7573 switch (QtMiscUtils::toAsciiLower(*c)) {
7582 subst = QLocaleData::c()->unsLongLongToString(u, precision, base, width, flags);
7595 if (length_mod == lm_L)
7596 d = va_arg(ap,
long double);
7598 d = va_arg(ap,
double);
7600 if (isAsciiUpper(*c))
7601 flags |= QLocaleData::CapitalEorX;
7603 QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
7604 switch (QtMiscUtils::toAsciiLower(*c)) {
7605 case 'e': form = QLocaleData::DFExponent;
break;
7607 case 'f': form = QLocaleData::DFDecimal;
break;
7608 case 'g': form = QLocaleData::DFSignificantDigits;
break;
7611 subst = QLocaleData::c()->doubleToString(d, precision, form, width, flags);
7616 if (length_mod == lm_l)
7617 subst = QChar::fromUcs2(va_arg(ap,
int));
7619 subst = QLatin1Char((uchar) va_arg(ap,
int));
7624 if (length_mod == lm_l) {
7625 const char16_t *buff = va_arg(ap,
const char16_t*);
7626 const auto *ch = buff;
7627 while (precision != 0 && *ch != 0) {
7631 subst.setUtf16(buff, ch - buff);
7632 }
else if (precision == -1) {
7633 subst = QString::fromUtf8(va_arg(ap,
const char*));
7635 const char *buff = va_arg(ap,
const char*);
7636 subst = QString::fromUtf8(buff, qstrnlen(buff, precision));
7642 void *arg = va_arg(ap,
void*);
7643 const quint64 i =
reinterpret_cast<quintptr>(arg);
7644 flags |= QLocaleData::ShowBase;
7645 subst = QLocaleData::c()->unsLongLongToString(i, precision, 16, width, flags);
7650 switch (length_mod) {
7652 signed char *n = va_arg(ap,
signed char*);
7657 short int *n = va_arg(ap,
short int*);
7662 long int *n = va_arg(ap,
long int*);
7667 qint64 *n = va_arg(ap, qint64*);
7672 int *n = va_arg(ap,
int*);
7673 *n =
int(result.size());
7681 for (
const char *cc = escape_start; cc != c; ++cc)
7682 result.append(QLatin1Char(*cc));
7686 if (flags & QLocaleData::LeftAdjusted)
7687 result.append(subst.leftJustified(width));
7689 result.append(subst.rightJustified(width));
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7724template <
typename Int>
7727#if defined(QT_CHECK_RANGE)
7728 if (base != 0 && (base < 2 || base > 36)) {
7729 qWarning(
"QString::toIntegral: Invalid base (%d)", base);
7734 QVarLengthArray<uchar> latin1(string.size());
7735 qt_to_latin1(latin1.data(), string.utf16(), string.size());
7736 QSimpleParsedNumber<Int> r;
7737 if constexpr (
std::is_signed_v<Int>)
7738 r = QLocaleData::bytearrayToLongLong(latin1, base);
7740 r = QLocaleData::bytearrayToUnsLongLong(latin1, base);
7746qlonglong QString::toIntegral_helper(QStringView string,
bool *ok,
int base)
7748 return toIntegral<qlonglong>(string, ok, base);
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7780qulonglong QString::toIntegral_helper(QStringView string,
bool *ok, uint base)
7782 return toIntegral<qulonglong>(string, ok, base);
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
7812
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
7841
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
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7991double QString::toDouble(
bool *ok)
const
7993 return QStringView(*
this).toDouble(ok);
7996double QStringView::toDouble(
bool *ok)
const
7998 QStringView string = qt_trimmed(*
this);
7999 QVarLengthArray<uchar> latin1(string.size());
8000 qt_to_latin1(latin1.data(), string.utf16(), string.size());
8001 auto r = qt_asciiToDouble(
reinterpret_cast<
const char *>(latin1.data()), string.size());
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8037float QString::toFloat(
bool *ok)
const
8039 return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
8042float QStringView::toFloat(
bool *ok)
const
8044 return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8064
8065
8066
8069
8070
8071
8074
8075
8076
8079
8080
8081QString &QString::setNum(qlonglong n,
int base)
8083 return *
this = number(n, base);
8087
8088
8089QString &QString::setNum(qulonglong n,
int base)
8091 return *
this = number(n, base);
8095
8096
8097
8100
8101
8102
8105
8106
8107
8108
8109
8110
8111
8113QString &QString::setNum(
double n,
char format,
int precision)
8115 return *
this = number(n, format, precision);
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8153QString QString::number(
long n,
int base)
8155 return number(qlonglong(n), base);
8159
8160
8161
8162
8163QString QString::number(ulong n,
int base)
8165 return number(qulonglong(n), base);
8169
8170
8171QString QString::number(
int n,
int base)
8173 return number(qlonglong(n), base);
8177
8178
8179QString QString::number(uint n,
int base)
8181 return number(qulonglong(n), base);
8185
8186
8187QString QString::number(qlonglong n,
int base)
8189#if defined(QT_CHECK_RANGE)
8190 if (base < 2 || base > 36) {
8191 qWarning(
"QString::setNum: Invalid base (%d)", base);
8195 bool negative = n < 0;
8197
8198
8199
8200 return qulltoBasicLatin(negative ? 1u + qulonglong(-(n + 1)) : qulonglong(n), base, negative);
8204
8205
8206QString QString::number(qulonglong n,
int base)
8208#if defined(QT_CHECK_RANGE)
8209 if (base < 2 || base > 36) {
8210 qWarning(
"QString::setNum: Invalid base (%d)", base);
8214 return qulltoBasicLatin(n, base,
false);
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229QString QString::number(
double n,
char format,
int precision)
8231 QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
8233 switch (QtMiscUtils::toAsciiLower(format)) {
8235 form = QLocaleData::DFDecimal;
8238 form = QLocaleData::DFExponent;
8241 form = QLocaleData::DFSignificantDigits;
8244#if defined(QT_CHECK_RANGE)
8245 qWarning(
"QString::setNum: Invalid format char '%c'", format);
8250 return qdtoBasicLatin(n, form, precision, isAsciiUpper(format));
8254template<
class ResultList,
class StringSource>
8255static ResultList splitString(
const StringSource &source, QStringView sep,
8256 Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
8259 typename StringSource::size_type start = 0;
8260 typename StringSource::size_type end;
8261 typename StringSource::size_type extra = 0;
8262 while ((end = QtPrivate::findString(QStringView(source.constData(), source.size()), start + extra, sep, cs)) != -1) {
8263 if (start != end || behavior == Qt::KeepEmptyParts)
8264 list.append(source.sliced(start, end - start));
8265 start = end + sep.size();
8266 extra = (sep.size() == 0 ? 1 : 0);
8268 if (start != source.size() || behavior == Qt::KeepEmptyParts)
8269 list.append(source.sliced(start));
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305QStringList QString::split(
const QString &sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
const
8307 return splitString<QStringList>(*
this, sep, behavior, cs);
8311
8312
8313
8314QStringList QString::split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
const
8316 return splitString<QStringList>(*
this, QStringView(&sep, 1), behavior, cs);
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336QList<QStringView> QStringView::split(QStringView sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
const
8338 return splitString<QList<QStringView>>(QStringView(*
this), sep, behavior, cs);
8341QList<QStringView> QStringView::split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
const
8343 return split(QStringView(&sep, 1), behavior, cs);
8346#if QT_CONFIG(regularexpression)
8348template<
class ResultList,
typename String,
typename MatchingFunction>
8349static ResultList splitString(
const String &source,
const QRegularExpression &re,
8350 MatchingFunction matchingFunction,
8351 Qt::SplitBehavior behavior)
8354 if (!re.isValid()) {
8355 qtWarnAboutInvalidRegularExpression(re.pattern(),
"QString::split");
8359 qsizetype start = 0;
8361 QRegularExpressionMatchIterator iterator = (re.*matchingFunction)(source, 0, QRegularExpression::NormalMatch, QRegularExpression::NoMatchOption);
8362 while (iterator.hasNext()) {
8363 QRegularExpressionMatch match = iterator.next();
8364 end = match.capturedStart();
8365 if (start != end || behavior == Qt::KeepEmptyParts)
8366 list.append(source.sliced(start, end - start));
8367 start = match.capturedEnd();
8370 if (start != source.size() || behavior == Qt::KeepEmptyParts)
8371 list.append(source.sliced(start));
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404QStringList QString::split(
const QRegularExpression &re, Qt::SplitBehavior behavior)
const
8406#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
8407 const auto matchingFunction = qOverload<
const QString &, qsizetype, QRegularExpression::MatchType, QRegularExpression::MatchOptions>(&QRegularExpression::globalMatch);
8409 const auto matchingFunction = &QRegularExpression::globalMatch;
8411 return splitString<QStringList>(*
this,
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430QList<QStringView> QStringView::split(
const QRegularExpression &re, Qt::SplitBehavior behavior)
const
8432 return splitString<QList<QStringView>>(*
this, re, &QRegularExpression::globalMatchView, behavior);
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462QString QString::repeated(qsizetype times)
const
8473 const qsizetype resultSize = times * d.size;
8476 result.reserve(resultSize);
8477 if (result.capacity() != resultSize)
8480 memcpy(result.d.data(), d.data(), d.size *
sizeof(QChar));
8482 qsizetype sizeSoFar = d.size;
8483 char16_t *end = result.d.data() + sizeSoFar;
8485 const qsizetype halfResultSize = resultSize >> 1;
8486 while (sizeSoFar <= halfResultSize) {
8487 memcpy(end, result.d.data(), sizeSoFar *
sizeof(QChar));
8491 memcpy(end, result.d.data(), (resultSize - sizeSoFar) *
sizeof(QChar));
8492 result.d.data()[resultSize] =
'\0';
8493 result.d.size = resultSize;
8497void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, qsizetype from)
8501 auto start =
reinterpret_cast<
const char16_t *>(data->constData());
8502 const char16_t *p = start + from;
8503 if (isAscii_helper(p, p + data->size() - from))
8505 if (p > start + from)
8506 from = p - start - 1;
8509 if (version == QChar::Unicode_Unassigned) {
8510 version = QChar::currentUnicodeVersion();
8512 const QString &s = *data;
8516 qsizetype pos = from;
8517 if (QChar::requiresSurrogates(n.ucs4)) {
8518 char16_t ucs4High = QChar::highSurrogate(n.ucs4);
8519 char16_t ucs4Low = QChar::lowSurrogate(n.ucs4);
8520 char16_t oldHigh = QChar::highSurrogate(n.old_mapping);
8521 char16_t oldLow = QChar::lowSurrogate(n.old_mapping);
8522 while (pos < s.size() - 1) {
8523 if (s.at(pos).unicode() == ucs4High && s.at(pos + 1).unicode() == ucs4Low) {
8526 d[pos] = QChar(oldHigh);
8527 d[++pos] = QChar(oldLow);
8532 while (pos < s.size()) {
8533 if (s.at(pos).unicode() == n.ucs4) {
8536 d[pos] = QChar(n.old_mapping);
8545 if (normalizationQuickCheckHelper(data, mode, from, &from))
8548 decomposeHelper(data, mode < QString::NormalizationForm_KD, version, from);
8550 canonicalOrderHelper(data, version, from);
8552 if (mode == QString::NormalizationForm_D || mode == QString::NormalizationForm_KD)
8555 composeHelper(data, version, from);
8559
8560
8561
8562QString QString::normalized(QString::NormalizationForm mode, QChar::UnicodeVersion version)
const
8564 QString copy = *
this;
8565 qt_string_normalize(©, mode, version, 0);
8569#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
8570static void checkArgEscape(QStringView s)
8575 if (!supportUnicodeDigitValuesInArg())
8578 const auto isNonAsciiDigit = [](QChar c) {
8579 return c.unicode() < u'0' || c.unicode() > u'9';
8582 if (std::any_of(s.begin(), s.end(), isNonAsciiDigit)) {
8583 const auto accumulateDigit = [](
int partial, QChar digit) {
8584 return partial * 10 + digit.digitValue();
8586 const int parsedNumber = std::accumulate(s.begin(), s.end(), 0, accumulateDigit);
8588 qWarning(
"QString::arg(): the replacement \"%%%ls\" contains non-ASCII digits;\n"
8589 " it is currently being interpreted as the %d-th substitution.\n"
8590 " This is deprecated; support for non-ASCII digits will be dropped\n"
8591 " in a future version of Qt.",
8592 qUtf16Printable(s.toString()),
8609 const QChar *uc_begin = s.begin();
8610 const QChar *uc_end = s.end();
8614 d.min_escape = INT_MAX;
8617 d.locale_occurrences = 0;
8619 const QChar *c = uc_begin;
8620 while (c != uc_end) {
8621 while (c != uc_end && c->unicode() !=
'%')
8626 const QChar *escape_start = c;
8630 bool locale_arg =
false;
8631 if (c->unicode() ==
'L') {
8637 int escape = qArgDigitValue(*c);
8643#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
8644 const QChar *escapeBegin = c;
8645 const QChar *escapeEnd = escapeBegin + 1;
8651 const int next_escape = qArgDigitValue(*c);
8652 if (next_escape != -1) {
8653 escape = (10 * escape) + next_escape;
8655#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
8661#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
8662 checkArgEscape(QStringView(escapeBegin, escapeEnd));
8672 d.locale_occurrences = 0;
8677 ++d.locale_occurrences;
8678 d.escape_len += c - escape_start;
8684 QStringView arg, QStringView larg, QChar fillChar)
8687 const qsizetype abs_field_width = qAbs(field_width);
8688 const qsizetype result_len =
8689 s.size() - d.escape_len
8690 + (d.occurrences - d.locale_occurrences) * qMax(abs_field_width, arg.size())
8691 + d.locale_occurrences * qMax(abs_field_width, larg.size());
8693 QString result(result_len, Qt::Uninitialized);
8694 QChar *rc =
const_cast<QChar *>(result.unicode());
8695 QChar *
const result_end = rc + result_len;
8696 qsizetype repl_cnt = 0;
8698 const QChar *c = s.begin();
8699 const QChar *
const uc_end = s.end();
8700 while (c != uc_end) {
8701 Q_ASSERT(d.occurrences > repl_cnt);
8703
8704
8706 const QChar *text_start = c;
8707 while (c->unicode() !=
'%')
8710 const QChar *escape_start = c++;
8711 const bool localize = c->unicode() ==
'L';
8715 int escape = qArgDigitValue(*c);
8716 if (escape != -1 && c + 1 != uc_end) {
8717 const int digit = qArgDigitValue(c[1]);
8720 escape = 10 * escape + digit;
8725 memcpy(rc, text_start, (c - text_start) *
sizeof(QChar));
8726 rc += c - text_start;
8730 memcpy(rc, text_start, (escape_start - text_start) *
sizeof(QChar));
8731 rc += escape_start - text_start;
8733 const QStringView use = localize ? larg : arg;
8734 const qsizetype pad_chars = abs_field_width - use.size();
8737 if (field_width > 0) {
8738 rc =
std::fill_n(rc, pad_chars, fillChar);
8742 memcpy(rc, use.data(), use.size() *
sizeof(QChar));
8745 if (field_width < 0) {
8746 rc =
std::fill_n(rc, pad_chars, fillChar);
8749 if (++repl_cnt == d.occurrences) {
8750 memcpy(rc, c, (uc_end - c) *
sizeof(QChar));
8752 Q_ASSERT(rc == result_end);
8757 Q_ASSERT(rc == result_end);
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799QString QString::arg_impl(QAnyStringView a,
int fieldWidth, QChar fillChar)
const
8801 ArgEscapeData d = findArgEscapes(*
this);
8803 if (Q_UNLIKELY(d.occurrences == 0)) {
8804 qWarning(
"QString::arg: Argument missing: \"%ls\", \"%ls\"",
qUtf16Printable(*
this),
8809 QVarLengthArray<
char16_t> out;
8810 QStringView operator()(QStringView in)
noexcept {
return in; }
8811 QStringView operator()(QLatin1StringView in)
8813 out.resize(in.size());
8814 qt_from_latin1(out.data(), in.data(), size_t(in.size()));
8817 QStringView operator()(QUtf8StringView in)
8819 out.resize(in.size());
8820 return QStringView{out.data(), QUtf8::convertToUnicode(out.data(), in)};
8824 QStringView sv = a.visit(std::ref(convert));
8825 return replaceArgEscapes(*
this, d, fieldWidth, sv, sv, fillChar);
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856QString QString::arg_impl(qlonglong a,
int fieldWidth,
int base, QChar fillChar)
const
8858 ArgEscapeData d = findArgEscapes(*
this);
8860 if (d.occurrences == 0) {
8861 qWarning(
"QString::arg: Argument missing: \"%ls\", %llu",
qUtf16Printable(*
this), a);
8865 unsigned flags = QLocaleData::NoFlags;
8867 if (fillChar == u'0')
8868 flags = QLocaleData::ZeroPadded;
8871 if (d.occurrences > d.locale_occurrences) {
8872 arg = QLocaleData::c()->longLongToString(a, -1, base, fieldWidth, flags);
8873 Q_ASSERT(fillChar != u'0' || fieldWidth <= arg.size());
8877 if (d.locale_occurrences > 0) {
8879 if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
8880 flags |= QLocaleData::GroupDigits;
8881 localeArg = locale.d->m_data->longLongToString(a, -1, base, fieldWidth, flags);
8882 Q_ASSERT(fillChar != u'0' || fieldWidth <= localeArg.size());
8885 return replaceArgEscapes(*
this, d, fieldWidth, arg, localeArg, fillChar);
8888QString QString::arg_impl(qulonglong a,
int fieldWidth,
int base, QChar fillChar)
const
8890 ArgEscapeData d = findArgEscapes(*
this);
8892 if (d.occurrences == 0) {
8893 qWarning(
"QString::arg: Argument missing: \"%ls\", %lld",
qUtf16Printable(*
this), a);
8897 unsigned flags = QLocaleData::NoFlags;
8899 if (fillChar == u'0')
8900 flags = QLocaleData::ZeroPadded;
8903 if (d.occurrences > d.locale_occurrences) {
8904 arg = QLocaleData::c()->unsLongLongToString(a, -1, base, fieldWidth, flags);
8905 Q_ASSERT(fillChar != u'0' || fieldWidth <= arg.size());
8909 if (d.locale_occurrences > 0) {
8911 if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
8912 flags |= QLocaleData::GroupDigits;
8913 localeArg = locale.d->m_data->unsLongLongToString(a, -1, base, fieldWidth, flags);
8914 Q_ASSERT(fillChar != u'0' || fieldWidth <= localeArg.size());
8917 return replaceArgEscapes(*
this, d, fieldWidth, arg, localeArg, fillChar);
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939QString QString::arg_impl(
double a,
int fieldWidth,
char format,
int precision, QChar fillChar)
const
8941 ArgEscapeData d = findArgEscapes(*
this);
8943 if (d.occurrences == 0) {
8944 qWarning(
"QString::arg: Argument missing: \"%ls\", %g",
qUtf16Printable(*
this), a);
8948 unsigned flags = QLocaleData::NoFlags;
8950 if (fillChar == u'0')
8951 flags |= QLocaleData::ZeroPadded;
8953 if (isAsciiUpper(format))
8954 flags |= QLocaleData::CapitalEorX;
8956 QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
8957 switch (QtMiscUtils::toAsciiLower(format)) {
8959 form = QLocaleData::DFDecimal;
8962 form = QLocaleData::DFExponent;
8965 form = QLocaleData::DFSignificantDigits;
8968#if defined(QT_CHECK_RANGE)
8969 qWarning(
"QString::arg: Invalid format char '%c'", format);
8975 if (d.occurrences > d.locale_occurrences) {
8976 arg = QLocaleData::c()->doubleToString(a, precision, form, fieldWidth,
8977 flags | QLocaleData::ZeroPadExponent);
8978 Q_ASSERT(fillChar != u'0' || !qt_is_finite(a)
8979 || fieldWidth <= arg.size());
8983 if (d.locale_occurrences > 0) {
8986 const QLocale::NumberOptions numberOptions = locale.numberOptions();
8987 if (!(numberOptions & QLocale::OmitGroupSeparator))
8988 flags |= QLocaleData::GroupDigits;
8989 if (!(numberOptions & QLocale::OmitLeadingZeroInExponent))
8990 flags |= QLocaleData::ZeroPadExponent;
8991 if (numberOptions & QLocale::IncludeTrailingZeroesAfterDot)
8992 flags |= QLocaleData::AddTrailingZeroes;
8993 localeArg = locale.d->m_data->doubleToString(a, precision, form, fieldWidth, flags);
8994 Q_ASSERT(fillChar != u'0' || !qt_is_finite(a)
8995 || fieldWidth <= localeArg.size());
8998 return replaceArgEscapes(*
this, d, fieldWidth, arg, localeArg, fillChar);
9001static inline char16_t to_unicode(
const QChar c) {
return c.unicode(); }
9004template <
typename Char>
9005static int getEscape(
const Char *uc, qsizetype *pos, qsizetype len)
9009 if (i < len && uc[i] == u'L')
9012 int escape = to_unicode(uc[i]) -
'0';
9013 if (uint(escape) >= 10U)
9018 int digit = to_unicode(uc[i]) -
'0';
9019 if (uint(digit) < 10U) {
9020 escape = (escape * 10) + digit;
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9068 constexpr Part(QAnyStringView s,
int num = -1)
9069 : string{s}, number{num} {}
9071 void reset(QAnyStringView s)
noexcept { *
this = {s, number}; }
9073 QAnyStringView string;
9082enum { ExpectedParts = 32 };
9085typedef QVarLengthArray<
int, ExpectedParts/2> ArgIndexToPlaceholderMap;
9087template <
typename StringView>
9088static ParseResult parseMultiArgFormatString_impl(StringView s)
9092 const auto uc = s.data();
9093 const auto len = s.size();
9094 const auto end = len - 1;
9099 if (uc[i] == u'%') {
9100 qsizetype percent = i;
9101 int number = getEscape(uc, &i, len);
9103 if (last != percent)
9104 result.push_back(Part{s.sliced(last, percent - last)});
9105 result.push_back(Part{s.sliced(percent, i - percent), number});
9114 result.push_back(Part{s.sliced(last, len - last)});
9119static ParseResult parseMultiArgFormatString(QAnyStringView s)
9121 return s.visit([] (
auto s) {
return parseMultiArgFormatString_impl(s); });
9124static ArgIndexToPlaceholderMap makeArgIndexToPlaceholderMap(
const ParseResult &parts)
9126 ArgIndexToPlaceholderMap result;
9128 for (
const Part &part : parts) {
9129 if (part.number >= 0)
9130 result.push_back(part.number);
9133 std::sort(result.begin(), result.end());
9134 result.erase(
std::unique(result.begin(), result.end()),
9140static qsizetype resolveStringRefsAndReturnTotalSize(ParseResult &parts,
const ArgIndexToPlaceholderMap &argIndexToPlaceholderMap,
const QtPrivate::
ArgBase *args[])
9143 qsizetype totalSize = 0;
9144 for (Part &part : parts) {
9145 if (part.number != -1) {
9146 const auto it = std::find(argIndexToPlaceholderMap.begin(), argIndexToPlaceholderMap.end(), part.number);
9147 if (it != argIndexToPlaceholderMap.end()) {
9148 const auto &arg = *args[it - argIndexToPlaceholderMap.begin()];
9151 part.reset(
static_cast<
const QLatin1StringArg&>(arg).string);
9154 part.reset(
static_cast<
const QAnyStringArg&>(arg).string);
9157 part.reset(
static_cast<
const QStringViewArg&>(arg).string);
9162 totalSize += part.string.size();
9172 ParseResult parts = parseMultiArgFormatString(pattern);
9175 ArgIndexToPlaceholderMap argIndexToPlaceholderMap = makeArgIndexToPlaceholderMap(parts);
9177 if (
static_cast<size_t>(argIndexToPlaceholderMap.size()) > numArgs)
9178 argIndexToPlaceholderMap.resize(qsizetype(numArgs));
9179 else if (Q_UNLIKELY(
static_cast<size_t>(argIndexToPlaceholderMap.size()) < numArgs))
9180 qWarning(
"QString::arg: %d argument(s) missing in %ls",
9181 int(numArgs - argIndexToPlaceholderMap.size()),
qUtf16Printable(pattern.toString()));
9184 const qsizetype totalSize = resolveStringRefsAndReturnTotalSize(parts, argIndexToPlaceholderMap, args);
9187 QString result(totalSize, Qt::Uninitialized);
9188 auto out =
const_cast<QChar*>(result.constData());
9190 struct Concatenate {
9192 QChar *operator()(QLatin1String part)
noexcept
9195 qt_from_latin1(
reinterpret_cast<
char16_t*>(out),
9196 part.data(), part.size());
9198 return out + part.size();
9200 QChar *operator()(QUtf8StringView part)
noexcept
9202 return QUtf8::convertToUnicode(out, part);
9204 QChar *operator()(QStringView part)
noexcept
9207 memcpy(out, part.data(), part.size() *
sizeof(QChar));
9208 return out + part.size();
9212 for (
const Part &part : parts)
9213 out = part.string.visit(Concatenate{out});
9216 result.truncate(out - result.cbegin());
9222
9223
9224
9225
9226
9227bool QString::isRightToLeft()
const
9229 return QtPrivate::isRightToLeft(QStringView(*
this));
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9268
9269
9270
9271
9272
9273
9274
9275
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9292
9293
9294
9295
9296
9297
9298
9301
9302
9303
9304
9305
9308
9309
9310
9311
9312
9313
9314
9317
9318
9319
9320
9321
9324
9325
9326
9327
9328
9329
9330
9331QString::iterator QString::erase(QString::const_iterator first, QString::const_iterator last)
9333 const auto start = std::distance(cbegin(), first);
9334 const auto len = std::distance(first, last);
9336 return begin() + start;
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9356
9357
9358
9359
9360
9361
9362
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376std::string QString::toStdString()
const
9382 auto writeToBuffer = [
this](
char *out, size_t) {
9383 char *last = QUtf8::convertFromUnicode(out, *
this);
9386 size_t maxSize = size() * 3;
9387#ifdef __cpp_lib_string_resize_and_overwrite
9389 result.resize_and_overwrite(maxSize, writeToBuffer);
9391 result.resize(maxSize);
9392 result.resize(writeToBuffer(result.data(), result.size()));
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9428
9429
9430
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446QString &QString::setRawData(
const QChar *unicode, qsizetype size)
9448 if (!unicode || !size) {
9451 *
this = fromRawData(unicode, size);
9456
9457
9458
9459
9460
9461
9464
9465
9466
9467
9468
9469
9470
9471
9472
9475
9476
9477
9478
9479
9480
9483
9484
9485
9486
9487
9488
9489
9490
9491
9493#if !defined(QT_NO_DATASTREAM)
9495
9496
9497
9498
9499
9500
9501
9503QDataStream &operator<<(QDataStream &out,
const QString &str)
9505 if (out.version() == 1) {
9506 out << str.toLatin1();
9508 if (!str.isNull() || out.version() < 3) {
9509 if ((out.byteOrder() == QDataStream::BigEndian) == (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
9510 out.writeBytes(
reinterpret_cast<
const char *>(str.unicode()),
9511 static_cast<qsizetype>(
sizeof(QChar) * str.size()));
9513 QVarLengthArray<
char16_t> buffer(str.size());
9514 qbswap<
sizeof(
char16_t)>(str.constData(), str.size(), buffer.data());
9515 out.writeBytes(
reinterpret_cast<
const char *>(buffer.data()),
9516 static_cast<qsizetype>(
sizeof(
char16_t) * buffer.size()));
9519 QDataStream::writeQSizeType(out, -1);
9526
9527
9528
9529
9530
9531
9532
9536 if (in.version() == 1) {
9539 str = QString::fromLatin1(l);
9541 qint64 size = QDataStream::readQSizeType(in);
9542 qsizetype bytes = size;
9543 if (size != bytes || size < -1) {
9545 in.setStatus(QDataStream::SizeLimitExceeded);
9550 }
else if (bytes > 0) {
9553 in.setStatus(QDataStream::ReadCorruptData);
9557 const qsizetype Step = 1024 * 1024;
9558 qsizetype len = bytes / 2;
9559 qsizetype allocated = 0;
9561 while (allocated < len) {
9562 int blockSize = qMin(Step, len - allocated);
9563 str.resize(allocated + blockSize);
9564 if (in.readRawData(
reinterpret_cast<
char *>(str.data()) + allocated * 2,
9565 blockSize * 2) != blockSize * 2) {
9567 in.setStatus(QDataStream::ReadPastEnd);
9570 allocated += blockSize;
9573 if ((in.byteOrder() == QDataStream::BigEndian)
9574 != (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
9575 char16_t *data =
reinterpret_cast<
char16_t *>(str.data());
9576 qbswap<
sizeof(*data)>(data, len, data);
9579 str = QString(QLatin1StringView(
""));
9587
9588
9589
9592
9593
9594
9597
9598
9599
9602
9603
9604
9605
9606
9607
9608
9609
9612 int isolateLevel = 0;
9617 switch (QChar::direction(c)) {
9658qsizetype
QtPrivate::count(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs)
noexcept
9662 if (haystack.size() > 500 && needle.size() > 5) {
9664 while ((i = matcher.indexIn(haystack, i + 1)) != -1)
9667 while ((i = QtPrivate::findString(haystack, i + 1, needle, cs)) != -1)
9673qsizetype
QtPrivate::count(QStringView haystack, QChar needle, Qt::CaseSensitivity cs)
noexcept
9675 if (cs == Qt::CaseSensitive)
9676 return std::count(haystack.cbegin(), haystack.cend(), needle);
9678 needle = foldCase(needle);
9679 return std::count_if(haystack.cbegin(), haystack.cend(),
9680 [needle](
const QChar c) {
return foldAndCompare(c, needle); });
9683qsizetype
QtPrivate::count(QLatin1StringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
9689 while ((i = matcher.indexIn(haystack, i + 1)) != -1)
9695qsizetype
QtPrivate::count(QLatin1StringView haystack, QStringView needle, Qt::CaseSensitivity cs)
9697 if (haystack.size() < needle.size())
9700 if (!QtPrivate::isLatin1(needle))
9706 QVarLengthArray<uchar> s(needle.size());
9707 qt_to_latin1_unchecked(s.data(), needle.utf16(), needle.size());
9711 while ((i = matcher.indexIn(haystack, i + 1)) != -1)
9717qsizetype
QtPrivate::count(QStringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
9719 if (haystack.size() < needle.size())
9722 QVarLengthArray<
char16_t> s = qt_from_latin1_to_qvla(needle);
9723 return QtPrivate::count(haystack, QStringView(s.data(), s.size()), cs);
9726qsizetype
QtPrivate::count(QLatin1StringView haystack, QChar needle, Qt::CaseSensitivity cs)
noexcept
9729 if (needle.unicode() > 0xff)
9732 if (cs == Qt::CaseSensitive) {
9733 return std::count(haystack.cbegin(), haystack.cend(), needle.toLatin1());
9735 return std::count_if(haystack.cbegin(), haystack.cend(),
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9762 return qt_starts_with_impl(haystack, needle, cs);
9767 return qt_starts_with_impl(haystack, needle, cs);
9772 return qt_starts_with_impl(haystack, needle, cs);
9775bool QtPrivate::
startsWith(QLatin1StringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
9777 return qt_starts_with_impl(haystack, needle, cs);
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9802 return qt_ends_with_impl(haystack, needle, cs);
9805bool QtPrivate::
endsWith(QStringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
9807 return qt_ends_with_impl(haystack, needle, cs);
9810bool QtPrivate::
endsWith(QLatin1StringView haystack, QStringView needle, Qt::CaseSensitivity cs)
noexcept
9812 return qt_ends_with_impl(haystack, needle, cs);
9815bool QtPrivate::
endsWith(QLatin1StringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
9817 return qt_ends_with_impl(haystack, needle, cs);
9822 const qsizetype l = haystack0.size();
9823 const qsizetype sl = needle0.size();
9825 return findString(haystack0, from, needle0[0], cs);
9828 if (
std::size_t(sl + from) >
std::size_t(l))
9836
9837
9838
9839
9840 if (l > 500 && sl > 5)
9841 return qFindStringBoyerMoore(haystack0, from, needle0, cs);
9843 auto sv = [sl](
const char16_t *v) {
return QStringView(v, sl); };
9845
9846
9847
9848
9849
9850 const char16_t *needle = needle0.utf16();
9851 const char16_t *haystack = haystack0.utf16() + from;
9852 const char16_t *end = haystack0.utf16() + (l - sl);
9853 const qregisteruint sl_minus_1 = sl - 1;
9854 qregisteruint hashNeedle = 0, hashHaystack = 0;
9857 if (cs == Qt::CaseSensitive) {
9858 for (idx = 0; idx < sl; ++idx) {
9859 hashNeedle = ((hashNeedle<<1) + needle[idx]);
9860 hashHaystack = ((hashHaystack<<1) + haystack[idx]);
9862 hashHaystack -= haystack[sl_minus_1];
9864 while (haystack <= end) {
9865 hashHaystack += haystack[sl_minus_1];
9866 if (hashHaystack == hashNeedle
9867 && QtPrivate::compareStrings(needle0, sv(haystack), Qt::CaseSensitive) == 0)
9868 return haystack - haystack0.utf16();
9874 const char16_t *haystack_start = haystack0.utf16();
9875 for (idx = 0; idx < sl; ++idx) {
9876 hashNeedle = (hashNeedle<<1) + foldCase(needle + idx, needle);
9877 hashHaystack = (hashHaystack<<1) + foldCase(haystack + idx, haystack_start);
9879 hashHaystack -= foldCase(haystack + sl_minus_1, haystack_start);
9881 while (haystack <= end) {
9882 hashHaystack += foldCase(haystack + sl_minus_1, haystack_start);
9883 if (hashHaystack == hashNeedle
9884 && QtPrivate::compareStrings(needle0, sv(haystack), Qt::CaseInsensitive) == 0)
9885 return haystack - haystack0.utf16();
9887 REHASH(foldCase(haystack, haystack_start));
9896 if (haystack.size() < needle.size())
9899 QVarLengthArray<
char16_t> s = qt_from_latin1_to_qvla(needle);
9900 return QtPrivate::findString(haystack, from, QStringView(
reinterpret_cast<
const QChar*>(s.constData()), s.size()), cs);
9905 if (haystack.size() < needle.size())
9908 if (!QtPrivate::isLatin1(needle))
9911 if (needle.size() == 1) {
9912 const char n = needle.front().toLatin1();
9913 return QtPrivate::findString(haystack, from, QLatin1StringView(&n, 1), cs);
9916 QVarLengthArray<
char> s(needle.size());
9917 qt_to_latin1_unchecked(
reinterpret_cast<uchar *>(s.data()), needle.utf16(), needle.size());
9918 return QtPrivate::findString(haystack, from, QLatin1StringView(s.data(), s.size()), cs);
9924 from += haystack.size();
9927 qsizetype adjustedSize = haystack.size() - from;
9928 if (adjustedSize < needle.size())
9930 if (needle.size() == 0)
9933 if (cs == Qt::CaseSensitive) {
9935 if (needle.size() == 1) {
9936 Q_ASSERT(haystack.data() !=
nullptr);
9937 if (
auto it = memchr(haystack.data() + from, needle.front().toLatin1(), adjustedSize))
9938 return static_cast<
const char *>(it) - haystack.data();
9943 return matcher.indexIn(haystack, from);
9956 const qsizetype threshold = 1;
9958 const qsizetype threshold = 13;
9960 if (needle.size() <= threshold) {
9961 const auto begin = haystack.begin();
9962 const auto end = haystack.end() - needle.size() + 1;
9963 auto ciMatch = CaseInsensitiveL1
::matcher(needle[0].toLatin1()
);
9964 const qsizetype nlen1 = needle.size() - 1;
9965 for (
auto it =
std::find_if(begin + from, end, ciMatch); it != end;
9966 it =
std::find_if(it + 1, end, ciMatch)) {
9968 if (!nlen1 || QLatin1StringView(it + 1, nlen1).compare(needle.sliced(1), cs) == 0)
9969 return std::distance(begin, it);
9975 return matcher.indexIn(haystack, from);
9978qsizetype
QtPrivate::lastIndexOf(QStringView haystack, qsizetype from,
char16_t needle, Qt::CaseSensitivity cs)
noexcept
9980 return qLastIndexOf(haystack, QChar(needle), from, cs);
9983qsizetype
QtPrivate::lastIndexOf(QStringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs)
noexcept
9985 return qLastIndexOf(haystack, from, needle, cs);
9988qsizetype
QtPrivate::lastIndexOf(QStringView haystack, qsizetype from, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
9990 return qLastIndexOf(haystack, from, needle, cs);
9993qsizetype
QtPrivate::lastIndexOf(QLatin1StringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs)
noexcept
9995 return qLastIndexOf(haystack, from, needle, cs);
9998qsizetype
QtPrivate::lastIndexOf(QLatin1StringView haystack, qsizetype from, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
10000 return qLastIndexOf(haystack, from, needle, cs);
10003#if QT_CONFIG(regularexpression)
10004qsizetype QtPrivate::indexOf(QStringView viewHaystack,
const QString *stringHaystack,
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
10006 if (!re.isValid()) {
10007 qtWarnAboutInvalidRegularExpression(re.pattern(),
"QString(View)::indexOf");
10011 QRegularExpressionMatch match = stringHaystack
10012 ? re.match(*stringHaystack, from)
10013 : re.matchView(viewHaystack, from);
10014 if (match.hasMatch()) {
10015 const qsizetype ret = match.capturedStart();
10017 *rmatch = std::move(match);
10024qsizetype QtPrivate::indexOf(QStringView haystack,
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
10026 return indexOf(haystack,
nullptr, re, from, rmatch);
10029qsizetype QtPrivate::lastIndexOf(QStringView viewHaystack,
const QString *stringHaystack,
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
10031 if (!re.isValid()) {
10032 qtWarnAboutInvalidRegularExpression(re.pattern(),
"QString(View)::lastIndexOf");
10036 qsizetype endpos = (from < 0) ? (viewHaystack.size() + from + 1) : (from + 1);
10037 QRegularExpressionMatchIterator iterator = stringHaystack
10038 ? re.globalMatch(*stringHaystack)
10039 : re.globalMatchView(viewHaystack);
10040 qsizetype lastIndex = -1;
10041 while (iterator.hasNext()) {
10042 QRegularExpressionMatch match = iterator.next();
10043 qsizetype start = match.capturedStart();
10044 if (start < endpos) {
10047 *rmatch = std::move(match);
10056qsizetype QtPrivate::lastIndexOf(QStringView haystack,
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
10058 return lastIndexOf(haystack,
nullptr, re, from, rmatch);
10061bool QtPrivate::contains(QStringView viewHaystack,
const QString *stringHaystack,
const QRegularExpression &re, QRegularExpressionMatch *rmatch)
10063 if (!re.isValid()) {
10064 qtWarnAboutInvalidRegularExpression(re.pattern(),
"QString(View)::contains");
10067 QRegularExpressionMatch m = stringHaystack
10068 ? re.match(*stringHaystack)
10069 : re.matchView(viewHaystack);
10070 bool hasMatch = m.hasMatch();
10071 if (hasMatch && rmatch)
10072 *rmatch = std::move(m);
10076bool QtPrivate::contains(QStringView haystack,
const QRegularExpression &re, QRegularExpressionMatch *rmatch)
10078 return contains(haystack,
nullptr, re, rmatch);
10081qsizetype QtPrivate::count(QStringView haystack,
const QRegularExpression &re)
10083 if (!re.isValid()) {
10084 qtWarnAboutInvalidRegularExpression(re.pattern(),
"QString(View)::count");
10087 qsizetype count = 0;
10088 qsizetype index = -1;
10089 qsizetype len = haystack.size();
10090 while (index <= len - 1) {
10091 QRegularExpressionMatch match = re.matchView(haystack, index + 1);
10092 if (!match.hasMatch())
10099 index = match.capturedStart();
10100 if (index < len && haystack[index].isHighSurrogate())
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119QString QString::toHtmlEscaped()
const
10121 const auto pos = std::u16string_view(*
this).find_first_of(u"<>&\"");
10122 if (pos == std::u16string_view::npos)
10125 const qsizetype len = size();
10126 rich.reserve(qsizetype(len * 1.1));
10127 rich += qToStringViewIgnoringNull(*
this).first(pos);
10128 for (
auto ch : qToStringViewIgnoringNull(*
this).sliced(pos)) {
10131 else if (ch == u'>')
10133 else if (ch == u'&')
10134 rich +=
"&"_L1;
10135 else if (ch == u'"')
10136 rich +=
"""_L1;
10145
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
10188#if QT_DEPRECATED_SINCE(6
, 8
)
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10240
10241
10242void QAbstractConcatenable::appendLatin1To(QLatin1StringView in, QChar *out)
noexcept
10244 qt_from_latin1(
reinterpret_cast<
char16_t *>(out), in.data(), size_t(in.size()));
10248
10249
10250
10251
10252
10253
10254
10255
10256
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
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 bool isAscii_helper(const char16_t *&ptr, const char16_t *end)
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
static void append_utf8(QString &qs, const char *cs, qsizetype len)
#define ATTRIBUTE_NO_SANITIZE
bool qt_is_ascii(const char *&ptr, const char *end) noexcept
static void replace_in_place(QString &str, QSpan< size_t > indices, qsizetype blen, QStringView after)
static bool checkCase(QStringView s, QUnicodeTables::Case c) noexcept
static void replace_helper(QString &str, QSpan< size_t > 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
static void replace_with_copy(QString &str, QSpan< size_t > indices, qsizetype blen, QStringView after)
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 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)
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)
void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, qsizetype from)
static uint parse_flag_characters(const char *&c) 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
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)