8#if QT_CONFIG(regularexpression)
9#include "qregularexpression.h"
12#include <private/qstringconverter_p.h>
13#include <private/qtools_p.h>
15#include "private/qsimd_p.h"
17#include <qdatastream.h>
31#include <private/qcore_mac_p.h>
34#include <private/qfunctions_p.h>
54# include <qt_windows.h>
55# if !defined(QT_BOOTSTRAPPED) && (defined(QT_NO_CAST_FROM_ASCII) || defined(QT_NO_CAST_TO_ASCII))
57# error "This file cannot be compiled with QT_NO_CAST_{TO,FROM}_ASCII, "
58 "otherwise some QString functions will not get exported."
67 if (sl_minus_1 < sizeof(sl_minus_1) * CHAR_BIT)
68 hashHaystack -= decltype(hashHaystack)(a) << sl_minus_1;
73using namespace Qt::StringLiterals;
74using namespace QtMiscUtils;
76const char16_t QString::_empty = 0;
82enum StringComparisonMode {
83 CompareStringsForEquality,
84 CompareStringsForOrdering
87template <
typename Pointer>
88char32_t foldCaseHelper(Pointer ch, Pointer start) =
delete;
91char32_t foldCaseHelper<
const QChar*>(
const QChar* ch,
const QChar* start)
93 return foldCase(
reinterpret_cast<
const char16_t*>(ch),
94 reinterpret_cast<
const char16_t*>(start));
98char32_t foldCaseHelper<
const char*>(
const char* ch,
const char*)
104char16_t valueTypeToUtf16(T t) =
delete;
107char16_t valueTypeToUtf16<QChar>(QChar t)
113char16_t valueTypeToUtf16<
char>(
char t)
115 return char16_t{uchar(t)};
119static inline bool foldAndCompare(
const T a,
const T b)
121 return foldCase(a) == b;
125
126
127
128
129
130
131
132template <
typename Haystack>
133static inline qsizetype qLastIndexOf(Haystack haystack, QChar needle,
134 qsizetype from, Qt::CaseSensitivity cs)
noexcept
136 if (haystack.size() == 0)
139 from += haystack.size();
140 else if (
std::size_t(from) >
std::size_t(haystack.size()))
141 from = haystack.size() - 1;
143 char16_t c = needle.unicode();
144 const auto b = haystack.data();
146 if (cs == Qt::CaseSensitive) {
148 if (valueTypeToUtf16(*n) == c)
153 if (foldCase(valueTypeToUtf16(*n)) == c)
160qLastIndexOf(QString, QChar, qsizetype, Qt::CaseSensitivity)
noexcept =
delete;
162template<
typename Haystack,
typename Needle>
163static qsizetype qLastIndexOf(Haystack haystack0, qsizetype from,
164 Needle needle0, Qt::CaseSensitivity cs)
noexcept
166 const qsizetype sl = needle0.size();
168 return qLastIndexOf(haystack0, needle0.front(), from, cs);
170 const qsizetype l = haystack0.size();
173 if (from == l && sl == 0)
175 const qsizetype delta = l - sl;
176 if (
std::size_t(from) >
std::size_t(l) || delta < 0)
181 auto sv = [sl](
const typename Haystack::value_type *v) {
return Haystack(v, sl); };
183 auto haystack = haystack0.data();
184 const auto needle = needle0.data();
185 const auto *end = haystack;
187 const qregisteruint sl_minus_1 = sl ? sl - 1 : 0;
188 const auto *n = needle + sl_minus_1;
189 const auto *h = haystack + sl_minus_1;
190 qregisteruint hashNeedle = 0, hashHaystack = 0;
192 if (cs == Qt::CaseSensitive) {
193 for (qsizetype idx = 0; idx < sl; ++idx) {
194 hashNeedle = (hashNeedle << 1) + valueTypeToUtf16(*(n - idx));
195 hashHaystack = (hashHaystack << 1) + valueTypeToUtf16(*(h - idx));
197 hashHaystack -= valueTypeToUtf16(*haystack);
199 while (haystack >= end) {
200 hashHaystack += valueTypeToUtf16(*haystack);
201 if (hashHaystack == hashNeedle
202 && QtPrivate::compareStrings(needle0, sv(haystack), Qt::CaseSensitive) == 0)
203 return haystack - end;
205 REHASH(valueTypeToUtf16(haystack[sl]));
208 for (qsizetype idx = 0; idx < sl; ++idx) {
209 hashNeedle = (hashNeedle << 1) + foldCaseHelper(n - idx, needle);
210 hashHaystack = (hashHaystack << 1) + foldCaseHelper(h - idx, end);
212 hashHaystack -= foldCaseHelper(haystack, end);
214 while (haystack >= end) {
215 hashHaystack += foldCaseHelper(haystack, end);
216 if (hashHaystack == hashNeedle
217 && QtPrivate::compareStrings(sv(haystack), needle0, Qt::CaseInsensitive) == 0)
218 return haystack - end;
220 REHASH(foldCaseHelper(haystack + sl, end));
226template <
typename Haystack,
typename Needle>
227bool qt_starts_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs)
noexcept
229 if (haystack.isNull())
230 return needle.isNull();
231 const auto haystackLen = haystack.size();
232 const auto needleLen = needle.size();
233 if (haystackLen == 0)
234 return needleLen == 0;
235 if (needleLen > haystackLen)
238 return QtPrivate::compareStrings(haystack.first(needleLen), needle, cs) == 0;
241template <
typename Haystack,
typename Needle>
242bool qt_ends_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs)
noexcept
244 if (haystack.isNull())
245 return needle.isNull();
246 const auto haystackLen = haystack.size();
247 const auto needleLen = needle.size();
248 if (haystackLen == 0)
249 return needleLen == 0;
250 if (haystackLen < needleLen)
253 return QtPrivate::compareStrings(haystack.last(needleLen), needle, cs) == 0;
257static void append_helper(QString &self, T view)
259 const auto strData = view.data();
260 const qsizetype strSize = view.size();
261 auto &d = self.data_ptr();
262 if (strData && strSize > 0) {
265 d.detachAndGrow(QArrayData::GrowsAtEnd, strSize,
nullptr,
nullptr);
266 Q_CHECK_PTR(d.data());
267 Q_ASSERT(strSize <= d.freeSpaceAtEnd());
269 auto dst =
std::next(d.data(), d.size);
270 if constexpr (std::is_same_v<T, QUtf8StringView>) {
271 dst = QUtf8::convertToUnicode(dst, view);
272 }
else if constexpr (std::is_same_v<T, QLatin1StringView>) {
273 QLatin1::convertToUnicode(dst, view);
277 "Can only operate on UTF-8 and Latin-1");
279 self.resize(
std::distance(d.begin(), dst));
280 }
else if (d.isNull() && !view.isNull()) {
281 self = QLatin1StringView(
"");
285template <uint MaxCount>
struct UnrollTailLoop
287 template <
typename RetType,
typename Functor1,
typename Functor2,
typename Number>
288 static inline RetType exec(Number count, RetType returnIfExited, Functor1 loopCheck, Functor2 returnIfFailed, Number i = 0)
291
292
293
294
295
296
299 return returnIfExited;
301 bool check = loopCheck(i);
303 return returnIfFailed(i);
305 return UnrollTailLoop<MaxCount - 1>::exec(count - 1, returnIfExited, loopCheck, returnIfFailed, i + 1);
308 template <
typename Functor,
typename Number>
309 static inline void exec(Number count, Functor code)
312
313
314
315 exec(count, 0, [=](Number i) ->
bool { code(i);
return false; }, [](Number) {
return 0; });
318template <>
template <
typename RetType,
typename Functor1,
typename Functor2,
typename Number>
319inline RetType UnrollTailLoop<0>::exec(Number, RetType returnIfExited, Functor1, Functor2, Number)
321 return returnIfExited;
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
353
355#if defined(__mips_dsp)
357extern "C" void qt_fromlatin1_mips_asm_unroll4 (
char16_t*,
const char*, uint);
358extern "C" void qt_fromlatin1_mips_asm_unroll8 (
char16_t*,
const char*, uint);
359extern "C" void qt_toLatin1_mips_dsp_asm(uchar *dst,
const char16_t *src,
int length);
362#if defined(__SSE2__
) && defined(Q_CC_GNU)
365# define ATTRIBUTE_NO_SANITIZE __attribute__((__no_sanitize_address__, __no_sanitize_thread__))
367# define ATTRIBUTE_NO_SANITIZE
371static constexpr bool UseSse4_1 =
bool(qCompilerCpuFeatures & CpuFeatureSSE4_1);
372static constexpr bool UseAvx2 = UseSse4_1 &&
373 (qCompilerCpuFeatures & CpuFeatureArchHaswell) == CpuFeatureArchHaswell;
376Q_ALWAYS_INLINE
static __m128i mm_load8_zero_extend(
const void *ptr)
378 const __m128i *dataptr =
static_cast<
const __m128i *>(ptr);
379 if constexpr (UseSse4_1) {
382 __m128i data = _mm_loadl_epi64(dataptr);
383 return _mm_cvtepu8_epi16(data);
387 __m128i data = _mm_loadl_epi64(dataptr);
388 return _mm_unpacklo_epi8(data, _mm_setzero_si128());
392static qsizetype qustrlen_sse2(
const char16_t *str)
noexcept
395 quintptr misalignment = quintptr(str) & 0xf;
396 Q_ASSERT((misalignment & 1) == 0);
397 const char16_t *ptr = str - (misalignment / 2);
401 const __m128i zeroes = _mm_setzero_si128();
402 __m128i data = _mm_load_si128(
reinterpret_cast<
const __m128i *>(ptr));
403 __m128i comparison = _mm_cmpeq_epi16(data, zeroes);
404 uint mask = _mm_movemask_epi8(comparison);
407 mask >>= misalignment;
412 return qCountTrailingZeroBits(mask) /
sizeof(
char16_t);
414 constexpr qsizetype Step =
sizeof(__m128i) /
sizeof(
char16_t);
415 qsizetype size = Step - misalignment /
sizeof(
char16_t);
420 data = _mm_load_si128(
reinterpret_cast<
const __m128i *>(str + size));
422 comparison = _mm_cmpeq_epi16(data, zeroes);
423 mask = _mm_movemask_epi8(comparison);
427 return size + qCountTrailingZeroBits(mask) /
sizeof(
char16_t);
434static bool simdTestMask(
const char *&ptr,
const char *end, quint32 maskval)
436 auto updatePtr = [&](uint result) {
438 uint idx = qCountTrailingZeroBits(~result);
443 if constexpr (UseSse4_1) {
446 auto updatePtrSimd = [&](__m128i data) ->
bool {
447 __m128i masked = _mm_and_si128(mask, data);
448 __m128i comparison = _mm_cmpeq_epi16(masked, _mm_setzero_si128());
449 uint result = _mm_movemask_epi8(comparison);
450 return updatePtr(result);
453 if constexpr (UseAvx2) {
455 const __m256i mask256 = _mm256_broadcastd_epi32(_mm_cvtsi32_si128(maskval));
456 while (ptr + 32 <= end) {
457 __m256i data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(ptr));
458 if (!_mm256_testz_si256(mask256, data)) {
460 __m256i masked256 = _mm256_and_si256(mask256, data);
461 __m256i comparison256 = _mm256_cmpeq_epi16(masked256, _mm256_setzero_si256());
462 return updatePtr(_mm256_movemask_epi8(comparison256));
467 mask = _mm256_castsi256_si128(mask256);
471 mask = _mm_set1_epi32(maskval);
472 while (ptr + 32 <= end) {
473 __m128i data1 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr));
474 __m128i data2 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr + 16));
475 if (!_mm_testz_si128(mask, data1))
476 return updatePtrSimd(data1);
479 if (!_mm_testz_si128(mask, data2))
480 return updatePtrSimd(data2);
486 if (ptr + 16 <= end) {
487 __m128i data1 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr));
488 if (!_mm_testz_si128(mask, data1))
489 return updatePtrSimd(data1);
494 if (ptr + 8 <= end) {
495 __m128i data1 = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr));
496 if (!_mm_testz_si128(mask, data1))
497 return updatePtrSimd(data1);
506 const __m128i mask = _mm_set1_epi32(maskval);
507 while (ptr + 16 <= end) {
508 __m128i data = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr));
509 __m128i masked = _mm_and_si128(mask, data);
510 __m128i comparison = _mm_cmpeq_epi16(masked, _mm_setzero_si128());
511 quint16 result = _mm_movemask_epi8(comparison);
512 if (result != 0xffff)
513 return updatePtr(result);
518 if (ptr + 8 <= end) {
519 __m128i data = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr));
520 __m128i masked = _mm_and_si128(mask, data);
521 __m128i comparison = _mm_cmpeq_epi16(masked, _mm_setzero_si128());
522 quint8 result = _mm_movemask_epi8(comparison);
524 return updatePtr(result);
531template <StringComparisonMode Mode,
typename Char> [[maybe_unused]]
532static int ucstrncmp_sse2(
const char16_t *a,
const Char *b, size_t l)
534 static_assert(
std::is_unsigned_v<Char>);
538 static const auto codeUnitAt = [](
const auto *n, qptrdiff idx) ->
int {
539 constexpr int Stride = 2;
546 auto ptr =
reinterpret_cast<
const uchar *>(n);
547 ptr += idx / (Stride /
sizeof(*n));
548 return *
reinterpret_cast<
decltype(n)>(ptr);
550 auto difference = [a, b](uint mask, qptrdiff offset) {
551 if (Mode == CompareStringsForEquality)
553 uint idx = qCountTrailingZeroBits(mask);
554 return codeUnitAt(a + offset, idx) - codeUnitAt(b + offset, idx);
557 static const auto load8Chars = [](
const auto *ptr) {
558 if (
sizeof(*ptr) == 2)
559 return _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr));
560 __m128i chunk = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr));
561 return _mm_unpacklo_epi8(chunk, _mm_setzero_si128());
563 static const auto load4Chars = [](
const auto *ptr) {
564 if (
sizeof(*ptr) == 2)
565 return _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr));
566 __m128i chunk = _mm_cvtsi32_si128(qFromUnaligned<quint32>(ptr));
567 return _mm_unpacklo_epi8(chunk, _mm_setzero_si128());
571 auto processChunk16Chars = [a, b](qptrdiff offset) -> uint {
572 if constexpr (UseAvx2) {
573 __m256i a_data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(a + offset));
575 if (
sizeof(Char) == 1) {
577 __m128i chunk = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(b + offset));
578 b_data = _mm256_cvtepu8_epi16(chunk);
580 b_data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(b + offset));
582 __m256i result = _mm256_cmpeq_epi16(a_data, b_data);
583 return _mm256_movemask_epi8(result);
586 __m128i a_data1 = load8Chars(a + offset);
587 __m128i a_data2 = load8Chars(a + offset + 8);
588 __m128i b_data1, b_data2;
589 if (
sizeof(Char) == 1) {
591 __m128i b_data = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(b + offset));
592 b_data1 = _mm_unpacklo_epi8(b_data, _mm_setzero_si128());
593 b_data2 = _mm_unpackhi_epi8(b_data, _mm_setzero_si128());
595 b_data1 = load8Chars(b + offset);
596 b_data2 = load8Chars(b + offset + 8);
598 __m128i result1 = _mm_cmpeq_epi16(a_data1, b_data1);
599 __m128i result2 = _mm_cmpeq_epi16(a_data2, b_data2);
600 return _mm_movemask_epi8(result1) | _mm_movemask_epi8(result2) << 16;
603 if (l >=
sizeof(__m256i) /
sizeof(
char16_t)) {
605 for ( ; l >= offset +
sizeof(__m256i) /
sizeof(
char16_t); offset +=
sizeof(__m256i) /
sizeof(
char16_t)) {
606 uint mask = ~processChunk16Chars(offset);
608 return difference(mask, offset);
612 if (size_t(offset) < l) {
613 offset = l -
sizeof(__m256i) /
sizeof(
char16_t);
614 uint mask = ~processChunk16Chars(offset);
615 return mask ? difference(mask, offset) : 0;
618 __m128i a_data1, b_data1;
619 __m128i a_data2, b_data2;
623 a_data1 = load8Chars(a);
624 b_data1 = load8Chars(b);
625 a_data2 = load8Chars(a + l - width);
626 b_data2 = load8Chars(b + l - width);
630 a_data1 = load4Chars(a);
631 b_data1 = load4Chars(b);
632 a_data2 = load4Chars(a + l - width);
633 b_data2 = load4Chars(b + l - width);
636 __m128i result = _mm_cmpeq_epi16(a_data1, b_data1);
637 ushort mask = ~_mm_movemask_epi8(result);
639 return difference(mask, 0);
641 result = _mm_cmpeq_epi16(a_data2, b_data2);
642 mask = ~_mm_movemask_epi8(result);
644 return difference(mask, l - width);
649 const auto lambda = [=](size_t i) ->
int {
652 return UnrollTailLoop<3>::exec(l, 0, lambda, lambda);
659qsizetype QtPrivate::qustrlen(
const char16_t *str)
noexcept
661#if defined(__SSE2__
) && !(defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)) && !(defined(__SANITIZE_THREAD__) || __has_feature(thread_sanitizer))
662 return qustrlen_sse2(str);
665 if (
sizeof(
wchar_t) ==
sizeof(
char16_t))
666 return wcslen(
reinterpret_cast<
const wchar_t *>(str));
668 qsizetype result = 0;
674qsizetype
QtPrivate::qustrnlen(
const char16_t *str, qsizetype maxlen)
noexcept
676 return qustrchr({ str, maxlen }, u'\0') - str;
680
681
682
683
684
685
686
690 const char16_t *n = str.utf16();
691 const char16_t *e = n + str.size();
698 if constexpr (UseAvx2) {
700 __m256i mch256 = _mm256_set1_epi32(c | (c << 16));
701 for (
const char16_t *next = n + 16; next <= e; n = next, next += 16) {
702 __m256i data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(n));
703 __m256i result = _mm256_cmpeq_epi16(data, mch256);
704 uint mask = uint(_mm256_movemask_epi8(result));
706 uint idx = qCountTrailingZeroBits(mask);
711 mch = _mm256_castsi256_si128(mch256);
713 mch = _mm_set1_epi32(c | (c << 16));
716 auto hasMatch = [mch, &n](__m128i data, ushort validityMask) {
717 __m128i result = _mm_cmpeq_epi16(data, mch);
718 uint mask = uint(_mm_movemask_epi8(result));
719 if ((mask & validityMask) == 0)
721 uint idx = qCountTrailingZeroBits(mask);
727 for (
const char16_t *next = n + 8; next <= e; n = next, next += 8) {
728 __m128i data = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(n));
729 if (hasMatch(data, 0xffff))
738# if !defined(__OPTIMIZE_SIZE__)
741 __m128i data = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(n));
742 if (hasMatch(data, 0xff))
748 return UnrollTailLoop<3>::exec(e - n, e,
749 [=](qsizetype i) {
return n[i] == c; },
750 [=](qsizetype i) {
return n + i; });
752#elif defined(__ARM_NEON__)
753 const uint16x8_t vmask = qvsetq_n_u16(1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7);
754 const uint16x8_t ch_vec = vdupq_n_u16(c);
755 for (
const char16_t *next = n + 8; next <= e; n = next, next += 8) {
756 uint16x8_t data = vld1q_u16(
reinterpret_cast<
const uint16_t *>(n));
757 uint mask = vaddvq_u16(vandq_u16(vceqq_u16(data, ch_vec), vmask));
760 return n + qCountTrailingZeroBits(mask);
765 return std::find(n, e, c);
769
770
771
772
773
774
778 const QChar *n = str.begin();
779 const QChar *e = str.end();
781 auto it =
std::find_if(n, e, [c](
auto ch) {
return foldAndCompare(ch, QChar(c)); });
782 return reinterpret_cast<
const char16_t *>(it);
792 if constexpr (UseAvx2) {
793 while (ptr + 32 <= end) {
794 __m256i data = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(ptr));
795 quint32 mask = _mm256_movemask_epi8(data);
797 uint idx = qCountTrailingZeroBits(mask);
806 while (ptr + 16 <= end) {
807 __m128i data = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(ptr));
808 quint32 mask = _mm_movemask_epi8(data);
810 uint idx = qCountTrailingZeroBits(mask);
819 if (ptr + 8 <= end) {
820 __m128i data = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(ptr));
821 quint8 mask = _mm_movemask_epi8(data);
823 uint idx = qCountTrailingZeroBits(mask);
831 while (ptr + 4 <= end) {
832 quint32 data = qFromUnaligned<quint32>(ptr);
833 if (data &= 0x80808080U) {
834 uint idx = QSysInfo::ByteOrder == QSysInfo::BigEndian
835 ? qCountLeadingZeroBits(data)
836 : qCountTrailingZeroBits(data);
844 if (quint8(*ptr) & 0x80)
853 const char *ptr = s.begin();
854 const char *end = s.end();
862 const char *ptr8 =
reinterpret_cast<
const char *>(ptr);
863 const char *end8 =
reinterpret_cast<
const char *>(end);
864 bool ok = simdTestMask(ptr8, end8, 0xff80ff80);
865 ptr =
reinterpret_cast<
const char16_t *>(ptr8);
880 const char16_t *ptr = s.utf16();
881 const char16_t *end = ptr + s.size();
888 const char16_t *ptr = s.utf16();
889 const char16_t *end = ptr + s.size();
892 const char *ptr8 =
reinterpret_cast<
const char *>(ptr);
893 const char *end8 =
reinterpret_cast<
const char *>(end);
894 if (!simdTestMask(ptr8, end8, 0xff00ff00))
896 ptr =
reinterpret_cast<
const char16_t *>(ptr8);
908 constexpr char32_t InvalidCodePoint = UINT_MAX;
912 const char32_t c = i
.next(InvalidCodePoint
);
913 if (c == InvalidCodePoint)
921Q_CORE_EXPORT
void qt_from_latin1(
char16_t *dst,
const char *str, size_t size)
noexcept
924
925
926
927
930 const __m128i nullMask = _mm_setzero_si128();
931 auto processOneChunk = [=](qptrdiff offset) {
932 const __m128i chunk = _mm_loadu_si128((
const __m128i*)(str + offset));
933 if constexpr (UseAvx2) {
935 const __m256i extended = _mm256_cvtepu8_epi16(chunk);
938 _mm256_storeu_si256((__m256i*)(dst + offset), extended);
941 const __m128i firstHalf = _mm_unpacklo_epi8(chunk, nullMask);
942 _mm_storeu_si128((__m128i*)(dst + offset), firstHalf);
945 const __m128i secondHalf = _mm_unpackhi_epi8 (chunk, nullMask);
946 _mm_storeu_si128((__m128i*)(dst + offset + 8), secondHalf);
950 const char *e = str + size;
951 if (size >=
sizeof(__m128i)) {
953 for ( ; str + offset +
sizeof(__m128i) <= e; offset +=
sizeof(__m128i))
954 processOneChunk(offset);
955 if (str + offset < e)
956 processOneChunk(size -
sizeof(__m128i));
960# if !defined(__OPTIMIZE_SIZE__)
964 const __m128i unpacked1 = mm_load8_zero_extend(str);
965 const __m128i unpacked2 = mm_load8_zero_extend(str + size - 8);
966 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst), unpacked1);
967 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst + size - 8), unpacked2);
969 const __m128i chunk1 = _mm_cvtsi32_si128(qFromUnaligned<quint32>(str));
970 const __m128i chunk2 = _mm_cvtsi32_si128(qFromUnaligned<quint32>(str + size - 4));
971 const __m128i unpacked1 = _mm_unpacklo_epi8(chunk1, nullMask);
972 const __m128i unpacked2 = _mm_unpacklo_epi8(chunk2, nullMask);
973 _mm_storel_epi64(
reinterpret_cast<__m128i *>(dst), unpacked1);
974 _mm_storel_epi64(
reinterpret_cast<__m128i *>(dst + size - 4), unpacked2);
979 return UnrollTailLoop<3>::exec(qsizetype(size), [=](qsizetype i) { dst[i] = uchar(str[i]); });
983#if defined(__mips_dsp)
984 static_assert(
sizeof(qsizetype) ==
sizeof(
int),
985 "oops, the assembler implementation needs to be called in a loop");
987 qt_fromlatin1_mips_asm_unroll8(dst, str, size);
989 qt_fromlatin1_mips_asm_unroll4(dst, str, size);
992 *dst++ = (uchar)*str++;
998 const qsizetype len = str.size();
999 QVarLengthArray<
char16_t> arr(len);
1000 qt_from_latin1(arr.data(), str.data(), len);
1004template <
bool Checked>
1007#if defined(__SSE2__
)
1008 auto questionMark256 = []() {
1009 if constexpr (UseAvx2)
1010 return _mm256_broadcastw_epi16(_mm_cvtsi32_si128(
'?'));
1014 auto outOfRange256 = []() {
1015 if constexpr (UseAvx2)
1016 return _mm256_broadcastw_epi16(_mm_cvtsi32_si128(0x100));
1020 __m128i questionMark, outOfRange;
1021 if constexpr (UseAvx2) {
1022 questionMark = _mm256_castsi256_si128(questionMark256);
1023 outOfRange = _mm256_castsi256_si128(outOfRange256);
1025 questionMark = _mm_set1_epi16(
'?');
1026 outOfRange = _mm_set1_epi16(0x100);
1029 auto mergeQuestionMarks = [=](__m128i chunk) {
1034 if constexpr (UseSse4_1) {
1036 chunk = _mm_min_epu16(chunk, outOfRange);
1037 const __m128i offLimitMask = _mm_cmpeq_epi16(chunk, outOfRange);
1038 chunk = _mm_blendv_epi8(chunk, questionMark, offLimitMask);
1042 const __m128i signedBitOffset = _mm_set1_epi16(
short(0x8000));
1043 const __m128i thresholdMask = _mm_set1_epi16(
short(0xff + 0x8000));
1045 const __m128i signedChunk = _mm_add_epi16(chunk, signedBitOffset);
1046 const __m128i offLimitMask = _mm_cmpgt_epi16(signedChunk, thresholdMask);
1050 const __m128i offLimitQuestionMark = _mm_and_si128(offLimitMask, questionMark);
1054 const __m128i correctBytes = _mm_andnot_si128(offLimitMask, chunk);
1057 chunk = _mm_or_si128(correctBytes, offLimitQuestionMark);
1059 Q_UNUSED(outOfRange);
1064 auto loadChunkAt = [=](qptrdiff offset) {
1065 __m128i chunk1, chunk2;
1066 if constexpr (UseAvx2) {
1067 __m256i chunk = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(src + offset));
1070 chunk = _mm256_min_epu16(chunk, outOfRange256);
1071 const __m256i offLimitMask = _mm256_cmpeq_epi16(chunk, outOfRange256);
1072 chunk = _mm256_blendv_epi8(chunk, questionMark256, offLimitMask);
1075 chunk2 = _mm256_extracti128_si256(chunk, 1);
1076 chunk1 = _mm256_castsi256_si128(chunk);
1078 chunk1 = _mm_loadu_si128((
const __m128i*)(src + offset));
1079 chunk1 = mergeQuestionMarks(chunk1);
1081 chunk2 = _mm_loadu_si128((
const __m128i*)(src + offset + 8));
1082 chunk2 = mergeQuestionMarks(chunk2);
1086 return _mm_packus_epi16(chunk1, chunk2);
1089 if (size_t(length) >=
sizeof(__m128i)) {
1091 qptrdiff offset = 0;
1092 for ( ; offset + 2 *
sizeof(__m128i) < size_t(length); offset +=
sizeof(__m128i))
1093 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst + offset), loadChunkAt(offset));
1096 __m128i last1 = loadChunkAt(offset);
1097 __m128i last2 = loadChunkAt(length -
sizeof(__m128i));
1098 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst + offset), last1);
1099 _mm_storeu_si128(
reinterpret_cast<__m128i *>(dst + length -
sizeof(__m128i)), last2);
1103# if !defined(__OPTIMIZE_SIZE__)
1108 __m128i chunk1 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(src));
1109 __m128i chunk2 = _mm_loadu_si128(
reinterpret_cast<
const __m128i *>(src + length - 8));
1110 chunk1 = mergeQuestionMarks(chunk1);
1111 chunk2 = mergeQuestionMarks(chunk2);
1114 const __m128i result1 = _mm_packus_epi16(chunk1, chunk1);
1115 const __m128i result2 = _mm_packus_epi16(chunk2, chunk2);
1116 _mm_storel_epi64(
reinterpret_cast<__m128i *>(dst), result1);
1117 _mm_storel_epi64(
reinterpret_cast<__m128i *>(dst + length - 8), result2);
1119 __m128i chunk1 = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(src));
1120 __m128i chunk2 = _mm_loadl_epi64(
reinterpret_cast<
const __m128i *>(src + length - 4));
1121 chunk1 = mergeQuestionMarks(chunk1);
1122 chunk2 = mergeQuestionMarks(chunk2);
1125 const __m128i result1 = _mm_packus_epi16(chunk1, chunk1);
1126 const __m128i result2 = _mm_packus_epi16(chunk2, chunk2);
1127 qToUnaligned(_mm_cvtsi128_si32(result1), dst);
1128 qToUnaligned(_mm_cvtsi128_si32(result2), dst + length - 4);
1133 length = length % 4;
1134 return UnrollTailLoop<3>::exec(length, [=](qsizetype i) {
1136 dst[i] = (src[i]>0xff) ?
'?' : (uchar) src[i];
1141 length = length % 16;
1143#elif defined(__ARM_NEON__)
1149 const qsizetype chunkCount = length >> 3;
1150 const uint16x8_t questionMark = vdupq_n_u16(
'?');
1151 const uint16x8_t thresholdMask = vdupq_n_u16(0xff);
1152 for (qsizetype i = 0; i < chunkCount; ++i) {
1153 uint16x8_t chunk = vld1q_u16((uint16_t *)src);
1157 const uint16x8_t offLimitMask = vcgtq_u16(chunk, thresholdMask);
1158 const uint16x8_t offLimitQuestionMark = vandq_u16(offLimitMask, questionMark);
1159 const uint16x8_t correctBytes = vbicq_u16(chunk, offLimitMask);
1160 chunk = vorrq_u16(correctBytes, offLimitQuestionMark);
1162 const uint8x8_t result = vmovn_u16(chunk);
1163 vst1_u8(dst, result);
1166 length = length % 8;
1169#if defined(__mips_dsp)
1170 static_assert(
sizeof(qsizetype) ==
sizeof(
int),
1171 "oops, the assembler implementation needs to be called in a loop");
1172 qt_toLatin1_mips_dsp_asm(dst, src, length);
1176 *dst++ = (*src>0xff) ?
'?' : (uchar) *src;
1186 qt_to_latin1_internal<
true>(dst, src, length);
1191 qt_to_latin1_internal<
false>(dst, src, length);
1198 return qt_lencmp(alen, blen);
1202 qsizetype l = qMin(alen, blen);
1204 for (i = 0; i < l; ++i) {
1208 int diff = foldCase(a[i], alast) - foldCase(b[i], blast);
1224 qsizetype l = qMin(alen, blen);
1226 for (i = 0; i < l; ++i) {
1227 int diff = foldCase(a[i]) - foldCase(
char16_t{uchar(b[i])});
1242 auto src1 =
reinterpret_cast<
const qchar8_t *>(utf8);
1243 auto end1 =
reinterpret_cast<
const qchar8_t *>(utf8end);
1247 char32_t uc1 = QChar::toCaseFolded(QUtf8Functions::nextUcs4FromUtf8(src1, end1));
1248 char32_t uc2 = QChar::toCaseFolded(src2.next());
1249 int diff = uc1 - uc2;
1258#if defined(__mips_dsp)
1260extern "C" int qt_ucstrncmp_mips_dsp_asm(
const char16_t *a,
1266template <StringComparisonMode Mode>
1267static int ucstrncmp(
const char16_t *a,
const char16_t *b, size_t l)
1273#ifndef __OPTIMIZE_SIZE__
1274# if defined(__mips_dsp)
1275 static_assert(
sizeof(uint) ==
sizeof(size_t));
1277 return qt_ucstrncmp_mips_dsp_asm(a, b, l);
1279# elif defined(__SSE2__
)
1280 return ucstrncmp_sse2<Mode>(a, b, l);
1281# elif defined(__ARM_NEON__)
1283 const char16_t *end = a + l;
1284 const uint16x8_t mask = qvsetq_n_u16( 1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7 );
1285 while (end - a > 7) {
1286 uint16x8_t da = vld1q_u16(
reinterpret_cast<
const uint16_t *>(a));
1287 uint16x8_t db = vld1q_u16(
reinterpret_cast<
const uint16_t *>(b));
1289 uint8_t r = ~(uint8_t)vaddvq_u16(vandq_u16(vceqq_u16(da, db), mask));
1292 if (Mode == CompareStringsForEquality)
1294 uint idx = qCountTrailingZeroBits(r);
1295 return a[idx] - b[idx];
1302 const auto lambda = [=](size_t i) ->
int {
1305 return UnrollTailLoop<7>::exec(l, 0, lambda, lambda);
1309 if (Mode == CompareStringsForEquality || QSysInfo::ByteOrder == QSysInfo::BigEndian)
1310 return memcmp(a, b, l *
sizeof(
char16_t));
1312 for (size_t i = 0; i < l; ++i) {
1313 if (
int diff = a[i] - b[i])
1319template <StringComparisonMode Mode>
1320static int ucstrncmp(
const char16_t *a,
const char *b, size_t l)
1322 const uchar *c =
reinterpret_cast<
const uchar *>(b);
1323 const char16_t *uc = a;
1324 const char16_t *e = uc + l;
1326#if defined(__SSE2__
) && !defined(__OPTIMIZE_SIZE__)
1327 return ucstrncmp_sse2<Mode>(uc, c, l);
1331 int diff = *uc - *c;
1341template <
typename Char2>
1342static bool ucstreq(
const char16_t *a, size_t alen,
const Char2 *b)
1344 return ucstrncmp<CompareStringsForEquality>(a, b, alen) == 0;
1348template <
typename Char2>
1349static int ucstrcmp(
const char16_t *a, size_t alen,
const Char2 *b, size_t blen)
1351 const size_t l = qMin(alen, blen);
1352 int cmp = ucstrncmp<CompareStringsForOrdering>(a, b, l);
1353 return cmp ? cmp : qt_lencmp(alen, blen);
1358static int latin1nicmp(
const char *lhsChar, qsizetype lSize,
const char *rhsChar, qsizetype rSize)
1361 Q_ASSERT(lSize >= 0 && rSize >= 0);
1363 return rSize ? -1 : 0;
1366 const qsizetype size =
std::min(lSize, rSize);
1368 Q_ASSERT(lhsChar && rhsChar);
1369 for (qsizetype i = 0; i < size; i++) {
1373 return qt_lencmp(lSize, rSize);
1378 Q_ASSERT(lhs.size() == rhs.size());
1379 return ucstreq(lhs.utf16(), lhs.size(), rhs.utf16());
1384 Q_ASSERT(lhs.size() == rhs.size());
1385 return ucstreq(lhs.utf16(), lhs.size(), rhs.latin1());
1390 return QtPrivate::equalStrings(rhs, lhs);
1395 Q_ASSERT(lhs.size() == rhs.size());
1396 return (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0);
1401 return QUtf8::compareUtf8(lhs, rhs) == 0;
1406 return QtPrivate::equalStrings(rhs, lhs);
1411 return QUtf8::compareUtf8(QByteArrayView(rhs), lhs) == 0;
1416 return QtPrivate::equalStrings(rhs, lhs);
1421#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
) || defined(QT_BOOTSTRAPPED) || defined(QT_STATIC)
1422 Q_ASSERT(lhs.size() == rhs.size());
1425 if (lhs.size() != rhs.size())
1428 return (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0);
1431bool QAnyStringView::equal(QAnyStringView lhs, QAnyStringView rhs)
noexcept
1433 if (lhs.size() != rhs.size() && lhs.isUtf8() == rhs.isUtf8())
1435 return lhs.visit([rhs](
auto lhs) {
1436 return rhs.visit([lhs](
auto rhs) {
1437 return QtPrivate::equalStrings(lhs, rhs);
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1459 if (cs == Qt::CaseSensitive)
1460 return ucstrcmp(lhs.utf16(), lhs.size(), rhs.utf16(), rhs.size());
1461 return ucstricmp(lhs.size(), lhs.utf16(), rhs.size(), rhs.utf16());
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1482 if (cs == Qt::CaseSensitive)
1483 return ucstrcmp(lhs.utf16(), lhs.size(), rhs.latin1(), rhs.size());
1484 return ucstricmp(lhs.size(), lhs.utf16(), rhs.size(), rhs.latin1());
1488
1489
1490
1491
1492
1495 return -compareStrings(rhs, lhs, cs);
1499
1500
1501
1502
1503
1506 return -compareStrings(rhs, lhs, cs);
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1528 return qt_lencmp(qsizetype(0), rhs.size());
1530 return qt_lencmp(lhs.size(), qsizetype(0));
1531 if (cs == Qt::CaseInsensitive)
1532 return latin1nicmp(lhs.data(), lhs.size(), rhs.data(), rhs.size());
1533 const auto l =
std::min(lhs.size(), rhs.size());
1534 int r = memcmp(lhs.data(), rhs.data(), l);
1535 return r ? r : qt_lencmp(lhs.size(), rhs.size());
1539
1540
1541
1542
1543
1546 return -QUtf8::compareUtf8(QByteArrayView(rhs), lhs, cs);
1550
1551
1552
1553
1554
1557 if (cs == Qt::CaseSensitive)
1558 return QUtf8::compareUtf8(lhs, rhs);
1559 return ucstricmp8(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1563
1564
1565
1566
1567
1570 return -compareStrings(rhs, lhs, cs);
1574
1575
1576
1577
1578
1581 return QUtf8::compareUtf8(QByteArrayView(lhs), QByteArrayView(rhs), cs);
1584int QAnyStringView::compare(QAnyStringView lhs, QAnyStringView rhs, Qt::CaseSensitivity cs)
noexcept
1586 return lhs.visit([rhs, cs](
auto lhs) {
1587 return rhs.visit([lhs, cs](
auto rhs) {
1588 return QtPrivate::compareStrings(lhs, rhs, cs);
1595#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
1596static bool supportUnicodeDigitValuesInArg()
1598 static const bool result = []() {
1599 static const char supportUnicodeDigitValuesEnvVar[]
1600 =
"QT_USE_UNICODE_DIGIT_VALUES_IN_STRING_ARG";
1602 if (qEnvironmentVariableIsSet(supportUnicodeDigitValuesEnvVar))
1603 return qEnvironmentVariableIntValue(supportUnicodeDigitValuesEnvVar) != 0;
1605#if QT_VERSION < QT_VERSION_CHECK(6
, 6
, 0
)
1618#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
1619 if (supportUnicodeDigitValuesInArg())
1620 return ch.digitValue();
1622 if (ch >= u'0' && ch <= u'9')
1623 return int(ch.unicode() - u'0');
1627#if QT_CONFIG(regularexpression)
1629static void qtWarnAboutInvalidRegularExpression(
const QRegularExpression &re,
const char *cls,
const char *method)
1631 extern void qtWarnAboutInvalidRegularExpression(
const QString &pattern,
const char *cls,
const char *method);
1632 qtWarnAboutInvalidRegularExpression(re.pattern(), cls, method);
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1668
1669
1670
1671
1672
1673
1674
1675
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2133
2134
2135
2138
2139
2140
2143
2144
2145
2148
2149
2150
2153
2154
2155
2156
2159
2160
2161
2162
2165
2166
2169
2170
2173
2174
2176
2177
2180
2181
2182
2183
2184
2186
2187
2188
2189
2190
2193
2194
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2210
2211
2212
2215
2216
2217
2218
2219
2220
2221
2222
2223
2226
2227
2228
2229
2230
2231
2232
2233
2236
2237
2238
2239
2240
2241
2242
2243
2246
2247
2248
2251
2252
2253
2254
2255
2256
2257
2258
2259
2262
2263
2264
2265
2266
2267
2268
2269
2272
2273
2274
2275
2276
2277
2278
2279
2280
2283
2284
2285
2288
2289
2290
2291
2292
2293
2294
2295
2296
2299
2300
2301
2302
2303
2304
2305
2306
2307
2310
2311
2312
2315
2316
2317
2318
2319
2320
2321
2322
2323
2326
2327
2328
2329
2330
2331
2334
2335
2336
2337
2338
2339
2340
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2363
2364
2365
2366
2367
2368
2369
2370
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2385
2386
2387
2388
2389
2392
2393
2394
2395
2396
2399
2400
2401
2402
2403
2404
2405
2406
2407
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2437qsizetype QString::toUcs4_helper(
const char16_t *uc, qsizetype length,
char32_t *out)
2439 qsizetype count = 0;
2441 QStringIterator i(QStringView(uc, length));
2443 out[count++] = i.next();
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495QString::QString(
const QChar *unicode, qsizetype size)
2501 size = QtPrivate::qustrlen(
reinterpret_cast<
const char16_t *>(unicode));
2503 d = DataPointer::fromRawData(&_empty, 0);
2505 d = DataPointer(size, size);
2506 Q_CHECK_PTR(d.data());
2507 memcpy(d.data(), unicode, size *
sizeof(QChar));
2508 d.data()[size] =
'\0';
2514
2515
2516
2517
2518
2519QString::QString(qsizetype size, QChar ch)
2522 d = DataPointer::fromRawData(&_empty, 0);
2524 d = DataPointer(size, size);
2525 Q_CHECK_PTR(d.data());
2526 d.data()[size] =
'\0';
2527 char16_t *b = d.data();
2528 char16_t *e = d.data() + size;
2529 const char16_t value = ch.unicode();
2530 std::fill(b, e, value);
2535
2536
2537
2538
2539
2540QString::QString(qsizetype size, Qt::Initialization)
2543 d = DataPointer::fromRawData(&_empty, 0);
2545 d = DataPointer(size, size);
2546 Q_CHECK_PTR(d.data());
2547 d.data()[size] =
'\0';
2552
2553
2554
2555
2556
2559
2560
2561QString::QString(QChar ch)
2563 d = DataPointer(1, 1);
2564 Q_CHECK_PTR(d.data());
2565 d.data()[0] = ch.unicode();
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2587
2588
2591
2592
2595
2596
2599
2600
2601
2602
2606
2607
2608
2611
2612
2613
2616
2617
2618
2621
2622
2623
2626
2627
2628
2629
2633 const auto capacityAtEnd = str.capacity() - str.data_ptr().freeSpaceAtBegin();
2634 return newSize > capacityAtEnd;
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2668void QString::resize(qsizetype size)
2673 if (d->needsDetach() || needsReallocate(*
this, size))
2674 reallocData(size, QArrayData::Grow);
2676 if (d->allocatedCapacity())
2677 d.data()[size] = u'\0';
2681
2682
2683
2684
2685
2686
2687
2688
2690void QString::resize(qsizetype newSize, QChar fillChar)
2692 const qsizetype oldSize = size();
2694 const qsizetype difference = size() - oldSize;
2696 std::fill_n(d.data() + oldSize, difference, fillChar.unicode());
2701
2702
2703
2704
2705
2706
2707
2708
2709
2711void QString::resizeForOverwrite(qsizetype size)
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
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
2764
2765
2766
2767
2768
2769
2770
2771
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2785void QString::reallocData(qsizetype alloc, QArrayData::AllocationOption option)
2788 d = DataPointer::fromRawData(&_empty, 0);
2794 const bool cannotUseReallocate = d.freeSpaceAtBegin() > 0;
2796 if (d->needsDetach() || cannotUseReallocate) {
2797 DataPointer dd(alloc, qMin(alloc, d.size), option);
2798 Q_CHECK_PTR(dd.data());
2800 ::memcpy(dd.data(), d.data(), dd.size *
sizeof(QChar));
2801 dd.data()[dd.size] = 0;
2804 d->reallocate(alloc, option);
2808void QString::reallocGrowData(qsizetype n)
2813 if (d->needsDetach()) {
2814 DataPointer dd(DataPointer::allocateGrow(d, n, QArrayData::GrowsAtEnd));
2815 Q_CHECK_PTR(dd.data());
2816 dd->copyAppend(d.data(), d.data() + d.size);
2817 dd.data()[dd.size] = 0;
2820 d->reallocate(d.constAllocatedCapacity() + n, QArrayData::Grow);
2825
2826
2827
2828
2829
2832
2833
2834
2835
2837QString &QString::operator=(
const QString &other)
noexcept
2844
2845
2846
2847
2848
2849
2852
2853
2854
2855
2856
2857QString &QString::operator=(QLatin1StringView other)
2859 const qsizetype capacityAtEnd = capacity() - d.freeSpaceAtBegin();
2860 if (isDetached() && other.size() <= capacityAtEnd) {
2861 d.size = other.size();
2862 d.data()[other.size()] = 0;
2863 qt_from_latin1(d.data(), other.latin1(), other.size());
2865 *
this = fromLatin1(other.latin1(), other.size());
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2897
2898
2899
2900
2901QString &QString::operator=(QChar ch)
2903 return assign(1, ch);
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2926
2927
2928
2929
2930
2931
2932
2933
2934
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2967
2968
2969template <
typename T>
2972 auto &str_d = str.data_ptr();
2973 qsizetype difference = 0;
2974 if (Q_UNLIKELY(i > str_d.size))
2975 difference = i - str_d.size;
2976 const qsizetype oldSize = str_d.size;
2977 const qsizetype insert_size = toInsert.size();
2978 const qsizetype newSize = str_d.size + difference + insert_size;
2979 const auto side = i == 0 ? QArrayData::GrowsAtBeginning : QArrayData::GrowsAtEnd;
2981 if (str_d.needsDetach() || needsReallocate(str, newSize)) {
2982 const auto cbegin = str.cbegin();
2983 const auto cend = str.cend();
2984 const auto insert_start = difference == 0 ? std::next(cbegin, i) : cend;
2988 other.data_ptr().detachAndGrow(side, newSize,
nullptr,
nullptr);
2989 other.append(QStringView(cbegin, insert_start));
2990 other.resize(i, u' ');
2991 other.append(toInsert);
2992 other.append(QStringView(insert_start, cend));
2997 str_d.detachAndGrow(side, difference + insert_size,
nullptr,
nullptr);
2998 Q_CHECK_PTR(str_d.data());
2999 str.resize(newSize);
3001 auto begin = str_d.begin();
3002 auto old_end =
std::next(begin, oldSize);
3003 std::fill_n(old_end, difference, u' ');
3004 auto insert_start =
std::next(begin, i);
3005 if (difference == 0)
3006 std::move_backward(insert_start, old_end, str_d.end());
3008 using Char = std::remove_cv_t<
typename T::value_type>;
3009 if constexpr(std::is_same_v<Char, QChar>)
3010 std::copy_n(
reinterpret_cast<
const char16_t *>(toInsert.data()), insert_size, insert_start);
3011 else if constexpr (std::is_same_v<Char,
char16_t>)
3012 std::copy_n(toInsert.data(), insert_size, insert_start);
3013 else if constexpr (std::is_same_v<Char,
char>)
3014 qt_from_latin1(insert_start, toInsert.data(), insert_size);
3018
3019
3020
3021
3022
3023
3024
3025QString &QString::insert(qsizetype i, QLatin1StringView str)
3027 const char *s = str.latin1();
3028 if (i < 0 || !s || !(*s))
3031 insert_helper(*
this, i, str);
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048QString &QString::insert(qsizetype i, QUtf8StringView s)
3050 auto insert_size = s.size();
3051 if (i < 0 || insert_size <= 0)
3054 qsizetype difference = 0;
3055 if (Q_UNLIKELY(i > d.size))
3056 difference = i - d.size;
3058 const qsizetype newSize = d.size + difference + insert_size;
3060 if (d.needsDetach() || needsReallocate(*
this, newSize)) {
3061 const auto cbegin =
this->cbegin();
3062 const auto insert_start = difference == 0 ? std::next(cbegin, i) : cend();
3064 other.reserve(newSize);
3065 other.append(QStringView(cbegin, insert_start));
3067 other.resize(i, u' ');
3069 other.append(QStringView(insert_start, cend()));
3075 d.detachAndGrow(QArrayData::GrowsAtEnd, difference + insert_size,
nullptr,
nullptr);
3076 Q_CHECK_PTR(d.data());
3085 QVarLengthArray<
char16_t> buffer(insert_size);
3086 char16_t *b = QUtf8::convertToUnicode(buffer.data(), s);
3087 insert_helper(*
this, i, QStringView(buffer.data(), b));
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105QString& QString::insert(qsizetype i,
const QChar *unicode, qsizetype size)
3107 if (i < 0 || size <= 0)
3111 if (!d->needsDetach() && QtPrivate::q_points_into_range(unicode, *
this)) {
3112 QVarLengthArray copy(unicode, unicode + size);
3113 insert(i, copy.data(), size);
3115 insert_helper(*
this, i, QStringView(unicode, size));
3122
3123
3124
3125
3126
3127
3128
3129
3130
3132QString& QString::insert(qsizetype i, QChar ch)
3136 return insert(i, &ch, 1);
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157QString &QString::append(
const QString &str)
3159 if (!str.isNull()) {
3161 if (Q_UNLIKELY(!str.d.isMutable()))
3165 }
else if (str.size()) {
3166 append(str.constData(), str.size());
3173
3174
3175
3176
3177
3178
3181
3182
3183
3184
3185
3186QString &QString::append(
const QChar *str, qsizetype len)
3188 if (str && len > 0) {
3189 static_assert(
sizeof(QChar) ==
sizeof(
char16_t),
"Unexpected difference in sizes");
3191 const char16_t *char16String =
reinterpret_cast<
const char16_t *>(str);
3192 d->growAppend(char16String, char16String + len);
3193 d.data()[d.size] = u'\0';
3199
3200
3201
3202
3203QString &QString::append(QLatin1StringView str)
3205 append_helper(*
this, str);
3210
3211
3212
3213
3214
3215QString &QString::append(QUtf8StringView str)
3217 append_helper(*
this, str);
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3248
3249
3250
3251
3252QString &QString::append(QChar ch)
3254 d.detachAndGrow(QArrayData::GrowsAtEnd, 1,
nullptr,
nullptr);
3255 d->copyAppend(1, ch.unicode());
3256 d.data()[d.size] =
'\0';
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3277
3278
3279
3280
3281
3284
3285
3286
3287
3288
3291
3292
3293
3294
3295
3296
3299
3300
3301
3302
3303
3304
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3333
3334
3335
3336
3337
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
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
3397
3398
3399
3400
3401
3402
3403
3404
3406QString &QString::assign(QAnyStringView s)
3408 if (s.size() <= capacity() && isDetached()) {
3409 const auto offset = d.freeSpaceAtBegin();
3411 d.setBegin(d.begin() - offset);
3413 s.visit([
this](
auto input) {
3414 this->append(input);
3417 *
this = s.toString();
3422#ifndef QT_BOOTSTRAPPED
3423QString &QString::assign_helper(
const char32_t *data, qsizetype len)
3426 const auto requiredCapacity = len * 2;
3427 if (requiredCapacity <= capacity() && isDetached()) {
3428 const auto offset = d.freeSpaceAtBegin();
3430 d.setBegin(d.begin() - offset);
3431 auto begin =
reinterpret_cast<QChar *>(d.begin());
3432 auto ba = QByteArrayView(
reinterpret_cast<
const std::byte*>(data), len *
sizeof(
char32_t));
3433 QStringConverter::State state;
3434 const auto end = QUtf32::convertToUnicode(begin, ba, &state, DetectEndianness);
3435 d.size = end - begin;
3436 d.data()[d.size] = u'\0';
3438 *
this = QString::fromUcs4(data, len);
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466QString &QString::remove(qsizetype pos, qsizetype len)
3471 if (size_t(pos) >= size_t(size()) || len <= 0)
3474 len = std::min(len, size() - pos);
3476 if (!d->isShared()) {
3477 d->erase(d.begin() + pos, len);
3478 d.data()[d.size] = u'\0';
3483 const qsizetype sz = size() - len;
3484 QString copy{sz, Qt::Uninitialized};
3485 auto begin = d.begin();
3486 auto toRemove_start = d.begin() + pos;
3487 copy.d->copyRanges({{begin, toRemove_start},
3488 {toRemove_start + len, d.end()}});
3497 const auto needleSize = needle.size();
3502 qsizetype i = s.indexOf(needle, 0, cs);
3506 QString::DataPointer &dptr = s.data_ptr();
3507 auto begin = dptr.begin();
3508 auto end = dptr.end();
3510 auto copyFunc = [&](
auto &dst) {
3511 auto src = begin + i + needleSize;
3513 i = s.indexOf(needle, std::distance(begin, src), cs);
3514 auto hit = i == -1 ? end : begin + i;
3515 dst =
std::copy(src, hit, dst);
3516 src = hit + needleSize;
3521 if (!dptr->needsDetach()) {
3522 auto dst = begin + i;
3523 dst = copyFunc(dst);
3524 s.truncate(
std::distance(begin, dst));
3526 QString copy{s.size(), Qt::Uninitialized};
3527 auto copy_begin = copy.begin();
3528 auto dst = std::copy(begin, begin + i, copy_begin);
3529 dst = copyFunc(dst);
3530 copy.resize(
std::distance(copy_begin, dst));
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547QString &QString::remove(
const QString &str, Qt::CaseSensitivity cs)
3549 const auto s = str.d.data();
3550 if (QtPrivate::q_points_into_range(s, d))
3551 removeStringImpl(*
this, QStringView{QVarLengthArray(s, s + str.size())}, cs);
3553 removeStringImpl(*
this, qToStringViewIgnoringNull(str), cs);
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572QString &QString::remove(QLatin1StringView str, Qt::CaseSensitivity cs)
3574 removeStringImpl(*
this, str, cs);
3579
3580
3581
3582
3583
3584
3585
3586
3587
3590
3591
3592
3593
3594
3595
3596
3597
3598
3601
3602
3603
3604
3605
3606
3607
3608
3609
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627QString &QString::remove(QChar ch, Qt::CaseSensitivity cs)
3629 const qsizetype idx = indexOf(ch, 0, cs);
3633 const bool isCase = cs == Qt::CaseSensitive;
3634 ch = isCase ? ch : ch.toCaseFolded();
3635 auto match = [ch, isCase](QChar x) {
3636 return ch == (isCase ? x : x.toCaseFolded());
3640 auto begin = d.begin();
3641 auto first_match = begin + idx;
3643 if (!d->isShared()) {
3644 auto it = std::remove_if(first_match, end, match);
3645 d->erase(it, std::distance(it, end));
3646 d.data()[d.size] = u'\0';
3651 QString copy{size(), Qt::Uninitialized};
3652 auto dst = copy.d.begin();
3653 auto it = std::copy(begin, first_match, dst);
3654 it = std::remove_copy_if(first_match + 1, end, it, match);
3655 copy.d.size = std::distance(dst, it);
3656 copy.d.data()[copy.d.size] = u'\0';
3657 *
this = std::move(copy);
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3677
3678
3679
3680
3681
3682
3683
3684
3688
3689
3690
3691
3695 const qsizetype alen = after.size();
3696 const char16_t *after_b = after.utf16();
3698 const QString::DataPointer &str_d = str.data_ptr();
3699 auto src_start = str_d.begin();
3700 const qsizetype newSize = str_d.size + indices.size() * (alen - blen);
3701 QString copy{ newSize, Qt::Uninitialized };
3702 QString::DataPointer ©_d = copy.data_ptr();
3703 auto dst = copy_d.begin();
3704 for (size_t index : indices) {
3705 auto hit = str_d.begin() + index;
3706 dst = std::copy(src_start, hit, dst);
3707 dst = std::copy_n(after_b, alen, dst);
3708 src_start = hit + blen;
3710 dst =
std::copy(src_start, str_d.end(), dst);
3716 qsizetype blen, QStringView after)
3718 const qsizetype alen = after.size();
3719 const char16_t *after_b = after.utf16();
3720 const char16_t *after_e = after.utf16() + after.size();
3723 for (size_t index : indices)
3724 std::copy_n(after_b, alen, str.data_ptr().begin() + index);
3725 }
else if (blen > alen) {
3726 char16_t *begin = str.data_ptr().begin();
3727 char16_t *hit = begin + indices.front();
3729 to =
std::copy_n(after_b, alen, to);
3730 char16_t *movestart = hit + blen;
3731 for (size_t index : indices.sliced(1)) {
3732 hit = begin + index;
3733 to = std::move(movestart, hit, to);
3734 to = std::copy_n(after_b, alen, to);
3735 movestart = hit + blen;
3737 to =
std::move(movestart, str.data_ptr().end(), to);
3738 str.resize(
std::distance(begin, to));
3740 const qsizetype oldSize = str.data_ptr().size;
3741 const qsizetype adjust = indices.size() * (alen - blen);
3742 const qsizetype newSize = oldSize + adjust;
3744 str.resize(newSize);
3745 char16_t *begin = str.data_ptr().begin();
3746 char16_t *moveend = begin + oldSize;
3747 char16_t *to = str.data_ptr().end();
3749 for (
auto it = indices.rbegin(), end = indices.rend(); it != end; ++it) {
3750 char16_t *hit = begin + *it;
3751 char16_t *movestart = hit + blen;
3752 to =
std::move_backward(movestart, moveend, to);
3753 to =
std::copy_backward(after_b, after_e, to);
3759static void replace_helper(QString &str, QSpan<size_t> indices, qsizetype blen, QStringView after)
3761 const qsizetype oldSize = str.data_ptr().size;
3762 const qsizetype adjust = indices.size() * (after.size() - blen);
3763 const qsizetype newSize = oldSize + adjust;
3764 if (str.data_ptr().needsDetach() || needsReallocate(str, newSize)) {
3765 replace_with_copy(str, indices, blen, after);
3769 if (QtPrivate::q_points_into_range(after.begin(), str))
3772 replace_in_place(str, indices, blen,
QVarLengthArray(after.begin(), after.end()));
3774 replace_in_place(str, indices, blen, after);
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793QString &QString::replace(qsizetype pos, qsizetype len,
const QString &after)
3795 return replace(pos, len, after.constData(), after.size());
3799
3800
3801
3802
3803
3804
3805
3806
3807QString &QString::replace(qsizetype pos, qsizetype len,
const QChar *after, qsizetype alen)
3811 if (size_t(pos) > size_t(
this->size()))
3813 if (len >
this->size() - pos)
3814 len =
this->size() - pos;
3817 replace_helper(*
this, QSpan(&index, 1), len, QStringView{after, alen});
3822
3823
3824
3825
3826
3827
3828QString &QString::replace(qsizetype pos, qsizetype len, QChar after)
3830 return replace(pos, len, &after, 1);
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856QString &QString::replace(
const QString &before,
const QString &after, Qt::CaseSensitivity cs)
3858 return replace(before.constData(), before.size(), after.constData(), after.size(), cs);
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875QString &QString::replace(
const QChar *before, qsizetype blen,
3876 const QChar *after, qsizetype alen,
3877 Qt::CaseSensitivity cs)
3883 if (cs == Qt::CaseSensitive && before == after && blen == alen)
3886 if (alen == 0 && blen == 0)
3888 if (alen == 1 && blen == 1)
3889 return replace(*before, *after, cs);
3891 QStringMatcher matcher(before, blen, cs);
3893 qsizetype index = 0;
3895 QVarLengthArray<size_t> indices;
3896 while ((index = matcher.indexIn(*
this, index)) != -1) {
3897 indices.push_back(index);
3903 if (indices.isEmpty())
3906 replace_helper(*
this, indices, blen, QStringView{after, alen});
3911
3912
3913
3914
3915
3916
3917QString& QString::replace(QChar ch,
const QString &after, Qt::CaseSensitivity cs)
3919 if (after.size() == 0)
3920 return remove(ch, cs);
3922 if (after.size() == 1)
3923 return replace(ch, after.front(), cs);
3928 const char16_t cc = (cs == Qt::CaseSensitive ? ch.unicode() : ch.toCaseFolded().unicode());
3930 QVarLengthArray<size_t> indices;
3931 if (cs == Qt::CaseSensitive) {
3932 const char16_t *begin = d.begin();
3933 const char16_t *end = d.end();
3934 QStringView view(begin, end);
3935 const char16_t *hit =
nullptr;
3936 while ((hit = QtPrivate::qustrchr(view, cc)) != end) {
3937 indices.push_back(std::distance(begin, hit));
3938 view = QStringView(std::next(hit), end);
3941 for (qsizetype i = 0; i < d.size; ++i)
3942 if (QChar::toCaseFolded(d.data()[i]) == cc)
3943 indices.push_back(i);
3945 if (indices.isEmpty())
3948 replace_helper(*
this, indices, 1, after);
3953
3954
3955
3956
3957
3958
3959QString& QString::replace(QChar before, QChar after, Qt::CaseSensitivity cs)
3961 const qsizetype idx = indexOf(before, 0, cs);
3965 const char16_t achar = after.unicode();
3966 char16_t bchar = before.unicode();
3968 auto matchesCIS = [](
char16_t beforeChar) {
3969 return [beforeChar](
char16_t ch) {
return foldAndCompare(ch, beforeChar); };
3972 auto hit = d.begin() + idx;
3973 if (!d.needsDetach()) {
3975 if (cs == Qt::CaseSensitive) {
3976 std::replace(hit, d.end(), bchar, achar);
3978 bchar = foldCase(bchar);
3979 std::replace_if(hit, d.end(), matchesCIS(bchar), achar);
3982 QString other{ d.size, Qt::Uninitialized };
3983 auto dest = std::copy(d.begin(), hit, other.d.begin());
3986 if (cs == Qt::CaseSensitive) {
3987 std::replace_copy(hit, d.end(), dest, bchar, achar);
3989 bchar = foldCase(bchar);
3990 std::replace_copy_if(hit, d.end(), dest, matchesCIS(bchar), achar);
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012QString &QString::replace(QLatin1StringView before, QLatin1StringView after, Qt::CaseSensitivity cs)
4014 const qsizetype alen = after.size();
4015 const qsizetype blen = before.size();
4016 if (blen == 1 && alen == 1)
4017 return replace(before.front(), after.front(), cs);
4019 QVarLengthArray<
char16_t> a = qt_from_latin1_to_qvla(after);
4020 QVarLengthArray<
char16_t> b = qt_from_latin1_to_qvla(before);
4021 return replace((
const QChar *)b.data(), blen, (
const QChar *)a.data(), alen, cs);
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038QString &QString::replace(QLatin1StringView before,
const QString &after, Qt::CaseSensitivity cs)
4040 const qsizetype blen = before.size();
4041 if (blen == 1 && after.size() == 1)
4042 return replace(before.front(), after.front(), cs);
4044 QVarLengthArray<
char16_t> b = qt_from_latin1_to_qvla(before);
4045 return replace((
const QChar *)b.data(), blen, after.constData(), after.d.size, cs);
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061QString &QString::replace(
const QString &before, QLatin1StringView after, Qt::CaseSensitivity cs)
4063 const qsizetype alen = after.size();
4064 if (before.size() == 1 && alen == 1)
4065 return replace(before.front(), after.front(), cs);
4067 QVarLengthArray<
char16_t> a = qt_from_latin1_to_qvla(after);
4068 return replace(before.constData(), before.d.size, (
const QChar *)a.data(), alen, cs);
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity cs)
4084 const qsizetype alen = after.size();
4086 return replace(c, after.front(), cs);
4088 QVarLengthArray<
char16_t> a = qt_from_latin1_to_qvla(after);
4089 return replace(&c, 1, (
const QChar *)a.data(), alen, cs);
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4105
4106
4107
4108
4109
4110
4111
4114
4115
4116
4117
4118
4119
4120
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4150
4151
4152
4153
4154
4155
4156
4157
4158
4161
4162
4163
4164
4165
4166
4167
4170
4171
4172
4173
4174
4175
4176
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4208
4209
4210
4211
4212
4213
4216
4217
4218
4219
4220
4221
4222
4225
4226
4227
4228
4229
4230
4231
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4260
4261
4262
4263
4264
4265
4268
4269
4270
4271
4272
4273
4274
4277
4278
4279
4280
4281
4282
4283
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4312
4313
4314
4315
4316
4317
4320
4321
4322
4323
4324
4325
4326
4329
4330
4331
4332
4333
4334
4335
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4364
4365
4366
4367
4368
4369
4372
4373
4374
4375
4376
4377
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502qsizetype QString::indexOf(
const QString &str, qsizetype from, Qt::CaseSensitivity cs)
const
4504 return QtPrivate::findString(QStringView(unicode(), size()), from, QStringView(str.unicode(), str.size()), cs);
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4537qsizetype QString::indexOf(QLatin1StringView str, qsizetype from, Qt::CaseSensitivity cs)
const
4539 return QtPrivate::findString(QStringView(unicode(), size()), from, str, cs);
4543
4544
4545
4546
4547
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571qsizetype QString::lastIndexOf(
const QString &str, qsizetype from, Qt::CaseSensitivity cs)
const
4573 return QtPrivate::lastIndexOf(QStringView(*
this), from, str, cs);
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619qsizetype QString::lastIndexOf(QLatin1StringView str, qsizetype from, Qt::CaseSensitivity cs)
const
4621 return QtPrivate::lastIndexOf(*
this, from, str, cs);
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4642
4643
4644
4645
4646
4649
4650
4651
4652
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4690#if QT_CONFIG(regularexpression)
4691struct QStringCapture
4697Q_DECLARE_TYPEINFO(QStringCapture, Q_PRIMITIVE_TYPE);
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717QString &QString::replace(
const QRegularExpression &re,
const QString &after)
4719 if (!re.isValid()) {
4720 qtWarnAboutInvalidRegularExpression(re,
"QString",
"replace");
4724 const QString copy(*
this);
4725 QRegularExpressionMatchIterator iterator = re.globalMatch(copy);
4726 if (!iterator.hasNext())
4729 reallocData(d.size, QArrayData::KeepSize);
4731 qsizetype numCaptures = re.captureCount();
4735 QVarLengthArray<QStringCapture> backReferences;
4736 const qsizetype al = after.size();
4737 const QChar *ac = after.unicode();
4739 for (qsizetype i = 0; i < al - 1; i++) {
4740 if (ac[i] == u'\\') {
4741 int no = ac[i + 1].digitValue();
4742 if (no > 0 && no <= numCaptures) {
4743 QStringCapture backReference;
4744 backReference.pos = i;
4745 backReference.len = 2;
4748 int secondDigit = ac[i + 2].digitValue();
4749 if (secondDigit != -1 && ((no * 10) + secondDigit) <= numCaptures) {
4750 no = (no * 10) + secondDigit;
4751 ++backReference.len;
4755 backReference.no = no;
4756 backReferences.append(backReference);
4765 qsizetype newLength = 0;
4766 qsizetype lastEnd = 0;
4767 QVarLengthArray<QStringView> chunks;
4768 const QStringView copyView{ copy }, afterView{ after };
4769 while (iterator.hasNext()) {
4770 QRegularExpressionMatch match = iterator.next();
4773 len = match.capturedStart() - lastEnd;
4775 chunks << copyView.mid(lastEnd, len);
4781 for (
const QStringCapture &backReference : std::as_const(backReferences)) {
4783 len = backReference.pos - lastEnd;
4785 chunks << afterView.mid(lastEnd, len);
4790 len = match.capturedLength(backReference.no);
4792 chunks << copyView.mid(match.capturedStart(backReference.no), len);
4796 lastEnd = backReference.pos + backReference.len;
4800 len = afterView.size() - lastEnd;
4802 chunks << afterView.mid(lastEnd, len);
4806 lastEnd = match.capturedEnd();
4810 if (copyView.size() > lastEnd) {
4811 chunks << copyView.mid(lastEnd);
4812 newLength += copyView.size() - lastEnd;
4819 for (
const QStringView &chunk : std::as_const(chunks)) {
4820 qsizetype len = chunk.size();
4821 memcpy(uc + i, chunk.constData(), len *
sizeof(QChar));
4830
4831
4832
4833
4834
4835
4836
4838qsizetype QString::count(
const QString &str, Qt::CaseSensitivity cs)
const
4840 return QtPrivate::count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs);
4844
4845
4846
4847
4848
4849
4850
4851
4853qsizetype QString::count(QChar ch, Qt::CaseSensitivity cs)
const
4855 return QtPrivate::count(QStringView(unicode(), size()), ch, cs);
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868qsizetype QString::count(QStringView str, Qt::CaseSensitivity cs)
const
4870 return QtPrivate::count(*
this, str, cs);
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4887
4888
4889
4890
4891
4892
4893
4896
4897
4898
4899
4900
4901
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4915#if QT_CONFIG(regularexpression)
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931qsizetype QString::indexOf(
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
const
4933 return QtPrivate::indexOf(QStringView(*
this),
this, re, from, rmatch);
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967qsizetype QString::lastIndexOf(
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
const
4969 return QtPrivate::lastIndexOf(QStringView(*
this),
this, re, from, rmatch);
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5006bool QString::contains(
const QRegularExpression &re, QRegularExpressionMatch *rmatch)
const
5008 return QtPrivate::contains(QStringView(*
this),
this, re, rmatch);
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029qsizetype QString::count(
const QRegularExpression &re)
const
5031 return QtPrivate::count(QStringView(*
this), re);
5035#if QT_DEPRECATED_SINCE(6
, 4
)
5037
5038
5039
5040
5041
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5100
5101
5102
5103
5104
5105
5106
5108QString QString::section(
const QString &sep, qsizetype start, qsizetype end, SectionFlags flags)
const
5110 const QList<QStringView> sections = QStringView{ *
this }.split(
5111 sep, Qt::KeepEmptyParts, (flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive : Qt::CaseSensitive);
5112 const qsizetype sectionsSize = sections.size();
5113 if (!(flags & SectionSkipEmpty)) {
5115 start += sectionsSize;
5117 end += sectionsSize;
5120 for (qsizetype k = 0; k < sectionsSize; ++k) {
5121 if (sections.at(k).isEmpty())
5125 start += sectionsSize - skip;
5127 end += sectionsSize - skip;
5129 if (start >= sectionsSize || end < 0 || start > end)
5133 qsizetype first_i = start, last_i = end;
5134 for (qsizetype x = 0, i = 0; x <= end && i < sectionsSize; ++i) {
5135 const QStringView §ion = sections.at(i);
5136 const bool empty = section.isEmpty();
5142 if (x > start && i > 0)
5146 if (!empty || !(flags & SectionSkipEmpty))
5149 if ((flags & SectionIncludeLeadingSep) && first_i > 0)
5151 if ((flags & SectionIncludeTrailingSep) && last_i < sectionsSize - 1)
5156#if QT_CONFIG(regularexpression)
5157struct qt_section_chunk
5162Q_DECLARE_TYPEINFO(qt_section_chunk, Q_RELOCATABLE_TYPE);
5164static QString extractSections(QSpan<qt_section_chunk> sections, qsizetype start, qsizetype end,
5165 QString::SectionFlags flags)
5167 const qsizetype sectionsSize = sections.size();
5169 if (!(flags & QString::SectionSkipEmpty)) {
5171 start += sectionsSize;
5173 end += sectionsSize;
5176 for (qsizetype k = 0; k < sectionsSize; ++k) {
5177 const qt_section_chunk §ion = sections[k];
5178 if (section.length == section.string.size())
5182 start += sectionsSize - skip;
5184 end += sectionsSize - skip;
5186 if (start >= sectionsSize || end < 0 || start > end)
5191 qsizetype first_i = start, last_i = end;
5192 for (qsizetype i = 0; x <= end && i < sectionsSize; ++i) {
5193 const qt_section_chunk §ion = sections[i];
5194 const bool empty = (section.length == section.string.size());
5201 ret += section.string;
5203 ret += section.string.mid(section.length);
5205 if (!empty || !(flags & QString::SectionSkipEmpty))
5209 if ((flags & QString::SectionIncludeLeadingSep) && first_i >= 0) {
5210 const qt_section_chunk §ion = sections[first_i];
5211 ret.prepend(section.string.left(section.length));
5214 if ((flags & QString::SectionIncludeTrailingSep)
5215 && last_i < sectionsSize - 1) {
5216 const qt_section_chunk §ion = sections[last_i + 1];
5217 ret += section.string.left(section.length);
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237QString QString::section(
const QRegularExpression &re, qsizetype start, qsizetype end, SectionFlags flags)
const
5239 if (!re.isValid()) {
5240 qtWarnAboutInvalidRegularExpression(re,
"QString",
"section");
5244 const QChar *uc = unicode();
5248 QRegularExpression sep(re);
5249 if (flags & SectionCaseInsensitiveSeps)
5250 sep.setPatternOptions(sep.patternOptions() | QRegularExpression::CaseInsensitiveOption);
5252 QVarLengthArray<qt_section_chunk> sections;
5253 qsizetype n = size(), m = 0, last_m = 0, last_len = 0;
5254 QRegularExpressionMatchIterator iterator = sep.globalMatch(*
this);
5255 while (iterator.hasNext()) {
5256 QRegularExpressionMatch match = iterator.next();
5257 m = match.capturedStart();
5258 sections.append(qt_section_chunk{last_len, QStringView{*
this}.sliced(last_m, m - last_m)});
5260 last_len = match.capturedLength();
5262 sections.append(qt_section_chunk{last_len, QStringView{*
this}.sliced(last_m, n - last_m)});
5264 return extractSections(sections, start, end, flags);
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320QString QString::mid(qsizetype position, qsizetype n)
const &
5322 qsizetype p = position;
5324 using namespace QtPrivate;
5325 switch (QContainerImplHelper::mid(size(), &p, &l)) {
5326 case QContainerImplHelper::Null:
5328 case QContainerImplHelper::Empty:
5329 return QString(DataPointer::fromRawData(&_empty, 0));
5330 case QContainerImplHelper::Full:
5332 case QContainerImplHelper::Subset:
5333 return sliced(p, l);
5335 Q_UNREACHABLE_RETURN(QString());
5338QString QString::mid(qsizetype position, qsizetype n) &&
5340 qsizetype p = position;
5342 using namespace QtPrivate;
5343 switch (QContainerImplHelper::mid(size(), &p, &l)) {
5344 case QContainerImplHelper::Null:
5346 case QContainerImplHelper::Empty:
5349 case QContainerImplHelper::Full:
5350 return std::move(*
this);
5351 case QContainerImplHelper::Subset:
5352 return std::move(*
this).sliced(p, l);
5354 Q_UNREACHABLE_RETURN(QString());
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403QString QString::sliced_helper(QString &str, qsizetype pos, qsizetype n)
5406 return QString(DataPointer::fromRawData(&_empty, 0));
5407 DataPointer d = std::move(str.d).sliced(pos, n);
5409 return QString(std::move(d));
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478bool QString::startsWith(
const QString& s, Qt::CaseSensitivity cs)
const
5480 return qt_starts_with_impl(QStringView(*
this), QStringView(s), cs);
5484
5485
5486bool QString::startsWith(QLatin1StringView s, Qt::CaseSensitivity cs)
const
5488 return qt_starts_with_impl(QStringView(*
this), s, cs);
5492
5493
5494
5495
5496
5497bool QString::startsWith(QChar c, Qt::CaseSensitivity cs)
const
5501 if (cs == Qt::CaseSensitive)
5503 return foldCase(at(0)) == foldCase(c);
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529bool QString::endsWith(
const QString &s, Qt::CaseSensitivity cs)
const
5531 return qt_ends_with_impl(QStringView(*
this), QStringView(s), cs);
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5547
5548
5549bool QString::endsWith(QLatin1StringView s, Qt::CaseSensitivity cs)
const
5551 return qt_ends_with_impl(QStringView(*
this), s, cs);
5555
5556
5557
5558
5559
5560bool QString::endsWith(QChar c, Qt::CaseSensitivity cs)
const
5564 if (cs == Qt::CaseSensitive)
5565 return at(size() - 1) == c;
5566 return foldCase(at(size() - 1)) == foldCase(c);
5573 const char32_t uc = it
.next();
5574 if (caseConversion(uc)[c].diff)
5582 return checkCase(s, QUnicodeTables::LowerCase);
5587 return checkCase(s, QUnicodeTables::UpperCase);
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603bool QString::isUpper()
const
5605 return QtPrivate::isUpper(qToStringViewIgnoringNull(*
this));
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621bool QString::isLower()
const
5623 return QtPrivate::isLower(qToStringViewIgnoringNull(*
this));
5628QByteArray QString::toLatin1_helper(
const QString &string)
5630 return qt_convert_to_latin1(string);
5634
5635
5636
5637
5638
5639
5640
5641
5642
5645 return string.visit([] (
auto string) {
return string.toString(); });
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5662 return qt_convert_to_latin1(string);
5666static QByteArray qt_convert_to_latin1(QStringView string)
5668 if (Q_UNLIKELY(string.isNull()))
5669 return QByteArray();
5671 QByteArray ba(string.size(), Qt::Uninitialized);
5675 qt_to_latin1(
reinterpret_cast<uchar *>(
const_cast<
char *>(ba.constData())),
5676 string.utf16(), string.size());
5680QByteArray QString::toLatin1_helper_inplace(QString &s)
5682 if (!s.isDetached())
5683 return qt_convert_to_latin1(s);
5691 qsizetype length = s.size();
5692 char16_t *sdata = s.d->data();
5693 Q_ASSERT(sdata[length] == u'\0');
5694 qt_to_latin1(
reinterpret_cast<uchar *>(sdata), sdata, length + 1);
5698 auto ba_d = std::move(s.d).reinterpreted<
char>();
5701 Q_ASSERT(ba_d.d->allocatedCapacity() >= ba_d.size);
5702 Q_ASSERT(s.isNull());
5703 Q_ASSERT(s.isEmpty());
5704 Q_ASSERT(s.constData() == QString().constData());
5706 return QByteArray(std::move(ba_d));
5710
5711
5712
5713
5714
5715
5718 if (Q_UNLIKELY(string.isNull()))
5719 return QByteArray();
5722 QByteArray ba(string.size() * 2, Qt::Uninitialized);
5723 const qsizetype sz = QUtf8::convertFromLatin1(ba.data(), string) - ba.data();
5730char16_t *QLatin1::convertToUnicode(
char16_t *out, QLatin1StringView in)
noexcept
5732 const qsizetype len = in.size();
5733 qt_from_latin1(out, in.data(), len);
5734 return std::next(out, len);
5737char *QLatin1::convertFromUnicode(
char *out, QStringView in)
noexcept
5739 const qsizetype len = in.size();
5740 qt_to_latin1(
reinterpret_cast<uchar *>(out), in.utf16(), len);
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5773QByteArray QString::toLocal8Bit_helper(
const QChar *data, qsizetype size)
5775 return qt_convert_to_local_8bit(QStringView(data, size));
5780 if (string.isNull())
5781 return QByteArray();
5782 QStringEncoder fromUtf16(QStringEncoder::System, QStringEncoder::Flag::Stateless);
5783 return fromUtf16(string);
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5803 return qt_convert_to_local_8bit(string);
5809
5810
5811
5812
5813
5814
5815
5816
5817
5819QByteArray QString::toUtf8_helper(
const QString &str)
5821 return qt_convert_to_utf8(str);
5827 return QByteArray();
5829 return QUtf8::convertFromUnicode(str);
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5846 return qt_convert_to_utf8(string);
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866QList<uint> QString::toUcs4()
const
5868 return qt_convert_to_ucs4(*
this);
5873 QList<uint> v(string.size());
5874 uint *a =
const_cast<uint*>(v.constData());
5878 v.resize(a - v.constData());
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5901 return qt_convert_to_ucs4(string);
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914QString QString::fromLatin1(QByteArrayView ba)
5919 }
else if (ba.size() == 0) {
5920 d = DataPointer::fromRawData(&_empty, 0);
5922 d = DataPointer(ba.size(), ba.size());
5923 Q_CHECK_PTR(d.data());
5924 d.data()[ba.size()] =
'\0';
5925 char16_t *dst = d.data();
5927 qt_from_latin1(dst, ba.data(), size_t(ba.size()));
5929 return QString(std::move(d));
5933
5934
5935
5936
5937
5938
5939
5940
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992QString QString::fromLocal8Bit(QByteArrayView ba)
5997 return QString(DataPointer::fromRawData(&_empty, 0));
5998 QStringDecoder toUtf16(QStringDecoder::System, QStringDecoder::Flag::Stateless);
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6024
6025
6026
6027
6028
6029
6032
6033
6034
6035
6036
6037
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061QString QString::fromUtf8(QByteArrayView ba)
6066 return QString(DataPointer::fromRawData(&_empty, 0));
6067 return QUtf8::convertToUnicode(ba);
6070#ifndef QT_BOOTSTRAPPED
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088QString QString::fromUtf16(
const char16_t *unicode, qsizetype size)
6093 size = QtPrivate::qustrlen(unicode);
6094 QStringDecoder toUtf16(QStringDecoder::Utf16, QStringDecoder::Flag::Stateless);
6095 return toUtf16(QByteArrayView(
reinterpret_cast<
const char *>(unicode), size * 2));
6099
6100
6101
6104
6105
6106
6107
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120QString QString::fromUcs4(
const char32_t *unicode, qsizetype size)
6125 if constexpr (
sizeof(
char32_t) ==
sizeof(
wchar_t))
6126 size = wcslen(
reinterpret_cast<
const wchar_t *>(unicode));
6128 size = std::char_traits<
char32_t>::length(unicode);
6130 QStringDecoder toUtf16(QStringDecoder::Utf32, QStringDecoder::Flag::Stateless);
6131 return toUtf16(QByteArrayView(
reinterpret_cast<
const char *>(unicode), size * 4));
6136
6137
6138
6139
6140
6141
6142
6143
6144QString& QString::setUnicode(
const QChar *unicode, qsizetype size)
6147 if (unicode && size)
6148 memcpy(d.data(), unicode, size *
sizeof(QChar));
6153
6154
6155
6156
6157
6158
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6177
6178
6179
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198QString QString::simplified_helper(
const QString &str)
6200 return QStringAlgorithms<
const QString>::simplified_helper(str);
6203QString QString::simplified_helper(QString &str)
6205 return QStringAlgorithms<QString>::simplified_helper(str);
6209 template <
typename StringView>
6210 StringView qt_trimmed(StringView s)
noexcept
6212 const auto [begin, end] = QStringAlgorithms<
const StringView>::trimmed_helper_positions(s);
6213 return StringView{begin, end};
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6234 return qt_trimmed(s);
6237QLatin1StringView
QtPrivate::trimmed(QLatin1StringView s)
noexcept
6239 return qt_trimmed(s);
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260QString QString::trimmed_helper(
const QString &str)
6262 return QStringAlgorithms<
const QString>::trimmed_helper(str);
6265QString QString::trimmed_helper(QString &str)
6267 return QStringAlgorithms<QString>::trimmed_helper(str);
6271
6272
6273
6274
6275
6276
6277
6278
6279
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6295
6296
6297
6298
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6378void QString::truncate(qsizetype pos)
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399void QString::chop(qsizetype n)
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6417QString& QString::fill(QChar ch, qsizetype size)
6419 resize(size < 0 ? d.size : size);
6421 std::fill(d.data(), d.data() + d.size, ch.unicode());
6426
6427
6428
6429
6430
6431
6432
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6448
6449
6450
6451
6452
6453
6454
6455
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6503
6504
6505
6506
6507
6510
6511
6512
6513
6514
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6545
6546
6547
6548
6549
6552
6553
6554
6555
6556
6559
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
6597
6600
6601
6602
6603
6604
6605
6606
6609
6610
6611
6612
6613
6614
6615
6616
6619
6620
6621
6622
6623
6624
6625
6628
6629
6630
6631
6632
6633
6634
6635
6636
6639
6640
6641
6642
6643
6644
6645
6646
6647
6650
6651
6652
6653
6654
6655
6656
6657
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
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
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733int QString::compare(
const QString &other, Qt::CaseSensitivity cs)
const noexcept
6735 return QtPrivate::compareStrings(*
this, other, cs);
6739
6740
6741
6742int QString::compare_helper(
const QChar *data1, qsizetype length1,
const QChar *data2, qsizetype length2,
6743 Qt::CaseSensitivity cs)
noexcept
6745 Q_ASSERT(length1 >= 0);
6746 Q_ASSERT(length2 >= 0);
6747 Q_ASSERT(data1 || length1 == 0);
6748 Q_ASSERT(data2 || length2 == 0);
6749 return QtPrivate::compareStrings(QStringView(data1, length1), QStringView(data2, length2), cs);
6753
6754
6755
6756
6757
6758int QString::compare(QLatin1StringView other, Qt::CaseSensitivity cs)
const noexcept
6760 return QtPrivate::compareStrings(*
this, other, cs);
6764
6765
6766
6767int QString::compare_helper(
const QChar *data1, qsizetype length1,
const char *data2, qsizetype length2,
6768 Qt::CaseSensitivity cs)
noexcept
6770 Q_ASSERT(length1 >= 0);
6771 Q_ASSERT(data1 || length1 == 0);
6773 return qt_lencmp(length1, 0);
6774 if (Q_UNLIKELY(length2 < 0))
6775 length2 = qsizetype(strlen(data2));
6776 return QtPrivate::compareStrings(QStringView(data1, length1),
6777 QUtf8StringView(data2, length2), cs);
6781
6782
6783
6786
6787
6788
6792 return QtPrivate::equalStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6797 const int res = QtPrivate::compareStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6798 return Qt::compareThreeWay(res, 0);
6803 return QtPrivate::equalStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6808 const int res = QtPrivate::compareStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6809 return Qt::compareThreeWay(res, 0);
6814 return QtPrivate::equalStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6819 const int res = QtPrivate::compareStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6820 return Qt::compareThreeWay(res, 0);
6825 return QtPrivate::equalStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6830 const int res = QtPrivate::compareStrings(QUtf8StringView(lhs), QStringView(&rhs, 1));
6831 return Qt::compareThreeWay(res, 0);
6835
6836
6837
6838bool QT_FASTCALL QChar::equal_helper(QChar lhs,
const char *rhs)
noexcept
6840 return QtPrivate::equalStrings(QStringView(&lhs, 1), QUtf8StringView(rhs));
6843int QT_FASTCALL QChar::compare_helper(QChar lhs,
const char *rhs)
noexcept
6845 return QtPrivate::compareStrings(QStringView(&lhs, 1), QUtf8StringView(rhs));
6849
6850
6851
6852bool QStringView::equal_helper(QStringView sv,
const char *data, qsizetype len)
6855 Q_ASSERT(data || len == 0);
6856 return QtPrivate::equalStrings(sv, QUtf8StringView(data, len));
6860
6861
6862
6863int QStringView::compare_helper(QStringView sv,
const char *data, qsizetype len)
6866 Q_ASSERT(data || len == 0);
6867 return QtPrivate::compareStrings(sv, QUtf8StringView(data, len));
6871
6872
6873
6874bool QLatin1StringView::equal_helper(QLatin1StringView s1,
const char *s2, qsizetype len)
noexcept
6878 Q_ASSERT(s2 || len == 0);
6879 return QtPrivate::equalStrings(s1, QUtf8StringView(s2, len));
6883
6884
6885
6886int QLatin1StringView::compare_helper(
const QLatin1StringView &s1,
const char *s2, qsizetype len)
noexcept
6890 Q_ASSERT(s2 || len == 0);
6891 return QtPrivate::compareStrings(s1, QUtf8StringView(s2, len));
6895
6896
6897
6898int QLatin1StringView::compare_helper(
const QChar *data1, qsizetype length1, QLatin1StringView s2,
6899 Qt::CaseSensitivity cs)
noexcept
6901 Q_ASSERT(length1 >= 0);
6902 Q_ASSERT(data1 || length1 == 0);
6903 return QtPrivate::compareStrings(QStringView(data1, length1), s2, cs);
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6955#if !defined(CSTR_LESS_THAN)
6956#define CSTR_LESS_THAN 1
6958#define CSTR_GREATER_THAN 3
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976int QString::localeAwareCompare(
const QString &other)
const
6978 return localeAwareCompare_helper(constData(), size(), other.constData(), other.size());
6982
6983
6984
6985int QString::localeAwareCompare_helper(
const QChar *data1, qsizetype length1,
6986 const QChar *data2, qsizetype length2)
6988 Q_ASSERT(length1 >= 0);
6989 Q_ASSERT(data1 || length1 == 0);
6990 Q_ASSERT(length2 >= 0);
6991 Q_ASSERT(data2 || length2 == 0);
6994 if (length1 == 0 || length2 == 0)
6995 return QtPrivate::compareStrings(QStringView(data1, length1), QStringView(data2, length2),
6999 return QCollator::defaultCompare(QStringView(data1, length1), QStringView(data2, length2));
7001 const QString lhs = QString::fromRawData(data1, length1).normalized(QString::NormalizationForm_C);
7002 const QString rhs = QString::fromRawData(data2, length2).normalized(QString::NormalizationForm_C);
7003# if defined(Q_OS_WIN)
7004 int res = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, (LPWSTR)lhs.constData(), lhs.length(), (LPWSTR)rhs.constData(), rhs.length(), NULL, NULL, 0);
7007 case CSTR_LESS_THAN:
7009 case CSTR_GREATER_THAN:
7014# elif defined (Q_OS_DARWIN)
7019 const CFStringRef thisString =
7020 CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault,
7021 reinterpret_cast<
const UniChar *>(lhs.constData()), lhs.length(), kCFAllocatorNull);
7022 const CFStringRef otherString =
7023 CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault,
7024 reinterpret_cast<
const UniChar *>(rhs.constData()), rhs.length(), kCFAllocatorNull);
7026 const int result = CFStringCompare(thisString, otherString, kCFCompareLocalized);
7027 CFRelease(thisString);
7028 CFRelease(otherString);
7030# elif defined(Q_OS_UNIX)
7032 return strcoll(lhs.toLocal8Bit().constData(), rhs.toLocal8Bit().constData());
7034# error "This case shouldn't happen"
7035 return QtPrivate::compareStrings(lhs, rhs, Qt::CaseSensitive);
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7054
7055
7056
7057
7058
7059
7060
7061
7062
7064const ushort *QString::utf16()
const
7066 if (!d->isMutable()) {
7068 const_cast<QString*>(
this)->reallocData(d.size, QArrayData::KeepSize);
7070 return reinterpret_cast<
const ushort *>(d.data());
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087QString &QString::nullTerminate()
7090 if (!d->isMutable())
7091 *
this = QString{constData(), size()};
7096
7097
7098
7099
7100
7101
7102
7103
7104QString QString::nullTerminated()
const &
7107 if (!d->isMutable())
7108 return QString{constData(), size()};
7112QString QString::nullTerminated() &&
7115 return std::move(*
this);
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7136QString QString::leftJustified(qsizetype width, QChar fill,
bool truncate)
const
7139 qsizetype len = size();
7140 qsizetype padlen = width - len;
7142 result.resize(len+padlen);
7144 memcpy(result.d.data(), d.data(),
sizeof(QChar)*len);
7145 QChar *uc = (QChar*)result.d.data() + len;
7150 result = left(width);
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7175QString QString::rightJustified(qsizetype width, QChar fill,
bool truncate)
const
7178 qsizetype len = size();
7179 qsizetype padlen = width - len;
7181 result.resize(len+padlen);
7182 QChar *uc = (QChar*)result.d.data();
7186 memcpy(
static_cast<
void *>(uc),
static_cast<
const void *>(d.data()),
sizeof(QChar)*len);
7189 result = left(width);
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235template <
typename T>
7271template <
typename T>
7274 const QChar *p = str.constBegin();
7275 const QChar *e = p + str.size();
7278 while (e != p && e[-1].isHighSurrogate())
7283 const char32_t uc = it
.next();
7284 if (caseConversion(uc)[which].diff) {
7286 return detachAndConvertCase(str, it, which);
7289 return std::move(str);
7293QString QString::toLower_helper(
const QString &str)
7295 return QUnicodeTables::convertCase(str, QUnicodeTables::LowerCase);
7298QString QString::toLower_helper(QString &str)
7300 return QUnicodeTables::convertCase(str, QUnicodeTables::LowerCase);
7304
7305
7306
7307
7308
7310QString QString::toCaseFolded_helper(
const QString &str)
7312 return QUnicodeTables::convertCase(str, QUnicodeTables::CaseFold);
7315QString QString::toCaseFolded_helper(QString &str)
7317 return QUnicodeTables::convertCase(str, QUnicodeTables::CaseFold);
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7336QString QString::toUpper_helper(
const QString &str)
7338 return QUnicodeTables::convertCase(str, QUnicodeTables::UpperCase);
7341QString QString::toUpper_helper(QString &str)
7343 return QUnicodeTables::convertCase(str, QUnicodeTables::UpperCase);
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7380QString QString::asprintf(
const char *cformat, ...)
7383 va_start(ap, cformat);
7384 QString s = vasprintf(cformat, ap);
7391 const qsizetype oldSize = qs.size();
7392 qs.resize(oldSize + len);
7393 const QChar *newEnd = QUtf8::convertToUnicode(qs.data() + oldSize, QByteArrayView(cs, len));
7394 qs.resize(newEnd - qs.constData());
7411 default:
return flags;
7419 Q_ASSERT(isAsciiDigit(*c));
7420 const char *
const stop = c + size;
7424 auto [result, used] = qstrntoull(c, size, 10);
7429 while (c < stop && isAsciiDigit(*c))
7431 return result < qulonglong(
std::numeric_limits<
int>::max()) ?
int(result) : 0;
7450 case 'L':
return lm_L;
7451 case 'j':
return lm_j;
7453 case 'Z':
return lm_z;
7454 case 't':
return lm_t;
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7474QString QString::vasprintf(
const char *cformat, va_list ap)
7476 if (!cformat || !*cformat) {
7478 return fromLatin1(
"");
7484 const char *c = cformat;
7485 const char *formatEnd = cformat + qstrlen(cformat);
7489 while (*c !=
'\0' && *c !=
'%')
7491 append_utf8(result, cb, qsizetype(c - cb));
7497 const char *escape_start = c;
7501 result.append(u'%');
7505 result.append(u'%');
7510 uint flags = parse_flag_characters(c);
7513 result.append(QLatin1StringView(escape_start));
7519 if (isAsciiDigit(*c)) {
7520 width = parse_field_width(c, formatEnd - c);
7521 }
else if (*c ==
'*') {
7522 width = va_arg(ap,
int);
7529 result.append(QLatin1StringView(escape_start));
7538 if (isAsciiDigit(*c)) {
7539 precision = parse_field_width(c, formatEnd - c);
7540 }
else if (*c ==
'*') {
7541 precision = va_arg(ap,
int);
7549 result.append(QLatin1StringView(escape_start));
7553 const LengthMod length_mod = parse_length_modifier(c);
7556 result.append(QLatin1StringView(escape_start));
7566 switch (length_mod) {
7567 case lm_none: i = va_arg(ap,
int);
break;
7568 case lm_hh: i = va_arg(ap,
int);
break;
7569 case lm_h: i = va_arg(ap,
int);
break;
7570 case lm_l: i = va_arg(ap,
long int);
break;
7571 case lm_ll: i = va_arg(ap, qint64);
break;
7572 case lm_j: i = va_arg(ap,
long int);
break;
7575 case lm_z: i = va_arg(ap, qsizetype);
break;
7576 case lm_t: i = va_arg(ap, qsizetype);
break;
7577 default: i = 0;
break;
7579 subst = QLocaleData::c()->longLongToString(i, precision, 10, width, flags);
7588 switch (length_mod) {
7589 case lm_none: u = va_arg(ap, uint);
break;
7590 case lm_hh: u = va_arg(ap, uint);
break;
7591 case lm_h: u = va_arg(ap, uint);
break;
7592 case lm_l: u = va_arg(ap, ulong);
break;
7593 case lm_ll: u = va_arg(ap, quint64);
break;
7594 case lm_t: u = va_arg(ap, size_t);
break;
7595 case lm_z: u = va_arg(ap, size_t);
break;
7596 default: u = 0;
break;
7599 if (isAsciiUpper(*c))
7600 flags |= QLocaleData::CapitalEorX;
7603 switch (QtMiscUtils::toAsciiLower(*c)) {
7612 subst = QLocaleData::c()->unsLongLongToString(u, precision, base, width, flags);
7625 if (length_mod == lm_L)
7626 d = va_arg(ap,
long double);
7628 d = va_arg(ap,
double);
7630 if (isAsciiUpper(*c))
7631 flags |= QLocaleData::CapitalEorX;
7633 QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
7634 switch (QtMiscUtils::toAsciiLower(*c)) {
7635 case 'e': form = QLocaleData::DFExponent;
break;
7637 case 'f': form = QLocaleData::DFDecimal;
break;
7638 case 'g': form = QLocaleData::DFSignificantDigits;
break;
7641 subst = QLocaleData::c()->doubleToString(d, precision, form, width, flags);
7646 if (length_mod == lm_l)
7647 subst = QChar::fromUcs2(va_arg(ap,
int));
7649 subst = QLatin1Char((uchar) va_arg(ap,
int));
7654 if (length_mod == lm_l) {
7655 const char16_t *buff = va_arg(ap,
const char16_t*);
7656 const auto *ch = buff;
7657 while (precision != 0 && *ch != 0) {
7661 subst.setUtf16(buff, ch - buff);
7662 }
else if (precision == -1) {
7663 subst = QString::fromUtf8(va_arg(ap,
const char*));
7665 const char *buff = va_arg(ap,
const char*);
7666 subst = QString::fromUtf8(buff, qstrnlen(buff, precision));
7672 void *arg = va_arg(ap,
void*);
7673 const quint64 i =
reinterpret_cast<quintptr>(arg);
7674 flags |= QLocaleData::ShowBase;
7675 subst = QLocaleData::c()->unsLongLongToString(i, precision, 16, width, flags);
7680 switch (length_mod) {
7682 signed char *n = va_arg(ap,
signed char*);
7687 short int *n = va_arg(ap,
short int*);
7692 long int *n = va_arg(ap,
long int*);
7697 qint64 *n = va_arg(ap, qint64*);
7702 int *n = va_arg(ap,
int*);
7703 *n =
int(result.size());
7711 for (
const char *cc = escape_start; cc != c; ++cc)
7712 result.append(QLatin1Char(*cc));
7716 if (flags & QLocaleData::LeftAdjusted)
7717 result.append(subst.leftJustified(width));
7719 result.append(subst.rightJustified(width));
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7754template <
typename Int>
7757#if defined(QT_CHECK_RANGE)
7758 if (base != 0 && (base < 2 || base > 36)) {
7759 qWarning(
"QString::toIntegral: Invalid base (%d)", base);
7764 QVarLengthArray<uchar> latin1(string.size());
7765 qt_to_latin1(latin1.data(), string.utf16(), string.size());
7766 QSimpleParsedNumber<Int> r;
7767 if constexpr (
std::is_signed_v<Int>)
7768 r = QLocaleData::bytearrayToLongLong(latin1, base);
7770 r = QLocaleData::bytearrayToUnsLongLong(latin1, base);
7776qlonglong QString::toIntegral_helper(QStringView string,
bool *ok,
int base)
7778 return toIntegral<qlonglong>(string, ok, base);
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7810qulonglong QString::toIntegral_helper(QStringView string,
bool *ok, uint base)
7812 return toIntegral<qulonglong>(string, ok, base);
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
7842
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
7870
7871
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
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
7927
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
7956
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
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8021double QString::toDouble(
bool *ok)
const
8023 return QStringView(*
this).toDouble(ok);
8026double QStringView::toDouble(
bool *ok)
const
8028 QStringView string = qt_trimmed(*
this);
8029 QVarLengthArray<uchar> latin1(string.size());
8030 qt_to_latin1(latin1.data(), string.utf16(), string.size());
8031 auto r = qt_asciiToDouble(
reinterpret_cast<
const char *>(latin1.data()), string.size());
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8067float QString::toFloat(
bool *ok)
const
8069 return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
8072float QStringView::toFloat(
bool *ok)
const
8074 return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8094
8095
8096
8099
8100
8101
8104
8105
8106
8109
8110
8111QString &QString::setNum(qlonglong n,
int base)
8113 return *
this = number(n, base);
8117
8118
8119QString &QString::setNum(qulonglong n,
int base)
8121 return *
this = number(n, base);
8125
8126
8127
8130
8131
8132
8135
8136
8137
8138
8139
8140
8141
8143QString &QString::setNum(
double n,
char format,
int precision)
8145 return *
this = number(n, format, precision);
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8183QString QString::number(
long n,
int base)
8185 return number(qlonglong(n), base);
8189
8190
8191
8192
8193QString QString::number(ulong n,
int base)
8195 return number(qulonglong(n), base);
8199
8200
8201QString QString::number(
int n,
int base)
8203 return number(qlonglong(n), base);
8207
8208
8209QString QString::number(uint n,
int base)
8211 return number(qulonglong(n), base);
8215
8216
8217QString QString::number(qlonglong n,
int base)
8219#if defined(QT_CHECK_RANGE)
8220 if (base < 2 || base > 36) {
8221 qWarning(
"QString::setNum: Invalid base (%d)", base);
8225 bool negative = n < 0;
8227
8228
8229
8230 return qulltoBasicLatin(negative ? 1u + qulonglong(-(n + 1)) : qulonglong(n), base, negative);
8234
8235
8236QString QString::number(qulonglong n,
int base)
8238#if defined(QT_CHECK_RANGE)
8239 if (base < 2 || base > 36) {
8240 qWarning(
"QString::setNum: Invalid base (%d)", base);
8244 return qulltoBasicLatin(n, base,
false);
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259QString QString::number(
double n,
char format,
int precision)
8261 QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
8263 switch (QtMiscUtils::toAsciiLower(format)) {
8265 form = QLocaleData::DFDecimal;
8268 form = QLocaleData::DFExponent;
8271 form = QLocaleData::DFSignificantDigits;
8274#if defined(QT_CHECK_RANGE)
8275 qWarning(
"QString::setNum: Invalid format char '%c'", format);
8280 return qdtoBasicLatin(n, form, precision, isAsciiUpper(format));
8284template<
class ResultList,
class StringSource>
8285static ResultList splitString(
const StringSource &source, QStringView sep,
8286 Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
8289 typename StringSource::size_type start = 0;
8290 typename StringSource::size_type end;
8291 typename StringSource::size_type extra = 0;
8292 while ((end = QtPrivate::findString(QStringView(source.constData(), source.size()), start + extra, sep, cs)) != -1) {
8293 if (start != end || behavior == Qt::KeepEmptyParts)
8294 list.append(source.sliced(start, end - start));
8295 start = end + sep.size();
8296 extra = (sep.size() == 0 ? 1 : 0);
8298 if (start != source.size() || behavior == Qt::KeepEmptyParts)
8299 list.append(source.sliced(start));
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335QStringList QString::split(
const QString &sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
const
8337 return splitString<QStringList>(*
this, sep, behavior, cs);
8341
8342
8343
8344QStringList QString::split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
const
8346 return splitString<QStringList>(*
this, QStringView(&sep, 1), behavior, cs);
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366QList<QStringView> QStringView::split(QStringView sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
const
8368 return splitString<QList<QStringView>>(QStringView(*
this), sep, behavior, cs);
8371QList<QStringView> QStringView::split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs)
const
8373 return split(QStringView(&sep, 1), behavior, cs);
8376#if QT_CONFIG(regularexpression)
8378template<
class ResultList,
typename String,
typename MatchingFunction>
8379static ResultList splitString(
const String &source,
const QRegularExpression &re,
8380 MatchingFunction matchingFunction,
8381 Qt::SplitBehavior behavior)
8384 if (!re.isValid()) {
8385 qtWarnAboutInvalidRegularExpression(re,
"QString",
"split");
8389 qsizetype start = 0;
8391 QRegularExpressionMatchIterator iterator = (re.*matchingFunction)(source, 0, QRegularExpression::NormalMatch, QRegularExpression::NoMatchOption);
8392 while (iterator.hasNext()) {
8393 QRegularExpressionMatch match = iterator.next();
8394 end = match.capturedStart();
8395 if (start != end || behavior == Qt::KeepEmptyParts)
8396 list.append(source.sliced(start, end - start));
8397 start = match.capturedEnd();
8400 if (start != source.size() || behavior == Qt::KeepEmptyParts)
8401 list.append(source.sliced(start));
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434QStringList QString::split(
const QRegularExpression &re, Qt::SplitBehavior behavior)
const
8436#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
8437 const auto matchingFunction = qOverload<
const QString &, qsizetype, QRegularExpression::MatchType, QRegularExpression::MatchOptions>(&QRegularExpression::globalMatch);
8439 const auto matchingFunction = &QRegularExpression::globalMatch;
8441 return splitString<QStringList>(*
this,
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460QList<QStringView> QStringView::split(
const QRegularExpression &re, Qt::SplitBehavior behavior)
const
8462 return splitString<QList<QStringView>>(*
this, re, &QRegularExpression::globalMatchView, behavior);
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492QString QString::repeated(qsizetype times)
const
8503 const qsizetype resultSize = times * d.size;
8506 result.reserve(resultSize);
8507 if (result.capacity() != resultSize)
8510 memcpy(result.d.data(), d.data(), d.size *
sizeof(QChar));
8512 qsizetype sizeSoFar = d.size;
8513 char16_t *end = result.d.data() + sizeSoFar;
8515 const qsizetype halfResultSize = resultSize >> 1;
8516 while (sizeSoFar <= halfResultSize) {
8517 memcpy(end, result.d.data(), sizeSoFar *
sizeof(QChar));
8521 memcpy(end, result.d.data(), (resultSize - sizeSoFar) *
sizeof(QChar));
8522 result.d.data()[resultSize] =
'\0';
8523 result.d.size = resultSize;
8527void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, qsizetype from)
8531 auto start =
reinterpret_cast<
const char16_t *>(data->constData());
8532 const char16_t *p = start + from;
8533 if (isAscii_helper(p, p + data->size() - from))
8535 if (p > start + from)
8536 from = p - start - 1;
8539 if (version == QChar::Unicode_Unassigned) {
8540 version = QChar::currentUnicodeVersion();
8542 const QString &s = *data;
8546 qsizetype pos = from;
8547 if (QChar::requiresSurrogates(n.ucs4)) {
8548 char16_t ucs4High = QChar::highSurrogate(n.ucs4);
8549 char16_t ucs4Low = QChar::lowSurrogate(n.ucs4);
8550 char16_t oldHigh = QChar::highSurrogate(n.old_mapping);
8551 char16_t oldLow = QChar::lowSurrogate(n.old_mapping);
8552 while (pos < s.size() - 1) {
8553 if (s.at(pos).unicode() == ucs4High && s.at(pos + 1).unicode() == ucs4Low) {
8556 d[pos] = QChar(oldHigh);
8557 d[++pos] = QChar(oldLow);
8562 while (pos < s.size()) {
8563 if (s.at(pos).unicode() == n.ucs4) {
8566 d[pos] = QChar(n.old_mapping);
8575 if (normalizationQuickCheckHelper(data, mode, from, &from))
8578 decomposeHelper(data, mode < QString::NormalizationForm_KD, version, from);
8580 canonicalOrderHelper(data, version, from);
8582 if (mode == QString::NormalizationForm_D || mode == QString::NormalizationForm_KD)
8585 composeHelper(data, version, from);
8589
8590
8591
8592QString QString::normalized(QString::NormalizationForm mode, QChar::UnicodeVersion version)
const
8594 QString copy = *
this;
8595 qt_string_normalize(©, mode, version, 0);
8599#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
8600static void checkArgEscape(QStringView s)
8605 if (!supportUnicodeDigitValuesInArg())
8608 const auto isNonAsciiDigit = [](QChar c) {
8609 return c.unicode() < u'0' || c.unicode() > u'9';
8612 if (std::any_of(s.begin(), s.end(), isNonAsciiDigit)) {
8613 const auto accumulateDigit = [](
int partial, QChar digit) {
8614 return partial * 10 + digit.digitValue();
8616 const int parsedNumber = std::accumulate(s.begin(), s.end(), 0, accumulateDigit);
8618 qWarning(
"QString::arg(): the replacement \"%%%ls\" contains non-ASCII digits;\n"
8619 " it is currently being interpreted as the %d-th substitution.\n"
8620 " This is deprecated; support for non-ASCII digits will be dropped\n"
8621 " in a future version of Qt.",
8622 qUtf16Printable(s.toString()),
8639 const QChar *uc_begin = s.begin();
8640 const QChar *uc_end = s.end();
8644 d.min_escape = INT_MAX;
8647 d.locale_occurrences = 0;
8649 const QChar *c = uc_begin;
8650 while (c != uc_end) {
8651 while (c != uc_end && c->unicode() !=
'%')
8656 const QChar *escape_start = c;
8660 bool locale_arg =
false;
8661 if (c->unicode() ==
'L') {
8667 int escape = qArgDigitValue(*c);
8673#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
8674 const QChar *escapeBegin = c;
8675 const QChar *escapeEnd = escapeBegin + 1;
8681 const int next_escape = qArgDigitValue(*c);
8682 if (next_escape != -1) {
8683 escape = (10 * escape) + next_escape;
8685#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
8691#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
8692 checkArgEscape(QStringView(escapeBegin, escapeEnd));
8702 d.locale_occurrences = 0;
8707 ++d.locale_occurrences;
8708 d.escape_len += c - escape_start;
8714 QStringView arg, QStringView larg, QChar fillChar)
8717 const qsizetype abs_field_width = qAbs(field_width);
8718 const qsizetype result_len =
8719 s.size() - d.escape_len
8720 + (d.occurrences - d.locale_occurrences) * qMax(abs_field_width, arg.size())
8721 + d.locale_occurrences * qMax(abs_field_width, larg.size());
8723 QString result(result_len, Qt::Uninitialized);
8724 QChar *rc =
const_cast<QChar *>(result.unicode());
8725 QChar *
const result_end = rc + result_len;
8726 qsizetype repl_cnt = 0;
8728 const QChar *c = s.begin();
8729 const QChar *
const uc_end = s.end();
8730 while (c != uc_end) {
8731 Q_ASSERT(d.occurrences > repl_cnt);
8733
8734
8736 const QChar *text_start = c;
8737 while (c->unicode() !=
'%')
8740 const QChar *escape_start = c++;
8741 const bool localize = c->unicode() ==
'L';
8745 int escape = qArgDigitValue(*c);
8746 if (escape != -1 && c + 1 != uc_end) {
8747 const int digit = qArgDigitValue(c[1]);
8750 escape = 10 * escape + digit;
8755 memcpy(rc, text_start, (c - text_start) *
sizeof(QChar));
8756 rc += c - text_start;
8760 memcpy(rc, text_start, (escape_start - text_start) *
sizeof(QChar));
8761 rc += escape_start - text_start;
8763 const QStringView use = localize ? larg : arg;
8764 const qsizetype pad_chars = abs_field_width - use.size();
8767 if (field_width > 0) {
8768 rc =
std::fill_n(rc, pad_chars, fillChar);
8772 memcpy(rc, use.data(), use.size() *
sizeof(QChar));
8775 if (field_width < 0) {
8776 rc =
std::fill_n(rc, pad_chars, fillChar);
8779 if (++repl_cnt == d.occurrences) {
8780 memcpy(rc, c, (uc_end - c) *
sizeof(QChar));
8782 Q_ASSERT(rc == result_end);
8787 Q_ASSERT(rc == result_end);
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829QString QString::arg_impl(QAnyStringView a,
int fieldWidth, QChar fillChar)
const
8831 ArgEscapeData d = findArgEscapes(*
this);
8833 if (Q_UNLIKELY(d.occurrences == 0)) {
8834 qWarning(
"QString::arg: Argument missing: \"%ls\", \"%ls\"",
qUtf16Printable(*
this),
8839 QVarLengthArray<
char16_t> out;
8840 QStringView operator()(QStringView in)
noexcept {
return in; }
8841 QStringView operator()(QLatin1StringView in)
8843 out.resize(in.size());
8844 qt_from_latin1(out.data(), in.data(), size_t(in.size()));
8847 QStringView operator()(QUtf8StringView in)
8849 out.resize(in.size());
8850 return QStringView{out.data(), QUtf8::convertToUnicode(out.data(), in)};
8854 QStringView sv = a.visit(std::ref(convert));
8855 return replaceArgEscapes(*
this, d, fieldWidth, sv, sv, fillChar);
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893QString QString::arg_impl(qlonglong a,
int fieldWidth,
int base, QChar fillChar)
const
8895 ArgEscapeData d = findArgEscapes(*
this);
8897 if (d.occurrences == 0) {
8898 qWarning(
"QString::arg: Argument missing: \"%ls\", %llu",
qUtf16Printable(*
this), a);
8902 unsigned flags = QLocaleData::NoFlags;
8904 if (fillChar == u'0')
8905 flags = QLocaleData::ZeroPadded;
8908 if (d.occurrences > d.locale_occurrences) {
8909 arg = QLocaleData::c()->longLongToString(a, -1, base, fieldWidth, flags);
8910 Q_ASSERT(fillChar != u'0' || fieldWidth <= arg.size());
8914 if (d.locale_occurrences > 0) {
8916 if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
8917 flags |= QLocaleData::GroupDigits;
8918 localeArg = locale.d->m_data->longLongToString(a, -1, base, fieldWidth, flags);
8919 Q_ASSERT(fillChar != u'0' || fieldWidth <= localeArg.size());
8922 return replaceArgEscapes(*
this, d, fieldWidth, arg, localeArg, fillChar);
8925QString QString::arg_impl(qulonglong a,
int fieldWidth,
int base, QChar fillChar)
const
8927 ArgEscapeData d = findArgEscapes(*
this);
8929 if (d.occurrences == 0) {
8930 qWarning(
"QString::arg: Argument missing: \"%ls\", %lld",
qUtf16Printable(*
this), a);
8934 unsigned flags = QLocaleData::NoFlags;
8936 if (fillChar == u'0')
8937 flags = QLocaleData::ZeroPadded;
8940 if (d.occurrences > d.locale_occurrences) {
8941 arg = QLocaleData::c()->unsLongLongToString(a, -1, base, fieldWidth, flags);
8942 Q_ASSERT(fillChar != u'0' || fieldWidth <= arg.size());
8946 if (d.locale_occurrences > 0) {
8948 if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
8949 flags |= QLocaleData::GroupDigits;
8950 localeArg = locale.d->m_data->unsLongLongToString(a, -1, base, fieldWidth, flags);
8951 Q_ASSERT(fillChar != u'0' || fieldWidth <= localeArg.size());
8954 return replaceArgEscapes(*
this, d, fieldWidth, arg, localeArg, fillChar);
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979QString QString::arg_impl(
double a,
int fieldWidth,
char format,
int precision, QChar fillChar)
const
8981 ArgEscapeData d = findArgEscapes(*
this);
8983 if (d.occurrences == 0) {
8984 qWarning(
"QString::arg: Argument missing: \"%ls\", %g",
qUtf16Printable(*
this), a);
8988 unsigned flags = QLocaleData::NoFlags;
8990 if (fillChar == u'0')
8991 flags |= QLocaleData::ZeroPadded;
8993 if (isAsciiUpper(format))
8994 flags |= QLocaleData::CapitalEorX;
8996 QLocaleData::DoubleForm form = QLocaleData::DFDecimal;
8997 switch (QtMiscUtils::toAsciiLower(format)) {
8999 form = QLocaleData::DFDecimal;
9002 form = QLocaleData::DFExponent;
9005 form = QLocaleData::DFSignificantDigits;
9008#if defined(QT_CHECK_RANGE)
9009 qWarning(
"QString::arg: Invalid format char '%c'", format);
9015 if (d.occurrences > d.locale_occurrences) {
9016 arg = QLocaleData::c()->doubleToString(a, precision, form, fieldWidth,
9017 flags | QLocaleData::ZeroPadExponent);
9018 Q_ASSERT(fillChar != u'0' || !qt_is_finite(a)
9019 || fieldWidth <= arg.size());
9023 if (d.locale_occurrences > 0) {
9026 const QLocale::NumberOptions numberOptions = locale.numberOptions();
9027 if (!(numberOptions & QLocale::OmitGroupSeparator))
9028 flags |= QLocaleData::GroupDigits;
9029 if (!(numberOptions & QLocale::OmitLeadingZeroInExponent))
9030 flags |= QLocaleData::ZeroPadExponent;
9031 if (numberOptions & QLocale::IncludeTrailingZeroesAfterDot)
9032 flags |= QLocaleData::AddTrailingZeroes;
9033 localeArg = locale.d->m_data->doubleToString(a, precision, form, fieldWidth, flags);
9034 Q_ASSERT(fillChar != u'0' || !qt_is_finite(a)
9035 || fieldWidth <= localeArg.size());
9038 return replaceArgEscapes(*
this, d, fieldWidth, arg, localeArg, fillChar);
9041static inline char16_t to_unicode(
const QChar c) {
return c.unicode(); }
9044template <
typename Char>
9045static int getEscape(
const Char *uc, qsizetype *pos, qsizetype len)
9049 if (i < len && uc[i] == u'L')
9052 int escape = to_unicode(uc[i]) -
'0';
9053 if (uint(escape) >= 10U)
9058 int digit = to_unicode(uc[i]) -
'0';
9059 if (uint(digit) < 10U) {
9060 escape = (escape * 10) + digit;
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9108 constexpr Part(QAnyStringView s,
int num = -1)
9109 : string{s}, number{num} {}
9111 void reset(QAnyStringView s)
noexcept { *
this = {s, number}; }
9113 QAnyStringView string;
9122enum { ExpectedParts = 32 };
9125typedef QVarLengthArray<
int, ExpectedParts/2> ArgIndexToPlaceholderMap;
9127template <
typename StringView>
9128static ParseResult parseMultiArgFormatString_impl(StringView s)
9132 const auto uc = s.data();
9133 const auto len = s.size();
9134 const auto end = len - 1;
9139 if (uc[i] == u'%') {
9140 qsizetype percent = i;
9141 int number = getEscape(uc, &i, len);
9143 if (last != percent)
9144 result.push_back(Part{s.sliced(last, percent - last)});
9145 result.push_back(Part{s.sliced(percent, i - percent), number});
9154 result.push_back(Part{s.sliced(last, len - last)});
9159static ParseResult parseMultiArgFormatString(QAnyStringView s)
9161 return s.visit([] (
auto s) {
return parseMultiArgFormatString_impl(s); });
9164static ArgIndexToPlaceholderMap makeArgIndexToPlaceholderMap(
const ParseResult &parts)
9166 ArgIndexToPlaceholderMap result;
9168 for (
const Part &part : parts) {
9169 if (part.number >= 0)
9170 result.push_back(part.number);
9173 std::sort(result.begin(), result.end());
9174 result.erase(
std::unique(result.begin(), result.end()),
9180static qsizetype resolveStringRefsAndReturnTotalSize(ParseResult &parts,
const ArgIndexToPlaceholderMap &argIndexToPlaceholderMap,
const QtPrivate::
ArgBase *args[])
9183 qsizetype totalSize = 0;
9184 for (Part &part : parts) {
9185 if (part.number != -1) {
9186 const auto it = std::find(argIndexToPlaceholderMap.begin(), argIndexToPlaceholderMap.end(), part.number);
9187 if (it != argIndexToPlaceholderMap.end()) {
9188 const auto &arg = *args[it - argIndexToPlaceholderMap.begin()];
9191 part.reset(
static_cast<
const QLatin1StringArg&>(arg).string);
9194 part.reset(
static_cast<
const QAnyStringArg&>(arg).string);
9197 part.reset(
static_cast<
const QStringViewArg&>(arg).string);
9202 totalSize += part.string.size();
9212 ParseResult parts = parseMultiArgFormatString(pattern);
9215 ArgIndexToPlaceholderMap argIndexToPlaceholderMap = makeArgIndexToPlaceholderMap(parts);
9217 if (
static_cast<size_t>(argIndexToPlaceholderMap.size()) > numArgs)
9218 argIndexToPlaceholderMap.resize(qsizetype(numArgs));
9219 else if (Q_UNLIKELY(
static_cast<size_t>(argIndexToPlaceholderMap.size()) < numArgs))
9220 qWarning(
"QString::arg: %d argument(s) missing in %ls",
9221 int(numArgs - argIndexToPlaceholderMap.size()),
qUtf16Printable(pattern.toString()));
9224 const qsizetype totalSize = resolveStringRefsAndReturnTotalSize(parts, argIndexToPlaceholderMap, args);
9227 QString result(totalSize, Qt::Uninitialized);
9228 auto out =
const_cast<QChar*>(result.constData());
9230 struct Concatenate {
9232 QChar *operator()(QLatin1String part)
noexcept
9235 qt_from_latin1(
reinterpret_cast<
char16_t*>(out),
9236 part.data(), part.size());
9238 return out + part.size();
9240 QChar *operator()(QUtf8StringView part)
noexcept
9242 return QUtf8::convertToUnicode(out, part);
9244 QChar *operator()(QStringView part)
noexcept
9247 memcpy(out, part.data(), part.size() *
sizeof(QChar));
9248 return out + part.size();
9252 for (
const Part &part : parts)
9253 out = part.string.visit(Concatenate{out});
9256 result.truncate(out - result.cbegin());
9262
9263
9264
9265
9266
9267bool QString::isRightToLeft()
const
9269 return QtPrivate::isRightToLeft(QStringView(*
this));
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9308
9309
9310
9311
9312
9313
9314
9315
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9332
9333
9334
9335
9336
9337
9338
9341
9342
9343
9344
9345
9348
9349
9350
9351
9352
9353
9354
9357
9358
9359
9360
9361
9364
9365
9366
9367
9368
9369
9370
9371QString::iterator QString::erase(QString::const_iterator first, QString::const_iterator last)
9373 const auto start = std::distance(cbegin(), first);
9374 const auto len = std::distance(first, last);
9376 return begin() + start;
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9396
9397
9398
9399
9400
9401
9402
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416std::string QString::toStdString()
const
9422 auto writeToBuffer = [
this](
char *out, size_t) {
9423 char *last = QUtf8::convertFromUnicode(out, *
this);
9426 size_t maxSize = size() * 3;
9427#ifdef __cpp_lib_string_resize_and_overwrite
9429 result.resize_and_overwrite(maxSize, writeToBuffer);
9431 result.resize(maxSize);
9432 result.resize(writeToBuffer(result.data(), result.size()));
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9468
9469
9470
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486QString &QString::setRawData(
const QChar *unicode, qsizetype size)
9488 if (!unicode || !size) {
9491 *
this = fromRawData(unicode, size);
9496
9497
9498
9499
9500
9501
9504
9505
9506
9507
9508
9509
9510
9511
9512
9515
9516
9517
9518
9519
9520
9523
9524
9525
9526
9527
9528
9529
9530
9531
9533#if !defined(QT_NO_DATASTREAM)
9535
9536
9537
9538
9539
9540
9541
9543QDataStream &operator<<(QDataStream &out,
const QString &str)
9545 if (out.version() == 1) {
9546 out << str.toLatin1();
9548 if (!str.isNull() || out.version() < 3) {
9549 if ((out.byteOrder() == QDataStream::BigEndian) == (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
9550 out.writeBytes(
reinterpret_cast<
const char *>(str.unicode()),
9551 static_cast<qsizetype>(
sizeof(QChar) * str.size()));
9553 QVarLengthArray<
char16_t> buffer(str.size());
9554 qbswap<
sizeof(
char16_t)>(str.constData(), str.size(), buffer.data());
9555 out.writeBytes(
reinterpret_cast<
const char *>(buffer.data()),
9556 static_cast<qsizetype>(
sizeof(
char16_t) * buffer.size()));
9559 QDataStream::writeQSizeType(out, -1);
9566
9567
9568
9569
9570
9571
9572
9576 if (in.version() == 1) {
9579 str = QString::fromLatin1(l);
9581 qint64 size = QDataStream::readQSizeType(in);
9582 qsizetype bytes = size;
9583 if (size != bytes || size < -1) {
9585 in.setStatus(QDataStream::SizeLimitExceeded);
9590 }
else if (bytes > 0) {
9593 in.setStatus(QDataStream::ReadCorruptData);
9597 const qsizetype Step = 1024 * 1024;
9598 qsizetype len = bytes / 2;
9599 qsizetype allocated = 0;
9601 while (allocated < len) {
9602 int blockSize = qMin(Step, len - allocated);
9603 str.resize(allocated + blockSize);
9604 if (in.readRawData(
reinterpret_cast<
char *>(str.data()) + allocated * 2,
9605 blockSize * 2) != blockSize * 2) {
9607 in.setStatus(QDataStream::ReadPastEnd);
9610 allocated += blockSize;
9613 if ((in.byteOrder() == QDataStream::BigEndian)
9614 != (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
9615 char16_t *data =
reinterpret_cast<
char16_t *>(str.data());
9616 qbswap<
sizeof(*data)>(data, len, data);
9619 str = QString(QLatin1StringView(
""));
9627
9628
9629
9632
9633
9634
9637
9638
9639
9642
9643
9644
9645
9646
9647
9648
9649
9652 int isolateLevel = 0;
9657 switch (QChar::direction(c)) {
9698qsizetype
QtPrivate::count(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs)
noexcept
9702 if (haystack.size() > 500 && needle.size() > 5) {
9704 while ((i = matcher.indexIn(haystack, i + 1)) != -1)
9707 while ((i = QtPrivate::findString(haystack, i + 1, needle, cs)) != -1)
9713qsizetype
QtPrivate::count(QStringView haystack, QChar needle, Qt::CaseSensitivity cs)
noexcept
9715 if (cs == Qt::CaseSensitive)
9716 return std::count(haystack.cbegin(), haystack.cend(), needle);
9718 needle = foldCase(needle);
9719 return std::count_if(haystack.cbegin(), haystack.cend(),
9720 [needle](
const QChar c) {
return foldAndCompare(c, needle); });
9723qsizetype
QtPrivate::count(QLatin1StringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
9729 while ((i = matcher.indexIn(haystack, i + 1)) != -1)
9735qsizetype
QtPrivate::count(QLatin1StringView haystack, QStringView needle, Qt::CaseSensitivity cs)
9737 if (haystack.size() < needle.size())
9740 if (!QtPrivate::isLatin1(needle))
9746 QVarLengthArray<uchar> s(needle.size());
9747 qt_to_latin1_unchecked(s.data(), needle.utf16(), needle.size());
9751 while ((i = matcher.indexIn(haystack, i + 1)) != -1)
9757qsizetype
QtPrivate::count(QStringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
9759 if (haystack.size() < needle.size())
9762 QVarLengthArray<
char16_t> s = qt_from_latin1_to_qvla(needle);
9763 return QtPrivate::count(haystack, QStringView(s.data(), s.size()), cs);
9766qsizetype
QtPrivate::count(QLatin1StringView haystack, QChar needle, Qt::CaseSensitivity cs)
noexcept
9769 if (needle.unicode() > 0xff)
9772 if (cs == Qt::CaseSensitive) {
9773 return std::count(haystack.cbegin(), haystack.cend(), needle.toLatin1());
9775 return std::count_if(haystack.cbegin(), haystack.cend(),
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9802 return qt_starts_with_impl(haystack, needle, cs);
9807 return qt_starts_with_impl(haystack, needle, cs);
9812 return qt_starts_with_impl(haystack, needle, cs);
9815bool QtPrivate::
startsWith(QLatin1StringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
9817 return qt_starts_with_impl(haystack, needle, cs);
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9842 return qt_ends_with_impl(haystack, needle, cs);
9845bool QtPrivate::
endsWith(QStringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
9847 return qt_ends_with_impl(haystack, needle, cs);
9850bool QtPrivate::
endsWith(QLatin1StringView haystack, QStringView needle, Qt::CaseSensitivity cs)
noexcept
9852 return qt_ends_with_impl(haystack, needle, cs);
9855bool QtPrivate::
endsWith(QLatin1StringView haystack, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
9857 return qt_ends_with_impl(haystack, needle, cs);
9862 const qsizetype l = haystack0.size();
9863 const qsizetype sl = needle0.size();
9865 return findString(haystack0, from, needle0[0], cs);
9868 if (
std::size_t(sl + from) >
std::size_t(l))
9876
9877
9878
9879
9880 if (l > 500 && sl > 5)
9881 return qFindStringBoyerMoore(haystack0, from, needle0, cs);
9883 auto sv = [sl](
const char16_t *v) {
return QStringView(v, sl); };
9885
9886
9887
9888
9889
9890 const char16_t *needle = needle0.utf16();
9891 const char16_t *haystack = haystack0.utf16() + from;
9892 const char16_t *end = haystack0.utf16() + (l - sl);
9893 const qregisteruint sl_minus_1 = sl - 1;
9894 qregisteruint hashNeedle = 0, hashHaystack = 0;
9897 if (cs == Qt::CaseSensitive) {
9898 for (idx = 0; idx < sl; ++idx) {
9899 hashNeedle = ((hashNeedle<<1) + needle[idx]);
9900 hashHaystack = ((hashHaystack<<1) + haystack[idx]);
9902 hashHaystack -= haystack[sl_minus_1];
9904 while (haystack <= end) {
9905 hashHaystack += haystack[sl_minus_1];
9906 if (hashHaystack == hashNeedle
9907 && QtPrivate::compareStrings(needle0, sv(haystack), Qt::CaseSensitive) == 0)
9908 return haystack - haystack0.utf16();
9914 const char16_t *haystack_start = haystack0.utf16();
9915 for (idx = 0; idx < sl; ++idx) {
9916 hashNeedle = (hashNeedle<<1) + foldCase(needle + idx, needle);
9917 hashHaystack = (hashHaystack<<1) + foldCase(haystack + idx, haystack_start);
9919 hashHaystack -= foldCase(haystack + sl_minus_1, haystack_start);
9921 while (haystack <= end) {
9922 hashHaystack += foldCase(haystack + sl_minus_1, haystack_start);
9923 if (hashHaystack == hashNeedle
9924 && QtPrivate::compareStrings(needle0, sv(haystack), Qt::CaseInsensitive) == 0)
9925 return haystack - haystack0.utf16();
9927 REHASH(foldCase(haystack, haystack_start));
9936 if (haystack.size() < needle.size())
9939 QVarLengthArray<
char16_t> s = qt_from_latin1_to_qvla(needle);
9940 return QtPrivate::findString(haystack, from, QStringView(
reinterpret_cast<
const QChar*>(s.constData()), s.size()), cs);
9945 if (haystack.size() < needle.size())
9948 if (!QtPrivate::isLatin1(needle))
9951 if (needle.size() == 1) {
9952 const char n = needle.front().toLatin1();
9953 return QtPrivate::findString(haystack, from, QLatin1StringView(&n, 1), cs);
9956 QVarLengthArray<
char> s(needle.size());
9957 qt_to_latin1_unchecked(
reinterpret_cast<uchar *>(s.data()), needle.utf16(), needle.size());
9958 return QtPrivate::findString(haystack, from, QLatin1StringView(s.data(), s.size()), cs);
9964 from += haystack.size();
9967 qsizetype adjustedSize = haystack.size() - from;
9968 if (adjustedSize < needle.size())
9970 if (needle.size() == 0)
9973 if (cs == Qt::CaseSensitive) {
9975 if (needle.size() == 1) {
9976 Q_ASSERT(haystack.data() !=
nullptr);
9977 if (
auto it = memchr(haystack.data() + from, needle.front().toLatin1(), adjustedSize))
9978 return static_cast<
const char *>(it) - haystack.data();
9983 return matcher.indexIn(haystack, from);
9996 const qsizetype threshold = 1;
9998 const qsizetype threshold = 13;
10000 if (needle.size() <= threshold) {
10001 const auto begin = haystack.begin();
10002 const auto end = haystack.end() - needle.size() + 1;
10004 const qsizetype nlen1 = needle.size() - 1;
10005 for (
auto it =
std::find_if(begin + from, end, ciMatch); it != end;
10006 it =
std::find_if(it + 1, end, ciMatch)) {
10008 if (!nlen1 || QLatin1StringView(it + 1, nlen1).compare(needle.sliced(1), cs) == 0)
10009 return std::distance(begin, it);
10015 return matcher.indexIn(haystack, from);
10018qsizetype
QtPrivate::lastIndexOf(QStringView haystack, qsizetype from,
char16_t needle, Qt::CaseSensitivity cs)
noexcept
10020 return qLastIndexOf(haystack, QChar(needle), from, cs);
10023qsizetype
QtPrivate::lastIndexOf(QStringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs)
noexcept
10025 return qLastIndexOf(haystack, from, needle, cs);
10028qsizetype
QtPrivate::lastIndexOf(QStringView haystack, qsizetype from, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
10030 return qLastIndexOf(haystack, from, needle, cs);
10033qsizetype
QtPrivate::lastIndexOf(QLatin1StringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs)
noexcept
10035 return qLastIndexOf(haystack, from, needle, cs);
10038qsizetype
QtPrivate::lastIndexOf(QLatin1StringView haystack, qsizetype from, QLatin1StringView needle, Qt::CaseSensitivity cs)
noexcept
10040 return qLastIndexOf(haystack, from, needle, cs);
10043#if QT_CONFIG(regularexpression)
10044qsizetype QtPrivate::indexOf(QStringView viewHaystack,
const QString *stringHaystack,
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
10046 if (!re.isValid()) {
10047 qtWarnAboutInvalidRegularExpression(re,
"QString(View)",
"indexOf");
10051 QRegularExpressionMatch match = stringHaystack
10052 ? re.match(*stringHaystack, from)
10053 : re.matchView(viewHaystack, from);
10054 if (match.hasMatch()) {
10055 const qsizetype ret = match.capturedStart();
10057 *rmatch = std::move(match);
10064qsizetype QtPrivate::indexOf(QStringView haystack,
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
10066 return indexOf(haystack,
nullptr, re, from, rmatch);
10069qsizetype QtPrivate::lastIndexOf(QStringView viewHaystack,
const QString *stringHaystack,
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
10071 if (!re.isValid()) {
10072 qtWarnAboutInvalidRegularExpression(re,
"QString(View)",
"lastIndexOf");
10076 qsizetype endpos = (from < 0) ? (viewHaystack.size() + from + 1) : (from + 1);
10077 QRegularExpressionMatchIterator iterator = stringHaystack
10078 ? re.globalMatch(*stringHaystack)
10079 : re.globalMatchView(viewHaystack);
10080 qsizetype lastIndex = -1;
10081 while (iterator.hasNext()) {
10082 QRegularExpressionMatch match = iterator.next();
10083 qsizetype start = match.capturedStart();
10084 if (start < endpos) {
10087 *rmatch = std::move(match);
10096qsizetype QtPrivate::lastIndexOf(QStringView haystack,
const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
10098 return lastIndexOf(haystack,
nullptr, re, from, rmatch);
10101bool QtPrivate::contains(QStringView viewHaystack,
const QString *stringHaystack,
const QRegularExpression &re, QRegularExpressionMatch *rmatch)
10103 if (!re.isValid()) {
10104 qtWarnAboutInvalidRegularExpression(re,
"QString(View)",
"contains");
10107 QRegularExpressionMatch m = stringHaystack
10108 ? re.match(*stringHaystack)
10109 : re.matchView(viewHaystack);
10110 bool hasMatch = m.hasMatch();
10111 if (hasMatch && rmatch)
10112 *rmatch = std::move(m);
10116bool QtPrivate::contains(QStringView haystack,
const QRegularExpression &re, QRegularExpressionMatch *rmatch)
10118 return contains(haystack,
nullptr, re, rmatch);
10121qsizetype QtPrivate::count(QStringView haystack,
const QRegularExpression &re)
10123 if (!re.isValid()) {
10124 qtWarnAboutInvalidRegularExpression(re,
"QString(View)",
"count");
10127 qsizetype count = 0;
10128 qsizetype index = -1;
10129 qsizetype len = haystack.size();
10130 while (index <= len - 1) {
10131 QRegularExpressionMatch match = re.matchView(haystack, index + 1);
10132 if (!match.hasMatch())
10139 index = match.capturedStart();
10140 if (index < len && haystack[index].isHighSurrogate())
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159QString QString::toHtmlEscaped()
const
10161 const auto pos = std::u16string_view(*
this).find_first_of(u"<>&\"");
10162 if (pos == std::u16string_view::npos)
10165 const qsizetype len = size();
10166 rich.reserve(qsizetype(len * 1.1));
10167 rich += qToStringViewIgnoringNull(*
this).first(pos);
10168 for (
auto ch : qToStringViewIgnoringNull(*
this).sliced(pos)) {
10171 else if (ch == u'>')
10173 else if (ch == u'&')
10174 rich +=
"&"_L1;
10175 else if (ch == u'"')
10176 rich +=
"""_L1;
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10228#if QT_DEPRECATED_SINCE(6
, 8
)
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10280
10281
10282void QAbstractConcatenable::appendLatin1To(QLatin1StringView in, QChar *out)
noexcept
10284 qt_from_latin1(
reinterpret_cast<
char16_t *>(out), in.data(), size_t(in.size()));
10288
10289
10290
10291
10292
10293
10294
10295
10296
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
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)
@ 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)
QtPrivate::QCaseInsensitiveLatin1Hash CaseInsensitiveL1
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)