-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathctype-uca.cc
11959 lines (11097 loc) · 473 KB
/
ctype-uca.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
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
443
444
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
480
481
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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
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
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2004, 2024, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
Without limiting anything contained in the foregoing, this file,
which is part of C Driver for MySQL (Connector/C), is also subject to the
Universal FOSS Exception, version 1.0, a copy of which can be found at
http://oss.oracle.com/licenses/universal-foss-exception.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/*
UCA (Unicode Collation Algorithm) support.
Features that are not implemented yet:
- No Normalization From D is done
+ No decomposition is done
+ No Thai/Lao orderding is done
- No combining marks processing is done
*/
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <algorithm>
#include <bitset>
#include <iterator>
#include <map>
#include <utility>
#include "m_ctype.h"
#include "m_string.h"
#include "my_byteorder.h"
#include "my_compiler.h"
#include "my_inttypes.h"
#include "my_loglevel.h"
#include "my_macros.h"
#include "mysys_err.h"
#include "strings/mb_wc.h"
#include "strings/str_uca_type.h"
#include "strings/uca900_data.h"
#include "strings/uca900_ja_data.h"
#include "strings/uca900_zh_data.h"
#include "strings/uca_data.h"
#include "template_utils.h"
MY_UCA_INFO my_uca_v400 = {
UCA_V400,
0xFFFF, /* maxchar */
uca_length, uca_weight, false, nullptr, /* contractions */
nullptr,
/* Logical positions */
0x0009, /* first_non_ignorable p != ignore */
0xA48C, /* last_non_ignorable Not a CJK and not UNASSIGNED */
0x0332, /* first_primary_ignorable p == 0 */
0x20EA, /* last_primary_ignorable */
0x0000, /* first_secondary_ignorable p,s == 0 */
0xFE73, /* last_secondary_ignorable p,s == 0 */
0x0000, /* first_tertiary_ignorable p,s,t == 0 */
0xFE73, /* last_tertiary_ignorable p,s,t == 0 */
0x0000, /* first_trailing */
0x0000, /* last_trailing */
0x0009, /* first_variable */
0x2183, /* last_variable */
0, /* extra_ce_pri_base, not used */
0, /* extra_ce_sec_base, not used */
0 /* extra_ce_ter_base, not used */
};
/******************************************************/
MY_UCA_INFO my_uca_v520 = {
UCA_V520,
0x10FFFF, /* maxchar */
uca520_length,
uca520_weight,
false,
nullptr, /* contractions */
nullptr,
0x0009, /* first_non_ignorable p != ignore */
0x1342E, /* last_non_ignorable Not a CJK and not UASSIGNED */
0x0332, /* first_primary_ignorable p == ignore */
0x101FD, /* last_primary_ignorable */
0x0000, /* first_secondary_ignorable p,s= ignore */
0xFE73, /* last_secondary_ignorable */
0x0000, /* first_tertiary_ignorable p,s,t == ignore */
0xFE73, /* last_tertiary_ignorable */
0x0000, /* first_trailing */
0x0000, /* last_trailing */
0x0009, /* first_variable if alt=non-ignorable: p != ignore */
0x1D371, /* last_variable if alt=shifter: p,s,t == ignore */
0, /* extra_ce_pri_base, not used */
0, /* extra_ce_sec_base, not used */
0 /* extra_ce_ter_base, not used */
};
/******************************************************/
/*
German Phonebook
*/
static const char german2[] =
"&AE << \\u00E6 <<< \\u00C6 << \\u00E4 <<< \\u00C4 "
"&OE << \\u0153 <<< \\u0152 << \\u00F6 <<< \\u00D6 "
"&UE << \\u00FC <<< \\u00DC ";
/*
Some sources treat LETTER A WITH DIAERESIS (00E4,00C4)
secondary greater than LETTER AE (00E6,00C6).
http://www.evertype.com/alphabets/icelandic.pdf
http://developer.mimer.com/collations/charts/icelandic.htm
Other sources do not provide any special rules
for LETTER A WITH DIAERESIS:
http://www.omniglot.com/writing/icelandic.htm
http://en.wikipedia.org/wiki/Icelandic_alphabet
http://oss.software.ibm.com/icu/charts/collation/is.html
Let's go the first way.
*/
static const char icelandic[] =
"& A < \\u00E1 <<< \\u00C1 "
"& D < \\u00F0 <<< \\u00D0 "
"& E < \\u00E9 <<< \\u00C9 "
"& I < \\u00ED <<< \\u00CD "
"& O < \\u00F3 <<< \\u00D3 "
"& U < \\u00FA <<< \\u00DA "
"& Y < \\u00FD <<< \\u00DD "
"& Z < \\u00FE <<< \\u00DE "
"< \\u00E6 <<< \\u00C6 << \\u00E4 <<< \\u00C4 "
"< \\u00F6 <<< \\u00D6 << \\u00F8 <<< \\u00D8 "
"< \\u00E5 <<< \\u00C5 ";
/*
Some sources treat I and Y primary different.
Other sources treat I and Y the same on primary level.
We'll go the first way.
*/
static const char latvian[] =
"& C < \\u010D <<< \\u010C "
"& G < \\u0123 <<< \\u0122 "
"& I < \\u0079 <<< \\u0059 "
"& K < \\u0137 <<< \\u0136 "
"& L < \\u013C <<< \\u013B "
"& N < \\u0146 <<< \\u0145 "
"& R < \\u0157 <<< \\u0156 "
"& S < \\u0161 <<< \\u0160 "
"& Z < \\u017E <<< \\u017D ";
static const char romanian[] =
"& A < \\u0103 <<< \\u0102 < \\u00E2 <<< \\u00C2 "
"& I < \\u00EE <<< \\u00CE "
"& S < \\u0219 <<< \\u0218 << \\u015F <<< \\u015E "
"& T < \\u021B <<< \\u021A << \\u0163 <<< \\u0162 ";
static const char slovenian[] =
"& C < \\u010D <<< \\u010C "
"& S < \\u0161 <<< \\u0160 "
"& Z < \\u017E <<< \\u017D ";
static const char polish[] =
"& A < \\u0105 <<< \\u0104 "
"& C < \\u0107 <<< \\u0106 "
"& E < \\u0119 <<< \\u0118 "
"& L < \\u0142 <<< \\u0141 "
"& N < \\u0144 <<< \\u0143 "
"& O < \\u00F3 <<< \\u00D3 "
"& S < \\u015B <<< \\u015A "
"& Z < \\u017A <<< \\u0179 < \\u017C <<< \\u017B";
static const char estonian[] =
"& S < \\u0161 <<< \\u0160 "
" < \\u007A <<< \\u005A "
" < \\u017E <<< \\u017D "
"& W < \\u00F5 <<< \\u00D5 "
"< \\u00E4 <<< \\u00C4 "
"< \\u00F6 <<< \\u00D6 "
"< \\u00FC <<< \\u00DC ";
// Standard Spanish, also for Galician.
static const char spanish[] = "& N < \\u00F1 <<< \\u00D1 ";
/*
Some sources treat V and W as similar on primary level.
We'll treat V and W as different on primary level.
*/
static const char swedish[] =
"& Y <<\\u00FC <<< \\u00DC "
"& Z < \\u00E5 <<< \\u00C5 "
"< \\u00E4 <<< \\u00C4 << \\u00E6 <<< \\u00C6 "
"< \\u00F6 <<< \\u00D6 << \\u00F8 <<< \\u00D8 ";
static const char turkish[] =
"& C < \\u00E7 <<< \\u00C7 "
"& G < \\u011F <<< \\u011E "
"& H < \\u0131 <<< \\u0049 "
"& O < \\u00F6 <<< \\u00D6 "
"& S < \\u015F <<< \\u015E "
"& U < \\u00FC <<< \\u00DC ";
static const char czech[] =
"& C < \\u010D <<< \\u010C "
"& H < ch <<< Ch <<< CH"
"& R < \\u0159 <<< \\u0158"
"& S < \\u0161 <<< \\u0160"
"& Z < \\u017E <<< \\u017D";
static const char danish[] = /* Also good for Norwegian */
"& Y << \\u00FC <<< \\u00DC << \\u0171 <<< \\u0170"
"& Z < \\u00E6 <<< \\u00C6 << \\u00E4 <<< \\u00C4"
" < \\u00F8 <<< \\u00D8 << \\u00F6 <<< \\u00D6 << \\u0151 <<< \\u0150"
" < \\u00E5 <<< \\u00C5 << aa <<< Aa <<< AA";
static const char lithuanian[] =
"& C << ch <<< Ch <<< CH< \\u010D <<< \\u010C"
"& E << \\u0119 <<< \\u0118 << \\u0117 <<< \\u0116"
"& I << y <<< Y"
"& S < \\u0161 <<< \\u0160"
"& Z < \\u017E <<< \\u017D";
static const char slovak[] =
"& A < \\u00E4 <<< \\u00C4"
"& C < \\u010D <<< \\u010C"
"& H < ch <<< Ch <<< CH"
"& O < \\u00F4 <<< \\u00D4"
"& S < \\u0161 <<< \\u0160"
"& Z < \\u017E <<< \\u017D";
static const char spanish2[] = /* Also good for Asturian and Galician */
"&C < ch <<< Ch <<< CH"
"&L < ll <<< Ll <<< LL"
"&N < \\u00F1 <<< \\u00D1";
static const char roman[] = /* i.e. Classical Latin */
"& I << j <<< J "
"& V << u <<< U ";
/*
Persian collation support was provided by
Jody McIntyre <mysql@modernduck.com>
To: internals@lists.mysql.com
Subject: Persian UTF8 collation support
Date: 17.08.2004
Contraction is not implemented. Some implementations do perform
contraction but others do not, and it is able to sort all my test
strings correctly.
Jody.
*/
static const char persian[] =
"& \\u066D < \\u064E < \\uFE76 < \\uFE77 < \\u0650 < \\uFE7A < \\uFE7B"
" < \\u064F < \\uFE78 < \\uFE79 < \\u064B < \\uFE70 < \\uFE71"
" < \\u064D < \\uFE74 < \\u064C < \\uFE72"
"& \\uFE7F < \\u0653 < \\u0654 < \\u0655 < \\u0670"
"& \\u0669 < \\u0622 < \\u0627 < \\u0671 < \\u0621 < \\u0623 < \\u0625"
" < \\u0624 < \\u0626"
"& \\u0642 < \\u06A9 < \\u0643"
"& \\u0648 < \\u0647 < \\u0629 < \\u06C0 < \\u06CC < \\u0649 < \\u064A"
"& \\uFE80 < \\uFE81 < \\uFE82 < \\uFE8D < \\uFE8E < \\uFB50 < \\uFB51"
" < \\uFE80 "
/*
FE80 appears both in reset and shift.
We need to break the rule here and reset to *new* FE80 again,
so weight for FE83 is calculated as P[FE80]+1, not as P[FE80]+8.
*/
" & \\uFE80 < \\uFE83 < \\uFE84 < \\uFE87 < \\uFE88 < \\uFE85"
" < \\uFE86 < \\u0689 < \\u068A"
"& \\uFEAE < \\uFDFC"
"& \\uFED8 < \\uFB8E < \\uFB8F < \\uFB90 < \\uFB91 < \\uFED9 < \\uFEDA"
" < \\uFEDB < \\uFEDC"
"& \\uFEEE < \\uFEE9 < \\uFEEA < \\uFEEB < \\uFEEC < \\uFE93 < \\uFE94"
" < \\uFBA4 < \\uFBA5 < \\uFBFC < \\uFBFD < \\uFBFE < \\uFBFF"
" < \\uFEEF < \\uFEF0 < \\uFEF1 < \\uFEF2 < \\uFEF3 < \\uFEF4"
" < \\uFEF5 < \\uFEF6 < \\uFEF7 < \\uFEF8 < \\uFEF9 < \\uFEFA"
" < \\uFEFB < \\uFEFC";
/*
Esperanto tailoring.
Contributed by Bertilo Wennergren <bertilow at gmail dot com>
September 1, 2005
*/
static const char esperanto[] =
"& C < \\u0109 <<< \\u0108"
"& G < \\u011D <<< \\u011C"
"& H < \\u0125 <<< \\u0124"
"& J < \\u0135 <<< \\u0134"
"& S < \\u015d <<< \\u015c"
"& U < \\u016d <<< \\u016c";
/*
A simplified version of Hungarian, without consonant contractions.
*/
static const char hungarian[] =
"&O < \\u00F6 <<< \\u00D6 << \\u0151 <<< \\u0150"
"&U < \\u00FC <<< \\u00DC << \\u0171 <<< \\u0170";
static const char croatian[] =
"&C < \\u010D <<< \\u010C < \\u0107 <<< \\u0106"
"&D < d\\u017E = \\u01C6 <<< d\\u017D <<< D\\u017E = \\u01C5 <<< D\\u017D "
"= \\u01C4"
" < \\u0111 <<< \\u0110"
"&L < lj = \\u01C9 <<< lJ <<< Lj = \\u01C8 <<< LJ = \\u01C7"
"&N < nj = \\u01CC <<< nJ <<< Nj = \\u01CB <<< NJ = \\u01CA"
"&S < \\u0161 <<< \\u0160"
"&Z < \\u017E <<< \\u017D";
/*
SCCII Part 1 : Collation Sequence (SLS1134)
2006/11/24
Harshula Jayasuriya <harshula at gmail dot com>
Language Technology Research Lab, University of Colombo / ICTA
*/
#if 0
static const char sinhala[]=
"& \\u0D96 < \\u0D82 < \\u0D83"
"& \\u0DA5 < \\u0DA4"
"& \\u0DD8 < \\u0DF2 < \\u0DDF < \\u0DF3"
"& \\u0DDE < \\u0DCA";
#else
static const char sinhala[] =
"& \\u0D96 < \\u0D82 < \\u0D83 < \\u0D9A < \\u0D9B < \\u0D9C < \\u0D9D"
"< \\u0D9E < \\u0D9F < \\u0DA0 < \\u0DA1 < \\u0DA2 < \\u0DA3"
"< \\u0DA5 < \\u0DA4 < \\u0DA6"
"< \\u0DA7 < \\u0DA8 < \\u0DA9 < \\u0DAA < \\u0DAB < \\u0DAC"
"< \\u0DAD < \\u0DAE < \\u0DAF < \\u0DB0 < \\u0DB1"
"< \\u0DB3 < \\u0DB4 < \\u0DB5 < \\u0DB6 < \\u0DB7 < \\u0DB8"
"< \\u0DB9 < \\u0DBA < \\u0DBB < \\u0DBD < \\u0DC0 < \\u0DC1"
"< \\u0DC2 < \\u0DC3 < \\u0DC4 < \\u0DC5 < \\u0DC6"
"< \\u0DCF"
"< \\u0DD0 < \\u0DD1 < \\u0DD2 < \\u0DD3 < \\u0DD4 < \\u0DD6"
"< \\u0DD8 < \\u0DF2 < \\u0DDF < \\u0DF3 < \\u0DD9 < \\u0DDA"
"< \\u0DDB < \\u0DDC < \\u0DDD < \\u0DDE < \\u0DCA";
#endif
static const char vietnamese[] =
" &A << \\u00E0 <<< \\u00C0" /* A */
" << \\u1EA3 <<< \\u1EA2"
" << \\u00E3 <<< \\u00C3"
" << \\u00E1 <<< \\u00C1"
" << \\u1EA1 <<< \\u1EA0"
" < \\u0103 <<< \\u0102" /* A WITH BREVE */
" << \\u1EB1 <<< \\u1EB0"
" << \\u1EB3 <<< \\u1EB2"
" << \\u1EB5 <<< \\u1EB4"
" << \\u1EAF <<< \\u1EAE"
" << \\u1EB7 <<< \\u1EB6"
" < \\u00E2 <<< \\u00C2" /* A WITH CIRCUMFLEX */
" << \\u1EA7 <<< \\u1EA6"
" << \\u1EA9 <<< \\u1EA8"
" << \\u1EAB <<< \\u1EAA"
" << \\u1EA5 <<< \\u1EA4"
" << \\u1EAD <<< \\u1EAC"
" &D < \\u0111 <<< \\u0110" /* D WITH STROKE */
" &E << \\u00E8 <<< \\u00C8" /* E */
" << \\u1EBB <<< \\u1EBA"
" << \\u1EBD <<< \\u1EBC"
" << \\u00E9 <<< \\u00C9"
" << \\u1EB9 <<< \\u1EB8"
" < \\u00EA <<< \\u00CA" /* E WITH CIRCUMFLEX */
" << \\u1EC1 <<< \\u1EC0"
" << \\u1EC3 <<< \\u1EC2"
" << \\u1EC5 <<< \\u1EC4"
" << \\u1EBF <<< \\u1EBE"
" << \\u1EC7 <<< \\u1EC6"
" &I << \\u00EC <<< \\u00CC" /* I */
" << \\u1EC9 <<< \\u1EC8"
" << \\u0129 <<< \\u0128"
" << \\u00ED <<< \\u00CD"
" << \\u1ECB <<< \\u1ECA"
" &O << \\u00F2 <<< \\u00D2" /* O */
" << \\u1ECF <<< \\u1ECE"
" << \\u00F5 <<< \\u00D5"
" << \\u00F3 <<< \\u00D3"
" << \\u1ECD <<< \\u1ECC"
" < \\u00F4 <<< \\u00D4" /* O WITH CIRCUMFLEX */
" << \\u1ED3 <<< \\u1ED2"
" << \\u1ED5 <<< \\u1ED4"
" << \\u1ED7 <<< \\u1ED6"
" << \\u1ED1 <<< \\u1ED0"
" << \\u1ED9 <<< \\u1ED8"
" < \\u01A1 <<< \\u01A0" /* O WITH HORN */
" << \\u1EDD <<< \\u1EDC"
" << \\u1EDF <<< \\u1EDE"
" << \\u1EE1 <<< \\u1EE0"
" << \\u1EDB <<< \\u1EDA"
" << \\u1EE3 <<< \\u1EE2"
" &U << \\u00F9 <<< \\u00D9" /* U */
" << \\u1EE7 <<< \\u1EE6"
" << \\u0169 <<< \\u0168"
" << \\u00FA <<< \\u00DA"
" << \\u1EE5 <<< \\u1EE4"
" < \\u01B0 <<< \\u01AF" /* U WITH HORN */
" << \\u1EEB <<< \\u1EEA"
" << \\u1EED <<< \\u1EEC"
" << \\u1EEF <<< \\u1EEE"
" << \\u1EE9 <<< \\u1EE8"
" << \\u1EF1 <<< \\u1EF0"
" &Y << \\u1EF3 <<< \\u1EF2" /* Y */
" << \\u1EF7 <<< \\u1EF6"
" << \\u1EF9 <<< \\u1EF8"
" << \\u00FD <<< \\u00DD"
" << \\u1EF5 <<< \\u1EF4";
/* German Phonebook */
static const char de_pb_cldr_30[] =
"&AE << \\u00E4 <<< \\u00C4 "
"&OE << \\u00F6 <<< \\u00D6 "
"&UE << \\u00FC <<< \\u00DC ";
/* Icelandic */
static const char is_cldr_30[] =
"&[before 1]b < \\u00E1 <<< \\u00C1 "
"& d << \\u0111 <<< \\u0110 < \\u00F0 <<< \\u00D0 "
"&[before 1]f < \\u00E9 <<< \\u00C9 "
"&[before 1]j < \\u00ED <<< \\u00CD "
"&[before 1]p < \\u00F3 <<< \\u00D3 "
"&[before 1]v < \\u00FA <<< \\u00DA "
"&[before 1]z < \\u00FD <<< \\u00DD "
"&[before 1]\\u01C0 < \\u00E6 <<< \\u00C6 << \\u00E4 <<< \\u00C4 "
"< \\u00F6 <<< \\u00D6 << \\u00F8 <<< \\u00D8 "
"< \\u00E5 <<< \\u00C5";
/* Latvian */
static const char lv_cldr_30[] =
"&[before 1]D < \\u010D <<< \\u010C "
"&[before 1]H < \\u0123 <<< \\u0122 "
"& I << y <<< Y "
"&[before 1]L < \\u0137 <<< \\u0136 "
"&[before 1]M < \\u013C <<< \\u013B "
"&[before 1]O < \\u0146 <<< \\u0145 "
"&[before 1]S < \\u0157 <<< \\u0156 "
"&[before 1]T < \\u0161 <<< \\u0160 "
"&[before 1]\\u01B7 < \\u017E <<< \\u017D";
/* Romanian */
static const char ro_cldr_30[] =
"&A < \\u0103 <<< \\u0102 < \\u00E2 <<< \\u00C2 "
"&I < \\u00EE <<< \\u00CE "
"&S < \\u015F = \\u0219 <<< \\u015E = \\u0218 "
"&T < \\u0163 = \\u021B <<< \\u0162 = \\u021A";
/* Slovenian */
static const char sl_cldr_30[] =
"&C < \\u010D <<< \\u010C < \\u0107 <<< \\u0106 "
"&D < \\u0111 <<< \\u0110 "
"&S < \\u0161 <<< \\u0160 "
"&Z < \\u017E <<< \\u017D";
/* Polish */
static const char pl_cldr_30[] =
"&A < \\u0105 <<< \\u0104 "
"&C < \\u0107 <<< \\u0106 "
"&E < \\u0119 <<< \\u0118 "
"&L < \\u0142 <<< \\u0141 "
"&N < \\u0144 <<< \\u0143 "
"&O < \\u00F3 <<< \\u00D3 "
"&S < \\u015B <<< \\u015A "
"&Z < \\u017A <<< \\u0179 < \\u017C <<< \\u017B";
/* Estonian */
static const char et_cldr_30[] =
"&[before 1]T < \\u0161 <<< \\u0160 < z <<< Z "
"< \\u017E <<< \\u017D "
"&[before 1]X < \\u00F5 <<< \\u00D5 < \\u00E4 <<< \\u00C4 "
"< \\u00F6 <<< \\u00D6 < \\u00FC <<< \\u00DC";
/* Swedish */
static const char sv_cldr_30[] =
"& D << \\u0111 <<< \\u0110 << \\u00F0 <<< \\u00D0 "
"& t <<< \\u00FE/h "
"& T <<< \\u00DE/H "
"& Y << \\u00FC <<< \\u00DC << \\u0171 <<< \\u0170 "
"&[before 1]\\u01C0 < \\u00E5 <<< \\u00C5 < \\u00E4 <<< \\u00C4 "
"<< \\u00E6 <<< \\u00C6 << \\u0119 <<< \\u0118 "
"< \\u00F6 <<< \\u00D6 << \\u00F8 <<< \\u00D8 "
"<< \\u0151 <<< \\u0150 << \\u0153 <<< \\u0152 "
"<< \\u00F4 <<< \\u00D4";
/* Turkish */
static const char tr_cldr_30[] =
"& C < \\u00E7 <<< \\u00C7 "
"& G < \\u011F <<< \\u011E "
"&[before 1]i < \\u0131 <<< I "
"& i <<< \\u0130 "
"& O < \\u00F6 <<< \\u00D6 "
"& S < \\u015F <<< \\u015E "
"& U < \\u00FC <<< \\u00DC ";
/* Czech */
static const char cs_cldr_30[] =
"&C < \\u010D <<< \\u010C "
"&H < ch <<< cH <<< Ch <<< CH "
"&R < \\u0159 <<< \\u0158"
"&S < \\u0161 <<< \\u0160"
"&Z < \\u017E <<< \\u017D";
/* Danish, same for Norwegian */
static const char da_cldr_30[] =
"& D << \\u0111 <<< \\u0110 << \\u00F0 <<< \\u00D0 "
"& t <<< \\u00FE/h "
"& T <<< \\u00DE/H "
"& Y << \\u00FC <<< \\u00DC << \\u0171 <<< \\u0170 "
"&[before 1]\\u01C0 < \\u00E6 <<< \\u00C6 << \\u00E4 <<< \\u00C4 "
"< \\u00F8 <<< \\u00D8 << \\u00F6 <<< \\u00D6 "
"<< \\u0151 <<< \\u0150 << \\u0153 <<< \\u0152 "
"< \\u00E5 <<< \\u00C5 <<< aa <<< Aa "
"<<< AA";
static Coll_param da_coll_param = {nullptr, false, CASE_FIRST_UPPER};
/* CASE FIRST OFF for Norwegian */
static Coll_param no_coll_param = {nullptr, false, CASE_FIRST_OFF};
/* Lithuanian */
static const char lt_cldr_30[] =
"&\\u0300 = \\u0307\\u0300 "
"&\\u0301 = \\u0307\\u0301 "
"&\\u0303 = \\u0307\\u0303 "
"&A << \\u0105 <<< \\u0104 "
"&C < \\u010D <<< \\u010C "
"&E << \\u0119 <<< \\u0118 << \\u0117 <<< \\u0116"
"&I << \\u012F <<< \\u012E << y <<< Y "
"&S < \\u0161 <<< \\u0160 "
"&U << \\u0173 <<< \\u0172 << \\u016B <<< \\u016A "
"&Z < \\u017E <<< \\u017D";
/* Slovak */
static const char sk_cldr_30[] =
"&A < \\u00E4 <<< \\u00C4 "
"&C < \\u010D <<< \\u010C "
"&H < ch <<< cH <<< Ch <<< CH "
"&O < \\u00F4 <<< \\u00D4 "
"&R < \\u0159 <<< \\u0158 "
"&S < \\u0161 <<< \\u0160 "
"&Z < \\u017E <<< \\u017D";
/* Spanish (Traditional) */
static const char es_trad_cldr_30[] =
"&N < \\u00F1 <<< \\u00D1 "
"&C < ch <<< Ch <<< CH "
"&l < ll <<< Ll <<< LL";
/* Persian */
#if 0
static const char fa_cldr_30[]=
"& \\u064E << \\u0650 << \\u064F << \\u064B << \\u064D "
"<< \\u064C "
"&[before 1]\\u0627 < \\u0622 "
"& \\u0627 << \\u0671 < \\u0621 << \\u0623 << \\u0672 "
"<< \\u0625 << \\u0673 << \\u0624 << \\u06CC\\u0654 "
"<<< \\u0649\\u0654 <<< \\u0626 "
"& \\u06A9 << \\u06AA << \\u06AB << \\u0643 << \\u06AC "
"<< \\u06AD << \\u06AE "
"& \\u06CF < \\u0647 << \\u06D5 << \\u06C1 << \\u0629 "
"<< \\u06C3 << \\u06C0 << \\u06BE "
"& \\u06CC << \\u0649 << \\u06D2 << \\u064A << \\u06D0 "
"<< \\u06D1 << \\u06CD << \\u06CE";
static Reorder_param fa_reorder_param= {
{CHARGRP_ARAB, CHARGRP_NONE}, {{{0, 0}, {0, 0}}}, 0
};
static Coll_param fa_coll_param= {
&fa_reorder_param, true
};
#endif
/* Hungarian */
static const char hu_cldr_30[] =
"&C < cs <<< Cs <<< CS "
"&D < dz <<< Dz <<< DZ "
"&DZ < dzs <<< Dzs <<< DZS "
"&G < gy <<< Gy <<< GY "
"&L < ly <<< Ly <<< LY "
"&N < ny <<< Ny <<< NY "
"&S < sz <<< Sz <<< SZ "
"&T < ty <<< Ty <<< TY "
"&Z < zs <<< Zs <<< ZS "
"&O < \\u00F6 <<< \\u00D6 << \\u0151 <<< \\u0150 "
"&U < \\u00FC <<< \\u00DC << \\u0171 <<< \\u0170 "
"&cs <<< ccs/cs "
"&Cs <<< Ccs/cs "
"&CS <<< CCS/CS "
"&dz <<< ddz/dz "
"&Dz <<< Ddz/dz "
"&DZ <<< DDZ/DZ "
"&dzs<<< ddzs/dzs "
"&Dzs<<< Ddzs/dzs "
"&DZS<<< DDZS/DZS "
"&gy <<< ggy/gy "
"&Gy <<< Ggy/gy "
"&GY <<< GGY/GY "
"&ly <<< lly/ly "
"&Ly <<< Lly/ly "
"&LY <<< LLY/LY "
"&ny <<< nny/ny "
"&Ny <<< Nny/ny "
"&NY <<< NNY/NY "
"&sz <<< ssz/sz "
"&Sz <<< Ssz/sz "
"&SZ <<< SSZ/SZ "
"&ty <<< tty/ty "
"&Ty <<< Tty/ty "
"&TY <<< TTY/TY "
"&zs <<< zzs/zs "
"&Zs <<< Zzs/zs "
"&ZS <<< ZZS/ZS";
/* Croatian, same for Serbian with Latin and Bosnian. */
static const char hr_cldr_30[] =
"&C < \\u010D <<< \\u010C < \\u0107 <<< \\u0106 "
"&D < d\\u017E <<< \\u01C6 <<< D\\u017E <<< \\u01C5 <<< D\\u017D "
"<<< \\u01C4 < \\u0111 <<< \\u0110 "
"&L < lj <<< \\u01C9 <<< Lj <<< \\u01C8 <<< LJ "
"<<< \\u01C7 "
"&N < nj <<< \\u01CC <<< Nj <<< \\u01CB <<< NJ "
"<<< \\u01CA "
"&S < \\u0161 <<< \\u0160 "
"&Z < \\u017E <<< \\u017D ";
static Reorder_param hr_reorder_param = {
{CHARGRP_LATIN, CHARGRP_CYRILLIC, CHARGRP_NONE}, {{{0, 0}, {0, 0}}}, 0, 0};
static Coll_param hr_coll_param = {&hr_reorder_param, false, CASE_FIRST_OFF};
/* Sinhala */
#if 0
static const char si_cldr_30[]=
"&\\u0D96 < \\u0D82 < \\u0D83 "
"&\\u0DA5 < \\u0DA4";
#endif
/* Vietnamese */
static const char vi_cldr_30[] =
"&\\u0300 << \\u0309 << \\u0303 << \\u0301 << \\u0323 "
"&a < \\u0103 <<< \\u0102 < \\u00E2 <<< \\u00C2 "
"&d < \\u0111 <<< \\u0110 "
"&e < \\u00EA <<< \\u00CA "
"&o < \\u00F4 <<< \\u00D4 < \\u01A1 <<< \\u01A0 "
"&u < \\u01B0 <<< \\u01AF";
static Coll_param vi_coll_param = {nullptr, true, CASE_FIRST_OFF};
static Reorder_param ja_reorder_param = {
/*
Per CLDR 30, Japanese reorder rule is defined as [Latn Kana Hani],
but for Hani characters, their weight is implicit according to UCA,
which is different from other character groups. We don't add "Hani"
below and will have special handling for them in
adjust_japanese_weight() and apply_reorder_param(). Implicit weight
has two collation elements. To make strnxfrm() run faster, we give
Japanese Han characters tailored weight which has only one collation
element. These characters' weight is defined in ja_han_pages.
*/
{CHARGRP_LATIN, CHARGRP_KANA, CHARGRP_NONE},
{{{0, 0}, {0, 0}}},
0,
0};
static Coll_param ja_coll_param = {&ja_reorder_param, false /*norm_enabled*/,
CASE_FIRST_OFF};
/*
The Chinese reorder rule is defined as [Hani]. This means all Han characters'
weight should be greater than the core group and smaller than any other
character groups.
The Han characters are separated into two parts. The CLDR collation
definition file, zh.xml, defines 41336 Han characters' order, and all other
Han characters have implicit weight.
Since the core group characters occupy the weight value from 0x0209 to 0x1C46
in DUCET, so we decide to set the weight of all Han characters defined in
zh.xml to be the value from 0x1C47 to 0xBDBE. The smallest weight value of
these Han characters, 0x1C47, being the largest weight value of the core
group plus one (0x1C46 + 1), ensures these Han characters sort greater than
the core group characters.
Also, we set the implicit weight to the Han characters like
[BDBF - BDC3, 0020, 0002][XXXX, 0000, 0000].
To tailor the weight of characters of Latin, Cyrillic and so on to be bigger
than all Han characters, we give these characters weights from 0xBDC4 to
0xF620. There are many character groups between the core group and the Han
group, so it would be a long list if we put them in the following reorder_grp
structure. But since it is a very simple weight shift, we put their calculated
weight here and do not calculate it in my_prepare_reorder().
NOTE: We use the zh.xml file from CLDR v33.1 to implement this Chinese
collation, because we found that the file of CLDR v30 is missing some very
common Han characters (the Han character 'small', etc).
*/
static Reorder_param zh_reorder_param = {
{CHARGRP_NONE}, {{{0x1C47, 0x54A3}, {0xBDC4, 0xF620}}}, 1, 0x54A3};
static Coll_param zh_coll_param = {&zh_reorder_param, false, CASE_FIRST_OFF};
/* Russian, same for Bulgerian and Mongolian with Cyrillic letters */
static Reorder_param ru_reorder_param = {
{CHARGRP_CYRILLIC, CHARGRP_NONE}, {{{0, 0}, {0, 0}}}, 0, 0};
static Coll_param ru_coll_param = {&ru_reorder_param, false /*norm_enabled*/,
CASE_FIRST_OFF};
static constexpr uint16 nochar[] = {0, 0};
/**
Unicode Collation Algorithm:
Collation element (weight) scanner,
for consequent scan of collations
weights from a string.
Only meant as a base class; instantiate uca_scanner_any or uca_scanner_900
instead of this.
*/
class my_uca_scanner {
protected:
my_uca_scanner(const CHARSET_INFO *cs_arg, const uchar *str, size_t length)
: wbeg(nochar),
sbeg(str),
send(str + length),
uca(cs_arg->uca),
cs(cs_arg),
sbeg_dup(str) {}
public:
/**
Get the level the scanner is currently working on. The string
can be scanned multiple times (if the collation requires multi-level
comparisons, e.g. for accent or case sensitivity); first to get
primary weights, then from the start again for secondary, etc.
*/
uint get_weight_level() const { return weight_lv; }
protected:
uint weight_lv{0}; /* 0 = Primary, 1 = Secondary, 2 = Tertiary */
const uint16 *wbeg; /* Beginning of the current weight string */
uint wbeg_stride{0}; /* Number of bytes between weights in string */
const uchar *sbeg; /* Beginning of the input string */
const uchar *send; /* End of the input string */
const MY_UCA_INFO *uca;
uint16 implicit[10];
my_wc_t prev_char{0}; // Previous code point we scanned, if any.
const CHARSET_INFO *cs;
uint num_of_ce_left{0};
const uchar *sbeg_dup; /* Backup of beginning of input string */
protected:
const uint16 *contraction_find(my_wc_t wc0, size_t *chars_skipped);
inline const uint16 *previous_context_find(my_wc_t wc0, my_wc_t wc1);
};
/*
Charset dependent scanner part, to optimize
some character sets.
*/
template <class Mb_wc>
struct uca_scanner_any : public my_uca_scanner {
uca_scanner_any(const Mb_wc mb_wc, const CHARSET_INFO *cs_arg,
const uchar *str, size_t length)
: my_uca_scanner(cs_arg, str, length), mb_wc(mb_wc) {
// UCA 9.0.0 uses a different table format from what this scanner expects.
assert(cs_arg->uca == nullptr || cs_arg->uca->version != UCA_V900);
}
uint get_char_index() const { return char_index; }
inline int next();
private:
/**
How many code points (possibly multibyte) we have scanned so far.
This includes code points with zero weight. Note that this is reset
once we get to the end of the string and restart the scanning for
the next weight level, but it is _not_ reset when we reach the
end of the last level.
*/
uint char_index{0};
const Mb_wc mb_wc;
inline int next_implicit(my_wc_t ch);
};
template <class Mb_wc, int LEVELS_FOR_COMPARE>
class uca_scanner_900 : public my_uca_scanner {
public:
uca_scanner_900(const Mb_wc mb_wc, const CHARSET_INFO *cs_arg,
const uchar *str, size_t length)
: my_uca_scanner(cs_arg, str, length), mb_wc(mb_wc) {}
inline int next();
/**
For each weight in sequence, call "func", which should have
a function signature of "bool func(int weight, bool is_level_separator)".
Stops the iteration early if "func" returns false.
This is morally equivalent to
int weight;
while ((weight= next()) >= 0)
{
if (!func(weight, weight == 0)) break;
}
except that it might employ optimizations internally to speed up
the process. These optimizations will not modify the number of calls
to func() (or their order), but might affect the internal scanner
state during the calls, so func() should not try to read from
the scanner except by calling public member functions.
As a special optimization, if "bool preaccept_data(int num_weights)"
returns true, the next "num_weights" calls to func() _must_ return
true. This is so that bounds checking costs can be amortized
over fewer calls.
*/
template <class T, class U>
inline void for_each_weight(T func, U preaccept_data);
private:
const Mb_wc mb_wc;
inline int next_raw();
inline int more_weight();
uint16 apply_case_first(uint16 weight);
uint16 apply_reorder_param(uint16 weight);
inline int next_implicit(my_wc_t ch);
void my_put_jamo_weights(my_wc_t *hangul_jamo, int jamo_cnt);
/*
apply_reorder_param() needs to return two weights for each origin
weight. This boolean signals whether we have already returned the
FB86 weight, and are ready to return the origin weight.
*/
bool return_origin_weight{true};
/*
For Japanese kana-sensitive collation, we only add quaternary
weight for katakana and hiragana, but not for others like latin
and kanji, because characters like latin and kanji can be already
distinguished from kana by three levels of weight.
has_quaternary_weight is to indicate whether quaternary weight is
needed for characters in string.
*/
bool has_quaternary_weight{false};
int handle_ja_contraction_quat_wt();
int handle_ja_common_quat_wt(my_wc_t wc);
};
/********** Helper functions to handle contraction ************/
/**
Mark a code point as a contraction part
@param flags Pointer to UCA contraction flag data
@param wc Unicode code point
@param flag flag: "is contraction head", "is contraction tail"
*/
static inline void my_uca_add_contraction_flag(char *flags, my_wc_t wc,
int flag) {
flags[wc & MY_UCA_CNT_FLAG_MASK] |= flag;
}
/**
Check if UCA level data has contractions.
@param uca Pointer to UCA data
@return Flags indicating if UCA with contractions
@retval 0 - no contractions
@retval 1 - there are some contractions
*/
static inline bool my_uca_have_contractions(const MY_UCA_INFO *uca) {
return uca->have_contractions;
}
struct trie_node_cmp {
bool operator()(const MY_CONTRACTION &a, const my_wc_t b) { return a.ch < b; }
bool operator()(const MY_CONTRACTION &a, const MY_CONTRACTION &b) {
return a.ch < b.ch;
}
};
static std::vector<MY_CONTRACTION>::const_iterator
find_contraction_part_in_trie(const std::vector<MY_CONTRACTION> &cont_nodes,
my_wc_t ch) {
if (cont_nodes.empty()) return cont_nodes.end();
return std::lower_bound(cont_nodes.begin(), cont_nodes.end(), ch,
trie_node_cmp());
}
static std::vector<MY_CONTRACTION>::iterator find_contraction_part_in_trie(
std::vector<MY_CONTRACTION> &cont_nodes, my_wc_t ch) {
if (cont_nodes.empty()) return cont_nodes.end();
return std::lower_bound(cont_nodes.begin(), cont_nodes.end(), ch,
trie_node_cmp());
}
/**
Find a contraction consisting of two code points and return its weight array
@param cont_nodes Vector that contains contraction nodes
@param wc1 First code point
@param wc2 Second code point
@return Weight array
@retval NULL - no contraction found
@retval ptr - contraction weight array
*/
const uint16 *my_uca_contraction2_weight(
const std::vector<MY_CONTRACTION> *cont_nodes, my_wc_t wc1, my_wc_t wc2) {
if (!cont_nodes) return nullptr;
if (!cont_nodes->empty()) {
std::vector<MY_CONTRACTION>::const_iterator node_it1 =
find_contraction_part_in_trie(*cont_nodes, wc1);
if (node_it1 == cont_nodes->end() || node_it1->ch != wc1) return nullptr;
std::vector<MY_CONTRACTION>::const_iterator node_it2 =
find_contraction_part_in_trie(node_it1->child_nodes, wc2);
if (node_it2 != node_it1->child_nodes.end() && node_it2->ch == wc2 &&
node_it2->is_contraction_tail)
return node_it2->weight;
}
return nullptr;
}
/**
Check if a code point can be previous context head
@param flags Pointer to UCA contraction flag data
@param wc Code point
@retval false - cannot be previous context head
@retval true - can be previous context head
*/
static inline bool my_uca_can_be_previous_context_head(const char *flags,
my_wc_t wc) {
return flags[wc & MY_UCA_CNT_FLAG_MASK] & MY_UCA_PREVIOUS_CONTEXT_HEAD;
}
/**
Check if a code point can be previous context tail
@param flags Pointer to UCA contraction flag data
@param wc Code point
@retval false - cannot be contraction tail
@retval true - can be contraction tail
*/
static inline bool my_uca_can_be_previous_context_tail(const char *flags,
my_wc_t wc) {
return flags[wc & MY_UCA_CNT_FLAG_MASK] & MY_UCA_PREVIOUS_CONTEXT_TAIL;
}
/**
Check if a string is a contraction of exactly the given length,
and return its weight array on success.
@param cont_nodes Vector that contains contraction nodes
@param wc Pointer to wide string
@param len String length