Permalink
Browse files

Unicodeによる表記に対応した

  • Loading branch information...
1 parent 54b8ce6 commit f0019c979235641e1e6c2f49189ed69fba6e092a @tokuhirom committed Oct 8, 2010
View
58 author/mktbl.pl
@@ -1,21 +1,64 @@
use strict;
use warnings;
+use autodie;
use JSON;
use Data::Dumper;
use LWP::Simple;
+use File::Basename;
+use File::Spec;
+
+my $c_docomo = slurp_json('http://svn.openpear.org/Text_Pictogram_Mobile/trunk/data/docomo_convert.json')->{docomo};
+my $e_docomo = slurp_json('http://svn.openpear.org/Text_Pictogram_Mobile/trunk/data/docomo_emoji.json')->{docomo};
+my $e_softbank = slurp_json('http://svn.openpear.org/Text_Pictogram_Mobile/trunk/data/softbank_emoji.json')->{softbank};
&main;exit;
sub main {
+ make_unicode_number_map();
+ make_emoji_number_map();
+
+ exit;
+}
+
+sub make_unicode_number_map {
+ my $ezweb; # "docomo unicode" to "ez emoji number"
+ my $softbank; # "docomo unicode" to "softbank unicode"
+
+ while (my ($docomo_id, $val) = each %$c_docomo) {
+ if ($val->{ezweb} =~ /^\d+$/) {
+ $ezweb->{$e_docomo->{$docomo_id}->{unicode}} = $val->{ezweb};
+ }
+ if ($val->{softbank} =~ /^\d+$/) {
+ $softbank->{$e_docomo->{$docomo_id}->{unicode}} = $e_softbank->{$val->{softbank}}->{unicode};
+ }
+ }
+
+ my $ofname = File::Spec->catfile(dirname(__FILE__), '..', "lib/HTML/Pictogram/MobileJp/Unicode/Map.pm");
+ open my $fh, ">:utf8", $ofname;
+ select $fh;
+ local $Data::Dumper::Sortkeys = 1;
+ local $Data::Dumper::Terse = 1;
+ print "package HTML::Pictogram::MobileJp::Unicode::Map;\n";
+ print "use strict;\n";
+ print "use warnings;\n";
+ print "# This file was generated automatically.\n";
+ print "use base qw/Exporter/;\n";
+ print "our \@EXPORT = qw/\$EZWEB \$SOFTBANK/;\n";
+ print "our \$EZWEB = ";
+ print Dumper($ezweb);
+ print ";\n";
+ print "our \$SOFTBANK = ";
+ print Dumper($softbank);
+ print ";\n";
+ print "1;\n";
+ close $fh;
+}
+
+sub make_emoji_number_map {
my $docomo;
my $ezweb;
my $softbank;
- my $au;
-
- my $c_docomo = slurp_json('http://svn.openpear.org/Text_Pictogram_Mobile/trunk/data/docomo_convert.json')->{docomo};
- my $e_docomo = slurp_json('http://svn.openpear.org/Text_Pictogram_Mobile/trunk/data/docomo_emoji.json')->{docomo};
- my $e_softbank = slurp_json('http://svn.openpear.org/Text_Pictogram_Mobile/trunk/data/softbank_emoji.json')->{softbank};
while (my ($docomo_id, $val) = each %$c_docomo) {
$ezweb->{$docomo_id} = $val->{ezweb};
$docomo->{$docomo_id} = $e_docomo->{$docomo_id}->{unicode};
@@ -26,6 +69,9 @@ sub main {
}
}
+ my $ofname = File::Spec->catfile(dirname(__FILE__), '..', "lib/HTML/Pictogram/MobileJp/EmojiNumber/Map.pm");
+ open my $fh, ">:utf8", $ofname;
+ select $fh;
local $Data::Dumper::Sortkeys = 1;
local $Data::Dumper::Terse = 1;
print "package HTML::Pictogram::MobileJp::EmojiNumber::Map;\n";
@@ -44,7 +90,7 @@ sub main {
print Dumper($softbank);
print ";\n";
print "1;\n";
- exit;
+ close $fh;
}
sub slurp_json {
View
2 lib/HTML/Pictogram/MobileJp/EmojiNumber.pm
@@ -63,6 +63,8 @@ HTML::Pictogram::MobileJp::EmojiNumber - [emoji:1] みたいに絵文字を記
絵文字の変換マップは Text_Pictogram_Mobile のものを拝借してます。
+変換不可能な絵文字は、絵文字の名称が表示されます。
+
=head1 AUTHOR
Tokuhiro Matsuno E<lt>tokuhirom AAJKLFJEF GMAIL COME<gt>
View
1 lib/HTML/Pictogram/MobileJp/EmojiNumber/Map.pm
@@ -1,5 +1,6 @@
package HTML::Pictogram::MobileJp::EmojiNumber::Map;
use strict;
+use warnings;
# This file was generated automatically.
use base qw/Exporter/;
our @EXPORT = qw/$DOCOMO $EZWEB $SOFTBANK/;
View
76 lib/HTML/Pictogram/MobileJp/Unicode.pm
@@ -0,0 +1,76 @@
+package HTML::Pictogram::MobileJp::Unicode;
+use strict;
+use warnings;
+use 5.00800;
+use HTML::Pictogram::MobileJp::Unicode::Map;
+
+sub convert {
+ my ( $class, $ma, $html ) = @_;
+
+ $html =~ s{(&#x([0-9a-f]{4});)}{
+ if ($ma->is_docomo) {
+ $1;
+ } elsif ($ma->is_softbank) {
+ if (my $e = $SOFTBANK->{$2}) {
+ "&#x$e;";
+ } else {
+ $1;
+ }
+ } elsif ($ma->is_ezweb) {
+ if (my $e = $EZWEB->{$2}) {
+ sprintf '<img localsrc="%d" />', $e;
+ } else {
+ $1;
+ }
+ } else {
+ # non-mobile
+ $1;
+ }
+ }gei;
+
+ $html;
+}
+
+1;
+__END__
+
+=encoding utf8
+
+=head1 NAME
+
+HTML::Pictogram::MobileJp::Unicode - &#xXXXX; とかくと3キャリで表示できるように変換できるライブラリ
+
+=head1 SYNOPSIS
+
+ use HTML::Pictogram::MobileJp::Unicode;
+ use HTTP::MobileAgent;
+
+ my $ma = HTTP::MobileAgent->new();
+ HTML::Pictogram::MobileJp::Unicode->convert($ma, $html);
+
+=head1 DESCRIPTION
+
+&#xXXXX; のようにユニコードの実体参照で絵文字を記述しておくと、それを各キャリヤにあわせた表記に変更してくれるライブラリ。
+
+サポート対象は 3G の3キャリです。
+
+絵文字の変換マップは Text_Pictogram_Mobile のものを拝借してます。
+
+絵文字として変換可能ではない &#xXXXX; は、変更されません。
+
+=head1 AUTHOR
+
+Tokuhiro Matsuno E<lt>tokuhirom AAJKLFJEF GMAIL COME<gt>
+
+=head1 SEE ALSO
+
+L<http://openpear.org/package/Text_Pictogram_Mobile>
+
+=head1 LICENSE
+
+Copyright (C) Tokuhiro Matsuno
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
View
442 lib/HTML/Pictogram/MobileJp/Unicode/Map.pm
@@ -0,0 +1,442 @@
+package HTML::Pictogram::MobileJp::Unicode::Map;
+use strict;
+use warnings;
+# This file was generated automatically.
+use base qw/Exporter/;
+our @EXPORT = qw/$EZWEB $SOFTBANK/;
+our $EZWEB = {
+ 'E63E' => '44',
+ 'E63F' => '107',
+ 'E640' => '95',
+ 'E641' => '191',
+ 'E642' => '16',
+ 'E643' => '190',
+ 'E644' => '305',
+ 'E645' => '481',
+ 'E646' => '192',
+ 'E647' => '193',
+ 'E648' => '194',
+ 'E649' => '195',
+ 'E64A' => '196',
+ 'E64B' => '197',
+ 'E64C' => '198',
+ 'E64D' => '199',
+ 'E64E' => '200',
+ 'E64F' => '201',
+ 'E650' => '202',
+ 'E651' => '203',
+ 'E653' => '45',
+ 'E654' => '306',
+ 'E655' => '220',
+ 'E656' => '219',
+ 'E657' => '421',
+ 'E658' => '307',
+ 'E659' => '222',
+ 'E65A' => '308',
+ 'E65B' => '172',
+ 'E65C' => '341',
+ 'E65D' => '217',
+ 'E65E' => '125',
+ 'E65F' => '125',
+ 'E660' => '216',
+ 'E661' => '379',
+ 'E662' => '168',
+ 'E663' => '112',
+ 'E664' => '156',
+ 'E665' => '375',
+ 'E666' => '376',
+ 'E667' => '212',
+ 'E668' => '205',
+ 'E669' => '378',
+ 'E66A' => '206',
+ 'E66B' => '213',
+ 'E66C' => '208',
+ 'E66D' => '99',
+ 'E66E' => '207',
+ 'E66F' => '146',
+ 'E670' => '93',
+ 'E671' => '52',
+ 'E672' => '65',
+ 'E673' => '245',
+ 'E674' => '124',
+ 'E675' => '104',
+ 'E676' => '289',
+ 'E677' => '110',
+ 'E678' => '70',
+ 'E67A' => '294',
+ 'E67B' => '309',
+ 'E67C' => '494',
+ 'E67D' => '311',
+ 'E67E' => '106',
+ 'E67F' => '176',
+ 'E680' => '177',
+ 'E681' => '94',
+ 'E682' => '83',
+ 'E683' => '122',
+ 'E684' => '312',
+ 'E685' => '144',
+ 'E686' => '313',
+ 'E687' => '85',
+ 'E688' => '161',
+ 'E689' => '395',
+ 'E68A' => '288',
+ 'E68B' => '232',
+ 'E68C' => '300',
+ 'E68D' => '414',
+ 'E68E' => '314',
+ 'E68F' => '315',
+ 'E690' => '316',
+ 'E691' => '317',
+ 'E692' => '318',
+ 'E693' => '817',
+ 'E694' => '319',
+ 'E695' => '320',
+ 'E696' => '43',
+ 'E697' => '42',
+ 'E698' => '728',
+ 'E699' => '729',
+ 'E69A' => '116',
+ 'E69B' => '178',
+ 'E69C' => '321',
+ 'E69D' => '322',
+ 'E69E' => '323',
+ 'E69F' => '15',
+ 'E6A1' => '134',
+ 'E6A2' => '251',
+ 'E6A3' => '169',
+ 'E6A4' => '234',
+ 'E6A5' => '71',
+ 'E6AC' => '226',
+ 'E6AE' => '508',
+ 'E6B3' => '490',
+ 'E6BA' => '46',
+ 'E6CE' => '513',
+ 'E6CF' => '784',
+ 'E6D0' => '166',
+ 'E6D3' => '108',
+ 'E6D6' => '109',
+ 'E6D7' => '299',
+ 'E6D8' => '385',
+ 'E6D9' => '120',
+ 'E6DA' => '118',
+ 'E6DB' => '324',
+ 'E6DC' => '119',
+ 'E6DD' => '334',
+ 'E6DE' => '730',
+ 'E6E0' => '818',
+ 'E6E1' => '4',
+ 'E6E2' => '180',
+ 'E6E3' => '181',
+ 'E6E4' => '182',
+ 'E6E5' => '183',
+ 'E6E6' => '184',
+ 'E6E7' => '185',
+ 'E6E8' => '186',
+ 'E6E9' => '187',
+ 'E6EA' => '188',
+ 'E6EB' => '325',
+ 'E6EC' => '51',
+ 'E6ED' => '803',
+ 'E6EE' => '265',
+ 'E6EF' => '266',
+ 'E6F0' => '257',
+ 'E6F1' => '258',
+ 'E6F2' => '441',
+ 'E6F3' => '444',
+ 'E6F4' => '327',
+ 'E6F5' => '731',
+ 'E6F6' => '343',
+ 'E6F7' => '224',
+ 'E6F9' => '273',
+ 'E6FA' => '420',
+ 'E6FB' => '77',
+ 'E6FC' => '262',
+ 'E6FD' => '281',
+ 'E6FE' => '268',
+ 'E6FF' => '291',
+ 'E700' => '732',
+ 'E701' => '261',
+ 'E702' => '2',
+ 'E703' => '733',
+ 'E704' => '734',
+ 'E705' => '329',
+ 'E706' => '330',
+ 'E707' => '263',
+ 'E708' => '282',
+ 'E70A' => '735',
+ 'E70B' => '326',
+ 'E70E' => '335',
+ 'E70F' => '290',
+ 'E710' => '295',
+ 'E711' => '805',
+ 'E712' => '221',
+ 'E713' => '48',
+ 'E715' => '233',
+ 'E716' => '337',
+ 'E717' => '806',
+ 'E718' => '152',
+ 'E719' => '149',
+ 'E71A' => '354',
+ 'E71B' => '72',
+ 'E71C' => '58',
+ 'E71D' => '215',
+ 'E71E' => '423',
+ 'E71F' => '25',
+ 'E720' => '441',
+ 'E721' => '446',
+ 'E723' => '351',
+ 'E724' => '779',
+ 'E725' => '450',
+ 'E726' => '349',
+ 'E727' => '287',
+ 'E728' => '264',
+ 'E729' => '348',
+ 'E72A' => '446',
+ 'E72B' => '443',
+ 'E72C' => '440',
+ 'E72D' => '259',
+ 'E72E' => '791',
+ 'E730' => '143',
+ 'E731' => '81',
+ 'E732' => '54',
+ 'E733' => '218',
+ 'E734' => '279',
+ 'E735' => '807',
+ 'E736' => '82',
+ 'E737' => '1',
+ 'E739' => '387',
+ 'E73B' => '386',
+ 'E73C' => '808',
+ 'E73D' => '809',
+ 'E73E' => '377',
+ 'E73F' => '810',
+ 'E740' => '342',
+ 'E741' => '53',
+ 'E742' => '241',
+ 'E743' => '113',
+ 'E744' => '739',
+ 'E745' => '434',
+ 'E746' => '811',
+ 'E747' => '133',
+ 'E748' => '235',
+ 'E749' => '244',
+ 'E74A' => '239',
+ 'E74B' => '400',
+ 'E74C' => '333',
+ 'E74D' => '424',
+ 'E74E' => '812',
+ 'E74F' => '78',
+ 'E750' => '252',
+ 'E751' => '203',
+ 'E752' => '454',
+ 'E753' => '814',
+ 'E754' => '248',
+ 'E755' => '254',
+ 'E756' => '12',
+ 'E757' => '350'
+}
+;
+our $SOFTBANK = {
+ 'E63E' => 'E04A',
+ 'E63F' => 'E049',
+ 'E640' => 'E04B',
+ 'E641' => 'E048',
+ 'E642' => 'E13D',
+ 'E643' => 'E443',
+ 'E645' => 'E43C',
+ 'E646' => 'E23F',
+ 'E647' => 'E240',
+ 'E648' => 'E241',
+ 'E649' => 'E242',
+ 'E64A' => 'E243',
+ 'E64B' => 'E244',
+ 'E64C' => 'E245',
+ 'E64D' => 'E246',
+ 'E64E' => 'E247',
+ 'E64F' => 'E248',
+ 'E650' => 'E249',
+ 'E651' => 'E24A',
+ 'E653' => 'E016',
+ 'E654' => 'E014',
+ 'E655' => 'E015',
+ 'E656' => 'E018',
+ 'E657' => 'E013',
+ 'E658' => 'E42A',
+ 'E659' => 'E132',
+ 'E65B' => 'E01E',
+ 'E65C' => 'E434',
+ 'E65D' => 'E435',
+ 'E65E' => 'E01B',
+ 'E65F' => 'E42E',
+ 'E660' => 'E159',
+ 'E661' => 'E202',
+ 'E662' => 'E01D',
+ 'E663' => 'E036',
+ 'E664' => 'E038',
+ 'E665' => 'E153',
+ 'E666' => 'E155',
+ 'E667' => 'E14D',
+ 'E668' => 'E154',
+ 'E669' => 'E158',
+ 'E66A' => 'E156',
+ 'E66B' => 'E03A',
+ 'E66C' => 'E14F',
+ 'E66D' => 'E14E',
+ 'E66E' => 'E151',
+ 'E66F' => 'E043',
+ 'E670' => 'E045',
+ 'E671' => 'E044',
+ 'E672' => 'E047',
+ 'E673' => 'E120',
+ 'E674' => 'E13E',
+ 'E675' => 'E313',
+ 'E676' => 'E03C',
+ 'E677' => 'E03D',
+ 'E678' => 'E236',
+ 'E67A' => 'E30A',
+ 'E67B' => 'E502',
+ 'E67C' => 'E503',
+ 'E67E' => 'E125',
+ 'E67F' => 'E30E',
+ 'E680' => 'E208',
+ 'E681' => 'E008',
+ 'E682' => 'E323',
+ 'E683' => 'E148',
+ 'E684' => 'E314',
+ 'E685' => 'E112',
+ 'E686' => 'E34B',
+ 'E687' => 'E009',
+ 'E688' => 'E00A',
+ 'E689' => 'E301',
+ 'E68A' => 'E12A',
+ 'E68C' => 'E126',
+ 'E68D' => 'E20C',
+ 'E68E' => 'E20E',
+ 'E68F' => 'E20D',
+ 'E690' => 'E20F',
+ 'E691' => 'E419',
+ 'E692' => 'E41B',
+ 'E693' => 'E010',
+ 'E694' => 'E011',
+ 'E695' => 'E012',
+ 'E696' => 'E238',
+ 'E697' => 'E237',
+ 'E698' => 'E536',
+ 'E699' => 'E007',
+ 'E69B' => 'E20A',
+ 'E69D' => 'E04C',
+ 'E69E' => 'E04C',
+ 'E69F' => 'E04C',
+ 'E6A1' => 'E052',
+ 'E6A2' => 'E04F',
+ 'E6A3' => 'E01C',
+ 'E6A4' => 'E033',
+ 'E6A5' => 'E239',
+ 'E6AC' => 'E324',
+ 'E6B2' => 'E11F',
+ 'E6B3' => 'E44B',
+ 'E6BA' => 'E02D',
+ 'E6CE' => 'E104',
+ 'E6CF' => 'E103',
+ 'E6D0' => 'E00B',
+ 'E6D3' => 'E103',
+ 'E6D8' => 'E229',
+ 'E6D9' => 'E03F',
+ 'E6DC' => 'E114',
+ 'E6DD' => 'E212',
+ 'E6DF' => 'E211',
+ 'E6E0' => 'E210',
+ 'E6E2' => 'E21C',
+ 'E6E3' => 'E21D',
+ 'E6E4' => 'E21E',
+ 'E6E5' => 'E21F',
+ 'E6E6' => 'E220',
+ 'E6E7' => 'E221',
+ 'E6E8' => 'E222',
+ 'E6E9' => 'E223',
+ 'E6EA' => 'E224',
+ 'E6EB' => 'E225',
+ 'E6EC' => 'E022',
+ 'E6ED' => 'E327',
+ 'E6EE' => 'E023',
+ 'E6EF' => 'E327',
+ 'E6F0' => 'E057',
+ 'E6F1' => 'E059',
+ 'E6F2' => 'E058',
+ 'E6F3' => 'E407',
+ 'E6F4' => 'E406',
+ 'E6F5' => 'E236',
+ 'E6F6' => 'E03E',
+ 'E6F7' => 'E123',
+ 'E6F9' => 'E003',
+ 'E6FA' => 'E32E',
+ 'E6FB' => 'E10F',
+ 'E6FC' => 'E334',
+ 'E6FD' => 'E00D',
+ 'E6FE' => 'E311',
+ 'E6FF' => 'E326',
+ 'E700' => 'E238',
+ 'E701' => 'E13C',
+ 'E702' => 'E021',
+ 'E706' => 'E331',
+ 'E707' => 'E331',
+ 'E708' => 'E330',
+ 'E70B' => 'E24D',
+ 'E70E' => 'E006',
+ 'E710' => 'E31C',
+ 'E713' => 'E325',
+ 'E715' => 'E12F',
+ 'E716' => 'E00C',
+ 'E719' => 'E301',
+ 'E71A' => 'E10E',
+ 'E71B' => 'E034',
+ 'E71D' => 'E136',
+ 'E71E' => 'E338',
+ 'E720' => 'E403',
+ 'E721' => 'E40A',
+ 'E723' => 'E108',
+ 'E724' => 'E416',
+ 'E725' => 'E40E',
+ 'E726' => 'E106',
+ 'E727' => 'E00E',
+ 'E728' => 'E105',
+ 'E729' => 'E405',
+ 'E72A' => 'E40A',
+ 'E72B' => 'E406',
+ 'E72C' => 'E402',
+ 'E72D' => 'E411',
+ 'E72E' => 'E413',
+ 'E731' => 'E24E',
+ 'E732' => 'E537',
+ 'E733' => 'E115',
+ 'E734' => 'E315',
+ 'E736' => 'E24F',
+ 'E737' => 'E252',
+ 'E739' => 'E22B',
+ 'E73B' => 'E22A',
+ 'E73E' => 'E157',
+ 'E73F' => 'E43E',
+ 'E740' => 'E03B',
+ 'E741' => 'E110',
+ 'E743' => 'E304',
+ 'E745' => 'E345',
+ 'E746' => 'E110',
+ 'E747' => 'E118',
+ 'E748' => 'E030',
+ 'E749' => 'E342',
+ 'E74A' => 'E046',
+ 'E74B' => 'E30B',
+ 'E74C' => 'E340',
+ 'E74D' => 'E339',
+ 'E74F' => 'E523',
+ 'E750' => 'E055',
+ 'E751' => 'E019',
+ 'E752' => 'E056',
+ 'E753' => 'E404',
+ 'E754' => 'E01A',
+ 'E755' => 'E10B',
+ 'E756' => 'E044',
+ 'E757' => 'E107'
+}
+;
+1;
View
0 t/01_simple.t → t/01_emoji_number.t
File renamed without changes.
View
24 t/02_unicode.t
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+use utf8;
+use HTML::Pictogram::MobileJp::Unicode;
+use Test::MobileAgent qw/:all/;
+use Test::More;
+use HTTP::MobileAgent;
+
+xxx('docomo', '&#xE63E;', '&#xE63E;');
+xxx('ezweb', '&#xE63E;', '<img localsrc="44" />');
+xxx('softbank', '&#xE63E;', '&#xE04A;');
+xxx('nonmobile', '&#xE63E;', '&#xE63E;');
+
+xxx('docomo', '&#xE70C;', '&#xE70C;'); # 拡張絵文字
+xxx('softbank', '&#xE69A;', '&#xE69A;'); # unmapped
+
+done_testing;
+
+sub xxx {
+ my ($type, $html, $expected) = @_;
+ my $ma = HTTP::MobileAgent->new(test_mobile_agent_headers($type));
+ is(HTML::Pictogram::MobileJp::Unicode->convert($ma, $html), $expected);
+}
+

0 comments on commit f0019c9

Please sign in to comment.