-
Notifications
You must be signed in to change notification settings - Fork 5
/
UnicodeData.bra
979 lines (952 loc) · 35.3 KB
/
UnicodeData.bra
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
{UnicodeData.bra
Read UnicodeData.txt and extract convert tables for
(1) case conversion (Uppercase Mapping, Lowercase Mapping columns) and
(2) character type (General Category column)
Produces
unicaseconv.c
unicaseconv.h
unichartypes.c
unichartypes.h
You need to install Bracmat to run this script:
git clone https://github.com/BartJongejan/Bracmat.git
After installing, start bracmat and then, after the prompt, type:
get$"UnicodeData.bra"
ABout once a year the unicode data are updated. Download the latest version from:
https://unicode.org/Public/UNIDATA/UnicodeData.txt
}
X=
(UnicodeDataFileName="UnicodeData.txt")
(UnicodeDataDate="2022-08-03 17:00")
(Upper=)
(Lower=)
( do
=
. 0:?p
& "
0 Code value normative Code value. For characters in the range U+0000..U+FFFD the code value uses a 4-digit hexadecimal format; for characters in the range U+10000..U+FFFFD the code value uses a 5-digit hexadecimal format; and for characters in the range U+100000..U+10FFFD the code value uses a 6-digit hexadecimal format.
1 Character name normative These names match exactly the names published in Chapter 14 of the Unicode Standard, Version 3.0.
2 General Category normative/informative This is a useful breakdown into various character types which can be used as a default categorization in implementations. See below for a brief explanation.
3 Canonical Combining Classes normative The classes used for the Canonical Ordering Algorithm in the Unicode Standard. These classes are also printed in Chapter 4 of the Unicode Standard.
4 Bidirectional Category normative See the list below for an explanation of the abbreviations used in this field. These are the categories required by the Bidirectional Behavior Algorithm in the Unicode Standard. These categories are summarized in Chapter 3 of the Unicode Standard.
5 Character Decomposition Mapping normative In the Unicode Standard, not all of the mappings are full (maximal) decompositions. Recursive application of look-up for decompositions will, in all cases, lead to a maximal decomposition. The decomposition mappings match exactly the decomposition mappings published with the character names in the Unicode Standard.
6 Decimal digit value normative This is a numeric field. If the character has the decimal digit property, as specified in Chapter 4 of the Unicode Standard, the value of that digit is represented with an integer value in this field
7 Digit value normative This is a numeric field. If the character represents a digit, not necessarily a decimal digit, the value is here. This covers digits which do not form decimal radix forms, such as the compatibility superscript digits
8 Numeric value normative This is a numeric field. If the character has the numeric property, as specified in Chapter 4 of the Unicode Standard, the value of that character is represented with an integer or rational number in this field. This includes fractions as, e.g., 1/5 for U+2155 VULGAR FRACTION ONE FIFTH Also included are numerical values for compatibility characters such as circled numbers.
9 Mirrored normative If the character has been identified as a mirrored character in bidirectional text, this field has the value Y; otherwise N. The list of mirrored characters is also printed in Chapter 4 of the Unicode Standard.
10 Unicode 1.0 Name informative This is the old name as published in Unicode 1.0. This name is only provided when it is significantly different from the Unicode 3.0 name for the character.
11 10646 comment field informative This is the ISO 10646 comment field. It appears in parentheses in the 10646 names list, or contains an asterisk to mark an Annex P note.
12 Uppercase Mapping informative Upper case equivalent mapping. If a character is part of an alphabet with case distinctions, and has an upper case equivalent, then the upper case equivalent is in this field. See the explanation below on case distinctions. These mappings are always one-to-one, not one-to-many or many-to-one. This field is informative.
13 Lowercase Mapping informative Similar to Uppercase mapping
14 Titlecase Mapping informative Similar to Uppercase mapping
Lu Uppercase_Letter an uppercase letter
Ll Lowercase_Letter a lowercase letter
Lt Titlecase_Letter a digraphic character, with first part uppercase
LC Cased_Letter Lu | Ll | Lt
Lm Modifier_Letter a modifier letter
Lo Other_Letter other letters, including syllables and ideographs
L Letter Lu | Ll | Lt | Lm | Lo
Mn Nonspacing_Mark a nonspacing combining mark (zero advance width)
Mc Spacing_Mark a spacing combining mark (positive advance width)
Me Enclosing_Mark an enclosing combining mark
M Mark Mn | Mc | Me
Nd Decimal_Number a decimal digit
Nl Letter_Number a letterlike numeric character
No Other_Number a numeric character of other type
N Number Nd | Nl | No
Pc Connector_Punctuation a connecting punctuation mark, like a tie
Pd Dash_Punctuation a dash or hyphen punctuation mark
Ps Open_Punctuation an opening punctuation mark (of a pair)
Pe Close_Punctuation a closing punctuation mark (of a pair)
Pi Initial_Punctuation an initial quotation mark
Pf Final_Punctuation a final quotation mark
Po Other_Punctuation a punctuation mark of other type
P Punctuation Pc | Pd | Ps | Pe | Pi | Pf | Po
Sm Math_Symbol a symbol of mathematical use
Sc Currency_Symbol a currency sign
Sk Modifier_Symbol a non-letterlike modifier symbol
So Other_Symbol a symbol of other type
S Symbol Sm | Sc | Sk | So
Zs Space_Separator a space character (of various non-zero widths)
Zl Line_Separator U+2028 LINE SEPARATOR only
Zp Paragraph_Separator U+2029 PARAGRAPH SEPARATOR only
Z Separator Zs | Zl | Zp
Cc Control a C0 or C1 control code
Cf Format a format control character
Cs Surrogate a surrogate code point
Co Private_Use a private-use character
Cn Unassigned a reserved unassigned code point or a noncharacter
C Other Cc | Cf | Cs | Co | Cn
"
& :?K
& :?u2l
& :?l2u
&
: ?let
: ?mark
: ?number
: ?punctuation
: ?symbol
: ?separator
: ?other
: ?dec
: ?Mdecomposed
& 0:?whs:?ML:?ALLL:?largest
& vap
$ ( (
=
. @( !arg
: ( ?"Code value"
";"
?"Character name"
";"
?"General Category"
";"
?"Canonical Combining Classes"
";"
?"Bidirectional Category"
";"
?"Character Decomposition Mapping"
";"
?"Decimal digit value"
";"
?"Digit value"
";"
?"Numeric value"
";"
?Mirrored
";"
?"Unicode 1.0 Name"
";"
?"10646 comment field"
";"
?"Uppercase Mapping"
";"
?"Lowercase Mapping"
";"
?"Titlecase Mapping"
& ( !"Lowercase Mapping":
| ( x2d$!"Code value":?V
. x2d$!"Lowercase Mapping":?W
. !W+-1*!V
. !"Code value"
. !"Lowercase Mapping"
)
!u2l
: ?u2l
)
& ( !"Uppercase Mapping":
| ( x2d$!"Code value":?V
. x2d$!"Uppercase Mapping":?W
. !W+-1*!V
. !"Code value"
. !"Uppercase Mapping"
)
!l2u
: ?l2u
)
& ( !"Character Decomposition Mapping":
| @( !"Character Decomposition Mapping"
: ( "<" ?where ">" ?decomposed
| ?decomposed
& ( @( !"Character name"
: "CJK COMPATIBILITY IDEOGRAPH" ?
)
& "CJK COMPATIBILITY IDEOGRAPH"
| !"Character name"
)
: ?where
& "Ligatures, CJK COMPATIBILITY IDEOGRAPH"
)
)
& !where+!whs:?whs
& ( x2d$!"Code value"
. !"Code value"
. !where
. !decomposed
. chu$(x2d$!"Code value")
. str
$ ( vap
$ ( (
=
. !arg:
| chu
$ ( x2d$!arg
: ( >!largest
: ?largest
| ?
)
)
)
. !decomposed
. " "
)
: ?
( [?LL
& !LL+!ALLL:?ALLL
& ( !LL:>!ML:?ML
& !"Code value" !decomposed
: ?Mdecomposed
|
)
)
)
)
!dec
: ?dec
)
& ( @(!"General Category":L ?k)
& ( x2d$!"Code value"
. !"Code value"
. !"Character name"
)
!let
: ?let
& ( !K:? !k ?
| !k !K:?K
& :?!k
)
& (!"Code value".!"Character name") !!k
: ?!k
&
| @(!"General Category":M ?)
& ( x2d$!"Code value"
. !"Code value"
. !"Character name"
. M
)
!mark
: ?mark
&
| @(!"General Category":N ?)
& ( x2d$!"Code value"
. !"Code value"
. !"Character name"
. N
)
!number
: ?number
&
| @(!"General Category":P ?)
& ( x2d$!"Code value"
. !"Code value"
. !"Character name"
. P
)
!punctuation
: ?punctuation
&
| @(!"General Category":S ?)
& ( x2d$!"Code value"
. !"Code value"
. !"Character name"
. S
)
!symbol
: ?symbol
&
| @(!"General Category":Z ?)
& ( x2d$!"Code value"
. !"Code value"
. !"Character name"
. Z
)
!separator
: ?separator
&
| @(!"General Category":C ?)
& ( x2d$!"Code value"
. !"Code value"
. !"Character name"
. C
)
!other
: ?other
|
)
)
)
& (x2d$!"Code value".!"General Category".!"Code value")
|
)
. !txt
. \n
)
: ?CGC
& lst$(whs,whs,NEW BIN)
& lst$(ML,ML,NEW)
& lst$(Mdecomposed,ML,NEW)
& lst$(ALLL,ML,NEW)
& lst$(largest d2x$!largest,ML,NEW)
& put$(d2x$!largest \n,ML,NEW)
& lst$(CGC,CGC,NEW,BIN)
& lst$(dec,dec,NEW BIN)
& 0:?periods
& !CGC
: ?CGC0
((~<65536.?) ?:?CGC1)
((~<131072.?) ?:?CGC2)
& !CGC0 STOP:?CGC0
& !CGC1 STOP:?CGC1
& !CGC2 STOP:?CGC2
& lst$(CGC0,CGC0,NEW BIN)
& lst$(CGC1,CGC1,NEW BIN)
& lst$(CGC2,CGC2,NEW BIN)
& ( statistics
= periods cat I i prI ign
. 0:?periods
& :?cat
& :?I
& 0:?i:?prI
& !arg:(?arg.?ign)
& map
$ ( (
= C H U
. !I:?prI
& !arg:(?I.?C.?H)
& ( !C:!cat&
| ( !cat:(|!ign)
&
| ( !i
. d2x$!i
. !cat
. !prI+-1*!i
)
)
: ?U
& ( !cat:
| !cat+!periods:?periods
)
& !I:?i
& !C:?cat
& !U
)
| (!i.d2x$!i.!cat.!prI+-1*!i)
)
. !arg
)
: ?stats
& ( !cat:
| !cat+!periods:?periods
)
& (!periods.!stats)
)
& statistics$(!CGC0.):(?periods0.?)
& statistics$(!CGC1.):(?periods1.?)
& statistics$(!CGC2.):(?periods2.?)
& 0:?default0:?default1
& :?def0:?def1
& ( !periods0
: ?
+ ( #?n*@?def
& !n:>!default0:?default0
& !def:?def0
& ~
)
+ ?
| out$(def0 !def0 default0 !default0)
)
& ( !periods1
: ?
+ ( #?n*@?def
& !n:>!default1:?default1
& !def:?def1
& ~
)
+ ?
| out$(def1 !def1 default1 !default1)
)
& lst$(periods0,periods0,NEW BIN)
& lst$(periods1,periods1,NEW BIN)
& lst$(periods2,periods2,NEW BIN)
& statistics$(!CGC0.!def0):(?.?Groups0)
& statistics$(!CGC1.!def1):(?.?Groups1)
& statistics$(!CGC2.):(?.?Groups2)
& lst$(Groups0,Groups0,NEW BIN)
& lst$(Groups1,Groups1,NEW BIN)
& lst$(Groups2,Groups2,NEW BIN)
& !Groups0:? [?lastindex0
& !Groups1:? [?lastindex1
& !Groups2:? [?lastindex2
& (lst$(K,K,NEW BIN)|)
& (lst$(let,let,NEW BIN)|)
& (lst$(u2l,u2l,NEW BIN)|)
& (lst$(l2u,l2u,NEW BIN)|)
& (lst$(mark,mark,NEW BIN)|)
& (lst$(number,number,NEW BIN)|)
& ( lst$(punctuation,punctuation,NEW BIN)
|
)
& (lst$(symbol,symbol,NEW BIN)|)
& (lst$(separator,separator,NEW BIN)|)
& (lst$(other,other,NEW BIN)|)
& 9:?crd
& ( theMarks
= m1 m2
. map
$ ( (
=
. !arg:(?.?.@(?:%@?m1 @?m2).?)
& -1+!crd:?crd
& ( !crd:0
& 10:?crd
& \n
|
)
"{"
e1
!m1
","
e2
!m2
"},"
)
. !arg
)
)
& "/*\n"
"Based on UnicodeData.txt ("
!(X.UnicodeDataDate)
")\n"
"Structures created with UnicodeData.bra"
\n
"*/\n\n"
"#include \"unichartypes.h\""
\n
"#include <assert.h>"
\n\n
"typedef enum {e1L,e1M,e1N,e1P,e1S,e1Z,e1C,e1} mark1;"
\n
"typedef enum {e2C,e2c,e2d,e2e,e2f,e2i,e2k,e2l,e2m,e2n,e2o,e2p,e2s,e2t,e2u,e2} mark2;"
\n
"typedef struct tmark {unsigned char m1:4; unsigned char m2:4;} tmark;"
\n
"typedef struct cletter {unsigned short int L;unsigned short int range;} cletter;"
\n
"typedef struct cletter2 {unsigned int L;unsigned int range;} cletter2;"
\n\n
"static const char * firstMark = \"LMNPSZC\";"
\n
"static const char * secondMark = \"Ccdefiklmnopstu\";"
\n\n
"tmark Mark[] = {"
theMarks$!Groups0
theMarks$!Groups1
theMarks$!Groups2
"{e1,e2}};"
\n\n
"cletter Cletters0[]={"
( 9:?crd
& map
$ ( (
=
. !arg:(?d.?h.?g.?l)
& -1+!crd:?crd
& ( !crd:0
& 10:?crd
& \n
|
)
"{0x"
!h
","
!l
"},"
)
. !Groups0
)
)
"{0xFFFF,0}};"
\n\n
"cletter Cletters1[]={"
( 9:?crd
& map
$ ( (
=
. !arg
: (?d.@(?:%@ ?h).?g.?l)
& -1+!crd:?crd
& ( !crd:0
& 10:?crd
& \n
|
)
"{0x"
!h
","
!l
"},"
)
. !Groups1
)
)
"{0xFFFF,0}};"
\n\n
"cletter2 Cletters2[]={"
( 9:?crd
& map
$ ( (
=
. !arg:(?d.@(?:?h).?g.?l)
& -1+!crd:?crd
& ( !crd:0
& 10:?crd
& \n
|
)
"{0x"
!h
","
!l
"},"
)
. !Groups2
)
)
"{0xFFFFF,0}};"
\n\n
"
const char * gencat(int a)
{
unsigned int pivot;
unsigned int lo;
unsigned int hi;
unsigned int offset;
cletter *Cletters;
const char *def;
static char returnVal[3] = { '0','0','0' };
if(a <= 0)
return 0;
lo = 0;
offset = 0;
Cletters = 0;
if(a < 0x10000)
{
pivot = 8;
hi = "
!lastindex0
"; /* Range starting at lastindex does not consists of letters, so pivot must always stay less than lastindex. */
assert(pivot < "
!lastindex0
");
Cletters = Cletters0;
def = \""
!def0
"\";
}
else if(a >= 0x20000)
{
int i;
for(i = 0;i < "
!lastindex2
";++i)
{
if(Cletters2[i].L <= (unsigned short)a && (unsigned short)a <= Cletters2[i].L + Cletters2[i].range)
{
tmark mrk = Mark[i + "
!lastindex0
" + "
!lastindex1
"];
returnVal[0] = firstMark[mrk.m1];
returnVal[1] = secondMark[mrk.m2];
returnVal[2] = '0';
break;
}
}
return returnVal;
}
else
{
a &= 0xFFFF;
pivot = "
!lastindex1
" >> 1;
hi = "
!lastindex1
";
Cletters = Cletters1;
def = \""
!def1
"\";
offset = "
!lastindex0
";
}
while(1)
{
assert(pivot < hi);
if((unsigned short)a < Cletters[pivot].L)
{
if(pivot == lo)
return def;
else
{
hi = pivot;
pivot = (pivot + lo) / 2;
}
}
else if((unsigned short)a <= Cletters[pivot].L + Cletters[pivot].range)
{
tmark mrk = Mark[pivot + offset];
returnVal[0] = firstMark[mrk.m1];
returnVal[1] = secondMark[mrk.m2];
returnVal[2] = '0';
return returnVal;
}
else if(pivot + 1 == hi)
return def;
else
{
lo = pivot + 1;
pivot = (hi + pivot) / 2;
}
}
}
"
: ?Cletters
& put$(str$!Cletters,"unichartypes.c",NEW,BIN)
& out$"unichartypes.c written"
& put
$ ( str
$ ( "#ifndef UNICHARTYPES_H"
\n
"#define UNICHARTYPES_H"
"\n/*\n"
"Uses the field 'General Category'. Values returned by gencat(int) are:"
\n\n
"Lu Uppercase_Letter an uppercase letter"
\n
"Ll Lowercase_Letter a lowercase letter"
\n
"Lt Titlecase_Letter a digraphic character, with first part uppercase"
\n
"LC Cased_Letter Lu | Ll | Lt"
\n
"Lm Modifier_Letter a modifier letter"
\n
"Lo Other_Letter other letters, including syllables and ideographs"
\n
"L Letter Lu | Ll | Lt | Lm | Lo"
\n
"Mn Nonspacing_Mark a nonspacing combining mark (zero advance width)"
\n
"Mc Spacing_Mark a spacing combining mark (positive advance width)"
\n
"Me Enclosing_Mark an enclosing combining mark"
\n
"M Mark Mn | Mc | Me"
\n
"Nd Decimal_Number a decimal digit"
\n
"Nl Letter_Number a letterlike numeric character"
\n
"No Other_Number a numeric character of other type"
\n
"N Number Nd | Nl | No"
\n
"Pc Connector_Punctuation a connecting punctuation mark, like a tie"
\n
"Pd Dash_Punctuation a dash or hyphen punctuation mark"
\n
"Ps Open_Punctuation an opening punctuation mark (of a pair)"
\n
"Pe Close_Punctuation a closing punctuation mark (of a pair)"
\n
"Pi Initial_Punctuation an initial quotation mark"
\n
"Pf Final_Punctuation a final quotation mark"
\n
"Po Other_Punctuation a punctuation mark of other type"
\n
"P Punctuation Pc | Pd | Ps | Pe | Pi | Pf | Po"
\n
"Sm Math_Symbol a symbol of mathematical use"
\n
"Sc Currency_Symbol a currency sign"
\n
"Sk Modifier_Symbol a non-letterlike modifier symbol"
\n
"So Other_Symbol a symbol of other type"
\n
"S Symbol Sm | Sc | Sk | So"
\n
"Zs Space_Separator a space character (of various non-zero widths)"
\n
"Zl Line_Separator U+2028 LINE SEPARATOR only"
\n
"Zp Paragraph_Separator U+2029 PARAGRAPH SEPARATOR only"
\n
"Z Separator Zs | Zl | Zp"
\n
"Cc Control a C0 or C1 control code"
\n
"Cf Format a format control character"
\n
"Cs Surrogate a surrogate code point"
\n
"Co Private_Use a private-use character"
\n
"Cn Unassigned a reserved unassigned code point or a noncharacter"
\n
"C Other Cc | Cf | Cs | Co | Cn"
"\n*/\n\n"
"#ifdef __cplusplus"
\n
"extern \"C\" const char * gencat(int a);"
\n
"#else"
\n
"extern const char* gencat(int a);"
\n
"#endif"
\n\n
"#endif"
\n
)
, "unichartypes.h"
, NEW
, BIN
)
& out$"unichartypes.h written"
& put
$ ( str
$ ( "/* Based on http://unicode.org/Public/UNIDATA/UnicodeData.txt "
!(X.UnicodeDataDate)
" ,\n"
" structures created with UnicodeData.bra"
\n
"*/\n\n"
"#include \"unicaseconv.h\""
\n
)
, "unicaseconv.c"
, NEW BIN
)
& ( comp
=
. !arg:(?arg.?name)
& put
$ ( str$("
struct ccaseconv " !name "[]={\n")
, ("unicaseconv.c",APP BIN)
| (str$(!name ".c"):?name,NEW BIN)
)
& (pat1=!d1&-1+!d1:?d1)
& (pat2=!d2&-2+!d2:?d2)
& ( setpat
=
' ( $pat1
& 1:?dif
& '$pat1:(=?pat)
| $pat2
& 2:?dif
& '$pat2:(=?pat)
)
: (=?pat)
)
& :?conv:?LL
& whl
' ( !setpat
& :?dd
& !arg
: ( ?d
& -1+!d:?d1
& -2+!d:?d2
. ?
. ?df
. ?
)
?
( ( ?ndd
. ?
. !df
& !ndd:!pat:?dd
. ?
)
?
& `~
| ?arg
& ( !dd:
& ( !d
. !df+!d
. !df
. d2x$!d:?let
. d2x$(!df+!d)
. 0:?inc
. 0:?range
. d2x$!d
. d2x$(!df+!d)
)
| ( !dd
. !df+!dd
. !df
. d2x$!dd:?let
. d2x$(!df+!dd)
. !dif:?inc
. !d+-1*!dd:?range
. d2x$!d
. d2x$(!df+!d)
)
)
!LL
: ?LL
& "{0x"
!let
","
!range
","
!inc
","
!df
"},\n"
!conv
: ?conv
)
)
& put
$ ( str$!conv
, "unicaseconv.c"|!name
, APP BIN
)
& put
$ ( "{0x1FFFFF,0,0,0}};
"
, "unicaseconv.c"|!name
, APP BIN
)
& ( "LETTER DECIMAL"
. "CASE CONVERTED LETTER DECIMAL"
. DELTA
. "LETTER HEX"
. "CASE CONVERTED LETTER HEX"
. INCREMENT
. RANGE
. "LAST LETTER HEX"
. "LAST CASE CONVERTED LETTER HEX"
)
!LL
)
& ( writeCaseconvFunctions
=
. put
$ ( "
int convertLetter(int a, struct ccaseconv * T)
{
int i;
if ((unsigned int)a < T[0].L || a > 0x10FFFF)
return a;
for (i = 1;; ++i)
{
if ((unsigned int)a < T[i].L)
{
--i;
if ( (unsigned int)a <= (unsigned int)(T[i].L + T[i].range)
&& ( T[i].inc < 2
|| !((a - T[i].L) & 1)
)
)
{
return a + T[i].dif;
}
else
{
break;
}
}
}
return a;
}
int toUpperUnicode(int a)
{
return convertLetter(a,l2u);
}
int toLowerUnicode(int a)
{
return convertLetter(a, u2l);
}
"
, "unicaseconv.c"
, APP BIN
)
)
& comp$(!l2u.l2u):?l2us
& lst$(l2us,l2us,NEW BIN)
& comp$(!u2l.u2l):?u2ls
& writeCaseconvFunctions$
& out$"unicaseconv.c written"
& put
$ ( str
$ ( "#ifndef UNICASECONV_H"
\n
"#define UNICASECONV_H"
\n
"/* Uses the fields Uppercase Mapping and Lowercase Mapping in Unicodedata.txt to convert lower case to upper case and vice versa */"
\n\n
"struct ccaseconv {unsigned int L:21;int range:11;unsigned int inc:2;int dif:20;};"
\n
"extern struct ccaseconv l2u[];"
\n
"extern struct ccaseconv u2l[];"
\n\n
"int convertLetter(int a, struct ccaseconv * T);"
\n
"int toUpperUnicode(int a);"
\n
"int toLowerUnicode(int a);"
\n\n
"#endif"
\n
)
, "unicaseconv.h"
, NEW BIN
)
& out$"unicaseconv.h written"
& lst$(u2ls,u2ls,NEW BIN)
& whl
' ( !K:%?k ?K
& lst$(!k,!k,NEW BIN)
)
)
( new
=
. ~
| get$(!(its.UnicodeDataFileName),STR)
: ?txt
& (its.do)$
& DONE
);
r=
get'"UnicodeData.bra"
& rmv$"UnicodeData.bak"
& ren$("UnicodeData.bra"."UnicodeData.bak")
& put
$ ( str
$ ( "{UnicodeData.bra
Read "
!(X.UnicodeDataFileName)
" and extract convert tables for
(1) case conversion (Uppercase Mapping, Lowercase Mapping columns) and
(2) character type (General Category column)
Produces
unicaseconv.c
unicaseconv.h
unichartypes.c
unichartypes.h
You need to install Bracmat to run this script:
git clone https://github.com/BartJongejan/Bracmat.git
After installing, start bracmat and then, after the prompt, type:
get$\"UnicodeData.bra\"
ABout once a year the unicode data are updated. Download the latest version from:
https://unicode.org/Public/UNIDATA/UnicodeData.txt
}
"
)
, "UnicodeData.bra"
, NEW BIN
)
& lst'(X,"UnicodeData.bra",APP BIN)
& put'(\n,"UnicodeData.bra",APP BIN)
& lst'(r,"UnicodeData.bra",APP BIN)
& put$(str$("\nnew'" X "&;\n"),"UnicodeData.bra",APP BIN)
& done;
new'X&;