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
133
134
135
136
137
138
139
140
141
144
145
146
147
148
149
150
151
152
153
154
157
158
159
160
161
162
163
164
167
168
169
170
171
172
173
174
177
178
179
180
181
182
183
184
185
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
210 if (cs == Qt::CaseSensitive) {
211 std::sort(that->begin(), that->end());
213 auto CISCompare = [](
const auto &s1,
const auto &s2) {
214 return s1.compare(s2, Qt::CaseInsensitive) < 0;
216 std::sort(that->begin(), that->end(), CISCompare);
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
239template <
typename String>
243 for (
const auto &s : that) {
244 if (s.contains(needle, cs))
251
252
253
254
255QStringList
QtPrivate::QStringList_filter(
const QStringList *that, QStringView str,
256 Qt::CaseSensitivity cs)
258 return filter_helper(*that, str, cs);
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294QStringList
QtPrivate::QStringList_filter(
const QStringList &that,
const QStringMatcher &matcher)
297 for (
const auto &s : that) {
298 if (matcher.indexIn(s) != -1)
307 for (
const auto &s : that) {
308 if (matcher.indexIn(s) != -1)
315
316
317
318
320QStringList
QtPrivate::QStringList_filter(
const QStringList &that, QLatin1StringView needle,
321 Qt::CaseSensitivity cs)
323 return filter_helper(that, needle, cs);
329 for (
const auto &string : stringList) {
330 if (string.size() == str.size() && string.compare(str, cs) == 0)
338
339
340
341
342
343
344
345
346
349
350
351
352
353
354
355
356
357
358bool QtPrivate::QStringList_contains(
const QStringList *that, QStringView str,
359 Qt::CaseSensitivity cs)
361 return stringList_contains(*that, str, cs);
365
366
367
368
369
370
371
372
373
374
375
376bool QtPrivate::QStringList_contains(
const QStringList *that, QLatin1StringView str,
377 Qt::CaseSensitivity cs)
379 return stringList_contains(*that, str, cs);
383#if QT_CONFIG(regularexpression)
385
386
387
388
389
390
391
392QStringList QtPrivate::QStringList_filter(
const QStringList *that,
const QRegularExpression &re)
395 for (
const auto &str : *that) {
396 if (str.contains(re))
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
424
425
426
427
430
431
432
433
436
437
438
439
440void QtPrivate::QStringList_replaceInStrings(QStringList *that, QStringView before,
441 QStringView after, Qt::CaseSensitivity cs)
445 for (qsizetype j = 0; j < that->size(); ++j) {
446 if (that->at(j).contains(before, cs)) {
454 for (; i < that->size(); ++i)
455 (*that)[i].replace(before.data(), before.size(), after.data(), after.size(), cs);
458#if QT_CONFIG(regularexpression)
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482void QtPrivate::QStringList_replaceInStrings(QStringList *that,
const QRegularExpression &re,
483 const QString &after)
487 for (qsizetype j = 0; j < that->size(); ++j) {
488 if (that->at(j).contains(re)) {
496 for (; i < that->size(); ++i)
497 (*that)[i].replace(re, after);
503 qsizetype result = 0;
504 if (!list.isEmpty()) {
505 for (
const auto &e : list)
506 result += e.size() + seplen;
513
514
515
516
517
518
519
520
523
524
525
526
527QString
QtPrivate::QStringList_join(
const QStringList *that,
const QChar *sep, qsizetype seplen)
529 const qsizetype totalLength = accumulatedSize(*that, seplen);
530 const qsizetype size = that->size();
533 if (totalLength == 0)
535 res.reserve(totalLength);
536 for (qsizetype i = 0; i < size; ++i) {
538 res.append(sep, seplen);
545
546
547
548
549QString
QtPrivate::QStringList_join(
const QStringList &list, QLatin1StringView sep)
552 if (!list.isEmpty()) {
553 result.reserve(accumulatedSize(list, sep.size()));
554 const auto end = list.end();
555 auto it = list.begin();
557 while (++it != end) {
566
567
568
569
570QString
QtPrivate::QStringList_join(
const QStringList *that, QStringView sep)
572 return QStringList_join(that, sep.data(), sep.size());
576
577
578
579
580
581
582
585
586
587
588
589
590
591
594
595
596
597
598
599
600
603
604
605
606
607
608
609
610
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
633template <
typename String>
635 Qt::CaseSensitivity cs)
638 from = qMax(from + that.size(), 0);
640 if (from >= that.size())
643 for (qsizetype i = from; i < that.size(); ++i) {
644 if (needle.compare(that.at(i), cs) == 0)
650qsizetype
QtPrivate::QStringList_indexOf(
const QStringList &that, QStringView needle,
651 qsizetype from, Qt::CaseSensitivity cs)
653 return indexOf_helper(that, needle, from, cs);
656qsizetype
QtPrivate::QStringList_indexOf(
const QStringList &that, QLatin1StringView needle,
657 qsizetype from, Qt::CaseSensitivity cs)
659 return indexOf_helper(that, needle, from, cs);
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
679template <
typename String>
681 Qt::CaseSensitivity cs)
685 else if (from >= that.size())
686 from = that.size() - 1;
688 for (qsizetype i = from; i >= 0; --i) {
689 if (needle.compare(that.at(i), cs) == 0)
696qsizetype
QtPrivate::QStringList_lastIndexOf(
const QStringList &that, QLatin1StringView needle,
697 qsizetype from, Qt::CaseSensitivity cs)
699 return lastIndexof_helper(that, needle, from, cs);
702qsizetype
QtPrivate::QStringList_lastIndexOf(
const QStringList &that, QStringView needle,
703 qsizetype from, Qt::CaseSensitivity cs)
705 return lastIndexof_helper(that, needle, from, cs);
708#if QT_CONFIG(regularexpression)
710
711
712
713
714
715
716
717
718
719
720qsizetype QtPrivate::QStringList_indexOf(
const QStringList *that,
const QRegularExpression &re, qsizetype from)
723 from = qMax(from + that->size(), qsizetype(0));
725 QString exactPattern = QRegularExpression::anchoredPattern(re.pattern());
726 QRegularExpression exactRe(exactPattern, re.patternOptions());
728 for (qsizetype i = from; i < that->size(); ++i) {
729 QRegularExpressionMatch m = exactRe.match(that->at(i));
737
738
739
740
741
742
743
744
745
746
747
748qsizetype QtPrivate::QStringList_lastIndexOf(
const QStringList *that,
const QRegularExpression &re, qsizetype from)
751 from += that->size();
752 else if (from >= that->size())
753 from = that->size() - 1;
755 QString exactPattern = QRegularExpression::anchoredPattern(re.pattern());
756 QRegularExpression exactRe(exactPattern, re.patternOptions());
758 for (qsizetype i = from; i >= 0; --i) {
759 QRegularExpressionMatch m = exactRe.match(that->at(i));
768
769
770
771
772
773
774
775
776
777
778qsizetype
QtPrivate::QStringList_removeDuplicates(QStringList *that)
780 QDuplicateTracker<QString> seen(that->size());
781 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)