forked from g0v/moedict-webkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
special2pack.pl
27 lines (27 loc) · 951 Bytes
/
special2pack.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
use strict;
use Encode;
for my $special (qw[ = @ ]) {
for my $lang (qw[ a t h c ]) {
next if $special eq '@' and $lang ne 'a' and $lang ne 'c';
my @files = sort glob("$lang/$special*.json") or next;
open my $out, '>:raw', "p${lang}ck/$special.txt";
select $out;
print "{";
for my $file (@files) {
next if $file =~ /=\.json$/;
my $payload = do { open my $fh, '<:raw', $file; local $/; <$fh>; };
$payload =~ s/\s*\n\s*//g;
my $escaped = $file;
$escaped =~ s!.*/!!;
$escaped =~ s!\.json!!;
$escaped =~ s!=!%3D!g;
Encode::_utf8_on($escaped);
$escaped =~ s!([^\x00-\xff])!sprintf '%%u%04X', ord $1!eg;
Encode::_utf8_off($escaped);
print "," unless $file eq $files[0];
print qq["$escaped":$payload\n];
}
print "}\n";
close $out;
}
}