forked from briandfoy/unicode-tussle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unicaps
executable file
·206 lines (175 loc) · 10.4 KB
/
unicaps
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
#!/usr/bin/env perl
#
# unicaps, mark 2
use 5.10.1;
use utf8;
use strict;
use autodie;
use warnings;
use warnings FATAL => "utf8";
use charnames qw(:full);
binmode(STDOUT, ":utf8");
# generates the following code:
#
# tr[aæbcdðeǝfgɠhiɨjklłmnoœɔȣprɹꝵstuʉɯvwyzʒγλπρψл]
# [ᴀᴁʙᴄᴅᴆᴇⱻꜰɢʛʜɪᵻᴊᴋʟᴌᴍɴᴏɶᴐᴕᴘʀᴚꝶꜱᴛᴜᵾꟺᴠᴡʏᴢᴣᴦᴧᴨᴩᴪᴫ];
#
my $to_smcap = generate_smcap_tr();
if (@ARGV == 0) {
if (-t STDIN) {
warn "$0: reading from stdin, type ^C to kill, ^D to end.\n";
}
while (<>) {
&$to_smcap;
print;
}
} else {
if (!-t STDIN) {
warn "$0: ignoring filenames in ARGV and treating ARGV as strings";
}
for ("@ARGV") {
&$to_smcap;
say;
}
}
exit;
######3
sub generate_smcap_tr {
# This table is generated (kinda) by the next function following. However,
# one can munge the flubbed entries it comments out to get better results,
# as I have done here below.
#
my @small2smcap = (
"\N{LATIN SMALL LETTER A}" => "\N{LATIN LETTER SMALL CAPITAL A}",
"\N{LATIN SMALL LETTER AE}" => "\N{LATIN LETTER SMALL CAPITAL AE}",
"\N{LATIN SMALL LETTER B}" => "\N{LATIN LETTER SMALL CAPITAL B}",
"\N{LATIN SMALL LETTER C}" => "\N{LATIN LETTER SMALL CAPITAL C}",
"\N{LATIN SMALL LETTER D}" => "\N{LATIN LETTER SMALL CAPITAL D}",
"\N{LATIN SMALL LETTER ETH}" => "\N{LATIN LETTER SMALL CAPITAL ETH}",
"\N{LATIN SMALL LETTER E}" => "\N{LATIN LETTER SMALL CAPITAL E}",
"\N{LATIN SMALL LETTER TURNED E}" => "\N{LATIN LETTER SMALL CAPITAL TURNED E}",
"\N{LATIN SMALL LETTER F}" => "\N{LATIN LETTER SMALL CAPITAL F}",
"\N{LATIN SMALL LETTER G}" => "\N{LATIN LETTER SMALL CAPITAL G}",
"\N{LATIN SMALL LETTER G WITH HOOK}" => "\N{LATIN LETTER SMALL CAPITAL G WITH HOOK}",
"\N{LATIN SMALL LETTER H}" => "\N{LATIN LETTER SMALL CAPITAL H}",
"\N{LATIN SMALL LETTER I}" => "\N{LATIN LETTER SMALL CAPITAL I}",
"\N{LATIN SMALL LETTER I WITH STROKE}" => "\N{LATIN SMALL CAPITAL LETTER I WITH STROKE}",
"\N{LATIN SMALL LETTER J}" => "\N{LATIN LETTER SMALL CAPITAL J}",
"\N{LATIN SMALL LETTER K}" => "\N{LATIN LETTER SMALL CAPITAL K}",
"\N{LATIN SMALL LETTER L}" => "\N{LATIN LETTER SMALL CAPITAL L}",
"\N{LATIN SMALL LETTER L WITH STROKE}" => "\N{LATIN LETTER SMALL CAPITAL L WITH STROKE}",
"\N{LATIN SMALL LETTER M}" => "\N{LATIN LETTER SMALL CAPITAL M}",
"\N{LATIN SMALL LETTER N}" => "\N{LATIN LETTER SMALL CAPITAL N}",
"\N{LATIN SMALL LETTER O}" => "\N{LATIN LETTER SMALL CAPITAL O}",
"\N{LATIN SMALL LIGATURE OE}" => "\N{LATIN LETTER SMALL CAPITAL OE}",
"\N{LATIN SMALL LETTER OPEN O}" => "\N{LATIN LETTER SMALL CAPITAL OPEN O}",
"\N{LATIN SMALL LETTER OU}" => "\N{LATIN LETTER SMALL CAPITAL OU}",
"\N{LATIN SMALL LETTER P}" => "\N{LATIN LETTER SMALL CAPITAL P}",
"\N{LATIN SMALL LETTER R}" => "\N{LATIN LETTER SMALL CAPITAL R}",
"\N{LATIN SMALL LETTER TURNED R}" => "\N{LATIN LETTER SMALL CAPITAL TURNED R}",
"\N{LATIN SMALL LETTER RUM}" => "\N{LATIN LETTER SMALL CAPITAL RUM}",
"\N{LATIN SMALL LETTER S}" => "\N{LATIN LETTER SMALL CAPITAL S}",
"\N{LATIN SMALL LETTER T}" => "\N{LATIN LETTER SMALL CAPITAL T}",
"\N{LATIN SMALL LETTER U}" => "\N{LATIN LETTER SMALL CAPITAL U}",
"\N{LATIN SMALL LETTER U BAR}" => "\N{LATIN SMALL CAPITAL LETTER U WITH STROKE}",
"\N{LATIN SMALL LETTER TURNED M}" => "\N{LATIN LETTER SMALL CAPITAL TURNED M}",
"\N{LATIN SMALL LETTER V}" => "\N{LATIN LETTER SMALL CAPITAL V}",
"\N{LATIN SMALL LETTER W}" => "\N{LATIN LETTER SMALL CAPITAL W}",
"\N{LATIN SMALL LETTER Y}" => "\N{LATIN LETTER SMALL CAPITAL Y}",
"\N{LATIN SMALL LETTER Z}" => "\N{LATIN LETTER SMALL CAPITAL Z}",
"\N{LATIN SMALL LETTER EZH}" => "\N{LATIN LETTER SMALL CAPITAL EZH}",
"\N{GREEK SMALL LETTER GAMMA}" => "\N{GREEK LETTER SMALL CAPITAL GAMMA}",
"\N{GREEK SMALL LETTER LAMDA}" => "\N{GREEK LETTER SMALL CAPITAL LAMDA}",
"\N{GREEK SMALL LETTER PI}" => "\N{GREEK LETTER SMALL CAPITAL PI}",
"\N{GREEK SMALL LETTER RHO}" => "\N{GREEK LETTER SMALL CAPITAL RHO}",
"\N{GREEK SMALL LETTER PSI}" => "\N{GREEK LETTER SMALL CAPITAL PSI}",
"\N{CYRILLIC SMALL LETTER EL}" => "\N{CYRILLIC LETTER SMALL CAPITAL EL}",
);
my @even = grep { $_ % 2 == 0 } 0 .. $#small2smcap;
my @odd = grep { $_ % 2 == 1 } 0 .. $#small2smcap;
sub J { join q() => @_ }
my $tr = "tr[" . J( @small2smcap[@even] ) . "]\n"
. " [" . J( @small2smcap[@odd] ) . "];\n";
say $tr if 0;
my $code = eval "sub { $tr }" || die;
return $code;
}
#######################################################################
sub gen_smcap_table {
my $fist = 0x00_0000;
my $last = 0x00_FFFF; # nothing interesting any further
for (my $smcap_cp = $fist; $smcap_cp <= $last; $smcap_cp++) {
# gaggy UTF-16 surrogates are invalid UTF-8 code points, avoid fatal in 5.12
next if $smcap_cp >= 0xD800 && $smcap_cp <= 0xDFFF;
# from utf8.c in perl src; must avoid fatals in 5.10
next if $smcap_cp >= 0xFDD0 && $smcap_cp <= 0xFDEF;
next if 0xFFFE == ($smcap_cp & 0xFFFE); # both FFFE and FFFF, in all planes
next unless chr($smcap_cp) =~ /\p{GC=Ll}/; # skip modifier and combining letters
my $smcap_name = charnames::viacode($smcap_cp);
next unless $smcap_name;
next unless $smcap_name =~ /SMALL CAPITAL/;
my $small_name = $smcap_name;
for ($small_name) {
s/LETTER SMALL CAPITAL/CAPITAL LETTER/
|| s/SMALL CAPITAL LETTER/CAPITAL LETTER/
|| die;
s/CAPITAL/SMALL/;
}
my $small_cp = charnames::vianame($small_name);
if (!defined $small_cp) {
$small_name =~ s/^/missing /;
print "## ";
}
printf "%-40s => %s,\n", map { qq("\\N{$_}") } $small_name, $smcap_name;
}
}
# Example of what it generates under Unicode 6.0 follows
__END__
"\N{LATIN SMALL LETTER G}" => "\N{LATIN LETTER SMALL CAPITAL G}",
"\N{LATIN SMALL LETTER I}" => "\N{LATIN LETTER SMALL CAPITAL I}",
"\N{LATIN SMALL LETTER N}" => "\N{LATIN LETTER SMALL CAPITAL N}",
## "\N{missing LATIN SMALL LETTER OE}" => "\N{LATIN LETTER SMALL CAPITAL OE}",
"\N{LATIN SMALL LETTER R}" => "\N{LATIN LETTER SMALL CAPITAL R}",
## "\N{missing LATIN SMALL LETTER INVERTED R}" => "\N{LATIN LETTER SMALL CAPITAL INVERTED R}",
"\N{LATIN SMALL LETTER Y}" => "\N{LATIN LETTER SMALL CAPITAL Y}",
"\N{LATIN SMALL LETTER B}" => "\N{LATIN LETTER SMALL CAPITAL B}",
"\N{LATIN SMALL LETTER G WITH HOOK}" => "\N{LATIN LETTER SMALL CAPITAL G WITH HOOK}",
"\N{LATIN SMALL LETTER H}" => "\N{LATIN LETTER SMALL CAPITAL H}",
"\N{LATIN SMALL LETTER L}" => "\N{LATIN LETTER SMALL CAPITAL L}",
"\N{LATIN SMALL LETTER A}" => "\N{LATIN LETTER SMALL CAPITAL A}",
"\N{LATIN SMALL LETTER AE}" => "\N{LATIN LETTER SMALL CAPITAL AE}",
## "\N{missing LATIN SMALL LETTER BARRED B}" => "\N{LATIN LETTER SMALL CAPITAL BARRED B}",
"\N{LATIN SMALL LETTER C}" => "\N{LATIN LETTER SMALL CAPITAL C}",
"\N{LATIN SMALL LETTER D}" => "\N{LATIN LETTER SMALL CAPITAL D}",
"\N{LATIN SMALL LETTER ETH}" => "\N{LATIN LETTER SMALL CAPITAL ETH}",
"\N{LATIN SMALL LETTER E}" => "\N{LATIN LETTER SMALL CAPITAL E}",
"\N{LATIN SMALL LETTER J}" => "\N{LATIN LETTER SMALL CAPITAL J}",
"\N{LATIN SMALL LETTER K}" => "\N{LATIN LETTER SMALL CAPITAL K}",
"\N{LATIN SMALL LETTER L WITH STROKE}" => "\N{LATIN LETTER SMALL CAPITAL L WITH STROKE}",
"\N{LATIN SMALL LETTER M}" => "\N{LATIN LETTER SMALL CAPITAL M}",
## "\N{missing LATIN SMALL LETTER REVERSED N}" => "\N{LATIN LETTER SMALL CAPITAL REVERSED N}",
"\N{LATIN SMALL LETTER O}" => "\N{LATIN LETTER SMALL CAPITAL O}",
"\N{LATIN SMALL LETTER OPEN O}" => "\N{LATIN LETTER SMALL CAPITAL OPEN O}",
"\N{LATIN SMALL LETTER OU}" => "\N{LATIN LETTER SMALL CAPITAL OU}",
"\N{LATIN SMALL LETTER P}" => "\N{LATIN LETTER SMALL CAPITAL P}",
## "\N{missing LATIN SMALL LETTER REVERSED R}" => "\N{LATIN LETTER SMALL CAPITAL REVERSED R}",
"\N{LATIN SMALL LETTER TURNED R}" => "\N{LATIN LETTER SMALL CAPITAL TURNED R}",
"\N{LATIN SMALL LETTER T}" => "\N{LATIN LETTER SMALL CAPITAL T}",
"\N{LATIN SMALL LETTER U}" => "\N{LATIN LETTER SMALL CAPITAL U}",
"\N{LATIN SMALL LETTER V}" => "\N{LATIN LETTER SMALL CAPITAL V}",
"\N{LATIN SMALL LETTER W}" => "\N{LATIN LETTER SMALL CAPITAL W}",
"\N{LATIN SMALL LETTER Z}" => "\N{LATIN LETTER SMALL CAPITAL Z}",
"\N{LATIN SMALL LETTER EZH}" => "\N{LATIN LETTER SMALL CAPITAL EZH}",
"\N{GREEK SMALL LETTER GAMMA}" => "\N{GREEK LETTER SMALL CAPITAL GAMMA}",
"\N{GREEK SMALL LETTER LAMDA}" => "\N{GREEK LETTER SMALL CAPITAL LAMDA}",
"\N{GREEK SMALL LETTER PI}" => "\N{GREEK LETTER SMALL CAPITAL PI}",
"\N{GREEK SMALL LETTER RHO}" => "\N{GREEK LETTER SMALL CAPITAL RHO}",
"\N{GREEK SMALL LETTER PSI}" => "\N{GREEK LETTER SMALL CAPITAL PSI}",
"\N{CYRILLIC SMALL LETTER EL}" => "\N{CYRILLIC LETTER SMALL CAPITAL EL}",
"\N{LATIN SMALL LETTER I WITH STROKE}" => "\N{LATIN SMALL CAPITAL LETTER I WITH STROKE}",
## "\N{missing LATIN SMALL LETTER U WITH STROKE}" => "\N{LATIN SMALL CAPITAL LETTER U WITH STROKE}",
"\N{LATIN SMALL LETTER TURNED E}" => "\N{LATIN LETTER SMALL CAPITAL TURNED E}",
"\N{LATIN SMALL LETTER F}" => "\N{LATIN LETTER SMALL CAPITAL F}",
"\N{LATIN SMALL LETTER S}" => "\N{LATIN LETTER SMALL CAPITAL S}",
"\N{LATIN SMALL LETTER RUM}" => "\N{LATIN LETTER SMALL CAPITAL RUM}",
"\N{LATIN SMALL LETTER TURNED M}" => "\N{LATIN LETTER SMALL CAPITAL TURNED M}",