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
|
#!/usr/bin/env perl
use strict;
my (%titlecase8, %uni8_decomp);
my (@titlecase16_keys, @titlecase16_values);
my (@titlecase32_keys, @titlecase32_values);
my (@uni16_decomp_keys, @uni16_decomp_values);
my (@uni32_decomp_keys, @uni32_decomp_values);
my (@multidecomp_keys, @multidecomp_offsets, @multidecomp_values);
while (<>) {
chomp $_;
my @arr = split(";");
my $code = eval("0x".$arr[0]);
my $decomp = $arr[5];
my $titlecode = $arr[14];
if ($titlecode ne "") {
# titlecase mapping
my $value = eval("0x$titlecode");
if ($value == $code) {
# the same character, ignore
} elsif ($code <= 0xff) {
die "Error: We've assumed 8bit keys have max. 16bit values" if ($value > 0xffff);
$titlecase8{$code} = $value;
} elsif ($code <= 0xffff) {
die "Error: We've assumed 16bit keys have max. 16bit values" if ($value > 0xffff);
push @titlecase16_keys, $code;
push @titlecase16_values, $value;
} else {
push @titlecase32_keys, $code;
push @titlecase32_values, $value;
}
} elsif ($decomp =~ /(?:\<[^>]*> )?(.+)/) {
# decompositions
my $decomp_codes = $1;
if ($decomp_codes =~ /^([0-9A-Z]*)$/i) {
# unicharacter decomposition. use separate lists for this
my $value = eval("0x$1");
if ($value > 0xffffffff) {
print STDERR "Error: We've assumed decomposition codes are max. 32bit\n";
exit 1;
}
if ($code <= 0xff) {
$uni8_decomp{$code} = $value;
} elsif ($code <= 0xffff) {
push @uni16_decomp_keys, $code;
push @uni16_decomp_values, $value;
} else {
push @uni32_decomp_keys, $code;
push @uni32_decomp_values, $value;
}
} else {
# multicharacter decomposition.
if ($code > 0xffffffff) {
print STDERR "Error: We've assumed multi-decomposition key codes are max. 32bit\n";
exit 1;
}
push @multidecomp_keys, $code;
push @multidecomp_offsets, scalar(@multidecomp_values);
foreach my $dcode (split(" ", $decomp_codes)) {
my $value = eval("0x$dcode");
if ($value > 0xffffffff) {
print STDERR "Error: We've assumed decomposition codes are max. 32bit\n";
exit 1;
}
push @multidecomp_values, $value;
}
push @multidecomp_values, 0;
}
}
}
sub print_list {
my @list = @{$_[0]};
my $last = $#list;
my $n = 0;
foreach my $key (@list) {
printf("0x%05x", $key);
last if ($n == $last);
print ",";
$n++;
if (($n % 8) == 0) {
print "\n\t";
} else {
print " ";
}
}
}
print "/* This file is automatically generated by unicodemap.pl from UnicodeData.txt
NOTE: decompositions for characters having titlecase characters
are not included, because we first translate everything to titlecase */\n";
sub print_map8 {
my %map = %{$_[0]};
my @list;
for (my $i = 0; $i <= 0xff; $i++) {
if (defined($map{$i})) {
push @list, $map{$i};
} else {
push @list, $i;
}
}
print_list(\@list);
}
print "static const uint16_t titlecase8_map[256] = {\n\t";
print_map8(\%titlecase8);
print "\n};\n";
print "static const uint16_t titlecase16_keys[] = {\n\t";
print_list(\@titlecase16_keys);
print "\n};\n";
print "static const uint16_t titlecase16_values[] = {\n\t";
print_list(\@titlecase16_values);
print "\n};\n";
print "static const uint32_t titlecase32_keys[] = {\n\t";
print_list(\@titlecase32_keys);
print "\n};\n";
print "static const uint32_t titlecase32_values[] = {\n\t";
print_list(\@titlecase32_values);
print "\n};\n";
print "static const uint16_t uni8_decomp_map[256] = {\n\t";
print_map8(\%uni8_decomp);
print "\n};\n";
print "static const uint16_t uni16_decomp_keys[] = {\n\t";
print_list(\@uni16_decomp_keys);
print "\n};\n";
print "static const uint32_t uni16_decomp_values[] = {\n\t";
print_list(\@uni16_decomp_values);
print "\n};\n";
print "static const uint32_t uni32_decomp_keys[] = {\n\t";
print_list(\@uni32_decomp_keys);
print "\n};\n";
print "static const uint32_t uni32_decomp_values[] = {\n\t";
print_list(\@uni32_decomp_values);
print "\n};\n";
print "static const uint32_t multidecomp_keys[] = {\n\t";
print_list(\@multidecomp_keys);
print "\n};\n";
print "static const uint16_t multidecomp_offsets[] = {\n\t";
print_list(\@multidecomp_offsets);
print "\n};\n";
print "static const uint32_t multidecomp_values[] = {\n\t";
print_list(\@multidecomp_values);
print "\n};\n";
|