14#define FLAG(x) (1
<< (x))
17
18
19
20
21
22
23
24
25
26
27
30
31
32
33
36
37
38
39
40
43
44
45
46
47
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
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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
584
585
586
589
590
591
594
595
596
597
598
599
602
603
604
605
606
607
608
609
610
611
612
615
616
617
618
619
620
623
624
625
626
627
628
629
632
633
634
635
636
637
638
639
640
643
644
645
646
647
648
649
650
651
652
653
656
657
658
659
660
661
662
663
664
665
666
669
670
671
672
673
674
677
678
679
680
681
682
685
686
687
688
689
690
693
694
695
696
697
698
701
702
703
704
705
706
709
710
711
712
713
714
717
718
719
720
721
722
723
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
757
758
759
760
761
764
765
766
767
768
769
772
773
774
775
776
777
780
781
782
783
784
785
786
787
790
791
792
793
794
795
796
797
798
799
800
801
802bool QChar::isPrint(
char32_t ucs4)
noexcept
804 if (ucs4 > LastValidCodePoint)
806 const int test =
FLAG(Other_Control) |
808 FLAG(Other_Surrogate) |
809 FLAG(Other_PrivateUse) |
810 FLAG(Other_NotAssigned);
811 return !(
FLAG(qGetProp(ucs4)->category) & test);
815
816
817
818
819
820
823
824
825
826
827
828
829
830
831
832
835
836
837bool QT_FASTCALL QChar::isSpace_helper(
char32_t ucs4)
noexcept
839 if (ucs4 > MaxSeparatorCodepoint)
842 const int test =
FLAG(Separator_Space) |
843 FLAG(Separator_Line) |
844 FLAG(Separator_Paragraph);
845 return FLAG(qGetProp(ucs4)->category) & test;
849
850
851
852
853
854
855
858
859
860
861
862
863
864
865
866bool QChar::isMark(
char32_t ucs4)
noexcept
868 if (ucs4 > LastValidCodePoint)
870 const int test =
FLAG(Mark_NonSpacing) |
871 FLAG(Mark_SpacingCombining) |
872 FLAG(Mark_Enclosing);
873 return FLAG(qGetProp(ucs4)->category) & test;
877
878
879
880
881
884
885
886
887
888
889
890
891
892bool QChar::isPunct(
char32_t ucs4)
noexcept
894 if (ucs4 > LastValidCodePoint)
896 const int test =
FLAG(Punctuation_Connector) |
897 FLAG(Punctuation_Dash) |
898 FLAG(Punctuation_Open) |
899 FLAG(Punctuation_Close) |
900 FLAG(Punctuation_InitialQuote) |
901 FLAG(Punctuation_FinalQuote) |
902 FLAG(Punctuation_Other);
903 return FLAG(qGetProp(ucs4)->category) & test;
907
908
909
910
911
914
915
916
917
918
919
920
921
922bool QChar::isSymbol(
char32_t ucs4)
noexcept
924 if (ucs4 > LastValidCodePoint)
926 const int test =
FLAG(Symbol_Math) |
927 FLAG(Symbol_Currency) |
928 FLAG(Symbol_Modifier) |
930 return FLAG(qGetProp(ucs4)->category) & test;
934
935
936
937
938
941
942
943
944
945
946
947
948
949
952
953
954bool QT_FASTCALL QChar::isLetter_helper(
char32_t ucs4)
noexcept
956 if (ucs4 > LastValidCodePoint)
958 const int test =
FLAG(Letter_Uppercase) |
959 FLAG(Letter_Lowercase) |
960 FLAG(Letter_Titlecase) |
961 FLAG(Letter_Modifier) |
963 return FLAG(qGetProp(ucs4)->category) & test;
967
968
969
970
971
972
973
976
977
978
979
980
981
982
983
984
985
986
989
990
991bool QT_FASTCALL QChar::isNumber_helper(
char32_t ucs4)
noexcept
993 if (ucs4 > LastValidCodePoint)
995 const int test =
FLAG(Number_DecimalDigit) |
996 FLAG(Number_Letter) |
998 return FLAG(qGetProp(ucs4)->category) & test;
1002
1003
1004
1005
1006
1009
1010
1011
1012
1013
1014
1015
1016
1017
1020
1021
1022bool QT_FASTCALL QChar::isLetterOrNumber_helper(
char32_t ucs4)
noexcept
1024 if (ucs4 > LastValidCodePoint)
1026 const int test =
FLAG(Letter_Uppercase) |
1027 FLAG(Letter_Lowercase) |
1028 FLAG(Letter_Titlecase) |
1029 FLAG(Letter_Modifier) |
1030 FLAG(Letter_Other) |
1031 FLAG(Number_DecimalDigit) |
1032 FLAG(Number_Letter) |
1034 return FLAG(qGetProp(ucs4)->category) & test;
1038
1039
1040
1041
1042
1043
1044
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1073
1074
1075
1076
1077
1080
1081
1082
1083
1084
1087
1088
1089
1090
1091
1092
1093
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1113
1114
1115
1116
1117
1118
1119
1120
1121
1124
1125
1126
1127
1128
1129
1130
1131
1132
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1148
1149
1150
1151
1152
1153
1154
1155
1156
1159
1160
1161
1162
1163
1164
1165
1168
1169
1170
1171
1172
1173
1174
1177
1178
1179
1180
1181
1182
1183
1186
1187
1188
1189
1190
1191
1192
1195
1196
1197
1198
1201
1202
1203
1204
1205
1206
1207int QChar::digitValue(
char32_t ucs4)
noexcept
1209 if (ucs4 > LastValidCodePoint)
1211 return qGetProp(ucs4)->digitValue;
1215
1216
1217
1218
1221
1222
1223
1224
1225
1226QChar::Category QChar::category(
char32_t ucs4)
noexcept
1228 if (ucs4 > LastValidCodePoint)
1229 return QChar::Other_NotAssigned;
1230 return (QChar::Category) qGetProp(ucs4)->category;
1234
1235
1236
1237
1240
1241
1242
1243
1244
1245QChar::Direction QChar::direction(
char32_t ucs4)
noexcept
1247 if (ucs4 > LastValidCodePoint)
1249 return (QChar::Direction) qGetProp(ucs4)->direction;
1253
1254
1255
1256
1257
1258
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270QChar::JoiningType QChar::joiningType(
char32_t ucs4)
noexcept
1272 if (ucs4 > LastValidCodePoint)
1273 return QChar::Joining_None;
1274 return QChar::JoiningType(qGetProp(ucs4)->joining);
1278
1279
1280
1281
1282
1283
1284
1285
1286
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301bool QChar::hasMirrored(
char32_t ucs4)
noexcept
1303 if (ucs4 > LastValidCodePoint)
1305 return qGetProp(ucs4)->mirrorDiff != 0;
1309
1310
1311
1312
1313
1314
1315
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1331
1332
1333
1334
1335
1336
1337
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1353
1354
1355
1356
1357
1358
1359
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1374
1375
1376
1377
1378
1379
1380
1383
1384
1385
1386
1387
1388
1389
1390
1391char32_t QChar::mirroredChar(
char32_t ucs4)
noexcept
1393 if (ucs4 > LastValidCodePoint)
1395 return ucs4 + qGetProp(ucs4)->mirrorDiff;
1410static const QChar * QT_FASTCALL decompositionHelper(
1411 char32_t ucs4, qsizetype *length, QChar::Decomposition *tag, QChar *buffer)
1413 if (ucs4 >= Hangul_SBase && ucs4 < Hangul_SBase + Hangul_SCount) {
1415 const char32_t SIndex = ucs4 - Hangul_SBase;
1416 buffer[0] = QChar(Hangul_LBase + SIndex / Hangul_NCount);
1417 buffer[1] = QChar(Hangul_VBase + (SIndex % Hangul_NCount) / Hangul_TCount);
1418 buffer[2] = QChar(Hangul_TBase + SIndex % Hangul_TCount);
1419 *length = buffer[2].unicode() == Hangul_TBase ? 2 : 3;
1420 *tag = QChar::Canonical;
1425 if (index == 0xffff) {
1427 *tag = QChar::NoDecomposition;
1431 const unsigned short *decomposition = uc_decomposition_map+index;
1432 *tag = QChar::Decomposition((*decomposition) & 0xff);
1433 *length = (*decomposition) >> 8;
1434 return reinterpret_cast<
const QChar *>(decomposition + 1);
1438
1439
1440
1441QString QChar::decomposition()
const
1443 return QChar::decomposition(ucs);
1447
1448
1449
1450
1451
1452
1453QString QChar::decomposition(
char32_t ucs4)
1457 QChar::Decomposition tag;
1458 const QChar *d = decompositionHelper(ucs4, &length, &tag, buffer);
1459 return QString(d, length);
1463
1464
1465
1466
1467
1470
1471
1472
1473
1474
1475
1476QChar::Decomposition QChar::decompositionTag(
char32_t ucs4)
noexcept
1478 if (ucs4 >= Hangul_SBase && ucs4 < Hangul_SBase + Hangul_SCount)
1479 return QChar::Canonical;
1481 if (index == 0xffff)
1482 return QChar::NoDecomposition;
1483 return (QChar::Decomposition)(uc_decomposition_map[index] & 0xff);
1487
1488
1489
1490
1491
1492
1493
1494
1495
1498
1499
1500
1501
1502
1503
1504unsigned char QChar::combiningClass(
char32_t ucs4)
noexcept
1506 if (ucs4 > LastValidCodePoint)
1508 return (
unsigned char) qGetProp(ucs4)->combiningClass;
1512
1513
1514
1515
1516
1519
1520
1521
1522
1523
1524
1525
1526
1527QChar::Script QChar::script(
char32_t ucs4)
noexcept
1529 if (ucs4 > LastValidCodePoint)
1530 return QChar::Script_Unknown;
1531 return (QChar::Script) qGetProp(ucs4)->script;
1535
1536
1537
1538
1541
1542
1543
1544
1545
1546
1547QChar::UnicodeVersion QChar::unicodeVersion(
char32_t ucs4)
noexcept
1549 if (ucs4 > LastValidCodePoint)
1550 return QChar::Unicode_Unassigned;
1551 return (QChar::UnicodeVersion) qGetProp(ucs4)->unicodeVersion;
1555
1556
1557QChar::UnicodeVersion QChar::currentUnicodeVersion()
noexcept
1569 auto begin()
const {
return chars; }
1570 auto end()
const {
return chars + sz; }
1572 auto data()
const {
return chars; }
1573 auto size()
const {
return sz; }
1575 Q_ASSERT(uc <= QChar::LastValidCodePoint);
1577 auto pp = result.chars;
1579 const auto fold = caseConversion(uc)[which];
1580 const auto caseDiff = fold.diff;
1582 if (Q_UNLIKELY(fold.special)) {
1584 auto length = *specialCase++;
1586 *pp++ = *specialCase++;
1589 for (
char16_t c : QChar::fromUcs4(uc + caseDiff))
1592 result.sz = pp - result.chars;
1596template <
typename T>
1597Q_DECL_CONST_FUNCTION
static inline T convertCase_helper(T uc, QUnicodeTables::Case which)
noexcept
1599 const auto fold = caseConversion(uc)[which];
1601 if (Q_UNLIKELY(fold.special)) {
1602 const ushort *specialCase = specialCaseMap + fold.diff;
1604 return *specialCase == 1 ? specialCase[1] : uc;
1607 return uc + fold.diff;
1611
1612
1613
1614
1615
1618
1619
1620
1621
1622
1623
1624
1625char32_t QChar::toLower(
char32_t ucs4)
noexcept
1627 if (ucs4 > LastValidCodePoint)
1629 return convertCase_helper(ucs4, QUnicodeTables::LowerCase);
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657char32_t QChar::toUpper(
char32_t ucs4)
noexcept
1659 if (ucs4 > LastValidCodePoint)
1661 return convertCase_helper(ucs4, QUnicodeTables::UpperCase);
1665
1666
1667
1668
1669
1672
1673
1674
1675
1676
1677
1678
1679char32_t QChar::toTitleCase(
char32_t ucs4)
noexcept
1681 if (ucs4 > LastValidCodePoint)
1683 return convertCase_helper(ucs4, QUnicodeTables::TitleCase);
1686static inline char32_t foldCase(
const char16_t *cur,
const char16_t *start)
1689 if (QChar::isLowSurrogate(*cur) && cur > start && QChar::isHighSurrogate(cur[-1]))
1690 ucs4 = QChar::surrogateToUcs4(cur[-1], *cur);
1703 return QChar(foldCase(ch.unicode()));
1707
1708
1709
1710
1711
1714
1715
1716
1717
1718
1719
1720char32_t QChar::toCaseFolded(
char32_t ucs4)
noexcept
1722 if (ucs4 > LastValidCodePoint)
1724 return convertCase_helper(ucs4, QUnicodeTables::CaseFold);
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1740
1741
1742
1743
1744
1745
1746
1747
1748
1751
1752
1753
1754
1757
1758
1759
1760
1763
1764
1767
1768
1769
1770
1771
1774
1775
1776
1777
1778
1781
1782
1783
1784
1785
1788
1789
1790
1791
1792
1795
1796
1797
1798
1799
1802
1803
1804
1805
1806
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1829static void decomposeHelper(QString *str,
bool canonical, QChar::UnicodeVersion version, qsizetype from)
1832 QChar::Decomposition tag;
1837 const unsigned short *utf16 =
reinterpret_cast<
unsigned short *>(s.data());
1838 const unsigned short *uc = utf16 + s.size();
1839 while (uc != utf16 + from) {
1840 const char16_t c = *(--uc);
1842 if (QChar::isLowSurrogate(c) && uc != utf16) {
1843 ushort high = *(uc - 1);
1844 if (QChar(high).isHighSurrogate()) {
1846 ucs4 = QChar::surrogateToUcs4(high, c);
1854 if (QChar::unicodeVersion(ucs4) > version)
1857 const QChar *d = decompositionHelper(ucs4, &length, &tag, buffer);
1858 if (!d || (canonical && tag != QChar::Canonical))
1861 qsizetype pos = uc - utf16;
1862 s.replace(pos, QChar::requiresSurrogates(ucs4) ? 2 : 1, d, length);
1864 utf16 =
reinterpret_cast<
unsigned short *>(s.data());
1865 uc = utf16 + pos + length;
1876{
return ligature1
.u1 < ligature2
.u1; }
1878{
return u1 < ligature
.u1; }
1880{
return ligature
.u1 < u1; }
1888{
return QChar::surrogateToUcs4(ligature1.p1.u1, ligature1.p1.u2) < QChar::surrogateToUcs4(ligature2.p1.u1, ligature2.p1.u2); }
1890{
return u1 < QChar::surrogateToUcs4(ligature.p1.u1, ligature.p1.u2); }
1892{
return QChar::surrogateToUcs4(ligature.p1.u1, ligature.p1.u2) < u1; }
1903 return Hangul_SBase + (LIndex * Hangul_VCount + VIndex) * Hangul_TCount;
1907 if (SIndex <
Hangul_SCount && (SIndex % Hangul_TCount) == 0) {
1915 if (index == 0xffff)
1918 ushort length = *ligatures++;
1919 if (QChar::requiresSurrogates(u1)) {
1922 if (r != data + length && QChar::surrogateToUcs4(r->p1.u1, r->p1.u2) == u1)
1923 return QChar::surrogateToUcs4(r->p2.u1, r->p2.u2);
1926 const UCS2Pair *r =
std::lower_bound(data, data + length, ushort(u1));
1927 if (r != data + length && r
->u1 == ushort(u1))
1934static void composeHelper(QString *str, QChar::UnicodeVersion version, qsizetype from)
1938 if (from < 0 || s.size() - from < 2)
1941 char32_t stcode = 0;
1942 qsizetype starter = -1;
1943 qsizetype next = -1;
1944 int lastCombining = 255;
1946 qsizetype pos = from;
1947 while (pos < s.size()) {
1950 const char16_t c = s.at(pos).unicode();
1951 if (QChar::isHighSurrogate(c) && pos < s.size() - 1) {
1952 ushort low = s.at(pos+1).unicode();
1953 if (QChar(low).isLowSurrogate()) {
1954 uc = QChar::surrogateToUcs4(c, low);
1964 if (p->unicodeVersion > version) {
1967 lastCombining = 255;
1972 int combining = p->combiningClass;
1973 if ((i == next || combining > lastCombining) && starter >= from) {
1978 QChar *d = s.data();
1981 for (QChar ch : QChar::fromUcs4(ligature))
1982 d[starter + j++] = ch;
1987 if (combining == 0) {
1992 lastCombining = combining;
2002 const qsizetype l = s.size()-1;
2004 qsizetype pos = from;
2006 qsizetype p2 = pos+1;
2008 if (
const char16_t hi = s.at(pos).unicode(); QChar::isHighSurrogate(hi)) {
2009 const char16_t low = s.at(p2).unicode();
2010 if (QChar::isLowSurrogate(low)) {
2011 u1 = QChar::surrogateToUcs4(hi, low);
2025 if (
const char16_t hi = s.at(p2).unicode(); QChar::isHighSurrogate(hi) && p2 < l) {
2026 const char16_t low = s.at(p2+1).unicode();
2027 if (QChar::isLowSurrogate(low)) {
2028 u2 = QChar::surrogateToUcs4(hi, low);
2040 if (p->unicodeVersion <= version)
2041 c2 = p->combiningClass;
2050 if (p->unicodeVersion <= version)
2051 c1 = p->combiningClass;
2055 QChar *uc = s.data();
2058 for (QChar ch : QChar::fromUcs4(u2))
2060 for (QChar ch : QChar::fromUcs4(u1))
2064 if (pos > 0 && s.at(pos).isLowSurrogate())
2068 if (QChar::requiresSurrogates(u1))
2074 if (QChar::requiresSurrogates(u1))
2088 static_assert(QString::NormalizationForm_D == 0);
2089 static_assert(QString::NormalizationForm_C == 1);
2090 static_assert(QString::NormalizationForm_KD == 2);
2091 static_assert(QString::NormalizationForm_KC == 3);
2093 enum { NFQC_YES = 0, NFQC_NO = 1, NFQC_MAYBE = 3 };
2095 const auto *string =
reinterpret_cast<
const char16_t *>(str->constData());
2096 qsizetype length = str->size();
2099 while (length > from && QChar::isHighSurrogate(string[length - 1]))
2102 uchar lastCombining = 0;
2103 for (qsizetype i = from; i < length; ++i) {
2105 const char16_t uc = string[i];
2114 if (QChar::isHighSurrogate(uc)) {
2115 ushort low = string[i + 1];
2116 if (!QChar::isLowSurrogate(low)) {
2123 ucs4 = QChar::surrogateToUcs4(uc, low);
2130 if (p->combiningClass < lastCombining && p->combiningClass > 0)
2133 const uchar check = (p->nfQuickCheck >> (mode << 1)) & 0x03;
2134 if (check != NFQC_YES)
2137 lastCombining = p->combiningClass;
2138 if (lastCombining == 0)
2142 if (length != str->size())
2143 *lastStable = str->size() - 1;
static constexpr unsigned short specialCaseMap[]
constexpr unsigned int MaxSpecialCaseLength
static constexpr unsigned short uc_ligature_map[]
static Q_DECL_CONST_FUNCTION Q_ALWAYS_INLINE const Properties * qGetProp(char32_t ucs4) noexcept
bool operator<(const UCS2SurrogatePair &ligature, char32_t u1)
static constexpr quint32 Hangul_VCount
static constexpr char32_t Hangul_SBase
static constexpr char32_t Hangul_VBase
bool operator<(ushort u1, const UCS2Pair &ligature)
static constexpr quint32 Hangul_LCount
static char32_t ligatureHelper(char32_t u1, char32_t u2)
bool operator<(const UCS2Pair &ligature, ushort u1)
static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, qsizetype from)
static constexpr char32_t Hangul_LBase
static constexpr char32_t Hangul_TBase
bool operator<(char32_t u1, const UCS2SurrogatePair &ligature)
bool operator<(const UCS2SurrogatePair &ligature1, const UCS2SurrogatePair &ligature2)
bool operator<(const UCS2Pair &ligature1, const UCS2Pair &ligature2)
static auto fullConvertCase(char32_t uc, QUnicodeTables::Case which) noexcept
static constexpr quint32 Hangul_NCount
static void decomposeHelper(QString *str, bool canonical, QChar::UnicodeVersion version, qsizetype from)
static void composeHelper(QString *str, QChar::UnicodeVersion version, qsizetype from)
static char32_t foldCase(const char16_t *cur, const char16_t *start)
static constexpr quint32 Hangul_SCount
static bool normalizationQuickCheckHelper(QString *str, QString::NormalizationForm mode, qsizetype from, qsizetype *lastStable)
static QChar foldCase(QChar ch) noexcept
static constexpr quint32 Hangul_TCount
static char16_t foldCase(char16_t ch) noexcept
uint QT_FASTCALL fetch1Pixel< QPixelLayout::BPP1LSB >(const uchar *src, int index)
#define GET_LIGATURE_INDEX(ucs4)
#define GET_DECOMPOSITION_INDEX(ucs4)
#define UNICODE_DATA_VERSION