root/lang/perl/Encode-JP-Mobile/tags/0.09/lib/Encode/JP/Mobile/Vodafone.pm @ 1737

Revision 1737, 1.7 kB (checked in by xcezx, 6 years ago)

/dotfiles/irssi/xcezx-config: 最近の。

  • lang/parl/irssi/scripts/delicious.pl: Finds URLs and posts them to del.icio.us on irssi
  • Property svn:keywords set to Id Revision
Line 
1package Encode::JP::Mobile::Vodafone;
2use strict;
3use base qw(Encode::Encoding);
4__PACKAGE__->Define(qw(x-sjis-vodafone));
5
6use Encode::Alias;
7define_alias('x-sjis-softbank' => 'x-sjis-vodafone');
8define_alias('shift_jis-softbank' => 'x-sjis-softbank');
9define_alias('shift_jis-vodafone' => 'x-sjis-vodafone');
10
11# G! => E001, G" => E002, G# => E003 ...
12# E! => E101, F! => E201, O! => E301, P! => E401, Q! => E501
13my %HighCharToBit = (G => 0xE000, E => 0xE100, F => 0xE200,
14                     O => 0xE300, P => 0xE400, Q => 0xE500);
15my %HighBitToChar = reverse %HighCharToBit;
16
17my $range = '\x{E001}-\x{E05A}\x{E101}-\x{E15A}\x{E201}-\x{E25A}\x{E301}-\x{E34D}\x{E401}-\x{E44C}\x{E501}-\x{E539}';
18my $InRange  = "[$range]";
19my $OutRange = "[^$range]";
20
21sub decode($$;$) {
22    my($self, $char, $check) = @_;
23    my $str = Encode::decode("cp932", $char, Encode::FB_PERLQQ);
24    $str =~ s{\x1b\x24([GEFOPQ])([\x20-\x7F]+)\x0f}{
25        join '', map chr($HighCharToBit{$1} | ord($_) - 32), split //, $2;
26    }ge;
27    $_[1] = $str if $check;
28    $str;
29}
30
31sub encode($$;$) {
32    my($self, $str, $check) = @_;
33    my $res = '';
34    $str =~ s{($InRange+)|($OutRange+)}{
35        my $in = defined $1;
36        my $m  = $in ? $1 : $2;
37        $res .= $in ? _encode_vodafone($m)
38            : Encode::encode("cp932", $m, $check);
39        ''
40    }egs;
41    $_[1] = $res if $check;
42    $res;
43}
44
45sub _encode_vodafone {
46    my $str = shift;
47    my @str = split //, $str;
48    my $res = "\x1b\x24";
49    my $buf = '';
50    for my $str (@str) {
51        my $high = ord($str) & 0xEF00;
52        my $low  = ord($str) & 0x00FF;
53        if ($buf ne $high) {
54            $res .= $HighBitToChar{$high};
55        }
56        $res .= chr($low+32);
57        $buf = $high;
58    }
59    $res . "\x0f";
60}
61
621;
Note: See TracBrowser for help on using the browser.