13#include <QtCore/private/qthread_p.h>
16QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QCollatorSortKeyPrivate)
17Q_LOGGING_CATEGORY(lcQCollator,
"qt.core.qcollator")
29 int currentGeneration = QLocalePrivate::s_generation.loadRelaxed();
30 if (Q_UNLIKELY(
generation != currentGeneration)) {
33 theCollator = QCollator();
51 if (QThreadData::currentThreadData())
52 storage.setLocalData(
nullptr);
57 auto &d = storage.localData();
64Q_GLOBAL_STATIC(GenerationalCollatorHolder, defaultCollator)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
224
225
226
227
228
229
230
231
232
233
234QCollator::QCollator()
240
241
242
243
244QCollator::QCollator(
const QLocale &locale)
245 : d(
new QCollatorPrivate(locale))
250
251
252QCollator::QCollator(
const QCollator &other)
257 d->ensureInitialized();
263
264
265QCollator::~QCollator()
267 if (d && !d->ref.deref())
272
273
274QCollator &QCollator::operator=(
const QCollator &other)
276 if (
this != &other) {
277 if (d && !d->ref.deref())
282 d->ensureInitialized();
290
291
292
293
294
295
296
297
298
299
302
303
304
305
306
307
310
311
312
315
316
317
318
319
320
321
323bool comparesEqual(
const QCollator &lhs,
const QCollator &rhs)
noexcept
327 if (!lhs.d || !rhs.d)
330 return lhs.d->options == rhs.d->options
331 && lhs.d->locale == rhs.d->locale;
335
336
337void QCollator::detach()
340 d =
new QCollatorPrivate(QLocale().collation());
342 }
else if (d->ref.loadRelaxed() != 1) {
343 QCollatorPrivate *x =
new QCollatorPrivate(d->locale);
344 x->options = d->options;
354
355
356
357
358void QCollator::setLocale(
const QLocale &locale)
360 if (locale ==
this->locale())
368
369
370
371
372
373
374
375QLocale QCollator::locale()
const
377 return d ? d->locale : QLocale().collation();
381
382
383
384
385void QCollator::setCaseSensitivity(Qt::CaseSensitivity cs)
387 if (cs == caseSensitivity())
391 d->options.setFlag(CollationOption::CaseInsensitive, cs == Qt::CaseInsensitive);
395
396
397
398
399
400
401
402
403
404
405
406Qt::CaseSensitivity QCollator::caseSensitivity()
const
408 return d && d->options.testFlag(CollationOption::CaseInsensitive) ? Qt::CaseInsensitive
413
414
415
416
417void QCollator::setNumericMode(
bool on)
419 if (on == numericMode())
423 d->options.setFlag(CollationOption::NumericSort, on);
427
428
429
430
431
432
433
434
435
436bool QCollator::numericMode()
const
438 return d && d->options.testFlag(CollationOption::NumericSort);
442
443
444
445
446void QCollator::setIgnorePunctuation(
bool on)
448 if (on == ignorePunctuation())
452 d->options.setFlag(CollationOption::IgnorePunctuation, on);
456
457
458
459
460
461
462
463bool QCollator::ignorePunctuation()
const
465 return d && d->options.testFlag(CollationOption::IgnorePunctuation);
469
470
471
472
473
474
475
476
477
478void QCollator::setOptions(CollationOptions options)
480 if (d && d->options == options)
483 d->options = options;
487
488
489
490
491
492QCollator::CollationOptions QCollator::options()
const
494 return d ? d->options : CollationOptions{};
498
499
500
501
502
503
504
505
508
509
510
511
512
513
514
515
518
519
520
521
524
525
526
527
530
531
532
533
534
535
536
537
538
539
540
541
542
543
546
547
548
549
550
551
552
553
554int QCollator::defaultCompare(QStringView s1, QStringView s2)
556 return defaultCollator->localData().collator().compare(s1, s2);
560
561
562
563
564
565
566
567QCollatorSortKey QCollator::defaultSortKey(QStringView key)
569 return defaultCollator->localData().collator().sortKey(key.toString());
573
574
575
576
577
578
579
580
581
582
583
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
605
606
607QCollatorSortKey::QCollatorSortKey(QCollatorSortKeyPrivate *d)
613
614
615QCollatorSortKey::QCollatorSortKey(
const QCollatorSortKey &other)
621
622
623
624
625
626
629
630
631QCollatorSortKey::~QCollatorSortKey()
636
637
638QCollatorSortKey& QCollatorSortKey::operator=(
const QCollatorSortKey &other)
640 if (
this != &other) {
647
648
649
650
651
652
655
656
657
658
659
660
661
662
663
664
665
666
667
670
671
672
675
676
677
678
679
680
681
682
683
684
685
686
GenerationalCollator & localData()
~GenerationalCollatorHolder()
GenerationalCollatorHolder()=default
Combined button and popup list for selecting options.
GenerationalCollator(const QCollator ©)
GenerationalCollator()=default