5#include <qstringlist.h>
6#if QT_CONFIG(regularexpression)
7# include <qregularexpression.h>
9#include <private/qduplicatetracker_p.h>
10#include <QtCore/qlatin1stringmatcher.h>
16
17
18
19
20
21
22
23
24
25
26
29
30
31
32
33
34
35
36
37
38
39
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
134
135
136
137
138
139
140
141
142
145
146
147
148
149
150
151
152
153
154
155
158
159
160
161
162
163
164
165
168
169
170
171
172
173
174
175
178
179
180
181
182
183
184
185
186
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
211 if (cs == Qt::CaseSensitive) {
212 std::sort(that->begin(), that->end());
214 auto CISCompare = [](
const auto &s1,
const auto &s2) {
215 return s1.compare(s2, Qt::CaseInsensitive) < 0;
217 std::sort(that->begin(), that->end(), CISCompare);
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
240template <
typename String>
244 for (
const auto &s : that) {
245 if (s.contains(needle, cs))
252
253
254
255
256QStringList
QtPrivate::QStringList_filter(
const QStringList *that, QStringView str,
257 Qt::CaseSensitivity cs)
259 return filter_helper(*that, str, cs);
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295QStringList
QtPrivate::QStringList_filter(
const QStringList &that,
const QStringMatcher &matcher)
298 for (
const auto &s : that) {
299 if (matcher.indexIn(s) != -1)
308 for (
const auto &s : that) {
309 if (matcher.indexIn(s) != -1)
316
317
318
319
321QStringList
QtPrivate::QStringList_filter(
const QStringList &that, QLatin1StringView needle,
322 Qt::CaseSensitivity cs)
324 return filter_helper(that, needle, cs);
330 for (
const auto &string : stringList) {
331 if (string.size() == str.size() && string.compare(str, cs) == 0)
339
340
341
342
343
344
345
346
347
350
351
352
353
354
355
356
357
358
359bool QtPrivate::QStringList_contains(
const QStringList *that, QStringView str,
360 Qt::CaseSensitivity cs)
362 return stringList_contains(*that, str, cs);
366
367
368
369
370
371
372
373
374
375
376
377bool QtPrivate::QStringList_contains(
const QStringList *that, QLatin1StringView str,
378 Qt::CaseSensitivity cs)
380 return stringList_contains(*that, str, cs);
384#if QT_CONFIG(regularexpression)
386
387
388
389
390
391
392
393QStringList QtPrivate::QStringList_filter(
const QStringList *that,
const QRegularExpression &re)
396 for (
const auto &str : *that) {
397 if (str.contains(re))
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
425
426
427
428
431
432
433
434
437
438
439
440
441void QtPrivate::QStringList_replaceInStrings(QStringList *that, QStringView before,
442 QStringView after, Qt::CaseSensitivity cs)
446 for (qsizetype j = 0; j < that->size(); ++j) {
447 if (that->at(j).contains(before, cs)) {
455 for (; i < that->size(); ++i)
456 (*that)[i].replace(before.data(), before.size(), after.data(), after.size(), cs);
459#if QT_CONFIG(regularexpression)
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483void QtPrivate::QStringList_replaceInStrings(QStringList *that,
const QRegularExpression &re,
484 const QString &after)
488 for (qsizetype j = 0; j < that->size(); ++j) {
489 if (that->at(j).contains(re)) {
497 for (; i < that->size(); ++i)
498 (*that)[i].replace(re, after);
504 qsizetype result = 0;
505 if (!list.isEmpty()) {
506 for (
const auto &e : list)
507 result += e.size() + seplen;
514
515
516
517
518
519
520
521
524
525
526
527
528QString
QtPrivate::QStringList_join(
const QStringList *that,
const QChar *sep, qsizetype seplen)
530 const qsizetype totalLength = accumulatedSize(*that, seplen);
531 const qsizetype size = that->size();
534 if (totalLength == 0)
536 res.reserve(totalLength);
537 for (qsizetype i = 0; i < size; ++i) {
539 res.append(sep, seplen);
546
547
548
549
550QString
QtPrivate::QStringList_join(
const QStringList &list, QLatin1StringView sep)
553 if (!list.isEmpty()) {
554 result.reserve(accumulatedSize(list, sep.size()));
555 const auto end = list.end();
556 auto it = list.begin();
558 while (++it != end) {
567
568
569
570
571QString
QtPrivate::QStringList_join(
const QStringList *that, QStringView sep)
573 return QStringList_join(that, sep.data(), sep.size());
577
578
579
580
581
582
583
586
587
588
589
590
591
592
595
596
597
598
599
600
601
604
605
606
607
608
609
610
611
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
634template <
typename String>
636 Qt::CaseSensitivity cs)
639 from = qMax(from + that.size(), 0);
641 if (from >= that.size())
644 for (qsizetype i = from; i < that.size(); ++i) {
645 if (needle.compare(that.at(i), cs) == 0)
651qsizetype
QtPrivate::QStringList_indexOf(
const QStringList &that, QStringView needle,
652 qsizetype from, Qt::CaseSensitivity cs)
654 return indexOf_helper(that, needle, from, cs);
657qsizetype
QtPrivate::QStringList_indexOf(
const QStringList &that, QLatin1StringView needle,
658 qsizetype from, Qt::CaseSensitivity cs)
660 return indexOf_helper(that, needle, from, cs);
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
680template <
typename String>
682 Qt::CaseSensitivity cs)
686 else if (from >= that.size())
687 from = that.size() - 1;
689 for (qsizetype i = from; i >= 0; --i) {
690 if (needle.compare(that.at(i), cs) == 0)
697qsizetype
QtPrivate::QStringList_lastIndexOf(
const QStringList &that, QLatin1StringView needle,
698 qsizetype from, Qt::CaseSensitivity cs)
700 return lastIndexof_helper(that, needle, from, cs);
703qsizetype
QtPrivate::QStringList_lastIndexOf(
const QStringList &that, QStringView needle,
704 qsizetype from, Qt::CaseSensitivity cs)
706 return lastIndexof_helper(that, needle, from, cs);
709#if QT_CONFIG(regularexpression)
711
712
713
714
715
716
717
718
719
720
721qsizetype QtPrivate::QStringList_indexOf(
const QStringList *that,
const QRegularExpression &re, qsizetype from)
724 from = qMax(from + that->size(), qsizetype(0));
726 QString exactPattern = QRegularExpression::anchoredPattern(re.pattern());
727 QRegularExpression exactRe(exactPattern, re.patternOptions());
729 for (qsizetype i = from; i < that->size(); ++i) {
730 QRegularExpressionMatch m = exactRe.match(that->at(i));
738
739
740
741
742
743
744
745
746
747
748
749qsizetype QtPrivate::QStringList_lastIndexOf(
const QStringList *that,
const QRegularExpression &re, qsizetype from)
752 from += that->size();
753 else if (from >= that->size())
754 from = that->size() - 1;
756 QString exactPattern = QRegularExpression::anchoredPattern(re.pattern());
757 QRegularExpression exactRe(exactPattern, re.patternOptions());
759 for (qsizetype i = from; i >= 0; --i) {
760 QRegularExpressionMatch m = exactRe.match(that->at(i));
769
770
771
772
773
774
775
776
777
778
779qsizetype
QtPrivate::QStringList_removeDuplicates(QStringList *that)
781 QDuplicateTracker<QString> seen(that->size());
782 return that->removeIf([&](
const QString &s) {
return seen.hasSeen(s); });
QT_BEGIN_NAMESPACEQStringListIterator
The QStringListIterator type definition provides a Java-style const iterator for QStringList.
qsizetype indexOf_helper(const QStringList &that, String needle, qsizetype from, Qt::CaseSensitivity cs)
static QStringList filter_helper(const QStringList &that, const String &needle, Qt::CaseSensitivity cs)
qsizetype lastIndexof_helper(const QStringList &that, String needle, qsizetype from, Qt::CaseSensitivity cs)
static bool stringList_contains(const QStringList &stringList, const T &str, Qt::CaseSensitivity cs)
static qsizetype accumulatedSize(const QStringList &list, qsizetype seplen)