root/lang/perl/Encode-JP-Mobile/trunk/tools/add-names-by-mapping.pl

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
2use strict;
3use lib "lib";
4
5use warnings;
6use YAML;
7use Encode;
8use Encode::JP::Mobile 0.20;
9use Encode::JP::Mobile::Charnames qw( unicode2name unicode2name_en );
10
11my($file, $to, $force) = @ARGV;
12
13my $dat = YAML::LoadFile($file);
14my $from = ($file =~ /(\w*)-table\.yaml/)[0] or die;
15$to ||= 'docomo';
16
17warn "Updating $from table by mapping to $to pictograms\n";
18
19for 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
34YAML::DumpFile($file, $dat);
Note: See TracBrowser for help on using the browser.