line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::VisualWidth::PP; |
2
|
6
|
|
|
6
|
|
451011
|
use strict; |
|
6
|
|
|
|
|
71
|
|
|
6
|
|
|
|
|
219
|
|
3
|
6
|
|
|
6
|
|
48
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
216
|
|
4
|
6
|
|
|
6
|
|
219
|
use 5.008001; |
|
6
|
|
|
|
|
29
|
|
5
|
6
|
|
|
6
|
|
2385
|
use parent qw(Exporter); |
|
6
|
|
|
|
|
2015
|
|
|
6
|
|
|
|
|
42
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
7
|
6
|
|
|
6
|
|
1553
|
use Unicode::EastAsianWidth; |
|
6
|
|
|
|
|
2051
|
|
|
6
|
|
|
|
|
2657
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(vwidth vtrim); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $EastAsian = $Unicode::EastAsianWidth::EastAsian; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub Spacing { |
14
|
10
|
|
|
10
|
0
|
198
|
$_[0] . <
|
15
|
|
|
|
|
|
|
-utf8::Nonspacing_Mark |
16
|
|
|
|
|
|
|
END |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub InVWPP1Fullwidth() { |
20
|
2
|
|
|
2
|
0
|
345
|
Spacing |
21
|
|
|
|
|
|
|
InEastAsianFullwidth() . InEastAsianWide() . InEastAsianAmbiguous() |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
sub InVWPP0Fullwidth() { |
24
|
4
|
|
|
4
|
0
|
907
|
Spacing |
25
|
|
|
|
|
|
|
InEastAsianFullwidth() . InEastAsianWide() |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
sub InVWPP1Halfwidth() { |
28
|
0
|
|
|
0
|
0
|
0
|
Spacing |
29
|
|
|
|
|
|
|
InEastAsianHalfwidth(). |
30
|
|
|
|
|
|
|
InEastAsianNarrow(). |
31
|
|
|
|
|
|
|
InEastAsianNeutral() |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
sub InVWPP0Halfwidth() { |
34
|
4
|
|
|
4
|
0
|
4733
|
Spacing |
35
|
|
|
|
|
|
|
InEastAsianHalfwidth(). |
36
|
|
|
|
|
|
|
InEastAsianNarrow(). |
37
|
|
|
|
|
|
|
InEastAsianNeutral(). |
38
|
|
|
|
|
|
|
InEastAsianAmbiguous() |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
0
|
0
|
0
|
sub vwidth { width(@_) } |
42
|
0
|
|
|
0
|
0
|
0
|
sub vtrim { trim(@_) } |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub width { |
45
|
26
|
|
|
26
|
0
|
241659
|
my $str = shift; |
46
|
|
|
|
|
|
|
|
47
|
26
|
|
|
|
|
65
|
my $ret = 0; |
48
|
26
|
100
|
|
|
|
75
|
if ($EastAsian) { |
49
|
6
|
|
|
6
|
|
592
|
while ($str =~ /(\p{InVWPP1Fullwidth}+)|(\p{InVWPP1Halfwidth}+)/g) { |
|
6
|
|
|
|
|
32
|
|
|
6
|
|
|
|
|
103
|
|
|
2
|
|
|
|
|
30
|
|
50
|
2
|
50
|
|
|
|
4092
|
$ret += $1 ? length($1) * 2 : length($2) |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} else { |
53
|
24
|
|
|
|
|
222
|
while ($str =~ /(\p{InVWPP0Fullwidth}+)|(\p{InVWPP0Halfwidth}+)/g) { |
54
|
33
|
100
|
|
|
|
14662
|
$ret += $1 ? length($1) * 2 : length($2) |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
26
|
|
|
|
|
127
|
$ret; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub trim { |
61
|
15
|
|
|
15
|
0
|
62
|
my ($str, $limit) = @_; |
62
|
|
|
|
|
|
|
|
63
|
15
|
|
|
|
|
30
|
my $cnt = 0; |
64
|
15
|
|
|
|
|
29
|
my $ret = ''; |
65
|
15
|
|
|
|
|
153
|
while ($str =~ /\G(\X)/g) { |
66
|
72
|
|
|
|
|
194
|
my $ch = $1; |
67
|
72
|
|
|
|
|
118
|
my $w = do { |
68
|
72
|
100
|
|
|
|
258
|
if ($ch =~ /\p{InFullwidth}/) { |
|
|
100
|
|
|
|
|
|
69
|
15
|
|
|
|
|
23
|
2; |
70
|
|
|
|
|
|
|
} elsif (length($ch) == 1) { |
71
|
42
|
|
|
|
|
1090
|
1; |
72
|
|
|
|
|
|
|
} else { |
73
|
15
|
|
|
|
|
38
|
width($ch); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
}; |
76
|
72
|
100
|
|
|
|
148
|
if ($cnt+$w <= $limit) { |
77
|
60
|
|
|
|
|
101
|
$ret .= $ch; |
78
|
60
|
|
|
|
|
210
|
$cnt += $w; |
79
|
|
|
|
|
|
|
} else { |
80
|
12
|
|
|
|
|
32
|
last; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
15
|
|
|
|
|
91
|
$ret; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
__END__ |