root/lang/perl/HTML-Entities-ConvertPictogramMobileJp/trunk/lib/HTML/Entities/ConvertPictogramMobileJp.pm @ 5341

Revision 5341, 2.4 kB (checked in by tokuhirom, 5 years ago)

hmm... kddi-phone can't display character reference of KDDI-Auto... orz.

Line 
1package HTML::Entities::ConvertPictogramMobileJp;
2use strict;
3use warnings;
4our $VERSION = '0.01';
5use Encode;
6use Encode::JP::Mobile;
7use Params::Validate;
8use base 'Exporter';
9our @EXPORT = qw/convert_pictogram_entities/;
10
11sub convert_pictogram_entities {
12    validate(@_ => +{
13        mobile_agent => +{ isa => 'HTTP::MobileAgent' },
14        html  => 1,
15    });
16    my %args = @_;
17
18    my $content = $args{html};
19    my $agent = $args{mobile_agent};
20    $content =~ s{(&\#x([A-Z0-9]+);)}{
21        if ($agent->is_softbank) {
22            _convert_unicode('softbank', $2)
23        } elsif ($agent->is_ezweb) {
24            sprintf '&#x%X;', unpack 'U*', decode "x-sjis-kddi-cp932-raw", encode( "x-sjis-kddi-auto", chr( hex $2 ));
25        } elsif ($agent->is_docomo && $agent->is_foma) {
26            _convert_unicode('docomo', $2)
27        } elsif (($agent->is_docomo && !$agent->is_foma) || $agent->is_airh_phone) {
28            _convert_sjis('docomo', $2);
29        } else {
30            $1;
31        }
32    }ge;
33    $content;
34}
35
36sub _convert_unicode {
37    my ($carrier, $unihex) = @_;
38    sprintf '&#x%X;', unpack 'U*', decode "x-utf8-$carrier", encode( "x-utf8-$carrier", chr( hex $unihex ));
39}
40
41sub _convert_sjis {
42    my ($carrier, $unihex) = @_;
43
44    sprintf '&#x%s;', uc unpack 'H*', encode("x-sjis-$carrier", chr(hex $unihex));
45}
46
471;
48__END__
49
50=encoding utf8
51
52=for stopwords utf8 pictogram DoCoMo KDDI SJIS SoftBank Unicode KDDI-Auto
53
54=head1 NAME
55
56HTML::Entities::ConvertPictogramMobileJp - convert pictogram entities
57
58=head1 SYNOPSIS
59
60    use HTTP::MobileAgent;
61    use HTML::Entities::ConvertPictogramMobileJp;
62    convert_pictogram_entities(
63        mobile_agent => HTTP::MobileAgent->new,
64        html  => "&#xE001",
65    );
66
67=head1 DESCRIPTION
68
69HTML::Entities::ConvertPictogramMobileJp is Japanese mobile phone's pictogram converter.
70
71HTML 中にふくまれる絵文字の Unicode 16進数値文字参照の DoCoMo 絵文字を、SoftBank/KDDI の絵文字に変換します。
72
73DoCoMo Mova/AirHPhone の場合には、 Unicode 実体参照ではなく SJIS の実体参照に変換して出力
74することに注意してください。これは、該当機種が、 SJIS の実体参照でないと表示できないためです。
75
76=head1 AUTHOR
77
78Tokuhiro Matsuno E<lt>tokuhirom@gmail.comE<gt>
79
80=head1 SEE ALSO
81
82L<Encode::JP::Mobile>
83
84=head1 LICENSE
85
86This library is free software; you can redistribute it and/or modify
87it under the same terms as Perl itself.
88
89=cut
Note: See TracBrowser for help on using the browser.