tools/qstring.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11 -
12 -
13 -
14 -
15 -
16 -
17int qFindString(const QChar *haystack, int haystackLen, int from, -
18 const QChar *needle, int needleLen, Qt::CaseSensitivity cs); -
19int qFindStringBoyerMoore(const QChar *haystack, int haystackLen, int from, -
20 const QChar *needle, int needleLen, Qt::CaseSensitivity cs); -
21static inline int qt_last_index_of(const QChar *haystack, int haystackLen, QChar needle, -
22 int from, Qt::CaseSensitivity cs); -
23static inline int qt_string_count(const QChar *haystack, int haystackLen, -
24 const QChar *needle, int needleLen, -
25 Qt::CaseSensitivity cs); -
26static inline int qt_string_count(const QChar *haystack, int haystackLen, -
27 QChar needle, Qt::CaseSensitivity cs); -
28static inline int qt_find_latin1_string(const QChar *hay, int size, QLatin1String needle, -
29 int from, Qt::CaseSensitivity cs); -
30static inline bool qt_starts_with(const QChar *haystack, int haystackLen, -
31 const QChar *needle, int needleLen, Qt::CaseSensitivity cs); -
32static inline bool qt_starts_with(const QChar *haystack, int haystackLen, -
33 QLatin1String needle, Qt::CaseSensitivity cs); -
34static inline bool qt_ends_with(const QChar *haystack, int haystackLen, -
35 const QChar *needle, int needleLen, Qt::CaseSensitivity cs); -
36static inline bool qt_ends_with(const QChar *haystack, int haystackLen, -
37 QLatin1String needle, Qt::CaseSensitivity cs); -
38 -
39 -
40static int ucstricmp(const ushort *a, const ushort *ae, const ushort *b, const ushort *be) -
41{ -
42 if (a == b)
-
43 return (ae - be);
-
44 if (a == 0)
-
45 return 1;
-
46 if (b == 0)
-
47 return -1;
-
48 -
49 const ushort *e = ae; -
50 if (be - b < ae - a)
-
51 e = a + (be - b);
-
52 -
53 uint alast = 0; -
54 uint blast = 0; -
55 while (a < e) {
-
56 -
57 -
58 -
59 int diff = foldCase(*a, alast) - foldCase(*b, blast); -
60 if ((diff))
-
61 return diff;
-
62 ++a; -
63 ++b; -
64 }
-
65 if (a == ae) {
-
66 if (b == be)
-
67 return 0;
-
68 return -1;
-
69 } -
70 return 1;
-
71} -
72 -
73 -
74static int ucstricmp(const ushort *a, const ushort *ae, const uchar *b, const uchar *be) -
75{ -
76 if (a == 0) {
-
77 if (b == 0)
-
78 return 0;
-
79 return 1;
-
80 } -
81 if (b == 0)
-
82 return -1;
-
83 -
84 const ushort *e = ae; -
85 if (be - b < ae - a)
-
86 e = a + (be - b);
-
87 -
88 while (a < e) {
-
89 int diff = foldCase(*a) - foldCase(*b); -
90 if ((diff))
-
91 return diff;
-
92 ++a; -
93 ++b; -
94 }
-
95 if (a == ae) {
-
96 if (b == be)
-
97 return 0;
-
98 return -1;
-
99 } -
100 return 1;
-
101} -
102 -
103 -
104static int ucstrncmp(const QChar *a, const QChar *b, int l) -
105{ -
106 while (l-- && *a == *b)
-
107 a++,b++;
-
108 if (l==-1)
-
109 return 0;
-
110 return a->unicode() - b->unicode();
-
111} -
112 -
113 -
114static int ucstrcmp(const QChar *a, int alen, const QChar *b, int blen) -
115{ -
116 if (a == b && alen == blen)
-
117 return 0;
-
118 int l = qMin(alen, blen); -
119 int cmp = ucstrncmp(a, b, l); -
120 return cmp ? cmp : (alen-blen);
-
121} -
122 -
123 -
124static int ucstrnicmp(const ushort *a, const ushort *b, int l) -
125{ -
126 return ucstricmp(a, a + l, b, b + l);
-
127} -
128static bool qMemEquals(const quint16 *a, const quint16 *b, int length) -
129{ -
130 if (a == b || !length)
-
131 return true;
-
132 -
133 register union { -
134 const quint16 *w; -
135 const quint32 *d; -
136 quintptr value; -
137 } sa, sb; -
138 sa.w = a; -
139 sb.w = b; -
140 -
141 -
142 if ((sa.value & 2) == (sb.value & 2)) {
-
143 -
144 if (sa.value & 2) {
-
145 -
146 -
147 if (*sa.w != *sb.w)
-
148 return false;
-
149 --length; -
150 ++sa.w; -
151 ++sb.w; -
152 -
153 -
154 }
-
155 -
156 -
157 -
158 register const quint32 *e = sa.d + (length >> 1); -
159 for ( ; sa.d != e; ++sa.d, ++sb.d) {
-
160 if (*sa.d != *sb.d)
-
161 return false;
-
162 }
-
163 -
164 -
165 return (length & 1) ? *sa.w == *sb.w : true;
-
166 } else { -
167 -
168 register const quint16 *e = sa.w + length; -
169 for ( ; sa.w != e; ++sa.w, ++sb.w) {
-
170 if (*sa.w != *sb.w)
-
171 return false;
-
172 }
-
173 }
-
174 return true;
-
175} -
176static int findChar(const QChar *str, int len, QChar ch, int from, -
177 Qt::CaseSensitivity cs) -
178{ -
179 const ushort *s = (const ushort *)str; -
180 ushort c = ch.unicode(); -
181 if (from < 0)
-
182 from = qMax(from + len, 0);
-
183 if (from < len) {
-
184 const ushort *n = s + from - 1; -
185 const ushort *e = s + len; -
186 if (cs == Qt::CaseSensitive) {
-
187 while (++n != e)
-
188 if (*n == c)
-
189 return n - s;
-
190 } else {
-
191 c = foldCase(c); -
192 while (++n != e)
-
193 if (foldCase(*n) == c)
-
194 return n - s;
-
195 }
-
196 } -
197 return -1;
-
198} -
199 -
200 -
201 -
202 -
203 -
204 -
205inline bool qIsUpper(char ch) -
206{ -
207 return ch >= 'A' && ch <= 'Z';
-
208} -
209 -
210inline bool qIsDigit(char ch) -
211{ -
212 return ch >= '0' && ch <= '9';
-
213} -
214 -
215inline char qToLower(char ch) -
216{ -
217 if (ch >= 'A' && ch <= 'Z')
-
218 return ch - 'A' + 'a';
-
219 else -
220 return ch;
-
221} -
222 -
223 -
224const QString::Null QString::null = { }; -
225int QString::toUcs4_helper(const ushort *uc, int length, uint *out) -
226{ -
227 int i = 0; -
228 for (; i < length; ++i) {
-
229 uint u = uc[i]; -
230 if (QChar::isHighSurrogate(u) && i + 1 < length) {
-
231 ushort low = uc[i+1]; -
232 if (QChar::isLowSurrogate(low)) {
-
233 ++i; -
234 u = QChar::surrogateToUcs4(u, low); -
235 }
-
236 }
-
237 *out++ = u; -
238 }
-
239 return i;
-
240} -
241QString::QString(const QChar *unicode, int size) -
242{ -
243 if (!unicode) {
-
244 d = Data::sharedNull(); -
245 } else {
-
246 if (size < 0) {
-
247 size = 0; -
248 while (unicode[size] != 0)
-
249 ++size;
-
250 }
-
251 if (!size) {
-
252 d = Data::allocate(0); -
253 } else {
-
254 d = Data::allocate(size + 1); -
255 do { if (!(d)) qBadAlloc(); } while (0);
-
256 d->size = size; -
257 memcpy(d->data(), unicode, size * sizeof(QChar)); -
258 d->data()[size] = '\0'; -
259 }
-
260 } -
261} -
262 -
263 -
264 -
265 -
266 -
267 -
268 -
269QString::QString(int size, QChar ch) -
270{ -
271 if (size <= 0) {
-
272 d = Data::allocate(0); -
273 } else {
-
274 d = Data::allocate(size + 1); -
275 do { if (!(d)) qBadAlloc(); } while (0);
-
276 d->size = size; -
277 d->data()[size] = '\0'; -
278 ushort *i = d->data() + size; -
279 ushort *b = d->data(); -
280 const ushort value = ch.unicode(); -
281 while (i != b)
-
282 *--i = value;
-
283 }
-
284} -
285 -
286 -
287 -
288 -
289 -
290 -
291 -
292QString::QString(int size, Qt::Initialization) -
293{ -
294 d = Data::allocate(size + 1); -
295 do { if (!(d)) qBadAlloc(); } while (0);
-
296 d->size = size; -
297 d->data()[size] = '\0'; -
298}
-
299QString::QString(QChar ch) -
300{ -
301 d = Data::allocate(2); -
302 do { if (!(d)) qBadAlloc(); } while (0);
-
303 d->size = 1; -
304 d->data()[0] = ch.unicode(); -
305 d->data()[1] = '\0'; -
306}
-
307void QString::resize(int size) -
308{ -
309 if (size < 0)
-
310 size = 0;
-
311 -
312 if (((d)->offset != sizeof(QStringData)) && !d->ref.isShared() && size < d->size) {
-
313 d->size = size; -
314 return;
-
315 } -
316 -
317 if (size == 0 && !d->capacityReserved) {
-
318 Data *x = Data::allocate(0); -
319 if (!d->ref.deref())
-
320 Data::deallocate(d);
-
321 d = x; -
322 } else {
-
323 if (d->ref.isShared() || uint(size) + 1u > d->alloc
-
324 || (!d->capacityReserved && size < d->size
-
325 && uint(size) + 1u < uint(d->alloc >> 1)))
-
326 reallocData(uint(size) + 1u, true);
-
327 if (d->alloc) {
-
328 d->size = size; -
329 d->data()[size] = '\0'; -
330 }
-
331 }
-
332} -
333void QString::reallocData(uint alloc, bool grow) -
334{ -
335 if (grow)
-
336 alloc = qAllocMore(alloc * sizeof(QChar), sizeof(Data)) / sizeof(QChar);
-
337 -
338 if (d->ref.isShared() || ((d)->offset != sizeof(QStringData))) {
-
339 Data::AllocationOptions allocOptions(d->capacityReserved ? Data::CapacityReserved : 0); -
340 Data *x = Data::allocate(alloc, allocOptions); -
341 do { if (!(x)) qBadAlloc(); } while (0);
-
342 x->size = qMin(int(alloc) - 1, d->size); -
343 ::memcpy(x->data(), d->data(), x->size * sizeof(QChar)); -
344 x->data()[x->size] = 0; -
345 if (!d->ref.deref())
-
346 Data::deallocate(d);
-
347 d = x; -
348 } else {
-
349 Data *p = static_cast<Data *>(::realloc(d, sizeof(Data) + alloc * sizeof(QChar))); -
350 do { if (!(p)) qBadAlloc(); } while (0);
-
351 d = p; -
352 d->alloc = alloc; -
353 d->offset = sizeof(QStringData); -
354 }
-
355} -
356 -
357void QString::expand(int i) -
358{ -
359 int sz = d->size; -
360 resize(qMax(i + 1, sz)); -
361 if (d->size - 1 > sz) {
-
362 ushort *n = d->data() + d->size - 1; -
363 ushort *e = d->data() + sz; -
364 while (n != e)
-
365 * --n = ' ';
-
366 }
-
367}
-
368QString &QString::operator=(const QString &other) -
369{ -
370 other.d->ref.ref(); -
371 if (!d->ref.deref())
-
372 Data::deallocate(d);
-
373 d = other.d; -
374 return *this;
-
375} -
376QString &QString::operator=(QChar ch) -
377{ -
378 return operator=(QString(ch));
-
379} -
380QString &QString::insert(int i, QLatin1String str) -
381{ -
382 const uchar *s = (const uchar *)str.latin1(); -
383 if (i < 0 || !s || !(*s))
-
384 return *this;
-
385 -
386 int len = str.size(); -
387 expand(qMax(d->size, i) + len - 1); -
388 -
389 ::memmove(d->data() + i + len, d->data() + i, (d->size - i - len) * sizeof(QChar)); -
390 for (int j = 0; j < len; ++j)
-
391 d->data()[i + j] = s[j];
-
392 return *this;
-
393} -
394QString& QString::insert(int i, const QChar *unicode, int size) -
395{ -
396 if (i < 0 || size <= 0)
-
397 return *this;
-
398 -
399 const ushort *s = (const ushort *)unicode; -
400 if (s >= d->data() && s < d->data() + d->alloc) {
-
401 -
402 ushort *tmp = static_cast<ushort *>(::malloc(size * sizeof(QChar))); -
403 do { if (!(tmp)) qBadAlloc(); } while (0);
-
404 memcpy(tmp, s, size * sizeof(QChar)); -
405 insert(i, reinterpret_cast<const QChar *>(tmp), size); -
406 ::free(tmp); -
407 return *this;
-
408 } -
409 -
410 expand(qMax(d->size, i) + size - 1); -
411 -
412 ::memmove(d->data() + i + size, d->data() + i, (d->size - i - size) * sizeof(QChar)); -
413 memcpy(d->data() + i, s, size * sizeof(QChar)); -
414 return *this;
-
415} -
416QString& QString::insert(int i, QChar ch) -
417{ -
418 if (i < 0)
-
419 i += d->size;
-
420 if (i < 0)
-
421 return *this;
-
422 expand(qMax(i, d->size)); -
423 ::memmove(d->data() + i + 1, d->data() + i, (d->size - i - 1) * sizeof(QChar)); -
424 d->data()[i] = ch.unicode(); -
425 return *this;
-
426} -
427QString &QString::append(const QString &str) -
428{ -
429 if (str.d != Data::sharedNull()) {
-
430 if (d == Data::sharedNull()) {
-
431 operator=(str); -
432 } else {
-
433 if (d->ref.isShared() || uint(d->size + str.d->size) + 1u > d->alloc)
-
434 reallocData(uint(d->size + str.d->size) + 1u, true);
-
435 memcpy(d->data() + d->size, str.d->data(), str.d->size * sizeof(QChar)); -
436 d->size += str.d->size; -
437 d->data()[d->size] = '\0'; -
438 }
-
439 } -
440 return *this;
-
441} -
442 -
443 -
444 -
445 -
446 -
447 -
448 -
449QString &QString::append(const QChar *str, int len) -
450{ -
451 if (str && len > 0) {
-
452 if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc)
-
453 reallocData(uint(d->size + len) + 1u, true);
-
454 memcpy(d->data() + d->size, str, len * sizeof(QChar)); -
455 d->size += len; -
456 d->data()[d->size] = '\0'; -
457 }
-
458 return *this;
-
459} -
460 -
461 -
462 -
463 -
464 -
465 -
466QString &QString::append(QLatin1String str) -
467{ -
468 const uchar *s = (const uchar *)str.latin1(); -
469 if (s) {
-
470 int len = str.size(); -
471 if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc)
-
472 reallocData(uint(d->size + len) + 1u, true);
-
473 ushort *i = d->data() + d->size; -
474 while ((*i++ = *s++))
-
475 ;
-
476 d->size += len; -
477 }
-
478 return *this;
-
479} -
480QString &QString::append(QChar ch) -
481{ -
482 if (d->ref.isShared() || uint(d->size) + 2u > d->alloc)
-
483 reallocData(uint(d->size) + 2u, true);
-
484 d->data()[d->size++] = ch.unicode(); -
485 d->data()[d->size] = '\0'; -
486 return *this;
-
487} -
488QString &QString::remove(int pos, int len) -
489{ -
490 if (pos < 0)
-
491 pos += d->size;
-
492 if (pos < 0 || pos >= d->size) {
-
493 -
494 } else if (len >= d->size - pos) {
-
495 resize(pos); -
496 } else if (len > 0) {
-
497 detach(); -
498 memmove(d->data() + pos, d->data() + pos + len, -
499 (d->size - pos - len + 1) * sizeof(ushort)); -
500 d->size -= len; -
501 }
-
502 return *this;
-
503} -
504QString &QString::remove(const QString &str, Qt::CaseSensitivity cs) -
505{ -
506 if (str.d->size) {
-
507 int i = 0; -
508 while ((i = indexOf(str, i, cs)) != -1)
-
509 remove(i, str.d->size);
-
510 }
-
511 return *this;
-
512} -
513QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) -
514{ -
515 int i = 0; -
516 ushort c = ch.unicode(); -
517 if (cs == Qt::CaseSensitive) {
-
518 while (i < d->size)
-
519 if (d->data()[i] == ch)
-
520 remove(i, 1);
-
521 else -
522 i++;
-
523 } else {
-
524 c = foldCase(c); -
525 while (i < d->size)
-
526 if (foldCase(d->data()[i]) == c)
-
527 remove(i, 1);
-
528 else -
529 i++;
-
530 }
-
531 return *this;
-
532} -
533QString &QString::replace(int pos, int len, const QString &after) -
534{ -
535 QString copy = after; -
536 return replace(pos, len, copy.constData(), copy.length());
-
537} -
538QString &QString::replace(int pos, int len, const QChar *unicode, int size) -
539{ -
540 if (pos < 0 || pos > d->size)
-
541 return *this;
-
542 if (len > d->size - pos)
-
543 len = d->size - pos;
-
544 -
545 uint index = pos; -
546 replace_helper(&index, 1, len, unicode, size); -
547 return *this;
-
548} -
549QString &QString::replace(int pos, int len, QChar after) -
550{ -
551 return replace(pos, len, &after, 1);
-
552} -
553QString &QString::replace(const QString &before, const QString &after, Qt::CaseSensitivity cs) -
554{ -
555 return replace(before.constData(), before.size(), after.constData(), after.size(), cs);
-
556} -
557 -
558 -
559 -
560 -
561void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar *after, int alen) -
562{ -
563 -
564 -
565 QChar *afterBuffer = const_cast<QChar *>(after); -
566 if (after >= reinterpret_cast<QChar *>(d->data()) && after < reinterpret_cast<QChar *>(d->data()) + d->size) {
-
567 afterBuffer = static_cast<QChar *>(::malloc(alen*sizeof(QChar))); -
568 do { if (!(afterBuffer)) qBadAlloc(); } while (0);
-
569 ::memcpy(afterBuffer, after, alen*sizeof(QChar)); -
570 }
-
571 -
572 try { -
573 if (blen == alen) {
-
574 -
575 detach(); -
576 for (int i = 0; i < nIndices; ++i)
-
577 memcpy(d->data() + indices[i], afterBuffer, alen * sizeof(QChar));
-
578 } else if (alen < blen) {
-
579 -
580 detach(); -
581 uint to = indices[0]; -
582 if (alen)
-
583 memcpy(d->data()+to, after, alen*sizeof(QChar));
-
584 to += alen; -
585 uint movestart = indices[0] + blen; -
586 for (int i = 1; i < nIndices; ++i) {
-
587 int msize = indices[i] - movestart; -
588 if (msize > 0) {
-
589 memmove(d->data() + to, d->data() + movestart, msize * sizeof(QChar)); -
590 to += msize; -
591 }
-
592 if (alen) {
-
593 memcpy(d->data() + to, afterBuffer, alen*sizeof(QChar)); -
594 to += alen; -
595 }
-
596 movestart = indices[i] + blen; -
597 }
-
598 int msize = d->size - movestart; -
599 if (msize > 0)
-
600 memmove(d->data() + to, d->data() + movestart, msize * sizeof(QChar));
-
601 resize(d->size - nIndices*(blen-alen)); -
602 } else {
-
603 -
604 int adjust = nIndices*(alen-blen); -
605 int newLen = d->size + adjust; -
606 int moveend = d->size; -
607 resize(newLen); -
608 -
609 while (nIndices) {
-
610 --nIndices; -
611 int movestart = indices[nIndices] + blen; -
612 int insertstart = indices[nIndices] + nIndices*(alen-blen); -
613 int moveto = insertstart + alen; -
614 memmove(d->data() + moveto, d->data() + movestart, -
615 (moveend - movestart)*sizeof(QChar)); -
616 memcpy(d->data() + insertstart, afterBuffer, alen*sizeof(QChar)); -
617 moveend = movestart-blen; -
618 }
-
619 }
-
620 } catch (const std::bad_alloc &) { -
621 if (afterBuffer != after)
-
622 ::free(afterBuffer);
-
623 throw;
-
624 } -
625 if (afterBuffer != after)
-
626 ::free(afterBuffer);
-
627}
-
628QString &QString::replace(const QChar *before, int blen, -
629 const QChar *after, int alen, -
630 Qt::CaseSensitivity cs) -
631{ -
632 if (d->size == 0) {
-
633 if (blen)
-
634 return *this;
-
635 } else {
-
636 if (cs == Qt::CaseSensitive && before == after && blen == alen)
-
637 return *this;
-
638 }
-
639 if (alen == 0 && blen == 0)
-
640 return *this;
-
641 -
642 QStringMatcher matcher(before, blen, cs); -
643 -
644 int index = 0; -
645 while (1) {
-
646 uint indices[1024]; -
647 uint pos = 0; -
648 while (pos < 1023) {
-
649 index = matcher.indexIn(*this, index); -
650 if (index == -1)
-
651 break;
-
652 indices[pos++] = index; -
653 index += blen; -
654 -
655 if (!blen)
-
656 index++;
-
657 }
-
658 if (!pos)
-
659 break;
-
660 -
661 replace_helper(indices, pos, blen, after, alen); -
662 -
663 if (index == -1)
-
664 break;
-
665 -
666 index += pos*(alen-blen); -
667 }
-
668 -
669 return *this;
-
670} -
671QString& QString::replace(QChar ch, const QString &after, Qt::CaseSensitivity cs) -
672{ -
673 if (after.d->size == 0)
-
674 return remove(ch, cs);
-
675 -
676 if (after.d->size == 1)
-
677 return replace(ch, after.d->data()[0], cs);
-
678 -
679 if (d->size == 0)
-
680 return *this;
-
681 -
682 ushort cc = (cs == Qt::CaseSensitive ? ch.unicode() : ch.toCaseFolded().unicode());
-
683 -
684 int index = 0; -
685 while (1) {
-
686 uint indices[1024]; -
687 uint pos = 0; -
688 if (cs == Qt::CaseSensitive) {
-
689 while (pos < 1023 && index < d->size) {
-
690 if (d->data()[index] == cc)
-
691 indices[pos++] = index;
-
692 index++; -
693 }
-
694 } else {
-
695 while (pos < 1023 && index < d->size) {
-
696 if (QChar::toCaseFolded(d->data()[index]) == cc)
-
697 indices[pos++] = index;
-
698 index++; -
699 }
-
700 }
-
701 if (!pos)
-
702 break;
-
703 -
704 replace_helper(indices, pos, 1, after.constData(), after.d->size); -
705 -
706 if (index == -1)
-
707 break;
-
708 -
709 index += pos*(after.d->size - 1); -
710 }
-
711 return *this;
-
712} -
713QString& QString::replace(QChar before, QChar after, Qt::CaseSensitivity cs) -
714{ -
715 ushort a = after.unicode(); -
716 ushort b = before.unicode(); -
717 if (d->size) {
-
718 detach(); -
719 ushort *i = d->data(); -
720 const ushort *e = i + d->size; -
721 if (cs == Qt::CaseSensitive) {
-
722 for (; i != e; ++i)
-
723 if (*i == b)
-
724 *i = a;
-
725 } else {
-
726 b = foldCase(b); -
727 for (; i != e; ++i)
-
728 if (foldCase(*i) == b)
-
729 *i = a;
-
730 }
-
731 } -
732 return *this;
-
733} -
734QString &QString::replace(QLatin1String before, QLatin1String after, Qt::CaseSensitivity cs) -
735{ -
736 int alen = after.size(); -
737 QVarLengthArray<ushort> a(alen); -
738 for (int i = 0; i < alen; ++i)
-
739 a[i] = (uchar)after.latin1()[i];
-
740 int blen = before.size(); -
741 QVarLengthArray<ushort> b(blen); -
742 for (int i = 0; i < blen; ++i)
-
743 b[i] = (uchar)before.latin1()[i];
-
744 return replace((const QChar *)b.data(), blen, (const QChar *)a.data(), alen, cs);
-
745} -
746QString &QString::replace(QLatin1String before, const QString &after, Qt::CaseSensitivity cs) -
747{ -
748 int blen = before.size(); -
749 QVarLengthArray<ushort> b(blen); -
750 for (int i = 0; i < blen; ++i)
-
751 b[i] = (uchar)before.latin1()[i];
-
752 return replace((const QChar *)b.data(), blen, after.constData(), after.d->size, cs);
-
753} -
754QString &QString::replace(const QString &before, QLatin1String after, Qt::CaseSensitivity cs) -
755{ -
756 int alen = after.size(); -
757 QVarLengthArray<ushort> a(alen); -
758 for (int i = 0; i < alen; ++i)
-
759 a[i] = (uchar)after.latin1()[i];
-
760 return replace(before.constData(), before.d->size, (const QChar *)a.data(), alen, cs);
-
761} -
762QString &QString::replace(QChar c, QLatin1String after, Qt::CaseSensitivity cs) -
763{ -
764 int alen = after.size(); -
765 QVarLengthArray<ushort> a(alen); -
766 for (int i = 0; i < alen; ++i)
-
767 a[i] = (uchar)after.latin1()[i];
-
768 return replace(&c, 1, (const QChar *)a.data(), alen, cs);
-
769} -
770bool operator==(const QString &s1, const QString &s2) -
771{ -
772 if (s1.d->size != s2.d->size)
-
773 return false;
-
774 -
775 return qMemEquals(s1.d->data(), s2.d->data(), s1.d->size);
-
776} -
777 -
778 -
779 -
780 -
781bool QString::operator==(QLatin1String other) const -
782{ -
783 if (d->size != other.size())
-
784 return false;
-
785 -
786 if (!other.size())
-
787 return isEmpty();
-
788 -
789 const ushort *uc = d->data(); -
790 const ushort *e = uc + d->size; -
791 const uchar *c = (uchar *)other.latin1(); -
792 -
793 while (uc < e) {
-
794 if (*uc != *c)
-
795 return false;
-
796 ++uc; -
797 ++c; -
798 }
-
799 return true;
-
800} -
801bool operator<(const QString &s1, const QString &s2) -
802{ -
803 return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0;
-
804} -
805 -
806 -
807 -
808 -
809bool QString::operator<(QLatin1String other) const -
810{ -
811 const uchar *c = (uchar *) other.latin1(); -
812 if (!c || *c == 0)
-
813 return false;
-
814 -
815 const ushort *uc = d->data(); -
816 const ushort *e = uc + qMin(d->size, other.size()); -
817 -
818 while (uc < e) {
-
819 if (*uc != *c)
-
820 break;
-
821 ++uc; -
822 ++c; -
823 }
-
824 return (uc == e ? d->size < other.size() : *uc < *c);
-
825} -
826bool QString::operator>(QLatin1String other) const -
827{ -
828 const uchar *c = (uchar *) other.latin1(); -
829 if (!c || *c == '\0')
-
830 return !isEmpty();
-
831 -
832 const ushort *uc = d->data(); -
833 const ushort *e = uc + qMin(d->size, other.size()); -
834 -
835 while (uc < e) {
-
836 if (*uc != *c)
-
837 break;
-
838 ++uc; -
839 ++c; -
840 }
-
841 return (uc == e) ? d->size > other.size() : *uc > *c;
-
842} -
843int QString::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const -
844{ -
845 return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs);
-
846} -
847int QString::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const -
848{ -
849 return qt_find_latin1_string(unicode(), size(), str, from, cs);
-
850} -
851 -
852int qFindString( -
853 const QChar *haystack0, int haystackLen, int from, -
854 const QChar *needle0, int needleLen, Qt::CaseSensitivity cs) -
855{ -
856 const int l = haystackLen; -
857 const int sl = needleLen; -
858 if (from < 0)
-
859 from += l;
-
860 if (uint(sl + from) > (uint)l)
-
861 return -1;
-
862 if (!sl)
-
863 return from;
-
864 if (!l)
-
865 return -1;
-
866 -
867 if (sl == 1)
-
868 return findChar(haystack0, haystackLen, needle0[0], from, cs);
-
869 -
870 -
871 -
872 -
873 -
874 -
875 if (l > 500 && sl > 5)
-
876 return qFindStringBoyerMoore(haystack0, haystackLen, from, -
877 needle0, needleLen, cs);
-
878 -
879 -
880 -
881 -
882 -
883 -
884 -
885 const ushort *needle = (const ushort *)needle0; -
886 const ushort *haystack = (const ushort *)haystack0 + from; -
887 const ushort *end = (const ushort *)haystack0 + (l-sl); -
888 const int sl_minus_1 = sl-1; -
889 int hashNeedle = 0, hashHaystack = 0, idx; -
890 -
891 if (cs == Qt::CaseSensitive) {
-
892 for (idx = 0; idx < sl; ++idx) {
-
893 hashNeedle = ((hashNeedle<<1) + needle[idx]); -
894 hashHaystack = ((hashHaystack<<1) + haystack[idx]); -
895 }
-
896 hashHaystack -= haystack[sl_minus_1]; -
897 -
898 while (haystack <= end) {
-
899 hashHaystack += haystack[sl_minus_1]; -
900 if (hashHaystack == hashNeedle
-
901 && ucstrncmp((const QChar *)needle, (const QChar *)haystack, sl) == 0)
-
902 return haystack - (const ushort *)haystack0;
-
903 -
904 if (sl_minus_1 < (int)sizeof(int) * 8) hashHaystack -= (*haystack) << sl_minus_1; hashHaystack <<= 1;
-
905 ++haystack; -
906 }
-
907 } else {
-
908 const ushort *haystack_start = (const ushort *)haystack0; -
909 for (idx = 0; idx < sl; ++idx) {
-
910 hashNeedle = (hashNeedle<<1) + foldCase(needle + idx, needle); -
911 hashHaystack = (hashHaystack<<1) + foldCase(haystack + idx, haystack_start); -
912 }
-
913 hashHaystack -= foldCase(haystack + sl_minus_1, haystack_start); -
914 -
915 while (haystack <= end) {
-
916 hashHaystack += foldCase(haystack + sl_minus_1, haystack_start); -
917 if (hashHaystack == hashNeedle && ucstrnicmp(needle, haystack, sl) == 0)
-
918 return haystack - (const ushort *)haystack0;
-
919 -
920 if (sl_minus_1 < (int)sizeof(int) * 8) hashHaystack -= (foldCase(haystack, haystack_start)) << sl_minus_1; hashHaystack <<= 1;
-
921 ++haystack; -
922 }
-
923 }
-
924 return -1;
-
925} -
926int QString::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const -
927{ -
928 return findChar(unicode(), length(), ch, from, cs);
-
929} -
930int QString::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const -
931{ -
932 return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs);
-
933} -
934 -
935static int lastIndexOfHelper(const ushort *haystack, int from, const ushort *needle, int sl, Qt::CaseSensitivity cs) -
936{ -
937 -
938 -
939 -
940 -
941 const ushort *end = haystack; -
942 haystack += from; -
943 const int sl_minus_1 = sl-1; -
944 const ushort *n = needle+sl_minus_1; -
945 const ushort *h = haystack+sl_minus_1; -
946 int hashNeedle = 0, hashHaystack = 0, idx; -
947 -
948 if (cs == Qt::CaseSensitive) {
-
949 for (idx = 0; idx < sl; ++idx) {
-
950 hashNeedle = ((hashNeedle<<1) + *(n-idx)); -
951 hashHaystack = ((hashHaystack<<1) + *(h-idx)); -
952 }
-
953 hashHaystack -= *haystack; -
954 -
955 while (haystack >= end) {
-
956 hashHaystack += *haystack; -
957 if (hashHaystack == hashNeedle
-
958 && ucstrncmp((const QChar *)needle, (const QChar *)haystack, sl) == 0)
-
959 return haystack - end;
-
960 --haystack; -
961 if (sl_minus_1 < (int)sizeof(int) * 8) hashHaystack -= (haystack[sl]) << sl_minus_1; hashHaystack <<= 1;
-
962 }
-
963 } else {
-
964 for (idx = 0; idx < sl; ++idx) {
-
965 hashNeedle = ((hashNeedle<<1) + foldCase(n-idx, needle)); -
966 hashHaystack = ((hashHaystack<<1) + foldCase(h-idx, end)); -
967 }
-
968 hashHaystack -= foldCase(haystack, end); -
969 -
970 while (haystack >= end) {
-
971 hashHaystack += foldCase(haystack, end); -
972 if (hashHaystack == hashNeedle && ucstrnicmp(needle, haystack, sl) == 0)
-
973 return haystack - end;
-
974 --haystack; -
975 if (sl_minus_1 < (int)sizeof(int) * 8) hashHaystack -= (foldCase(haystack + sl, end)) << sl_minus_1; hashHaystack <<= 1;
-
976 }
-
977 }
-
978 return -1;
-
979} -
980int QString::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const -
981{ -
982 const int sl = str.d->size; -
983 if (sl == 1)
-
984 return lastIndexOf(QChar(str.d->data()[0]), from, cs);
-
985 -
986 const int l = d->size; -
987 if (from < 0)
-
988 from += l;
-
989 int delta = l-sl; -
990 if (from == l && sl == 0)
-
991 return from;
-
992 if (from < 0 || from >= l || delta < 0)
-
993 return -1;
-
994 if (from > delta)
-
995 from = delta;
-
996 -
997 return lastIndexOfHelper(d->data(), from, str.d->data(), str.d->size, cs);
-
998} -
999int QString::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const -
1000{ -
1001 const int sl = str.size(); -
1002 if (sl == 1)
-
1003 return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs);
-
1004 -
1005 const int l = d->size; -
1006 if (from < 0)
-
1007 from += l;
-
1008 int delta = l-sl; -
1009 if (from == l && sl == 0)
-
1010 return from;
-
1011 if (from < 0 || from >= l || delta < 0)
-
1012 return -1;
-
1013 if (from > delta)
-
1014 from = delta;
-
1015 -
1016 QVarLengthArray<ushort> s(sl); -
1017 for (int i = 0; i < sl; ++i)
-
1018 s[i] = str.latin1()[i];
-
1019 -
1020 return lastIndexOfHelper(d->data(), from, s.data(), sl, cs);
-
1021} -
1022 -
1023 -
1024 -
1025 -
1026 -
1027 -
1028 -
1029int QString::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const -
1030{ -
1031 return qt_last_index_of(unicode(), size(), ch, from, cs);
-
1032} -
1033int QString::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const -
1034{ -
1035 const int sl = str.size(); -
1036 if (sl == 1)
-
1037 return lastIndexOf(str.at(0), from, cs);
-
1038 -
1039 const int l = d->size; -
1040 if (from < 0)
-
1041 from += l;
-
1042 int delta = l - sl; -
1043 if (from == l && sl == 0)
-
1044 return from;
-
1045 if (from < 0 || from >= l || delta < 0)
-
1046 return -1;
-
1047 if (from > delta)
-
1048 from = delta;
-
1049 -
1050 return lastIndexOfHelper(d->data(), from, reinterpret_cast<const ushort*>(str.unicode()), -
1051 str.size(), cs);
-
1052} -
1053 -
1054 -
1055struct QStringCapture -
1056{ -
1057 int pos; -
1058 int len; -
1059 int no; -
1060}; -
1061QString& QString::replace(const QRegExp &rx, const QString &after) -
1062{ -
1063 QRegExp rx2(rx); -
1064 -
1065 if (isEmpty() && rx2.indexIn(*this) == -1)
-
1066 return *this;
-
1067 -
1068 reallocData(uint(d->size) + 1u); -
1069 -
1070 int index = 0; -
1071 int numCaptures = rx2.captureCount(); -
1072 int al = after.length(); -
1073 QRegExp::CaretMode caretMode = QRegExp::CaretAtZero; -
1074 -
1075 if (numCaptures > 0) {
-
1076 const QChar *uc = after.unicode(); -
1077 int numBackRefs = 0; -
1078 -
1079 for (int i = 0; i < al - 1; i++) {
-
1080 if (uc[i] == QLatin1Char('\\')) {
-
1081 int no = uc[i + 1].digitValue(); -
1082 if (no > 0 && no <= numCaptures)
-
1083 numBackRefs++;
-
1084 }
-
1085 }
-
1086 -
1087 -
1088 -
1089 -
1090 if (numBackRefs > 0) {
-
1091 QVarLengthArray<QStringCapture, 16> captures(numBackRefs); -
1092 int j = 0; -
1093 -
1094 for (int i = 0; i < al - 1; i++) {
-
1095 if (uc[i] == QLatin1Char('\\')) {
-
1096 int no = uc[i + 1].digitValue(); -
1097 if (no > 0 && no <= numCaptures) {
-
1098 QStringCapture capture; -
1099 capture.pos = i; -
1100 capture.len = 2; -
1101 -
1102 if (i < al - 2) {
-
1103 int secondDigit = uc[i + 2].digitValue(); -
1104 if (secondDigit != -1 && ((no * 10) + secondDigit) <= numCaptures) {
-
1105 no = (no * 10) + secondDigit; -
1106 ++capture.len; -
1107 }
-
1108 }
-
1109 -
1110 capture.no = no; -
1111 captures[j++] = capture; -
1112 }
-
1113 }
-
1114 }
-
1115 -
1116 while (index <= length()) {
-
1117 index = rx2.indexIn(*this, index, caretMode); -
1118 if (index == -1)
-
1119 break;
-
1120 -
1121 QString after2(after); -
1122 for (j = numBackRefs - 1; j >= 0; j--) {
-
1123 const QStringCapture &capture = captures[j]; -
1124 after2.replace(capture.pos, capture.len, rx2.cap(capture.no)); -
1125 }
-
1126 -
1127 replace(index, rx2.matchedLength(), after2); -
1128 index += after2.length(); -
1129 -
1130 -
1131 if (rx2.matchedLength() == 0)
-
1132 ++index;
-
1133 -
1134 caretMode = QRegExp::CaretWontMatch; -
1135 }
-
1136 return *this;
-
1137 } -
1138 }
-
1139 -
1140 -
1141 -
1142 -
1143 -
1144 while (index != -1) {
-
1145 struct { -
1146 int pos; -
1147 int length; -
1148 } replacements[2048]; -
1149 -
1150 int pos = 0; -
1151 int adjust = 0; -
1152 while (pos < 2047) {
-
1153 index = rx2.indexIn(*this, index, caretMode); -
1154 if (index == -1)
-
1155 break;
-
1156 int ml = rx2.matchedLength(); -
1157 replacements[pos].pos = index; -
1158 replacements[pos++].length = ml; -
1159 index += ml; -
1160 adjust += al - ml; -
1161 -
1162 if (!ml)
-
1163 index++;
-
1164 }
-
1165 if (!pos)
-
1166 break;
-
1167 replacements[pos].pos = d->size; -
1168 int newlen = d->size + adjust; -
1169 -
1170 -
1171 -
1172 if (index != -1)
-
1173 index += adjust;
-
1174 QString newstring; -
1175 newstring.reserve(newlen + 1); -
1176 QChar *newuc = newstring.data(); -
1177 QChar *uc = newuc; -
1178 int copystart = 0; -
1179 int i = 0; -
1180 while (i < pos) {
-
1181 int copyend = replacements[i].pos; -
1182 int size = copyend - copystart; -
1183 memcpy(uc, d->data() + copystart, size * sizeof(QChar)); -
1184 uc += size; -
1185 memcpy(uc, after.d->data(), al * sizeof(QChar)); -
1186 uc += al; -
1187 copystart = copyend + replacements[i].length; -
1188 i++; -
1189 }
-
1190 memcpy(uc, d->data() + copystart, (d->size - copystart) * sizeof(QChar)); -
1191 newstring.resize(newlen); -
1192 *this = newstring; -
1193 caretMode = QRegExp::CaretWontMatch; -
1194 }
-
1195 return *this;
-
1196} -
1197QString &QString::replace(const QRegularExpression &re, const QString &after) -
1198{ -
1199 if (!re.isValid()) {
evaluated: !re.isValid()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:33
2-33
1200 QMessageLogger("tools/qstring.cpp", 2951, __PRETTY_FUNCTION__).warning("QString::replace: invalid QRegularExpresssionQRegularExpression object"); -
1201 return *this;
executed: return *this;
Execution Count:2
2
1202 } -
1203 -
1204 const QString copy(*this); -
1205 QRegularExpressionMatchIterator iterator = re.globalMatch(copy); -
1206 if (!iterator.hasNext())
evaluated: !iterator.hasNext()
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:21
12-21
1207 return *this;
executed: return *this;
Execution Count:12
12
1208 -
1209 reallocData(uint(d->size) + 1u); -
1210 -
1211 int numCaptures = re.captureCount(); -
1212 -
1213 -
1214 -
1215 QVector<QStringCapture> backReferences; -
1216 const int al = after.length(); -
1217 const QChar *ac = after.unicode(); -
1218 -
1219 for (int i = 0; i < al - 1; i++) {
evaluated: i < al - 1
TRUEFALSE
yes
Evaluation Count:138
yes
Evaluation Count:21
21-138
1220 if (ac[i] == QLatin1Char('\\')) {
evaluated: ac[i] == QLatin1Char('\\')
TRUEFALSE
yes
Evaluation Count:55
yes
Evaluation Count:83
55-83
1221 int no = ac[i + 1].digitValue(); -
1222 if (no > 0 && no <= numCaptures) {
evaluated: no > 0
TRUEFALSE
yes
Evaluation Count:51
yes
Evaluation Count:4
evaluated: no <= numCaptures
TRUEFALSE
yes
Evaluation Count:48
yes
Evaluation Count:3
3-51
1223 QStringCapture backReference; -
1224 backReference.pos = i; -
1225 backReference.len = 2; -
1226 -
1227 if (i < al - 2) {
evaluated: i < al - 2
TRUEFALSE
yes
Evaluation Count:43
yes
Evaluation Count:5
5-43
1228 int secondDigit = ac[i + 2].digitValue(); -
1229 if (secondDigit != -1 && ((no * 10) + secondDigit) <= numCaptures) {
evaluated: secondDigit != -1
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:15
evaluated: ((no * 10) + secondDigit) <= numCaptures
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:22
6-28
1230 no = (no * 10) + secondDigit; -
1231 ++backReference.len; -
1232 }
executed: }
Execution Count:6
6
1233 }
executed: }
Execution Count:43
43
1234 -
1235 backReference.no = no; -
1236 backReferences.append(backReference); -
1237 }
executed: }
Execution Count:48
48
1238 }
executed: }
Execution Count:55
55
1239 }
executed: }
Execution Count:138
138
1240 -
1241 -
1242 -
1243 -
1244 -
1245 int newLength = 0; -
1246 int lastEnd = 0; -
1247 QVector<QStringRef> chunks; -
1248 while (iterator.hasNext()) {
evaluated: iterator.hasNext()
TRUEFALSE
yes
Evaluation Count:38
yes
Evaluation Count:21
21-38
1249 QRegularExpressionMatch match = iterator.next(); -
1250 int len; -
1251 -
1252 len = match.capturedStart() - lastEnd; -
1253 if (len > 0) {
evaluated: len > 0
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:34
4-34
1254 chunks << copy.midRef(lastEnd, len); -
1255 newLength += len; -
1256 }
executed: }
Execution Count:4
4
1257 -
1258 lastEnd = 0; -
1259 -
1260 for (QForeachContainer<__typeof__(backReferences)> _container_(backReferences); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QStringCapture &backReference = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
1261 -
1262 len = backReference.pos - lastEnd; -
1263 if (len > 0) {
evaluated: len > 0
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:30
28-30
1264 chunks << after.midRef(lastEnd, len); -
1265 newLength += len; -
1266 }
executed: }
Execution Count:28
28
1267 -
1268 -
1269 len = match.capturedLength(backReference.no); -
1270 if (len > 0) {
evaluated: len > 0
TRUEFALSE
yes
Evaluation Count:57
yes
Evaluation Count:1
1-57
1271 chunks << copy.midRef(match.capturedStart(backReference.no), len); -
1272 newLength += len; -
1273 }
executed: }
Execution Count:57
57
1274 -
1275 lastEnd = backReference.pos + backReference.len; -
1276 }
executed: }
Execution Count:58
58
1277 -
1278 -
1279 len = after.length() - lastEnd; -
1280 if (len > 0) {
evaluated: len > 0
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:11
11-27
1281 chunks << after.midRef(lastEnd, len); -
1282 newLength += len; -
1283 }
executed: }
Execution Count:27
27
1284 -
1285 lastEnd = match.capturedEnd(); -
1286 }
executed: }
Execution Count:38
38
1287 -
1288 -
1289 if (copy.length() > lastEnd) {
evaluated: copy.length() > lastEnd
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:14
7-14
1290 chunks << copy.midRef(lastEnd); -
1291 newLength += copy.length() - lastEnd; -
1292 }
executed: }
Execution Count:7
7
1293 -
1294 -
1295 resize(newLength); -
1296 int i = 0; -
1297 QChar *uc = data(); -
1298 for (QForeachContainer<__typeof__(chunks)> _container_(chunks); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QStringRef &chunk = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
1299 int len = chunk.length(); -
1300 memcpy(uc + i, chunk.unicode(), len * sizeof(QChar)); -
1301 i += len; -
1302 }
executed: }
Execution Count:123
123
1303 -
1304 return *this;
executed: return *this;
Execution Count:21
21
1305} -
1306int QString::count(const QString &str, Qt::CaseSensitivity cs) const -
1307{ -
1308 return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs);
-
1309} -
1310 -
1311 -
1312 -
1313 -
1314 -
1315 -
1316 -
1317int QString::count(QChar ch, Qt::CaseSensitivity cs) const -
1318{ -
1319 return qt_string_count(unicode(), size(), ch, cs);
-
1320 } -
1321int QString::count(const QStringRef &str, Qt::CaseSensitivity cs) const -
1322{ -
1323 return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs);
-
1324} -
1325int QString::indexOf(const QRegExp& rx, int from) const -
1326{ -
1327 QRegExp rx2(rx); -
1328 return rx2.indexIn(*this, from);
-
1329} -
1330int QString::indexOf(QRegExp& rx, int from) const -
1331{ -
1332 return rx.indexIn(*this, from);
-
1333} -
1334int QString::lastIndexOf(const QRegExp& rx, int from) const -
1335{ -
1336 QRegExp rx2(rx); -
1337 return rx2.lastIndexIn(*this, from);
-
1338} -
1339int QString::lastIndexOf(QRegExp& rx, int from) const -
1340{ -
1341 return rx.lastIndexIn(*this, from);
-
1342} -
1343int QString::count(const QRegExp& rx) const -
1344{ -
1345 QRegExp rx2(rx); -
1346 int count = 0; -
1347 int index = -1; -
1348 int len = length(); -
1349 while (index < len - 1) {
-
1350 index = rx2.indexIn(*this, index + 1); -
1351 if (index == -1)
-
1352 break;
-
1353 count++; -
1354 }
-
1355 return count;
-
1356} -
1357int QString::indexOf(const QRegularExpression& re, int from) const -
1358{ -
1359 if (!re.isValid()) {
partially evaluated: !re.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:64
0-64
1360 QMessageLogger("tools/qstring.cpp", 3276, __PRETTY_FUNCTION__).warning("QString::indexOf: invalid QRegularExpresssionQRegularExpression object"); -
1361 return -1;
never executed: return -1;
0
1362 } -
1363 -
1364 QRegularExpressionMatch match = re.match(*this, from); -
1365 if (match.hasMatch())
evaluated: match.hasMatch()
TRUEFALSE
yes
Evaluation Count:33
yes
Evaluation Count:31
31-33
1366 return match.capturedStart();
executed: return match.capturedStart();
Execution Count:33
33
1367 -
1368 return -1;
executed: return -1;
Execution Count:31
31
1369} -
1370int QString::lastIndexOf(const QRegularExpression &re, int from) const -
1371{ -
1372 if (!re.isValid()) {
evaluated: !re.isValid()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:18
1-18
1373 QMessageLogger("tools/qstring.cpp", 3302, __PRETTY_FUNCTION__).warning("QString::lastIndexOf: invalid QRegularExpresssionQRegularExpression object"); -
1374 return -1;
executed: return -1;
Execution Count:1
1
1375 } -
1376 -
1377 int endpos = (from < 0) ? (size() + from + 1) : (from + 1);
evaluated: (from < 0)
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:12
6-12
1378 -
1379 QRegularExpressionMatchIterator iterator = re.globalMatch(*this); -
1380 int lastIndex = -1; -
1381 while (iterator.hasNext()) {
evaluated: iterator.hasNext()
TRUEFALSE
yes
Evaluation Count:34
yes
Evaluation Count:13
13-34
1382 QRegularExpressionMatch match = iterator.next(); -
1383 int start = match.capturedStart(); -
1384 if (start < endpos)
evaluated: start < endpos
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:5
5-29
1385 lastIndex = start;
executed: lastIndex = start;
Execution Count:29
29
1386 else -
1387 break;
executed: break;
Execution Count:5
5
1388 } -
1389 -
1390 return lastIndex;
executed: return lastIndex;
Execution Count:18
18
1391} -
1392 -
1393 -
1394 -
1395 -
1396 -
1397 -
1398 -
1399bool QString::contains(const QRegularExpression &re) const -
1400{ -
1401 if (!re.isValid()) {
evaluated: !re.isValid()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:5
1-5
1402 QMessageLogger("tools/qstring.cpp", 3331, __PRETTY_FUNCTION__).warning("QString::contains: invalid QRegularExpresssionQRegularExpression object"); -
1403 return false;
executed: return false;
Execution Count:1
1
1404 } -
1405 QRegularExpressionMatch match = re.match(*this); -
1406 return match.hasMatch();
executed: return match.hasMatch();
Execution Count:5
5
1407} -
1408int QString::count(const QRegularExpression &re) const -
1409{ -
1410 if (!re.isValid()) {
evaluated: !re.isValid()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-2
1411 QMessageLogger("tools/qstring.cpp", 3353, __PRETTY_FUNCTION__).warning("QString::count: invalid QRegularExpresssionQRegularExpression object"); -
1412 return 0;
executed: return 0;
Execution Count:1
1
1413 } -
1414 int count = 0; -
1415 int index = -1; -
1416 int len = length(); -
1417 while (index < len - 1) {
partially evaluated: index < len - 1
TRUEFALSE
yes
Evaluation Count:5
no
Evaluation Count:0
0-5
1418 QRegularExpressionMatch match = re.match(*this, index + 1); -
1419 if (!match.hasMatch())
evaluated: !match.hasMatch()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:3
2-3
1420 break;
executed: break;
Execution Count:2
2
1421 index = match.capturedStart(); -
1422 count++; -
1423 }
executed: }
Execution Count:3
3
1424 return count;
executed: return count;
Execution Count:2
2
1425} -
1426QString QString::section(const QString &sep, int start, int end, SectionFlags flags) const -
1427{ -
1428 QStringList sections = split(sep, KeepEmptyParts, -
1429 (flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive : Qt::CaseSensitive); -
1430 if (sections.isEmpty())
-
1431 return QString();
-
1432 if (!(flags & SectionSkipEmpty)) {
-
1433 if (start < 0)
-
1434 start += sections.count();
-
1435 if (end < 0)
-
1436 end += sections.count();
-
1437 } else {
-
1438 int skip = 0; -
1439 for (int k=0; k<sections.size(); ++k) {
-
1440 if (sections.at(k).isEmpty())
-
1441 skip++;
-
1442 }
-
1443 if (start < 0)
-
1444 start += sections.count() - skip;
-
1445 if (end < 0)
-
1446 end += sections.count() - skip;
-
1447 }
-
1448 int x = 0; -
1449 QString ret; -
1450 int first_i = start, last_i = end; -
1451 for (int i = 0; x <= end && i < sections.size(); ++i) {
-
1452 QString section = sections.at(i); -
1453 const bool empty = section.isEmpty(); -
1454 if (x >= start) {
-
1455 if(x == start)
-
1456 first_i = i;
-
1457 if(x == end)
-
1458 last_i = i;
-
1459 if(x > start)
-
1460 ret += sep;
-
1461 ret += section; -
1462 }
-
1463 if (!empty || !(flags & SectionSkipEmpty))
-
1464 x++;
-
1465 }
-
1466 if((flags & SectionIncludeLeadingSep) && first_i)
-
1467 ret.prepend(sep);
-
1468 if((flags & SectionIncludeTrailingSep) && last_i < sections.size()-1)
-
1469 ret += sep;
-
1470 return ret;
-
1471} -
1472 -
1473 -
1474class qt_section_chunk { -
1475public: -
1476 qt_section_chunk(int l, QString s) { length = l; string = s; }
-
1477 int length; -
1478 QString string; -
1479}; -
1480 -
1481static QString extractSections(const QList<qt_section_chunk> &sections, -
1482 int start, -
1483 int end, -
1484 QString::SectionFlags flags) -
1485{ -
1486 if (start < 0)
-
1487 start += sections.count();
-
1488 if (end < 0)
-
1489 end += sections.count();
-
1490 -
1491 QString ret; -
1492 int x = 0; -
1493 int first_i = start, last_i = end; -
1494 for (int i = 0; x <= end && i < sections.size(); ++i) {
-
1495 const qt_section_chunk &section = sections.at(i); -
1496 const bool empty = (section.length == section.string.length()); -
1497 if (x >= start) {
-
1498 if (x == start)
-
1499 first_i = i;
-
1500 if (x == end)
-
1501 last_i = i;
-
1502 if (x != start)
-
1503 ret += section.string;
-
1504 else -
1505 ret += section.string.mid(section.length);
-
1506 } -
1507 if (!empty || !(flags & QString::SectionSkipEmpty))
-
1508 x++;
-
1509 }
-
1510 -
1511 if ((flags & QString::SectionIncludeLeadingSep) && first_i < sections.size()) {
-
1512 const qt_section_chunk &section = sections.at(first_i); -
1513 ret.prepend(section.string.left(section.length)); -
1514 }
-
1515 -
1516 if ((flags & QString::SectionIncludeTrailingSep) && last_i+1 <= sections.size()-1) {
-
1517 const qt_section_chunk &section = sections.at(last_i+1); -
1518 ret += section.string.left(section.length); -
1519 }
-
1520 -
1521 return ret;
-
1522} -
1523QString QString::section(const QRegExp &reg, int start, int end, SectionFlags flags) const -
1524{ -
1525 const QChar *uc = unicode(); -
1526 if(!uc)
-
1527 return QString();
-
1528 -
1529 QRegExp sep(reg); -
1530 sep.setCaseSensitivity((flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive -
1531 : Qt::CaseSensitive); -
1532 -
1533 QList<qt_section_chunk> sections; -
1534 int n = length(), m = 0, last_m = 0, last_len = 0; -
1535 while ((m = sep.indexIn(*this, m)) != -1) {
-
1536 sections.append(qt_section_chunk(last_len, QString(uc + last_m, m - last_m))); -
1537 last_m = m; -
1538 last_len = sep.matchedLength(); -
1539 m += qMax(sep.matchedLength(), 1); -
1540 }
-
1541 sections.append(qt_section_chunk(last_len, QString(uc + last_m, n - last_m))); -
1542 -
1543 return extractSections(sections, start, end, flags);
-
1544} -
1545QString QString::section(const QRegularExpression &re, int start, int end, SectionFlags flags) const -
1546{ -
1547 if (!re.isValid()) {
-
1548 QMessageLogger("tools/qstring.cpp", 3597, __PRETTY_FUNCTION__).warning("QString::section: invalid QRegularExpression object"); -
1549 return QString();
-
1550 } -
1551 -
1552 const QChar *uc = unicode(); -
1553 if (!uc)
-
1554 return QString();
-
1555 -
1556 QRegularExpression sep(re); -
1557 if (flags & SectionCaseInsensitiveSeps)
-
1558 sep.setPatternOptions(sep.patternOptions() | QRegularExpression::CaseInsensitiveOption);
-
1559 -
1560 QList<qt_section_chunk> sections; -
1561 int n = length(), m = 0, last_m = 0, last_len = 0; -
1562 QRegularExpressionMatchIterator iterator = sep.globalMatch(*this); -
1563 while (iterator.hasNext()) {
-
1564 QRegularExpressionMatch match = iterator.next(); -
1565 m = match.capturedStart(); -
1566 sections.append(qt_section_chunk(last_len, QString(uc + last_m, m - last_m))); -
1567 last_m = m; -
1568 last_len = match.capturedLength(); -
1569 }
-
1570 sections.append(qt_section_chunk(last_len, QString(uc + last_m, n - last_m))); -
1571 -
1572 return extractSections(sections, start, end, flags);
-
1573} -
1574QString QString::left(int n) const -
1575{ -
1576 if (n >= d->size || n < 0)
-
1577 return *this;
-
1578 return QString((const QChar*) d->data(), n);
-
1579} -
1580QString QString::right(int n) const -
1581{ -
1582 if (n >= d->size || n < 0)
-
1583 return *this;
-
1584 return QString((const QChar*) d->data() + d->size - n, n);
-
1585} -
1586QString QString::mid(int position, int n) const -
1587{ -
1588 if (position > d->size)
-
1589 return QString();
-
1590 if (position < 0) {
-
1591 if (n < 0 || n + position >= d->size)
-
1592 return *this;
-
1593 if (n + position <= 0)
-
1594 return QString();
-
1595 -
1596 n += position; -
1597 position = 0; -
1598 } else if (n < 0 || n > d->size - position)
-
1599 n = d->size - position;
-
1600 if (position == 0 && n == d->size)
-
1601 return *this;
-
1602 return QString((const QChar*) d->data() + position, n);
-
1603} -
1604bool QString::startsWith(const QString& s, Qt::CaseSensitivity cs) const -
1605{ -
1606 return qt_starts_with(isNull() ? 0 : unicode(), size(), -
1607 s.isNull() ? 0 : s.unicode(), s.size(), cs);
-
1608} -
1609 -
1610 -
1611 -
1612 -
1613bool QString::startsWith(QLatin1String s, Qt::CaseSensitivity cs) const -
1614{ -
1615 return qt_starts_with(isNull() ? 0 : unicode(), size(), s, cs);
-
1616} -
1617 -
1618 -
1619 -
1620 -
1621 -
1622 -
1623 -
1624bool QString::startsWith(QChar c, Qt::CaseSensitivity cs) const -
1625{ -
1626 return d->size -
1627 && (cs == Qt::CaseSensitive -
1628 ? d->data()[0] == c -
1629 : foldCase(d->data()[0]) == foldCase(c.unicode()));
-
1630} -
1631bool QString::startsWith(const QStringRef &s, Qt::CaseSensitivity cs) const -
1632{ -
1633 return qt_starts_with(isNull() ? 0 : unicode(), size(), -
1634 s.isNull() ? 0 : s.unicode(), s.size(), cs);
-
1635} -
1636bool QString::endsWith(const QString& s, Qt::CaseSensitivity cs) const -
1637{ -
1638 return qt_ends_with(isNull() ? 0 : unicode(), size(), -
1639 s.isNull() ? 0 : s.unicode(), s.size(), cs);
-
1640 } -
1641bool QString::endsWith(const QStringRef &s, Qt::CaseSensitivity cs) const -
1642{ -
1643 return qt_ends_with(isNull() ? 0 : unicode(), size(), -
1644 s.isNull() ? 0 : s.unicode(), s.size(), cs);
-
1645} -
1646 -
1647 -
1648 -
1649 -
1650 -
1651bool QString::endsWith(QLatin1String s, Qt::CaseSensitivity cs) const -
1652{ -
1653 return qt_ends_with(isNull() ? 0 : unicode(), size(), s, cs);
-
1654} -
1655 -
1656 -
1657 -
1658 -
1659 -
1660 -
1661 -
1662bool QString::endsWith(QChar c, Qt::CaseSensitivity cs) const -
1663{ -
1664 return d->size -
1665 && (cs == Qt::CaseSensitive -
1666 ? d->data()[d->size - 1] == c -
1667 : foldCase(d->data()[d->size - 1]) == foldCase(c.unicode()));
-
1668} -
1669 -
1670 -
1671 -
1672static inline __m128i mergeQuestionMarks(__m128i chunk) -
1673{ -
1674 const __m128i questionMark = _mm_set1_epi16('?'); -
1675 const __m128i signedBitOffset = _mm_set1_epi16(0x8000); -
1676 const __m128i thresholdMask = _mm_set1_epi16(0xff + 0x8000); -
1677 -
1678 const __m128i signedChunk = _mm_add_epi16(chunk, signedBitOffset); -
1679 const __m128i offLimitMask = _mm_cmpgt_epi16(signedChunk, thresholdMask); -
1680 -
1681 -
1682 -
1683 -
1684 -
1685 -
1686 -
1687 const __m128i offLimitQuestionMark = _mm_and_si128(offLimitMask, questionMark); -
1688 -
1689 -
1690 -
1691 const __m128i correctBytes = _mm_andnot_si128(offLimitMask, chunk); -
1692 -
1693 -
1694 chunk = _mm_or_si128(correctBytes, offLimitQuestionMark); -
1695 -
1696 -
1697 return chunk;
-
1698} -
1699 -
1700 -
1701static QByteArray toLatin1_helper(const QChar *data, int length) -
1702{ -
1703 QByteArray ba; -
1704 if (length) {
-
1705 ba.resize(length); -
1706 const ushort *src = reinterpret_cast<const ushort *>(data); -
1707 uchar *dst = (uchar*) ba.data(); -
1708 -
1709 if (length >= 16) {
-
1710 const int chunkCount = length >> 4; -
1711 -
1712 for (int i = 0; i < chunkCount; ++i) {
-
1713 __m128i chunk1 = _mm_loadu_si128((__m128i*)src); -
1714 chunk1 = mergeQuestionMarks(chunk1); -
1715 src += 8; -
1716 -
1717 __m128i chunk2 = _mm_loadu_si128((__m128i*)src); -
1718 chunk2 = mergeQuestionMarks(chunk2); -
1719 src += 8; -
1720 -
1721 -
1722 const __m128i result = _mm_packus_epi16(chunk1, chunk2); -
1723 -
1724 _mm_storeu_si128((__m128i*)dst, result); -
1725 dst += 16; -
1726 }
-
1727 length = length % 16; -
1728 }
-
1729 while (length--) {
-
1730 *dst++ = (*src>0xff) ? '?' : (uchar) *src;
-
1731 ++src; -
1732 }
-
1733 }
-
1734 return ba;
-
1735} -
1736QByteArray QString::toLatin1() const -
1737{ -
1738 return toLatin1_helper(unicode(), length());
-
1739} -
1740QByteArray QString::toLocal8Bit() const -
1741{ -
1742 -
1743 QTextCodec *localeCodec = QTextCodec::codecForLocale(); -
1744 if (localeCodec)
-
1745 return localeCodec->fromUnicode(*this);
-
1746 -
1747 return toLatin1();
-
1748} -
1749QByteArray QString::toUtf8() const -
1750{ -
1751 if (isNull())
-
1752 return QByteArray();
-
1753 -
1754 return QUtf8::convertFromUnicode(constData(), length(), 0);
-
1755} -
1756QVector<uint> QString::toUcs4() const -
1757{ -
1758 QVector<uint> v(length()); -
1759 uint *a = v.data(); -
1760 int len = toUcs4_helper(d->data(), length(), a); -
1761 v.resize(len); -
1762 return v;
-
1763} -
1764 -
1765QString::Data *QString::fromLatin1_helper(const char *str, int size) -
1766{ -
1767 Data *d; -
1768 if (!str) {
-
1769 d = Data::sharedNull(); -
1770 } else if (size == 0 || (!*str && size < 0)) {
-
1771 d = Data::allocate(0); -
1772 } else {
-
1773 if (size < 0)
-
1774 size = qstrlen(str);
-
1775 d = Data::allocate(size + 1); -
1776 do { if (!(d)) qBadAlloc(); } while (0);
-
1777 d->size = size; -
1778 d->data()[size] = '\0'; -
1779 ushort *dst = d->data(); -
1780 -
1781 -
1782 -
1783 -
1784 -
1785 if (size >= 16) {
-
1786 int chunkCount = size >> 4; -
1787 const __m128i nullMask = _mm_set1_epi32(0); -
1788 for (int i = 0; i < chunkCount; ++i) {
-
1789 const __m128i chunk = _mm_loadu_si128((__m128i*)str); -
1790 str += 16; -
1791 -
1792 -
1793 const __m128i firstHalf = _mm_unpacklo_epi8(chunk, nullMask); -
1794 _mm_storeu_si128((__m128i*)dst, firstHalf); -
1795 dst += 8; -
1796 -
1797 -
1798 const __m128i secondHalf = _mm_unpackhi_epi8 (chunk, nullMask); -
1799 _mm_storeu_si128((__m128i*)dst, secondHalf); -
1800 dst += 8; -
1801 }
-
1802 size = size % 16; -
1803 }
-
1804 -
1805 while (size--)
-
1806 *dst++ = (uchar)*str++;
-
1807 }
-
1808 return d;
-
1809} -
1810 -
1811QString::Data *QString::fromAscii_helper(const char *str, int size) -
1812{ -
1813 QString s = fromUtf8(str, size); -
1814 s.d->ref.ref(); -
1815 return s.d;
-
1816} -
1817QString QString::fromLocal8Bit_helper(const char *str, int size) -
1818{ -
1819 if (!str)
-
1820 return QString();
-
1821 if (size == 0 || (!*str && size < 0)) {
-
1822 QStringDataPtr empty = { Data::allocate(0) }; -
1823 return QString(empty);
-
1824 } -
1825 -
1826 if (size < 0)
-
1827 size = qstrlen(str);
-
1828 QTextCodec *codec = QTextCodec::codecForLocale(); -
1829 if (codec)
-
1830 return codec->toUnicode(str, size);
-
1831 -
1832 return fromLatin1(str, size);
-
1833} -
1834QString QString::fromUtf8_helper(const char *str, int size) -
1835{ -
1836 if (!str)
-
1837 return QString();
-
1838 -
1839 qt_noop(); -
1840 return QUtf8::convertToUnicode(str, size, 0);
-
1841} -
1842QString QString::fromUtf16(const ushort *unicode, int size) -
1843{ -
1844 if (!unicode)
-
1845 return QString();
-
1846 if (size < 0) {
-
1847 size = 0; -
1848 while (unicode[size] != 0)
-
1849 ++size;
-
1850 }
-
1851 return QUtf16::convertToUnicode((const char *)unicode, size*2, 0);
-
1852} -
1853QString QString::fromUcs4(const uint *unicode, int size) -
1854{ -
1855 if (!unicode)
-
1856 return QString();
-
1857 if (size < 0) {
-
1858 size = 0; -
1859 while (unicode[size] != 0)
-
1860 ++size;
-
1861 }
-
1862 return QUtf32::convertToUnicode((const char *)unicode, size*4, 0);
-
1863} -
1864QString& QString::setUnicode(const QChar *unicode, int size) -
1865{ -
1866 resize(size); -
1867 if (unicode && size)
-
1868 memcpy(d->data(), unicode, size * sizeof(QChar));
-
1869 return *this;
-
1870} -
1871QString QString::simplified() const -
1872{ -
1873 if (d->size == 0)
-
1874 return *this;
-
1875 -
1876 const QChar * const start = reinterpret_cast<QChar *>(d->data()); -
1877 const QChar *from = start; -
1878 const QChar *fromEnd = start + d->size; -
1879 for(;;) { -
1880 QChar ch = *from; -
1881 if (!ch.isSpace())
-
1882 break;
-
1883 if (++from == fromEnd) {
-
1884 -
1885 QStringDataPtr empty = { Data::allocate(0) }; -
1886 return QString(empty);
-
1887 } -
1888 }
-
1889 -
1890 -
1891 -
1892 while (fromEnd[-1].isSpace())
-
1893 fromEnd--;
-
1894 -
1895 -
1896 const QChar *copyFrom = from; -
1897 int copyCount; -
1898 for(;;) { -
1899 if (++from == fromEnd) {
-
1900 -
1901 return mid(copyFrom - start, from - copyFrom);
-
1902 } -
1903 QChar ch = *from; -
1904 if (!ch.isSpace())
-
1905 continue;
-
1906 if (ch != QLatin1Char(' ')) {
-
1907 copyCount = from - copyFrom; -
1908 break;
-
1909 } -
1910 ch = *++from; -
1911 if (ch.isSpace()) {
-
1912 copyCount = from - copyFrom - 1; -
1913 break;
-
1914 } -
1915 }
-
1916 -
1917 -
1918 -
1919 -
1920 QString result((fromEnd - from) + copyCount, Qt::Uninitialized); -
1921 QChar *to = reinterpret_cast<QChar *>(result.d->data()); -
1922 ::memcpy(to, copyFrom, copyCount * 2); -
1923 to += copyCount; -
1924 fromEnd--; -
1925 QChar ch; -
1926 for(;;) { -
1927 *to++ = QLatin1Char(' '); -
1928 do { -
1929 ch = *++from; -
1930 } while (ch.isSpace());
-
1931 if (from == fromEnd)
-
1932 break;
-
1933 do { -
1934 *to++ = ch; -
1935 ch = *++from; -
1936 if (from == fromEnd)
-
1937 goto done;
-
1938 } while (!ch.isSpace());
-
1939 -
1940 }
-
1941 done:
-
1942 *to++ = ch; -
1943 result.truncate(to - reinterpret_cast<QChar *>(result.d->data())); -
1944 return result;
-
1945} -
1946QString QString::trimmed() const -
1947{ -
1948 if (d->size == 0)
-
1949 return *this;
-
1950 const QChar *s = (const QChar*)d->data(); -
1951 if (!s->isSpace() && !s[d->size-1].isSpace())
-
1952 return *this;
-
1953 int start = 0; -
1954 int end = d->size - 1; -
1955 while (start<=end && s[start].isSpace())
-
1956 start++;
-
1957 if (start <= end) {
-
1958 while (end && s[end].isSpace())
-
1959 end--;
-
1960 }
-
1961 int l = end - start + 1; -
1962 if (l <= 0) {
-
1963 QStringDataPtr empty = { Data::allocate(0) }; -
1964 return QString(empty);
-
1965 } -
1966 return QString(s + start, l);
-
1967} -
1968void QString::truncate(int pos) -
1969{ -
1970 if (pos < d->size)
-
1971 resize(pos);
-
1972}
-
1973void QString::chop(int n) -
1974{ -
1975 if (n > 0)
-
1976 resize(d->size - n);
-
1977}
-
1978QString& QString::fill(QChar ch, int size) -
1979{ -
1980 resize(size < 0 ? d->size : size); -
1981 if (d->size) {
-
1982 QChar *i = (QChar*)d->data() + d->size; -
1983 QChar *b = (QChar*)d->data(); -
1984 while (i != b)
-
1985 *--i = ch;
-
1986 }
-
1987 return *this;
-
1988} -
1989int QString::compare(const QString &other, Qt::CaseSensitivity cs) const -
1990{ -
1991 if (cs == Qt::CaseSensitive)
-
1992 return ucstrcmp(constData(), length(), other.constData(), other.length());
-
1993 return ucstricmp(d->data(), d->data() + d->size, other.d->data(), other.d->data() + other.d->size);
-
1994} -
1995 -
1996 -
1997 -
1998 -
1999 -
2000int QString::compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, -
2001 Qt::CaseSensitivity cs) -
2002{ -
2003 if (cs == Qt::CaseSensitive)
-
2004 return ucstrcmp(data1, length1, data2, length2);
-
2005 register const ushort *s1 = reinterpret_cast<const ushort *>(data1); -
2006 register const ushort *s2 = reinterpret_cast<const ushort *>(data2); -
2007 return ucstricmp(s1, s1 + length1, s2, s2 + length2);
-
2008} -
2009 -
2010 -
2011 -
2012 -
2013 -
2014 -
2015 -
2016int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const -
2017{ -
2018 return compare_helper(unicode(), length(), other, cs);
-
2019} -
2020int QString::compare_helper(const QChar *data1, int length1, const char *data2, int length2, -
2021 Qt::CaseSensitivity cs) -
2022{ -
2023 -
2024 const QString s2 = QString::fromUtf8(data2, length2 == -1 ? (data2 ? int(strlen(data2)) : -1) : length2); -
2025 return compare_helper(data1, length1, s2.constData(), s2.size(), cs);
-
2026} -
2027int QString::compare_helper(const QChar *data1, int length1, QLatin1String s2, -
2028 Qt::CaseSensitivity cs) -
2029{ -
2030 const ushort *uc = reinterpret_cast<const ushort *>(data1); -
2031 const ushort *uce = uc + length1; -
2032 const uchar *c = (uchar *)s2.latin1(); -
2033 -
2034 if (!c)
-
2035 return length1;
-
2036 -
2037 if (cs == Qt::CaseSensitive) {
-
2038 const ushort *e = uc + length1; -
2039 if (s2.size() < length1)
-
2040 e = uc + s2.size();
-
2041 while (uc < e) {
-
2042 int diff = *uc - *c; -
2043 if (diff)
-
2044 return diff;
-
2045 uc++, c++; -
2046 }
-
2047 -
2048 if (uc == uce) {
-
2049 if (c == (const uchar *)s2.latin1() + s2.size())
-
2050 return 0;
-
2051 return -1;
-
2052 } -
2053 return 1;
-
2054 } else { -
2055 return ucstricmp(uc, uce, c, c + s2.size());
-
2056 } -
2057} -
2058int QString::localeAwareCompare(const QString &other) const -
2059{ -
2060 return localeAwareCompare_helper(constData(), length(), other.constData(), other.length());
-
2061} -
2062 -
2063 -
2064 -
2065 -
2066 -
2067int QString::localeAwareCompare_helper(const QChar *data1, int length1, -
2068 const QChar *data2, int length2) -
2069{ -
2070 -
2071 if (length1 == 0 || length2 == 0)
-
2072 return ucstrcmp(data1, length1, data2, length2);
-
2073 QCollator collator; -
2074 return collator.compare(data1, length1, data2, length2);
-
2075} -
2076const ushort *QString::utf16() const -
2077{ -
2078 if (((d)->offset != sizeof(QStringData))) {
-
2079 -
2080 const_cast<QString*>(this)->reallocData(uint(d->size) + 1u); -
2081 }
-
2082 return d->data();
-
2083} -
2084QString QString::leftJustified(int width, QChar fill, bool truncate) const -
2085{ -
2086 QString result; -
2087 int len = length(); -
2088 int padlen = width - len; -
2089 if (padlen > 0) {
-
2090 result.resize(len+padlen); -
2091 if (len)
-
2092 memcpy(result.d->data(), d->data(), sizeof(QChar)*len);
-
2093 QChar *uc = (QChar*)result.d->data() + len; -
2094 while (padlen--)
-
2095 * uc++ = fill;
-
2096 } else {
-
2097 if (truncate)
-
2098 result = left(width);
-
2099 else -
2100 result = *this;
-
2101 } -
2102 return result;
-
2103} -
2104QString QString::rightJustified(int width, QChar fill, bool truncate) const -
2105{ -
2106 QString result; -
2107 int len = length(); -
2108 int padlen = width - len; -
2109 if (padlen > 0) {
-
2110 result.resize(len+padlen); -
2111 QChar *uc = (QChar*)result.d->data(); -
2112 while (padlen--)
-
2113 * uc++ = fill;
-
2114 if (len)
-
2115 memcpy(uc, d->data(), sizeof(QChar)*len);
-
2116 } else {
-
2117 if (truncate)
-
2118 result = left(width);
-
2119 else -
2120 result = *this;
-
2121 } -
2122 return result;
-
2123} -
2124QString QString::toLower() const -
2125{ -
2126 const ushort *p = d->data(); -
2127 if (!p)
-
2128 return *this;
-
2129 -
2130 const ushort *e = p + d->size; -
2131 -
2132 while (e != p && QChar::isHighSurrogate(*(e - 1)))
-
2133 --e;
-
2134 -
2135 const QUnicodeTables::Properties *prop; -
2136 while (p != e) {
-
2137 if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
-
2138 ushort high = *p++; -
2139 prop = qGetProp(QChar::surrogateToUcs4(high, *p)); -
2140 } else {
-
2141 prop = qGetProp(*p); -
2142 }
-
2143 if (prop->lowerCaseDiff) {
-
2144 if (QChar::isLowSurrogate(*p))
-
2145 --p;
-
2146 QString s(d->size, Qt::Uninitialized); -
2147 memcpy(s.d->data(), d->data(), (p - d->data())*sizeof(ushort)); -
2148 ushort *pp = s.d->data() + (p - d->data()); -
2149 while (p != e) {
-
2150 if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
-
2151 *pp = *p++; -
2152 prop = qGetProp(QChar::surrogateToUcs4(*pp++, *p)); -
2153 } else {
-
2154 prop = qGetProp(*p); -
2155 }
-
2156 if (prop->lowerCaseSpecial) {
-
2157 const ushort *specialCase = specialCaseMap + prop->lowerCaseDiff; -
2158 ushort length = *specialCase++; -
2159 int pos = pp - s.d->data(); -
2160 s.resize(s.d->size + length - 1); -
2161 pp = s.d->data() + pos; -
2162 while (length--)
-
2163 *pp++ = *specialCase++;
-
2164 } else {
-
2165 *pp++ = *p + prop->lowerCaseDiff; -
2166 }
-
2167 ++p; -
2168 }
-
2169 -
2170 -
2171 while (e != d->data() + d->size)
-
2172 *pp++ = *e++;
-
2173 -
2174 return s;
-
2175 } -
2176 ++p; -
2177 }
-
2178 return *this;
-
2179} -
2180 -
2181 -
2182 -
2183 -
2184 -
2185QString QString::toCaseFolded() const -
2186{ -
2187 const ushort *p = d->data(); -
2188 if (!p)
-
2189 return *this;
-
2190 -
2191 const ushort *e = p + d->size; -
2192 -
2193 while (e != p && QChar::isHighSurrogate(*(e - 1)))
-
2194 --e;
-
2195 -
2196 const QUnicodeTables::Properties *prop; -
2197 while (p != e) {
-
2198 if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
-
2199 ushort high = *p++; -
2200 prop = qGetProp(QChar::surrogateToUcs4(high, *p)); -
2201 } else {
-
2202 prop = qGetProp(*p); -
2203 }
-
2204 if (prop->caseFoldDiff) {
-
2205 if (QChar::isLowSurrogate(*p))
-
2206 --p;
-
2207 QString s(d->size, Qt::Uninitialized); -
2208 memcpy(s.d->data(), d->data(), (p - d->data())*sizeof(ushort)); -
2209 ushort *pp = s.d->data() + (p - d->data()); -
2210 while (p != e) {
-
2211 if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
-
2212 *pp = *p++; -
2213 prop = qGetProp(QChar::surrogateToUcs4(*pp++, *p)); -
2214 } else {
-
2215 prop = qGetProp(*p); -
2216 }
-
2217 if (prop->caseFoldSpecial) {
-
2218 const ushort *specialCase = specialCaseMap + prop->caseFoldDiff; -
2219 ushort length = *specialCase++; -
2220 qt_noop(); -
2221 (void)length; -
2222 *pp++ = *specialCase; -
2223 -
2224 } else {
-
2225 *pp++ = *p + prop->caseFoldDiff; -
2226 }
-
2227 ++p; -
2228 }
-
2229 -
2230 -
2231 while (e != d->data() + d->size)
-
2232 *pp++ = *e++;
-
2233 -
2234 return s;
-
2235 } -
2236 ++p; -
2237 }
-
2238 return *this;
-
2239} -
2240QString QString::toUpper() const -
2241{ -
2242 const ushort *p = d->data(); -
2243 if (!p)
-
2244 return *this;
-
2245 -
2246 const ushort *e = p + d->size; -
2247 -
2248 while (e != p && QChar::isHighSurrogate(*(e - 1)))
-
2249 --e;
-
2250 -
2251 const QUnicodeTables::Properties *prop; -
2252 while (p != e) {
-
2253 if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
-
2254 ushort high = *p++; -
2255 prop = qGetProp(QChar::surrogateToUcs4(high, *p)); -
2256 } else {
-
2257 prop = qGetProp(*p); -
2258 }
-
2259 if (prop->upperCaseDiff) {
-
2260 if (QChar::isLowSurrogate(*p))
-
2261 --p;
-
2262 QString s(d->size, Qt::Uninitialized); -
2263 memcpy(s.d->data(), d->data(), (p - d->data())*sizeof(ushort)); -
2264 ushort *pp = s.d->data() + (p - d->data()); -
2265 while (p != e) {
-
2266 if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
-
2267 *pp = *p++; -
2268 prop = qGetProp(QChar::surrogateToUcs4(*pp++, *p)); -
2269 } else {
-
2270 prop = qGetProp(*p); -
2271 }
-
2272 if (prop->upperCaseSpecial) {
-
2273 const ushort *specialCase = specialCaseMap + prop->upperCaseDiff; -
2274 ushort length = *specialCase++; -
2275 int pos = pp - s.d->data(); -
2276 s.resize(s.d->size + length - 1); -
2277 pp = s.d->data() + pos; -
2278 while (length--)
-
2279 *pp++ = *specialCase++;
-
2280 } else {
-
2281 *pp++ = *p + prop->upperCaseDiff; -
2282 }
-
2283 ++p; -
2284 }
-
2285 -
2286 -
2287 while (e != d->data() + d->size)
-
2288 *pp++ = *e++;
-
2289 -
2290 return s;
-
2291 } -
2292 ++p; -
2293 }
-
2294 return *this;
-
2295} -
2296QString &QString::sprintf(const char *cformat, ...) -
2297{ -
2298 va_list ap; -
2299 __builtin_va_start(ap,cformat); -
2300 QString &s = vsprintf(cformat, ap); -
2301 __builtin_va_end(ap); -
2302 return s;
-
2303} -
2304QString &QString::vsprintf(const char* cformat, va_list ap) -
2305{ -
2306 QLocale locale(QLocale::C); -
2307 -
2308 if (!cformat || !*cformat) {
-
2309 -
2310 *this = fromLatin1(""); -
2311 return *this;
-
2312 } -
2313 -
2314 -
2315 -
2316 QString result; -
2317 const char *c = cformat; -
2318 for (;;) { -
2319 -
2320 while (*c != '\0' && *c != '%')
-
2321 result.append(QLatin1Char(*c++));
-
2322 -
2323 if (*c == '\0')
-
2324 break;
-
2325 -
2326 -
2327 const char *escape_start = c; -
2328 ++c; -
2329 -
2330 if (*c == '\0') {
-
2331 result.append(QLatin1Char('%')); -
2332 break;
-
2333 } -
2334 if (*c == '%') {
-
2335 result.append(QLatin1Char('%')); -
2336 ++c; -
2337 continue;
-
2338 } -
2339 -
2340 -
2341 uint flags = 0; -
2342 bool no_more_flags = false; -
2343 do { -
2344 switch (*c) { -
2345 case '#': flags |= QLocalePrivate::Alternate; break;
-
2346 case '0': flags |= QLocalePrivate::ZeroPadded; break;
-
2347 case '-': flags |= QLocalePrivate::LeftAdjusted; break;
-
2348 case ' ': flags |= QLocalePrivate::BlankBeforePositive; break;
-
2349 case '+': flags |= QLocalePrivate::AlwaysShowSign; break;
-
2350 case '\'': flags |= QLocalePrivate::ThousandsGroup; break;
-
2351 default: no_more_flags = true; break;
-
2352 } -
2353 -
2354 if (!no_more_flags)
-
2355 ++c;
-
2356 } while (!no_more_flags);
-
2357 -
2358 if (*c == '\0') {
-
2359 result.append(QLatin1String(escape_start)); -
2360 break;
-
2361 } -
2362 -
2363 -
2364 int width = -1; -
2365 if (qIsDigit(*c)) {
-
2366 QString width_str; -
2367 while (*c != '\0' && qIsDigit(*c))
-
2368 width_str.append(QLatin1Char(*c++));
-
2369 -
2370 -
2371 -
2372 width = width_str.toInt(); -
2373 }
-
2374 else if (*c == '*') {
-
2375 width = __builtin_va_arg(ap,int); -
2376 if (width < 0)
-
2377 width = -1;
-
2378 ++c; -
2379 }
-
2380 -
2381 if (*c == '\0') {
-
2382 result.append(QLatin1String(escape_start)); -
2383 break;
-
2384 } -
2385 -
2386 -
2387 int precision = -1; -
2388 if (*c == '.') {
-
2389 ++c; -
2390 if (qIsDigit(*c)) {
-
2391 QString precision_str; -
2392 while (*c != '\0' && qIsDigit(*c))
-
2393 precision_str.append(QLatin1Char(*c++));
-
2394 -
2395 -
2396 -
2397 precision = precision_str.toInt(); -
2398 }
-
2399 else if (*c == '*') {
-
2400 precision = __builtin_va_arg(ap,int); -
2401 if (precision < 0)
-
2402 precision = -1;
-
2403 ++c; -
2404 }
-
2405 } -
2406 -
2407 if (*c == '\0') {
-
2408 result.append(QLatin1String(escape_start)); -
2409 break;
-
2410 } -
2411 -
2412 -
2413 enum LengthMod { lm_none, lm_hh, lm_h, lm_l, lm_ll, lm_L, lm_j, lm_z, lm_t }; -
2414 LengthMod length_mod = lm_none; -
2415 switch (*c) { -
2416 case 'h': -
2417 ++c; -
2418 if (*c == 'h') {
-
2419 length_mod = lm_hh; -
2420 ++c; -
2421 }
-
2422 else -
2423 length_mod = lm_h;
-
2424 break;
-
2425 -
2426 case 'l': -
2427 ++c; -
2428 if (*c == 'l') {
-
2429 length_mod = lm_ll; -
2430 ++c; -
2431 }
-
2432 else -
2433 length_mod = lm_l;
-
2434 break;
-
2435 -
2436 case 'L': -
2437 ++c; -
2438 length_mod = lm_L; -
2439 break;
-
2440 -
2441 case 'j': -
2442 ++c; -
2443 length_mod = lm_j; -
2444 break;
-
2445 -
2446 case 'z': -
2447 case 'Z': -
2448 ++c; -
2449 length_mod = lm_z; -
2450 break;
-
2451 -
2452 case 't': -
2453 ++c; -
2454 length_mod = lm_t; -
2455 break;
-
2456 -
2457 default: break;
-
2458 } -
2459 -
2460 if (*c == '\0') {
-
2461 result.append(QLatin1String(escape_start)); -
2462 break;
-
2463 } -
2464 -
2465 -
2466 QString subst; -
2467 switch (*c) { -
2468 case 'd': -
2469 case 'i': { -
2470 qint64 i; -
2471 switch (length_mod) { -
2472 case lm_none: i = __builtin_va_arg(ap,int); break;
-
2473 case lm_hh: i = __builtin_va_arg(ap,int); break;
-
2474 case lm_h: i = __builtin_va_arg(ap,int); break;
-
2475 case lm_l: i = __builtin_va_arg(ap,long int); break;
-
2476 case lm_ll: i = __builtin_va_arg(ap,qint64); break;
-
2477 case lm_j: i = __builtin_va_arg(ap,long int); break;
-
2478 case lm_z: i = __builtin_va_arg(ap,size_t); break;
-
2479 case lm_t: i = __builtin_va_arg(ap,int); break;
-
2480 default: i = 0; break;
-
2481 } -
2482 subst = locale.d->longLongToString(i, precision, 10, width, flags); -
2483 ++c; -
2484 break;
-
2485 } -
2486 case 'o': -
2487 case 'u': -
2488 case 'x': -
2489 case 'X': { -
2490 quint64 u; -
2491 switch (length_mod) { -
2492 case lm_none: u = __builtin_va_arg(ap,uint); break;
-
2493 case lm_hh: u = __builtin_va_arg(ap,uint); break;
-
2494 case lm_h: u = __builtin_va_arg(ap,uint); break;
-
2495 case lm_l: u = __builtin_va_arg(ap,ulong); break;
-
2496 case lm_ll: u = __builtin_va_arg(ap,quint64); break;
-
2497 case lm_z: u = __builtin_va_arg(ap,size_t); break;
-
2498 default: u = 0; break;
-
2499 } -
2500 -
2501 if (qIsUpper(*c))
-
2502 flags |= QLocalePrivate::CapitalEorX;
-
2503 -
2504 int base = 10; -
2505 switch (qToLower(*c)) { -
2506 case 'o': -
2507 base = 8; break;
-
2508 case 'u': -
2509 base = 10; break;
-
2510 case 'x': -
2511 base = 16; break;
-
2512 default: break;
-
2513 } -
2514 subst = locale.d->unsLongLongToString(u, precision, base, width, flags); -
2515 ++c; -
2516 break;
-
2517 } -
2518 case 'E': -
2519 case 'e': -
2520 case 'F': -
2521 case 'f': -
2522 case 'G': -
2523 case 'g': -
2524 case 'A': -
2525 case 'a': { -
2526 double d; -
2527 if (length_mod == lm_L)
-
2528 d = __builtin_va_arg(ap,long double);
-
2529 else -
2530 d = __builtin_va_arg(ap,double);
-
2531 -
2532 if (qIsUpper(*c))
-
2533 flags |= QLocalePrivate::CapitalEorX;
-
2534 -
2535 QLocalePrivate::DoubleForm form = QLocalePrivate::DFDecimal; -
2536 switch (qToLower(*c)) { -
2537 case 'e': form = QLocalePrivate::DFExponent; break;
-
2538 case 'a': -
2539 case 'f': form = QLocalePrivate::DFDecimal; break;
-
2540 case 'g': form = QLocalePrivate::DFSignificantDigits; break;
-
2541 default: break;
-
2542 } -
2543 subst = locale.d->doubleToString(d, precision, form, width, flags); -
2544 ++c; -
2545 break;
-
2546 } -
2547 case 'c': { -
2548 if (length_mod == lm_l)
-
2549 subst = QChar((ushort) __builtin_va_arg(ap,int));
-
2550 else -
2551 subst = QLatin1Char((uchar) __builtin_va_arg(ap,int));
-
2552 ++c; -
2553 break;
-
2554 } -
2555 case 's': { -
2556 if (length_mod == lm_l) {
-
2557 const ushort *buff = __builtin_va_arg(ap,const ushort*); -
2558 const ushort *ch = buff; -
2559 while (*ch != 0)
-
2560 ++ch;
-
2561 subst.setUtf16(buff, ch - buff); -
2562 } else
-
2563 subst = QString::fromUtf8(__builtin_va_arg(ap,const char*));
-
2564 if (precision != -1)
-
2565 subst.truncate(precision);
-
2566 ++c; -
2567 break;
-
2568 } -
2569 case 'p': { -
2570 void *arg = __builtin_va_arg(ap,void*); -
2571 -
2572 -
2573 -
2574 quint64 i = reinterpret_cast<unsigned long>(arg); -
2575 -
2576 flags |= QLocalePrivate::Alternate; -
2577 subst = locale.d->unsLongLongToString(i, precision, 16, width, flags); -
2578 ++c; -
2579 break;
-
2580 } -
2581 case 'n': -
2582 switch (length_mod) { -
2583 case lm_hh: { -
2584 signed char *n = __builtin_va_arg(ap,signed char*); -
2585 *n = result.length(); -
2586 break;
-
2587 } -
2588 case lm_h: { -
2589 short int *n = __builtin_va_arg(ap,short int*); -
2590 *n = result.length(); -
2591 break;
-
2592 } -
2593 case lm_l: { -
2594 long int *n = __builtin_va_arg(ap,long int*); -
2595 *n = result.length(); -
2596 break;
-
2597 } -
2598 case lm_ll: { -
2599 qint64 *n = __builtin_va_arg(ap,qint64*); -
2600 volatile uint tmp = result.length(); -
2601 *n = tmp; -
2602 break;
-
2603 } -
2604 default: { -
2605 int *n = __builtin_va_arg(ap,int*); -
2606 *n = result.length(); -
2607 break;
-
2608 } -
2609 } -
2610 ++c; -
2611 break;
-
2612 -
2613 default: -
2614 for (const char *cc = escape_start; cc != c; ++cc)
-
2615 result.append(QLatin1Char(*cc));
-
2616 continue;
-
2617 } -
2618 -
2619 if (flags & QLocalePrivate::LeftAdjusted)
-
2620 result.append(subst.leftJustified(width));
-
2621 else -
2622 result.append(subst.rightJustified(width));
-
2623 } -
2624 -
2625 *this = result; -
2626 -
2627 return *this;
-
2628} -
2629qint64 QString::toLongLong(bool *ok, int base) const -
2630{ -
2631 -
2632 -
2633 -
2634 -
2635 -
2636 -
2637 -
2638 QLocale c_locale(QLocale::C); -
2639 return c_locale.d->stringToLongLong(*this, base, ok, QLocalePrivate::FailOnGroupSeparators);
-
2640} -
2641quint64 QString::toULongLong(bool *ok, int base) const -
2642{ -
2643 -
2644 -
2645 -
2646 -
2647 -
2648 -
2649 -
2650 QLocale c_locale(QLocale::C); -
2651 return c_locale.d->stringToUnsLongLong(*this, base, ok, QLocalePrivate::FailOnGroupSeparators);
-
2652} -
2653long QString::toLong(bool *ok, int base) const -
2654{ -
2655 qint64 v = toLongLong(ok, base); -
2656 if (v < (-9223372036854775807L - 1L) || v > 9223372036854775807L) {
-
2657 if (ok)
-
2658 *ok = false;
-
2659 v = 0; -
2660 }
-
2661 return (long)v;
-
2662} -
2663ulong QString::toULong(bool *ok, int base) const -
2664{ -
2665 quint64 v = toULongLong(ok, base); -
2666 if (v > (9223372036854775807L * 2UL + 1UL)) {
-
2667 if (ok)
-
2668 *ok = false;
-
2669 v = 0; -
2670 }
-
2671 return (ulong)v;
-
2672} -
2673int QString::toInt(bool *ok, int base) const -
2674{ -
2675 qint64 v = toLongLong(ok, base); -
2676 if (v < (-2147483647 - 1) || v > 2147483647) {
-
2677 if (ok)
-
2678 *ok = false;
-
2679 v = 0; -
2680 }
-
2681 return v;
-
2682} -
2683uint QString::toUInt(bool *ok, int base) const -
2684{ -
2685 quint64 v = toULongLong(ok, base); -
2686 if (v > (2147483647 * 2U + 1U)) {
-
2687 if (ok)
-
2688 *ok = false;
-
2689 v = 0; -
2690 }
-
2691 return (uint)v;
-
2692} -
2693short QString::toShort(bool *ok, int base) const -
2694{ -
2695 long v = toLongLong(ok, base); -
2696 if (v < (-32767 - 1) || v > 32767) {
-
2697 if (ok)
-
2698 *ok = false;
-
2699 v = 0; -
2700 }
-
2701 return (short)v;
-
2702} -
2703ushort QString::toUShort(bool *ok, int base) const -
2704{ -
2705 ulong v = toULongLong(ok, base); -
2706 if (v > (32767 * 2 + 1)) {
-
2707 if (ok)
-
2708 *ok = false;
-
2709 v = 0; -
2710 }
-
2711 return (ushort)v;
-
2712} -
2713double QString::toDouble(bool *ok) const -
2714{ -
2715 QLocale c_locale(QLocale::C); -
2716 return c_locale.d->stringToDouble(*this, ok, QLocalePrivate::FailOnGroupSeparators);
-
2717} -
2718float QString::toFloat(bool *ok) const -
2719{ -
2720 bool myOk; -
2721 double d = toDouble(&myOk); -
2722 if (!myOk) {
-
2723 if (ok != 0)
-
2724 *ok = false;
-
2725 return 0.0;
-
2726 } -
2727 if (qIsInf(d))
-
2728 return float(d);
-
2729 if (d > 3.4028234663852886e+38 || d < -3.4028234663852886e+38) {
-
2730 if (ok != 0)
-
2731 *ok = false;
-
2732 return 0.0;
-
2733 } -
2734 if (ok != 0)
-
2735 *ok = true;
-
2736 return float(d);
-
2737} -
2738QString &QString::setNum(qlonglong n, int base) -
2739{ -
2740 -
2741 -
2742 -
2743 -
2744 -
2745 -
2746 QLocale locale(QLocale::C); -
2747 *this = locale.d->longLongToString(n, -1, base); -
2748 return *this;
-
2749} -
2750 -
2751 -
2752 -
2753 -
2754QString &QString::setNum(qulonglong n, int base) -
2755{ -
2756 -
2757 -
2758 -
2759 -
2760 -
2761 -
2762 QLocale locale(QLocale::C); -
2763 *this = locale.d->unsLongLongToString(n, -1, base); -
2764 return *this;
-
2765} -
2766QString &QString::setNum(double n, char f, int prec) -
2767{ -
2768 QLocalePrivate::DoubleForm form = QLocalePrivate::DFDecimal; -
2769 uint flags = 0; -
2770 -
2771 if (qIsUpper(f))
-
2772 flags = QLocalePrivate::CapitalEorX;
-
2773 f = qToLower(f); -
2774 -
2775 switch (f) { -
2776 case 'f': -
2777 form = QLocalePrivate::DFDecimal; -
2778 break;
-
2779 case 'e': -
2780 form = QLocalePrivate::DFExponent; -
2781 break;
-
2782 case 'g': -
2783 form = QLocalePrivate::DFSignificantDigits; -
2784 break;
-
2785 default: -
2786 -
2787 -
2788 -
2789 break;
-
2790 } -
2791 -
2792 QLocale locale(QLocale::C); -
2793 *this = locale.d->doubleToString(n, prec, form, -1, flags); -
2794 return *this;
-
2795} -
2796QString QString::number(long n, int base) -
2797{ -
2798 QString s; -
2799 s.setNum(n, base); -
2800 return s;
-
2801} -
2802 -
2803 -
2804 -
2805 -
2806 -
2807 -
2808QString QString::number(ulong n, int base) -
2809{ -
2810 QString s; -
2811 s.setNum(n, base); -
2812 return s;
-
2813} -
2814 -
2815 -
2816 -
2817 -
2818QString QString::number(int n, int base) -
2819{ -
2820 QString s; -
2821 s.setNum(n, base); -
2822 return s;
-
2823} -
2824 -
2825 -
2826 -
2827 -
2828QString QString::number(uint n, int base) -
2829{ -
2830 QString s; -
2831 s.setNum(n, base); -
2832 return s;
-
2833} -
2834 -
2835 -
2836 -
2837 -
2838QString QString::number(qlonglong n, int base) -
2839{ -
2840 QString s; -
2841 s.setNum(n, base); -
2842 return s;
-
2843} -
2844 -
2845 -
2846 -
2847 -
2848QString QString::number(qulonglong n, int base) -
2849{ -
2850 QString s; -
2851 s.setNum(n, base); -
2852 return s;
-
2853} -
2854QString QString::number(double n, char f, int prec) -
2855{ -
2856 QString s; -
2857 s.setNum(n, f, prec); -
2858 return s;
-
2859} -
2860QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const -
2861{ -
2862 QStringList list; -
2863 int start = 0; -
2864 int extra = 0; -
2865 int end; -
2866 while ((end = indexOf(sep, start + extra, cs)) != -1) {
-
2867 if (start != end || behavior == KeepEmptyParts)
-
2868 list.append(mid(start, end - start));
-
2869 start = end + sep.size(); -
2870 extra = (sep.size() == 0 ? 1 : 0);
-
2871 }
-
2872 if (start != size() || behavior == KeepEmptyParts)
-
2873 list.append(mid(start));
-
2874 return list;
-
2875} -
2876 -
2877 -
2878 -
2879 -
2880QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const -
2881{ -
2882 QStringList list; -
2883 int start = 0; -
2884 int end; -
2885 while ((end = indexOf(sep, start, cs)) != -1) {
-
2886 if (start != end || behavior == KeepEmptyParts)
-
2887 list.append(mid(start, end - start));
-
2888 start = end + 1; -
2889 }
-
2890 if (start != size() || behavior == KeepEmptyParts)
-
2891 list.append(mid(start));
-
2892 return list;
-
2893} -
2894QStringList QString::split(const QRegExp &rx, SplitBehavior behavior) const -
2895{ -
2896 QRegExp rx2(rx); -
2897 QStringList list; -
2898 int start = 0; -
2899 int extra = 0; -
2900 int end; -
2901 while ((end = rx2.indexIn(*this, start + extra)) != -1) {
-
2902 int matchedLen = rx2.matchedLength(); -
2903 if (start != end || behavior == KeepEmptyParts)
-
2904 list.append(mid(start, end - start));
-
2905 start = end + matchedLen; -
2906 extra = (matchedLen == 0) ? 1 : 0;
-
2907 }
-
2908 if (start != size() || behavior == KeepEmptyParts)
-
2909 list.append(mid(start));
-
2910 return list;
-
2911} -
2912QStringList QString::split(const QRegularExpression &re, SplitBehavior behavior) const -
2913{ -
2914 QStringList list; -
2915 if (!re.isValid()) {
-
2916 QMessageLogger("tools/qstring.cpp", 6452, __PRETTY_FUNCTION__).warning("QString::split: invalid QRegularExpression object"); -
2917 return list;
-
2918 } -
2919 -
2920 int start = 0; -
2921 int end = 0; -
2922 QRegularExpressionMatchIterator iterator = re.globalMatch(*this); -
2923 while (iterator.hasNext()) {
-
2924 QRegularExpressionMatch match = iterator.next(); -
2925 end = match.capturedStart(); -
2926 if (start != end || behavior == KeepEmptyParts)
-
2927 list.append(mid(start, end - start));
-
2928 start = match.capturedEnd(); -
2929 }
-
2930 -
2931 if (start != size() || behavior == KeepEmptyParts)
-
2932 list.append(mid(start));
-
2933 -
2934 return list;
-
2935} -
2936QString QString::repeated(int times) const -
2937{ -
2938 if (d->size == 0)
-
2939 return *this;
-
2940 -
2941 if (times <= 1) {
-
2942 if (times == 1)
-
2943 return *this;
-
2944 return QString();
-
2945 } -
2946 -
2947 const int resultSize = times * d->size; -
2948 -
2949 QString result; -
2950 result.reserve(resultSize); -
2951 if (result.d->alloc != uint(resultSize) + 1u)
-
2952 return QString();
-
2953 -
2954 memcpy(result.d->data(), d->data(), d->size * sizeof(ushort)); -
2955 -
2956 int sizeSoFar = d->size; -
2957 ushort *end = result.d->data() + sizeSoFar; -
2958 -
2959 const int halfResultSize = resultSize >> 1; -
2960 while (sizeSoFar <= halfResultSize) {
-
2961 memcpy(end, result.d->data(), sizeSoFar * sizeof(ushort)); -
2962 end += sizeSoFar; -
2963 sizeSoFar <<= 1; -
2964 }
-
2965 memcpy(end, result.d->data(), (resultSize - sizeSoFar) * sizeof(ushort)); -
2966 result.d->data()[resultSize] = '\0'; -
2967 result.d->size = resultSize; -
2968 return result;
-
2969} -
2970 -
2971void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, int from) -
2972{ -
2973 bool simple = true; -
2974 const QChar *p = data->constData(); -
2975 int len = data->length(); -
2976 for (int i = from; i < len; ++i) {
-
2977 if (p[i].unicode() >= 0x80) {
-
2978 simple = false; -
2979 break;
-
2980 } -
2981 }
-
2982 if (simple)
-
2983 return;
-
2984 -
2985 if (version == QChar::Unicode_Unassigned) {
-
2986 version = QChar::currentUnicodeVersion(); -
2987 } else if (int(version) <= NormalizationCorrectionsVersionMax) {
-
2988 const QString &s = *data; -
2989 QChar *d = 0; -
2990 for (int i = 0; i < NumNormalizationCorrections; ++i) {
-
2991 const NormalizationCorrection &n = uc_normalization_corrections[i]; -
2992 if (n.version > version) {
-
2993 int pos = from; -
2994 if (QChar::requiresSurrogates(n.ucs4)) {
-
2995 ushort ucs4High = QChar::highSurrogate(n.ucs4); -
2996 ushort ucs4Low = QChar::lowSurrogate(n.ucs4); -
2997 ushort oldHigh = QChar::highSurrogate(n.old_mapping); -
2998 ushort oldLow = QChar::lowSurrogate(n.old_mapping); -
2999 while (pos < s.length() - 1) {
-
3000 if (s.at(pos).unicode() == ucs4High && s.at(pos + 1).unicode() == ucs4Low) {
-
3001 if (!d)
-
3002 d = data->data();
-
3003 d[pos] = QChar(oldHigh); -
3004 d[++pos] = QChar(oldLow); -
3005 }
-
3006 ++pos; -
3007 }
-
3008 } else {
-
3009 while (pos < s.length()) {
-
3010 if (s.at(pos).unicode() == n.ucs4) {
-
3011 if (!d)
-
3012 d = data->data();
-
3013 d[pos] = QChar(n.old_mapping); -
3014 }
-
3015 ++pos; -
3016 }
-
3017 }
-
3018 } -
3019 }
-
3020 }
-
3021 decomposeHelper(data, mode < QString::NormalizationForm_KD, version, from); -
3022 -
3023 canonicalOrderHelper(data, version, from); -
3024 -
3025 if (mode == QString::NormalizationForm_D || mode == QString::NormalizationForm_KD)
-
3026 return;
-
3027 -
3028 composeHelper(data, version, from); -
3029}
-
3030 -
3031 -
3032 -
3033 -
3034 -
3035QString QString::normalized(QString::NormalizationForm mode, QChar::UnicodeVersion version) const -
3036{ -
3037 QString copy = *this; -
3038 qt_string_normalize(&copy, mode, version, 0); -
3039 return copy;
-
3040} -
3041 -
3042 -
3043struct ArgEscapeData -
3044{ -
3045 int min_escape; -
3046 int occurrences; -
3047 int locale_occurrences; -
3048 -
3049 int escape_len; -
3050}; -
3051 -
3052static ArgEscapeData findArgEscapes(const QString &s) -
3053{ -
3054 const QChar *uc_begin = s.unicode(); -
3055 const QChar *uc_end = uc_begin + s.length(); -
3056 -
3057 ArgEscapeData d; -
3058 -
3059 d.min_escape = 2147483647; -
3060 d.occurrences = 0; -
3061 d.escape_len = 0; -
3062 d.locale_occurrences = 0; -
3063 -
3064 const QChar *c = uc_begin; -
3065 while (c != uc_end) {
-
3066 while (c != uc_end && c->unicode() != '%')
-
3067 ++c;
-
3068 -
3069 if (c == uc_end)
-
3070 break;
-
3071 const QChar *escape_start = c; -
3072 if (++c == uc_end)
-
3073 break;
-
3074 -
3075 bool locale_arg = false; -
3076 if (c->unicode() == 'L') {
-
3077 locale_arg = true; -
3078 if (++c == uc_end)
-
3079 break;
-
3080 }
-
3081 -
3082 if (c->digitValue() == -1)
-
3083 continue;
-
3084 -
3085 int escape = c->digitValue(); -
3086 ++c; -
3087 -
3088 if (c != uc_end && c->digitValue() != -1) {
-
3089 escape = (10 * escape) + c->digitValue(); -
3090 ++c; -
3091 }
-
3092 -
3093 if (escape > d.min_escape)
-
3094 continue;
-
3095 -
3096 if (escape < d.min_escape) {
-
3097 d.min_escape = escape; -
3098 d.occurrences = 0; -
3099 d.escape_len = 0; -
3100 d.locale_occurrences = 0; -
3101 }
-
3102 -
3103 ++d.occurrences; -
3104 if (locale_arg)
-
3105 ++d.locale_occurrences;
-
3106 d.escape_len += c - escape_start; -
3107 }
-
3108 return d;
-
3109} -
3110 -
3111static QString replaceArgEscapes(const QString &s, const ArgEscapeData &d, int field_width, -
3112 const QString &arg, const QString &larg, QChar fillChar = QLatin1Char(' ')) -
3113{ -
3114 const QChar *uc_begin = s.unicode(); -
3115 const QChar *uc_end = uc_begin + s.length(); -
3116 -
3117 int abs_field_width = qAbs(field_width); -
3118 int result_len = s.length() -
3119 - d.escape_len -
3120 + (d.occurrences - d.locale_occurrences) -
3121 *qMax(abs_field_width, arg.length()) -
3122 + d.locale_occurrences -
3123 *qMax(abs_field_width, larg.length()); -
3124 -
3125 QString result(result_len, Qt::Uninitialized); -
3126 QChar *result_buff = (QChar*) result.unicode(); -
3127 -
3128 QChar *rc = result_buff; -
3129 const QChar *c = uc_begin; -
3130 int repl_cnt = 0; -
3131 while (c != uc_end) {
-
3132 -
3133 -
3134 -
3135 -
3136 const QChar *text_start = c; -
3137 -
3138 while (c->unicode() != '%')
-
3139 ++c;
-
3140 -
3141 const QChar *escape_start = c++; -
3142 -
3143 bool locale_arg = false; -
3144 if (c->unicode() == 'L') {
-
3145 locale_arg = true; -
3146 ++c; -
3147 }
-
3148 -
3149 int escape = c->digitValue(); -
3150 if (escape != -1) {
-
3151 if (c + 1 != uc_end && (c + 1)->digitValue() != -1) {
-
3152 escape = (10 * escape) + (c + 1)->digitValue(); -
3153 ++c; -
3154 }
-
3155 }
-
3156 -
3157 if (escape != d.min_escape) {
-
3158 memcpy(rc, text_start, (c - text_start)*sizeof(QChar)); -
3159 rc += c - text_start; -
3160 }
-
3161 else { -
3162 ++c; -
3163 -
3164 memcpy(rc, text_start, (escape_start - text_start)*sizeof(QChar)); -
3165 rc += escape_start - text_start; -
3166 -
3167 uint pad_chars; -
3168 if (locale_arg)
-
3169 pad_chars = qMax(abs_field_width, larg.length()) - larg.length();
-
3170 else -
3171 pad_chars = qMax(abs_field_width, arg.length()) - arg.length();
-
3172 -
3173 if (field_width > 0) {
-
3174 for (uint i = 0; i < pad_chars; ++i)
-
3175 (rc++)->unicode() = fillChar.unicode();
-
3176 }
-
3177 -
3178 if (locale_arg) {
-
3179 memcpy(rc, larg.unicode(), larg.length()*sizeof(QChar)); -
3180 rc += larg.length(); -
3181 }
-
3182 else { -
3183 memcpy(rc, arg.unicode(), arg.length()*sizeof(QChar)); -
3184 rc += arg.length(); -
3185 }
-
3186 -
3187 if (field_width < 0) {
-
3188 for (uint i = 0; i < pad_chars; ++i)
-
3189 (rc++)->unicode() = fillChar.unicode();
-
3190 }
-
3191 -
3192 if (++repl_cnt == d.occurrences) {
-
3193 memcpy(rc, c, (uc_end - c)*sizeof(QChar)); -
3194 rc += uc_end - c; -
3195 qt_noop(); -
3196 c = uc_end; -
3197 }
-
3198 }
-
3199 } -
3200 qt_noop(); -
3201 -
3202 return result;
-
3203} -
3204QString QString::arg(const QString &a, int fieldWidth, QChar fillChar) const -
3205{ -
3206 ArgEscapeData d = findArgEscapes(*this); -
3207 -
3208 if (d.occurrences == 0) {
-
3209 QMessageLogger("tools/qstring.cpp", 6806, __PRETTY_FUNCTION__).warning("QString::arg: Argument missing: %s, %s", toLocal8Bit().data(), -
3210 a.toLocal8Bit().data()); -
3211 return *this;
-
3212 } -
3213 return replaceArgEscapes(*this, d, fieldWidth, a, a, fillChar);
-
3214} -
3215QString QString::arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const -
3216{ -
3217 ArgEscapeData d = findArgEscapes(*this); -
3218 -
3219 if (d.occurrences == 0) {
-
3220 QMessageLogger("tools/qstring.cpp", 6991, __PRETTY_FUNCTION__).warning() << "QString::arg: Argument missing:" << *this << ',' << a; -
3221 return *this;
-
3222 } -
3223 -
3224 unsigned flags = QLocalePrivate::NoFlags; -
3225 if (fillChar == QLatin1Char('0'))
-
3226 flags = QLocalePrivate::ZeroPadded;
-
3227 -
3228 QString arg; -
3229 if (d.occurrences > d.locale_occurrences)
-
3230 arg = QLocale::c().d->longLongToString(a, -1, base, fieldWidth, flags);
-
3231 -
3232 QString locale_arg; -
3233 if (d.locale_occurrences > 0) {
-
3234 QLocale locale; -
3235 if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
-
3236 flags |= QLocalePrivate::ThousandsGroup;
-
3237 locale_arg = locale.d->longLongToString(a, -1, base, fieldWidth, flags); -
3238 }
-
3239 -
3240 return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar);
-
3241} -
3242QString QString::arg(qulonglong a, int fieldWidth, int base, QChar fillChar) const -
3243{ -
3244 ArgEscapeData d = findArgEscapes(*this); -
3245 -
3246 if (d.occurrences == 0) {
-
3247 QMessageLogger("tools/qstring.cpp", 7035, __PRETTY_FUNCTION__).warning() << "QString::arg: Argument missing:" << *this << ',' << a; -
3248 return *this;
-
3249 } -
3250 -
3251 unsigned flags = QLocalePrivate::NoFlags; -
3252 if (fillChar == QLatin1Char('0'))
-
3253 flags = QLocalePrivate::ZeroPadded;
-
3254 -
3255 QString arg; -
3256 if (d.occurrences > d.locale_occurrences)
-
3257 arg = QLocale::c().d->unsLongLongToString(a, -1, base, fieldWidth, flags);
-
3258 -
3259 QString locale_arg; -
3260 if (d.locale_occurrences > 0) {
-
3261 QLocale locale; -
3262 if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
-
3263 flags |= QLocalePrivate::ThousandsGroup;
-
3264 locale_arg = locale.d->unsLongLongToString(a, -1, base, fieldWidth, flags); -
3265 }
-
3266 -
3267 return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar);
-
3268} -
3269QString QString::arg(QChar a, int fieldWidth, QChar fillChar) const -
3270{ -
3271 QString c; -
3272 c += a; -
3273 return arg(c, fieldWidth, fillChar);
-
3274} -
3275 -
3276 -
3277 -
3278 -
3279 -
3280 -
3281QString QString::arg(char a, int fieldWidth, QChar fillChar) const -
3282{ -
3283 QString c; -
3284 c += QLatin1Char(a); -
3285 return arg(c, fieldWidth, fillChar);
-
3286} -
3287QString QString::arg(double a, int fieldWidth, char fmt, int prec, QChar fillChar) const -
3288{ -
3289 ArgEscapeData d = findArgEscapes(*this); -
3290 -
3291 if (d.occurrences == 0) {
-
3292 QMessageLogger("tools/qstring.cpp", 7147, __PRETTY_FUNCTION__).warning("QString::arg: Argument missing: %s, %g", toLocal8Bit().data(), a); -
3293 return *this;
-
3294 } -
3295 -
3296 unsigned flags = QLocalePrivate::NoFlags; -
3297 if (fillChar == QLatin1Char('0'))
-
3298 flags = QLocalePrivate::ZeroPadded;
-
3299 -
3300 if (qIsUpper(fmt))
-
3301 flags |= QLocalePrivate::CapitalEorX;
-
3302 fmt = qToLower(fmt); -
3303 -
3304 QLocalePrivate::DoubleForm form = QLocalePrivate::DFDecimal; -
3305 switch (fmt) { -
3306 case 'f': -
3307 form = QLocalePrivate::DFDecimal; -
3308 break;
-
3309 case 'e': -
3310 form = QLocalePrivate::DFExponent; -
3311 break;
-
3312 case 'g': -
3313 form = QLocalePrivate::DFSignificantDigits; -
3314 break;
-
3315 default: -
3316 -
3317 -
3318 -
3319 break;
-
3320 } -
3321 -
3322 QString arg; -
3323 if (d.occurrences > d.locale_occurrences)
-
3324 arg = QLocale::c().d->doubleToString(a, prec, form, fieldWidth, flags);
-
3325 -
3326 QString locale_arg; -
3327 if (d.locale_occurrences > 0) {
-
3328 QLocale locale; -
3329 -
3330 if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
-
3331 flags |= QLocalePrivate::ThousandsGroup;
-
3332 locale_arg = locale.d->doubleToString(a, prec, form, fieldWidth, flags); -
3333 }
-
3334 -
3335 return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar);
-
3336} -
3337 -
3338static int getEscape(const QChar *uc, int *pos, int len, int maxNumber = 999) -
3339{ -
3340 int i = *pos; -
3341 ++i; -
3342 if (i < len && uc[i] == QLatin1Char('L'))
-
3343 ++i;
-
3344 if (i < len) {
-
3345 int escape = uc[i].unicode() - '0'; -
3346 if (uint(escape) >= 10U)
-
3347 return -1;
-
3348 ++i; -
3349 while (i < len) {
-
3350 int digit = uc[i].unicode() - '0'; -
3351 if (uint(digit) >= 10U)
-
3352 break;
-
3353 escape = (escape * 10) + digit; -
3354 ++i; -
3355 }
-
3356 if (escape <= maxNumber) {
-
3357 *pos = i; -
3358 return escape;
-
3359 } -
3360 }
-
3361 return -1;
-
3362} -
3363 -
3364QString QString::multiArg(int numArgs, const QString **args) const -
3365{ -
3366 QString result; -
3367 QMap<int, int> numbersUsed; -
3368 const QChar *uc = (const QChar *) d->data(); -
3369 const int len = d->size; -
3370 const int end = len - 1; -
3371 int lastNumber = -1; -
3372 int i = 0; -
3373 -
3374 -
3375 while (i < end) {
-
3376 if (uc[i] == QLatin1Char('%')) {
-
3377 int number = getEscape(uc, &i, len); -
3378 if (number != -1) {
-
3379 numbersUsed.insert(number, -1); -
3380 continue;
-
3381 } -
3382 }
-
3383 ++i; -
3384 }
-
3385 -
3386 -
3387 QMap<int, int>::iterator j = numbersUsed.begin(); -
3388 QMap<int, int>::iterator jend = numbersUsed.end(); -
3389 int arg = 0; -
3390 while (j != jend && arg < numArgs) {
-
3391 *j = arg++; -
3392 lastNumber = j.key(); -
3393 ++j; -
3394 }
-
3395 -
3396 -
3397 if (numArgs > arg) {
-
3398 QMessageLogger("tools/qstring.cpp", 7253, __PRETTY_FUNCTION__).warning("QString::arg: %d argument(s) missing in %s", numArgs - arg, toLocal8Bit().data()); -
3399 numArgs = arg; -
3400 }
-
3401 -
3402 i = 0; -
3403 while (i < len) {
-
3404 if (uc[i] == QLatin1Char('%') && i != end) {
-
3405 int number = getEscape(uc, &i, len, lastNumber); -
3406 int arg = numbersUsed[number]; -
3407 if (number != -1 && arg != -1) {
-
3408 result += *args[arg]; -
3409 continue;
-
3410 } -
3411 }
-
3412 result += uc[i++]; -
3413 }
-
3414 return result;
-
3415} -
3416 -
3417 -
3418 -
3419 -
3420 -
3421 -
3422bool QString::isSimpleText() const -
3423{ -
3424 const ushort *p = d->data(); -
3425 const ushort * const end = p + d->size; -
3426 while (p < end) {
-
3427 ushort uc = *p; -
3428 -
3429 if (uc > 0x058f && (uc < 0x1100 || uc > 0xfb0f)) {
-
3430 return false;
-
3431 } -
3432 p++; -
3433 }
-
3434 -
3435 return true;
-
3436} -
3437 -
3438 -
3439 -
3440 -
3441 -
3442bool QString::isRightToLeft() const -
3443{ -
3444 const ushort *p = d->data(); -
3445 const ushort * const end = p + d->size; -
3446 while (p < end) {
-
3447 uint ucs4 = *p; -
3448 if (QChar::isHighSurrogate(ucs4) && p < end - 1) {
-
3449 ushort low = p[1]; -
3450 if (QChar::isLowSurrogate(low)) {
-
3451 ucs4 = QChar::surrogateToUcs4(ucs4, low); -
3452 ++p; -
3453 }
-
3454 }
-
3455 switch (QChar::direction(ucs4)) -
3456 { -
3457 case QChar::DirL: -
3458 return false;
-
3459 case QChar::DirR: -
3460 case QChar::DirAL: -
3461 return true;
-
3462 default: -
3463 break;
-
3464 } -
3465 ++p; -
3466 }
-
3467 return false;
-
3468} -
3469QString QString::fromRawData(const QChar *unicode, int size) -
3470{ -
3471 Data *x; -
3472 if (!unicode) {
-
3473 x = Data::sharedNull(); -
3474 } else if (!size) {
-
3475 x = Data::allocate(0); -
3476 } else {
-
3477 x = Data::fromRawData(reinterpret_cast<const ushort *>(unicode), size); -
3478 do { if (!(x)) qBadAlloc(); } while (0);
-
3479 }
-
3480 QStringDataPtr dataPtr = { x }; -
3481 return QString(dataPtr);
-
3482} -
3483QString &QString::setRawData(const QChar *unicode, int size) -
3484{ -
3485 if (d->ref.isShared() || d->alloc) {
-
3486 *this = fromRawData(unicode, size); -
3487 } else {
-
3488 if (unicode) {
-
3489 d->size = size; -
3490 d->offset = reinterpret_cast<const char *>(unicode) - reinterpret_cast<char *>(d); -
3491 } else {
-
3492 d->offset = sizeof(QStringData); -
3493 d->size = 0; -
3494 }
-
3495 } -
3496 return *this;
-
3497} -
3498QDataStream &operator<<(QDataStream &out, const QString &str) -
3499{ -
3500 if (out.version() == 1) {
-
3501 out << str.toLatin1(); -
3502 } else {
-
3503 if (!str.isNull() || out.version() < 3) {
-
3504 if ((out.byteOrder() == QDataStream::BigEndian) == (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
-
3505 out.writeBytes(reinterpret_cast<const char *>(str.unicode()), sizeof(QChar) * str.length()); -
3506 } else {
-
3507 QVarLengthArray<ushort> buffer(str.length()); -
3508 const ushort *data = reinterpret_cast<const ushort *>(str.constData()); -
3509 for (int i = 0; i < str.length(); i++) {
-
3510 buffer[i] = qbswap(*data); -
3511 ++data; -
3512 }
-
3513 out.writeBytes(reinterpret_cast<const char *>(buffer.data()), sizeof(ushort) * buffer.size()); -
3514 }
-
3515 } else { -
3516 -
3517 out << (quint32)0xffffffff; -
3518 }
-
3519 } -
3520 return out;
-
3521} -
3522QDataStream &operator>>(QDataStream &in, QString &str) -
3523{ -
3524 -
3525 -
3526 -
3527 -
3528 -
3529 -
3530 if (in.version() == 1) {
-
3531 QByteArray l; -
3532 in >> l; -
3533 str = QString::fromLatin1(l); -
3534 } else {
-
3535 quint32 bytes = 0; -
3536 in >> bytes; -
3537 if (bytes == 0xffffffff) {
-
3538 str.clear(); -
3539 } else if (bytes > 0) {
-
3540 if (bytes & 0x1) {
-
3541 str.clear(); -
3542 in.setStatus(QDataStream::ReadCorruptData); -
3543 return in;
-
3544 } -
3545 -
3546 const quint32 Step = 1024 * 1024; -
3547 quint32 len = bytes / 2; -
3548 quint32 allocated = 0; -
3549 -
3550 while (allocated < len) {
-
3551 int blockSize = qMin(Step, len - allocated); -
3552 str.resize(allocated + blockSize); -
3553 if (in.readRawData(reinterpret_cast<char *>(str.data()) + allocated * 2, -
3554 blockSize * 2) != blockSize * 2) {
-
3555 str.clear(); -
3556 in.setStatus(QDataStream::ReadPastEnd); -
3557 return in;
-
3558 } -
3559 allocated += blockSize; -
3560 }
-
3561 -
3562 if ((in.byteOrder() == QDataStream::BigEndian) -
3563 != (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
-
3564 ushort *data = reinterpret_cast<ushort *>(str.data()); -
3565 while (len--) {
-
3566 *data = qbswap(*data); -
3567 ++data; -
3568 }
-
3569 }
-
3570 } else {
-
3571 str = QString(QLatin1String("")); -
3572 }
-
3573 } -
3574 return in;
-
3575} -
3576QString QStringRef::toString() const { -
3577 if (!m_string)
-
3578 return QString();
-
3579 if (m_size && m_position == 0 && m_size == m_string->size())
-
3580 return *m_string;
-
3581 return QString(m_string->unicode() + m_position, m_size);
-
3582} -
3583 -
3584 -
3585 -
3586 -
3587 -
3588 -
3589 -
3590bool operator==(const QStringRef &s1,const QStringRef &s2) -
3591{ return (s1.size() == s2.size() && -
3592 qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));
-
3593} -
3594 -
3595 -
3596 -
3597 -
3598 -
3599 -
3600bool operator==(const QString &s1,const QStringRef &s2) -
3601{ return (s1.size() == s2.size() && -
3602 qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));
-
3603} -
3604 -
3605 -
3606 -
3607 -
3608 -
3609 -
3610bool operator==(QLatin1String s1, const QStringRef &s2) -
3611{ -
3612 if (s1.size() != s2.size())
-
3613 return false;
-
3614 -
3615 const ushort *uc = reinterpret_cast<const ushort *>(s2.unicode()); -
3616 const ushort *e = uc + s2.size(); -
3617 const uchar *c = reinterpret_cast<const uchar *>(s1.latin1()); -
3618 if (!c)
-
3619 return s2.isEmpty();
-
3620 -
3621 while (*c) {
-
3622 if (uc == e || *uc != *c)
-
3623 return false;
-
3624 ++uc; -
3625 ++c; -
3626 }
-
3627 return (uc == e);
-
3628} -
3629bool operator<(const QStringRef &s1,const QStringRef &s2) -
3630{ -
3631 return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0;
-
3632} -
3633QStringRef QStringRef::appendTo(QString *string) const -
3634{ -
3635 if (!string)
-
3636 return QStringRef();
-
3637 int pos = string->size(); -
3638 string->insert(pos, unicode(), size()); -
3639 return QStringRef(string, pos, size());
-
3640} -
3641QString &QString::append(const QStringRef &str) -
3642{ -
3643 if (str.string() == this) {
-
3644 str.appendTo(this); -
3645 } else if (str.string()) {
-
3646 int oldSize = size(); -
3647 resize(oldSize + str.size()); -
3648 memcpy(data() + oldSize, str.unicode(), str.size() * sizeof(QChar)); -
3649 }
-
3650 return *this;
-
3651} -
3652QStringRef QString::leftRef(int n) const -
3653{ -
3654 if (n >= d->size || n < 0)
-
3655 n = d->size;
-
3656 return QStringRef(this, 0, n);
-
3657} -
3658QStringRef QString::rightRef(int n) const -
3659{ -
3660 if (n >= d->size || n < 0)
-
3661 n = d->size;
-
3662 return QStringRef(this, d->size - n, n);
-
3663} -
3664QStringRef QString::midRef(int position, int n) const -
3665{ -
3666 if (position > d->size)
-
3667 return QStringRef();
-
3668 if (position < 0) {
-
3669 if (n < 0 || n + position >= d->size)
-
3670 return QStringRef(this, 0, d->size);
-
3671 if (n + position <= 0)
-
3672 return QStringRef();
-
3673 -
3674 n += position; -
3675 position = 0; -
3676 } else if (n < 0 || n > d->size - position)
-
3677 n = d->size - position;
-
3678 return QStringRef(this, position, n);
-
3679} -
3680int QStringRef::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const -
3681{ -
3682 return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs);
-
3683} -
3684int QStringRef::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const -
3685{ -
3686 return findChar(unicode(), length(), ch, from, cs);
-
3687} -
3688int QStringRef::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const -
3689{ -
3690 return qt_find_latin1_string(unicode(), size(), str, from, cs);
-
3691} -
3692int QStringRef::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const -
3693{ -
3694 return qFindString(unicode(), size(), from, str.unicode(), str.size(), cs);
-
3695} -
3696int QStringRef::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const -
3697{ -
3698 const int sl = str.size(); -
3699 if (sl == 1)
-
3700 return lastIndexOf(str.at(0), from, cs);
-
3701 -
3702 const int l = size();; -
3703 if (from < 0)
-
3704 from += l;
-
3705 int delta = l - sl; -
3706 if (from == l && sl == 0)
-
3707 return from;
-
3708 if (from < 0 || from >= l || delta < 0)
-
3709 return -1;
-
3710 if (from > delta)
-
3711 from = delta;
-
3712 -
3713 return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, -
3714 reinterpret_cast<const ushort*>(str.unicode()), str.size(), cs);
-
3715} -
3716int QStringRef::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const -
3717{ -
3718 return qt_last_index_of(unicode(), size(), ch, from, cs);
-
3719} -
3720int QStringRef::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const -
3721{ -
3722 const int sl = str.size(); -
3723 if (sl == 1)
-
3724 return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs);
-
3725 -
3726 const int l = size(); -
3727 if (from < 0)
-
3728 from += l;
-
3729 int delta = l - sl; -
3730 if (from == l && sl == 0)
-
3731 return from;
-
3732 if (from < 0 || from >= l || delta < 0)
-
3733 return -1;
-
3734 if (from > delta)
-
3735 from = delta;
-
3736 -
3737 QVarLengthArray<ushort> s(sl); -
3738 for (int i = 0; i < sl; ++i)
-
3739 s[i] = str.latin1()[i];
-
3740 -
3741 return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, s.data(), sl, cs);
-
3742} -
3743int QStringRef::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const -
3744{ -
3745 const int sl = str.size(); -
3746 if (sl == 1)
-
3747 return lastIndexOf(str.at(0), from, cs);
-
3748 -
3749 const int l = size(); -
3750 if (from < 0)
-
3751 from += l;
-
3752 int delta = l - sl; -
3753 if (from == l && sl == 0)
-
3754 return from;
-
3755 if (from < 0 || from >= l || delta < 0)
-
3756 return -1;
-
3757 if (from > delta)
-
3758 from = delta;
-
3759 -
3760 return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, -
3761 reinterpret_cast<const ushort*>(str.unicode()), -
3762 str.size(), cs);
-
3763} -
3764int QStringRef::count(const QString &str, Qt::CaseSensitivity cs) const -
3765{ -
3766 return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs);
-
3767} -
3768int QStringRef::count(QChar ch, Qt::CaseSensitivity cs) const -
3769{ -
3770 return qt_string_count(unicode(), size(), ch, cs);
-
3771} -
3772int QStringRef::count(const QStringRef &str, Qt::CaseSensitivity cs) const -
3773{ -
3774 return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs);
-
3775} -
3776bool QStringRef::startsWith(const QString &str, Qt::CaseSensitivity cs) const -
3777{ -
3778 return qt_starts_with(isNull() ? 0 : unicode(), size(), -
3779 str.isNull() ? 0 : str.unicode(), str.size(), cs);
-
3780} -
3781 -
3782 -
3783 -
3784 -
3785 -
3786 -
3787bool QStringRef::startsWith(QLatin1String str, Qt::CaseSensitivity cs) const -
3788{ -
3789 return qt_starts_with(isNull() ? 0 : unicode(), size(), str, cs);
-
3790} -
3791 -
3792 -
3793 -
3794 -
3795 -
3796 -
3797bool QStringRef::startsWith(const QStringRef &str, Qt::CaseSensitivity cs) const -
3798{ -
3799 return qt_starts_with(isNull() ? 0 : unicode(), size(), -
3800 str.isNull() ? 0 : str.unicode(), str.size(), cs);
-
3801} -
3802bool QStringRef::startsWith(QChar ch, Qt::CaseSensitivity cs) const -
3803{ -
3804 if (!isEmpty()) {
-
3805 const ushort *data = reinterpret_cast<const ushort*>(unicode()); -
3806 return (cs == Qt::CaseSensitive -
3807 ? data[0] == ch -
3808 : foldCase(data[0]) == foldCase(ch.unicode()));
-
3809 } else { -
3810 return false;
-
3811 } -
3812} -
3813bool QStringRef::endsWith(const QString &str, Qt::CaseSensitivity cs) const -
3814{ -
3815 return qt_ends_with(isNull() ? 0 : unicode(), size(), -
3816 str.isNull() ? 0 : str.unicode(), str.size(), cs);
-
3817} -
3818bool QStringRef::endsWith(QChar ch, Qt::CaseSensitivity cs) const -
3819{ -
3820 if (!isEmpty()) {
-
3821 const ushort *data = reinterpret_cast<const ushort*>(unicode()); -
3822 const int size = length(); -
3823 return (cs == Qt::CaseSensitive -
3824 ? data[size - 1] == ch -
3825 : foldCase(data[size - 1]) == foldCase(ch.unicode()));
-
3826 } else { -
3827 return false;
-
3828 } -
3829} -
3830 -
3831 -
3832 -
3833 -
3834 -
3835 -
3836bool QStringRef::endsWith(QLatin1String str, Qt::CaseSensitivity cs) const -
3837{ -
3838 return qt_ends_with(isNull() ? 0 : unicode(), size(), str, cs);
-
3839} -
3840 -
3841 -
3842 -
3843 -
3844 -
3845 -
3846bool QStringRef::endsWith(const QStringRef &str, Qt::CaseSensitivity cs) const -
3847{ -
3848 return qt_ends_with(isNull() ? 0 : unicode(), size(), -
3849 str.isNull() ? 0 : str.unicode(), str.size(), cs);
-
3850} -
3851static inline int qt_last_index_of(const QChar *haystack, int haystackLen, QChar needle, -
3852 int from, Qt::CaseSensitivity cs) -
3853{ -
3854 ushort c = needle.unicode(); -
3855 if (from < 0)
-
3856 from += haystackLen;
-
3857 if (from < 0 || from >= haystackLen)
-
3858 return -1;
-
3859 if (from >= 0) {
-
3860 const ushort *b = reinterpret_cast<const ushort*>(haystack); -
3861 const ushort *n = b + from; -
3862 if (cs == Qt::CaseSensitive) {
-
3863 for (; n >= b; --n)
-
3864 if (*n == c)
-
3865 return n - b;
-
3866 } else {
-
3867 c = foldCase(c); -
3868 for (; n >= b; --n)
-
3869 if (foldCase(*n) == c)
-
3870 return n - b;
-
3871 }
-
3872 } -
3873 return -1;
-
3874 -
3875 -
3876} -
3877 -
3878static inline int qt_string_count(const QChar *haystack, int haystackLen, -
3879 const QChar *needle, int needleLen, -
3880 Qt::CaseSensitivity cs) -
3881{ -
3882 int num = 0; -
3883 int i = -1; -
3884 if (haystackLen > 500 && needleLen > 5) {
-
3885 QStringMatcher matcher(needle, needleLen, cs); -
3886 while ((i = matcher.indexIn(haystack, haystackLen, i + 1)) != -1)
-
3887 ++num;
-
3888 } else {
-
3889 while ((i = qFindString(haystack, haystackLen, i + 1, needle, needleLen, cs)) != -1)
-
3890 ++num;
-
3891 }
-
3892 return num;
-
3893} -
3894 -
3895static inline int qt_string_count(const QChar *unicode, int size, QChar ch, -
3896 Qt::CaseSensitivity cs) -
3897{ -
3898 ushort c = ch.unicode(); -
3899 int num = 0; -
3900 const ushort *b = reinterpret_cast<const ushort*>(unicode); -
3901 const ushort *i = b + size; -
3902 if (cs == Qt::CaseSensitive) {
-
3903 while (i != b)
-
3904 if (*--i == c)
-
3905 ++num;
-
3906 } else {
-
3907 c = foldCase(c); -
3908 while (i != b)
-
3909 if (foldCase(*(--i)) == c)
-
3910 ++num;
-
3911 }
-
3912 return num;
-
3913} -
3914 -
3915static inline int qt_find_latin1_string(const QChar *haystack, int size, -
3916 QLatin1String needle, -
3917 int from, Qt::CaseSensitivity cs) -
3918{ -
3919 const char *latin1 = needle.latin1(); -
3920 int len = needle.size(); -
3921 QVarLengthArray<ushort> s(len); -
3922 for (int i = 0; i < len; ++i)
-
3923 s[i] = latin1[i];
-
3924 -
3925 return qFindString(haystack, size, from, -
3926 reinterpret_cast<const QChar*>(s.constData()), len, cs);
-
3927} -
3928 -
3929static inline bool qt_starts_with(const QChar *haystack, int haystackLen, -
3930 const QChar *needle, int needleLen, Qt::CaseSensitivity cs) -
3931{ -
3932 if (!haystack)
-
3933 return !needle;
-
3934 if (haystackLen == 0)
-
3935 return needleLen == 0;
-
3936 if (needleLen > haystackLen)
-
3937 return false;
-
3938 -
3939 const ushort *h = reinterpret_cast<const ushort*>(haystack); -
3940 const ushort *n = reinterpret_cast<const ushort*>(needle); -
3941 -
3942 if (cs == Qt::CaseSensitive) {
-
3943 return qMemEquals(h, n, needleLen);
-
3944 } else { -
3945 uint last = 0; -
3946 uint olast = 0; -
3947 for (int i = 0; i < needleLen; ++i)
-
3948 if (foldCase(h[i], last) != foldCase(n[i], olast))
-
3949 return false;
-
3950 }
-
3951 return true;
-
3952} -
3953 -
3954static inline bool qt_starts_with(const QChar *haystack, int haystackLen, -
3955 QLatin1String needle, Qt::CaseSensitivity cs) -
3956{ -
3957 if (!haystack)
-
3958 return !needle.latin1();
-
3959 if (haystackLen == 0)
-
3960 return !needle.latin1() || *needle.latin1() == 0;
-
3961 const int slen = needle.size(); -
3962 if (slen > haystackLen)
-
3963 return false;
-
3964 const ushort *data = reinterpret_cast<const ushort*>(haystack); -
3965 const uchar *latin = reinterpret_cast<const uchar*>(needle.latin1()); -
3966 if (cs == Qt::CaseSensitive) {
-
3967 for (int i = 0; i < slen; ++i)
-
3968 if (data[i] != latin[i])
-
3969 return false;
-
3970 } else {
-
3971 for (int i = 0; i < slen; ++i)
-
3972 if (foldCase(data[i]) != foldCase((ushort)latin[i]))
-
3973 return false;
-
3974 }
-
3975 return true;
-
3976} -
3977 -
3978static inline bool qt_ends_with(const QChar *haystack, int haystackLen, -
3979 const QChar *needle, int needleLen, Qt::CaseSensitivity cs) -
3980{ -
3981 if (!haystack)
-
3982 return !needle;
-
3983 if (haystackLen == 0)
-
3984 return needleLen == 0;
-
3985 const int pos = haystackLen - needleLen; -
3986 if (pos < 0)
-
3987 return false;
-
3988 -
3989 const ushort *h = reinterpret_cast<const ushort*>(haystack); -
3990 const ushort *n = reinterpret_cast<const ushort*>(needle); -
3991 -
3992 if (cs == Qt::CaseSensitive) {
-
3993 return qMemEquals(h + pos, n, needleLen);
-
3994 } else { -
3995 uint last = 0; -
3996 uint olast = 0; -
3997 for (int i = 0; i < needleLen; i++)
-
3998 if (foldCase(h[pos+i], last) != foldCase(n[i], olast))
-
3999 return false;
-
4000 }
-
4001 return true;
-
4002} -
4003 -
4004 -
4005static inline bool qt_ends_with(const QChar *haystack, int haystackLen, -
4006 QLatin1String needle, Qt::CaseSensitivity cs) -
4007{ -
4008 if (!haystack)
-
4009 return !needle.latin1();
-
4010 if (haystackLen == 0)
-
4011 return !needle.latin1() || *needle.latin1() == 0;
-
4012 const int slen = needle.size(); -
4013 int pos = haystackLen - slen; -
4014 if (pos < 0)
-
4015 return false;
-
4016 const uchar *latin = reinterpret_cast<const uchar*>(needle.latin1()); -
4017 const ushort *data = reinterpret_cast<const ushort*>(haystack); -
4018 if (cs == Qt::CaseSensitive) {
-
4019 for (int i = 0; i < slen; i++)
-
4020 if (data[pos+i] != latin[i])
-
4021 return false;
-
4022 } else {
-
4023 for (int i = 0; i < slen; i++)
-
4024 if (foldCase(data[pos+i]) != foldCase((ushort)latin[i]))
-
4025 return false;
-
4026 }
-
4027 return true;
-
4028} -
4029QByteArray QStringRef::toLatin1() const -
4030{ -
4031 return toLatin1_helper(unicode(), length());
-
4032} -
4033QByteArray QStringRef::toLocal8Bit() const -
4034{ -
4035 -
4036 QTextCodec *localeCodec = QTextCodec::codecForLocale(); -
4037 if (localeCodec)
-
4038 return localeCodec->fromUnicode(unicode(), length());
-
4039 -
4040 return toLatin1();
-
4041} -
4042QByteArray QStringRef::toUtf8() const -
4043{ -
4044 if (isNull())
-
4045 return QByteArray();
-
4046 -
4047 return QUtf8::convertFromUnicode(constData(), length(), 0);
-
4048} -
4049QVector<uint> QStringRef::toUcs4() const -
4050{ -
4051 QVector<uint> v(length()); -
4052 uint *a = v.data(); -
4053 int len = QString::toUcs4_helper(reinterpret_cast<const ushort *>(unicode()), length(), a); -
4054 v.resize(len); -
4055 return v;
-
4056} -
4057QString QString::toHtmlEscaped() const -
4058{ -
4059 QString rich; -
4060 const int len = length(); -
4061 rich.reserve(int(len * 1.1)); -
4062 for (int i = 0; i < len; ++i) {
-
4063 if (at(i) == QLatin1Char('<'))
-
4064 rich += QLatin1String("&lt;");
-
4065 else if (at(i) == QLatin1Char('>'))
-
4066 rich += QLatin1String("&gt;");
-
4067 else if (at(i) == QLatin1Char('&'))
-
4068 rich += QLatin1String("&amp;");
-
4069 else if (at(i) == QLatin1Char('"'))
-
4070 rich += QLatin1String("&quot;");
-
4071 else -
4072 rich += at(i);
-
4073 } -
4074 rich.squeeze(); -
4075 return rich;
-
4076} -
4077 -
4078 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial