line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Unicode::EastAsianWidth::Detect; |
2
|
2
|
|
|
2
|
|
21272
|
use 5.008005; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
60
|
|
3
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
63
|
|
4
|
2
|
|
|
2
|
|
18
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
67
|
|
5
|
2
|
|
|
2
|
|
1753
|
use POSIX qw(setlocale LC_CTYPE); |
|
2
|
|
|
|
|
13730
|
|
|
2
|
|
|
|
|
14
|
|
6
|
2
|
|
|
2
|
|
2230
|
use base 'Exporter'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1239
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw/is_cjk_lang /; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# based on https://sourceware.org/cgi-bin/cvsweb.cgi/src/newlib/libc/locale/locale.c?rev=1.51&content-type=text/x-cvsweb-markup&cvsroot=src |
12
|
|
|
|
|
|
|
sub is_cjk_lang { |
13
|
7
|
|
33
|
7
|
0
|
31
|
my $locale = shift || setlocale(LC_CTYPE); |
14
|
|
|
|
|
|
|
# ignore C locale |
15
|
7
|
100
|
|
|
|
28
|
return 0 if $locale eq 'POSIX'; |
16
|
6
|
100
|
66
|
|
|
37
|
return 0 if $locale eq 'C' || $locale =~ /^C[-.]/; |
17
|
5
|
|
|
|
|
9
|
my $charset = $locale; |
18
|
5
|
50
|
|
|
|
17
|
if ($^O eq 'MSWin32') { |
19
|
0
|
|
|
|
|
0
|
$charset =~ s/^[a-zA-Z][a-zA-Z]+(?:_[a-zA-Z][a-zA-Z]+)?\.(.+)/$1/; |
20
|
0
|
0
|
|
|
|
0
|
$charset = "cp$charset" if $charset =~ /^[0-9]+$/; |
21
|
|
|
|
|
|
|
} else { |
22
|
5
|
|
|
|
|
33
|
$charset =~ s/^[a-z][a-z][a-z]?(?:_[A-Z][A-Z])?\.(.+)/$1/; |
23
|
|
|
|
|
|
|
} |
24
|
5
|
50
|
|
|
|
13
|
return unless $charset; |
25
|
5
|
|
|
|
|
9
|
my $cjk_narrow = $charset =~ /\@cjknarrow$/; |
26
|
5
|
|
|
|
|
10
|
$charset =~ s/@.*//; |
27
|
5
|
0
|
|
|
|
44
|
my $mbc_max = |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$charset =~ /^utf-?8$/i ? 6 : |
29
|
|
|
|
|
|
|
$charset =~ /^jis$/i ? 8 : |
30
|
|
|
|
|
|
|
$charset =~ /^eucjp$/i ? 3 : |
31
|
|
|
|
|
|
|
$charset =~ /^euc(?:kr|cn)$/i ? 2 : |
32
|
|
|
|
|
|
|
$charset =~ /^(?:sjis|cp932)$/i ? 2 : |
33
|
|
|
|
|
|
|
$charset =~ /^big5$/i ? 2 : |
34
|
|
|
|
|
|
|
$charset =~ /^(?:gbk|gb2312)$/i ? 2 : 1; |
35
|
5
|
100
|
33
|
|
|
83
|
return !$cjk_narrow |
36
|
|
|
|
|
|
|
&& $mbc_max > 1 |
37
|
|
|
|
|
|
|
&& ($charset !~ /^U/ |
38
|
|
|
|
|
|
|
|| $locale =~ /^ja/ |
39
|
|
|
|
|
|
|
|| $locale =~ /^ko/ |
40
|
|
|
|
|
|
|
|| $locale =~ /^zh/) ? 1 : 0; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
__END__ |