line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Entities::ImodePictogram; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
45080
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
141
|
|
4
|
2
|
|
|
2
|
|
10
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
121
|
|
5
|
|
|
|
|
|
|
$VERSION = 0.06; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
10
|
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
260
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
@EXPORT = qw(encode_pictogram decode_pictogram remove_pictogram); |
11
|
|
|
|
|
|
|
@EXPORT_OK = qw(find_pictogram); |
12
|
|
|
|
|
|
|
%EXPORT_TAGS = ( all => [ @EXPORT, @EXPORT_OK ] ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $one_byte = '[\x00-\x7F\xA1-\xDF]'; |
15
|
|
|
|
|
|
|
my $two_bytes = '[\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC]'; |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
2
|
|
10
|
use vars qw($Sjis_re $Pictogram_re $ExtPictorgram_re); |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
1453
|
|
18
|
|
|
|
|
|
|
$Sjis_re = qr<$one_byte|$two_bytes>; |
19
|
|
|
|
|
|
|
$Pictogram_re = '\xF8[\x9F-\xFC]|\xF9[\x40-\x7E\x80-\xB0]'; |
20
|
|
|
|
|
|
|
$ExtPictorgram_re = '\xF9[\xB1-\xFC]'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub find_pictogram (\$&) { |
23
|
7
|
|
|
7
|
1
|
13
|
my($r_text, $callback) = @_; |
24
|
|
|
|
|
|
|
|
25
|
7
|
|
|
|
|
11
|
my $num_found = 0; |
26
|
7
|
|
|
|
|
201
|
$$r_text =~ s{(($Pictogram_re)|($ExtPictorgram_re)|$Sjis_re)}{ |
27
|
60
|
|
|
|
|
137
|
my $orig_match = $1; |
28
|
60
|
100
|
100
|
|
|
250
|
if (defined $2 || defined $3) { |
29
|
18
|
|
|
|
|
21
|
$num_found++; |
30
|
18
|
|
|
|
|
39
|
my $number = unpack 'n', $orig_match; |
31
|
18
|
|
|
|
|
61
|
$callback->($orig_match, $number, _num2cp($number)); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
42
|
|
|
|
|
152
|
$orig_match; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
}eg; |
37
|
|
|
|
|
|
|
|
38
|
7
|
|
|
|
|
32
|
return $num_found; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub encode_pictogram { |
42
|
3
|
|
|
3
|
1
|
29
|
my($text, %opt) = @_; |
43
|
|
|
|
|
|
|
find_pictogram($text, sub { |
44
|
8
|
|
|
8
|
|
19
|
my($char, $number, $cp) = @_; |
45
|
8
|
100
|
100
|
|
|
43
|
if ($opt{unicode} || $cp >= 59148) { |
46
|
5
|
|
|
|
|
36
|
return sprintf '%x;', $cp; |
47
|
|
|
|
|
|
|
} else { |
48
|
3
|
|
|
|
|
20
|
return '' . $number . ';'; |
49
|
|
|
|
|
|
|
} |
50
|
3
|
|
|
|
|
29
|
}); |
51
|
3
|
|
|
|
|
35
|
return $text; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub decode_pictogram { |
55
|
3
|
|
|
3
|
1
|
6
|
my $html = shift; |
56
|
3
|
|
|
|
|
25
|
$html =~ s{(\&\#(\d{5});)|(\&\#x([0-9a-fA-F]{4});)}{ |
57
|
8
|
100
|
|
|
|
35
|
if (defined $1) { |
|
|
50
|
|
|
|
|
|
58
|
3
|
|
|
|
|
9
|
my $cp = _num2cp($2); |
59
|
3
|
50
|
|
|
|
25
|
defined $cp ? pack('n', $2) : $1; |
60
|
|
|
|
|
|
|
} elsif (defined $3) { |
61
|
5
|
|
|
|
|
15
|
my $num = _cp2num(hex($4)); |
62
|
5
|
50
|
|
|
|
36
|
defined $num ? pack('n', $num) : $3; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
}eg; |
65
|
3
|
|
|
|
|
16
|
return $html; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub remove_pictogram { |
69
|
2
|
|
|
2
|
1
|
4
|
my $text = shift; |
70
|
|
|
|
|
|
|
find_pictogram($text, sub { |
71
|
5
|
|
|
5
|
|
19
|
return ''; |
72
|
2
|
|
|
|
|
13
|
}); |
73
|
2
|
|
|
|
|
16
|
return $text; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _num2cp { |
77
|
21
|
|
|
21
|
|
29
|
my $num = shift; |
78
|
21
|
100
|
66
|
|
|
220
|
if ($num >= 63647 && $num <= 63740) { |
|
|
50
|
33
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
79
|
13
|
|
|
|
|
35
|
return $num - 4705; |
80
|
|
|
|
|
|
|
} elsif (($num >= 63808 && $num <= 63817) || |
81
|
|
|
|
|
|
|
($num >= 63824 && $num <= 63838) || |
82
|
|
|
|
|
|
|
($num >= 63858 && $num <= 63870)) { |
83
|
0
|
|
|
|
|
0
|
return $num - 4772; |
84
|
|
|
|
|
|
|
} elsif ($num >= 63872 && $num <= 63996) { |
85
|
8
|
|
|
|
|
25
|
return $num - 4773; |
86
|
|
|
|
|
|
|
} else { |
87
|
0
|
|
|
|
|
0
|
return; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _cp2num { |
92
|
5
|
|
|
5
|
|
7
|
my $cp = shift; |
93
|
5
|
100
|
66
|
|
|
96
|
if ($cp >= 58942 && $cp <= 59035) { |
|
|
50
|
33
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
94
|
1
|
|
|
|
|
2
|
return $cp + 4705; |
95
|
|
|
|
|
|
|
} elsif (($cp >= 59036 && $cp <= 59045) || |
96
|
|
|
|
|
|
|
($cp >= 59052 && $cp <= 59066) || |
97
|
|
|
|
|
|
|
($cp >= 59086 && $cp <= 59098)) { |
98
|
0
|
|
|
|
|
0
|
return $cp + 4772; |
99
|
|
|
|
|
|
|
} elsif (($cp >= 59099 && $cp <= 59146) || |
100
|
|
|
|
|
|
|
($cp >= 59148 && $cp <= 59223)) { |
101
|
4
|
|
|
|
|
8
|
return $cp + 4773; |
102
|
|
|
|
|
|
|
} else { |
103
|
0
|
|
|
|
|
|
return; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
__END__ |