|
Revision 6289, 0.9 kB
(checked in by tomi-ru, 10 months ago)
|
|
small fix for tools/
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | #!/usr/bin/perl |
|---|
| 2 | use strict; |
|---|
| 3 | use lib "lib"; |
|---|
| 4 | |
|---|
| 5 | use warnings; |
|---|
| 6 | use YAML; |
|---|
| 7 | use Encode; |
|---|
| 8 | use Encode::JP::Mobile 0.20; |
|---|
| 9 | use Encode::JP::Mobile::Charnames qw( unicode2name unicode2name_en ); |
|---|
| 10 | |
|---|
| 11 | my($file, $to, $force) = @ARGV; |
|---|
| 12 | |
|---|
| 13 | my $dat = YAML::LoadFile($file); |
|---|
| 14 | my $from = ($file =~ /(\w*)-table\.yaml/)[0] or die; |
|---|
| 15 | $to ||= 'docomo'; |
|---|
| 16 | |
|---|
| 17 | warn "Updating $from table by mapping to $to pictograms\n"; |
|---|
| 18 | |
|---|
| 19 | for my $r (@$dat) { |
|---|
| 20 | for my $key ( qw( name name_en ) ) { |
|---|
| 21 | next if exists $r->{$key} && !$force; |
|---|
| 22 | my $code = $from eq 'kddi' ? 'unicode_auto' : 'unicode'; |
|---|
| 23 | my $char = chr hex $r->{$code}; |
|---|
| 24 | eval { |
|---|
| 25 | my $mapped = decode("x-utf8-$to", encode("x-utf8-$to", $char, Encode::FB_CROAK)); |
|---|
| 26 | my $func = $key eq 'name' ? \&unicode2name : \&unicode2name_en; |
|---|
| 27 | my $name = $func->(ord $mapped); |
|---|
| 28 | $r->{$key} = encode_utf8($name) if $name; |
|---|
| 29 | }; |
|---|
| 30 | warn $@ if $@; |
|---|
| 31 | } |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | YAML::DumpFile($file, $dat); |
|---|