line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::Han::Utils; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
70368
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
103
|
|
4
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
108
|
|
5
|
3
|
|
|
3
|
|
17
|
use base 'Exporter'; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
288
|
|
6
|
3
|
|
|
3
|
|
17
|
use vars qw/$VERSION @EXPORT_OK/; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
267
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.13'; |
8
|
|
|
|
|
|
|
@EXPORT_OK = qw/Unihan_value csplit cdecode csubstr clength/; |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
3206
|
use Encode; |
|
3
|
|
|
|
|
46682
|
|
|
3
|
|
|
|
|
327
|
|
11
|
3
|
|
|
3
|
|
24029
|
use Encode::Detect::CJK qw(detect); |
|
3
|
|
|
|
|
233838
|
|
|
3
|
|
|
|
|
1499
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub cdecode { |
14
|
9
|
|
|
9
|
1
|
18
|
my $word = shift; |
15
|
9
|
|
|
|
|
212
|
my $encoding = detect($word); |
16
|
9
|
100
|
|
|
|
1961
|
$encoding = 'cp936' if $encoding eq 'iso-8859-1'; # hard fix |
17
|
9
|
|
|
|
|
36
|
$word = decode($encoding, $word); |
18
|
9
|
|
|
|
|
11369
|
return $word; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub Unihan_value { |
22
|
9
|
|
|
9
|
1
|
39
|
my $word = shift; |
23
|
9
|
50
|
|
|
|
78
|
$word = cdecode($word) unless Encode::is_utf8($word); |
24
|
9
|
|
|
|
|
42
|
my @unihan = map { uc sprintf("%x",$_) } unpack ("U*", $word); |
|
21
|
|
|
|
|
95
|
|
25
|
9
|
100
|
|
|
|
78
|
return wantarray?@unihan:(join('', @unihan)); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub csplit { |
29
|
3
|
|
|
3
|
1
|
7
|
my $word = shift; |
30
|
3
|
|
|
|
|
11
|
my $encoding = detect($word); |
31
|
3
|
|
|
|
|
251
|
my @return_words; |
32
|
3
|
|
|
|
|
8
|
my @code = Unihan_value($word); |
33
|
3
|
|
|
|
|
8
|
foreach my $code (@code) { |
34
|
9
|
|
|
|
|
31
|
my $value = pack("U*", hex $code); |
35
|
9
|
|
|
|
|
31
|
$value = encode($encoding, $value); |
36
|
9
|
50
|
|
|
|
235
|
push @return_words, $value if ($value); |
37
|
|
|
|
|
|
|
} |
38
|
3
|
50
|
|
|
|
23
|
return wantarray?@return_words:(join('', @return_words)); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub csubstr { |
42
|
1
|
|
|
1
|
1
|
3
|
my ($word, $offset, $len) = @_; |
43
|
1
|
|
|
|
|
4
|
my @words = csplit($word); |
44
|
1
|
50
|
|
|
|
5
|
$len = scalar @words - $offset unless ($len); |
45
|
1
|
|
|
|
|
5
|
@words = splice(@words, $offset, $len); |
46
|
1
|
50
|
|
|
|
9
|
return wantarray?@words:(join('', @words)); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub clength { |
50
|
1
|
|
|
1
|
1
|
3
|
my $word = shift; |
51
|
1
|
|
|
|
|
5
|
my @words = csplit($word); |
52
|
1
|
|
|
|
|
6
|
return scalar @words; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
__END__ |