-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.pl
executable file
·60 lines (43 loc) · 1.15 KB
/
generate.pl
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
#!/usr/bin/env perl
use Getopt::Long;
sub escape {
my $val = shift;
$val =~ s/\\/\\\\/gs;
$val =~ s/"/\\"/g;
$val =~ s/([\x00-\x1f])/sprintf("\\x%02x", ord($1))/ges;
return $val;
}
`wget http://search.cpan.org/CPAN/authors/id/S/SB/SBURKE/Text-Unidecode-1.30.tar.gz`;
`tar xf Text-Unidecode-1.30.tar.gz`;
`mkdir -p pl`;
`mv Text-Unidecode-1.30/lib/Text/Unidecode/x*.pm pl`;
my $input = "./pl/";
my $output = "./";
$result = GetOptions(
"input=s" => \$input,
"output=s" => \$output,
);
push(@INC, $input);
open(OUT, sprintf(">%s/table.go", $output));
print OUT "//\n";
print OUT "//go:generate perl generate.pl\n";
print OUT "//\n";
print OUT "\n";
print OUT "package unidecode\n";
print OUT "\n";
print OUT "// Table ...\n";
print OUT "var Table = map[rune]string{\n";
for (my $n = 0; $n < 256; ++$n) {
eval(sprintf("require x%02x;\n", $n));
next unless( $#{$Text::Unidecode::Char[$n]} >= 0 );
printf OUT " // 0x%02x00 - 0x%02xff\n", $n, $n;
my $m = 0;
for my $t (@{$Text::Unidecode::Char[$n]}) {
printf OUT " '\\u%02x%02x': \"%s\",\n", $n, $m, &escape($t);
$m++;
}
}
print OUT "}\n";
close(OUT);
`rm -rf Text-Unidecode-1.30*`;
`rm -rf pl`;