line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::VisualWidth::PP; |
2
|
5
|
|
|
5
|
|
121556
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
153
|
|
3
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
124
|
|
4
|
5
|
|
|
5
|
|
104
|
use 5.008001; |
|
5
|
|
|
|
|
20
|
|
|
5
|
|
|
|
|
184
|
|
5
|
5
|
|
|
5
|
|
4293
|
use parent qw(Exporter); |
|
5
|
|
|
|
|
1469
|
|
|
5
|
|
|
|
|
27
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
7
|
5
|
|
|
5
|
|
2073
|
use Unicode::EastAsianWidth; |
|
5
|
|
|
|
|
1416
|
|
|
5
|
|
|
|
|
1790
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(vwidth vtrim); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $EastAsian = $Unicode::EastAsianWidth::EastAsian; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub InVWPP1Fullwidth() { |
14
|
2
|
|
|
2
|
0
|
240
|
InEastAsianFullwidth() . InEastAsianWide() . InEastAsianAmbiguous() |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
sub InVWPP0Fullwidth() { |
17
|
3
|
|
|
3
|
0
|
477
|
InEastAsianFullwidth() . InEastAsianWide() |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
sub InVWPP1Halfwidth() { |
20
|
0
|
|
|
0
|
0
|
0
|
InEastAsianHalfwidth(). |
21
|
|
|
|
|
|
|
InEastAsianNarrow(). |
22
|
|
|
|
|
|
|
InEastAsianNeutral() |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
sub InVWPP0Halfwidth() { |
25
|
3
|
|
|
3
|
0
|
1020
|
InEastAsianHalfwidth(). |
26
|
|
|
|
|
|
|
InEastAsianNarrow(). |
27
|
|
|
|
|
|
|
InEastAsianNeutral(). |
28
|
|
|
|
|
|
|
InEastAsianAmbiguous() |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
0
|
0
|
sub vwidth { width(@_) } |
32
|
0
|
|
|
0
|
0
|
0
|
sub vtrim { trim(@_) } |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub width { |
35
|
7
|
|
|
7
|
0
|
43
|
my $str = shift; |
36
|
|
|
|
|
|
|
|
37
|
7
|
|
|
|
|
14
|
my $ret = 0; |
38
|
7
|
100
|
|
|
|
24
|
if ($EastAsian) { |
39
|
5
|
|
|
5
|
|
1091
|
while ($str =~ /(\p{InVWPP1Fullwidth}+)|(\p{InVWPP1Halfwidth}+)/g) { |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
71
|
|
|
2
|
|
|
|
|
24
|
|
40
|
2
|
50
|
|
|
|
2737
|
$ret += $1 ? length($1) * 2 : length($2) |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} else { |
43
|
5
|
|
|
|
|
58
|
while ($str =~ /(\p{InVWPP0Fullwidth}+)|(\p{InVWPP0Halfwidth}+)/g) { |
44
|
6
|
100
|
|
|
|
7987
|
$ret += $1 ? length($1) * 2 : length($2) |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
7
|
|
|
|
|
45
|
$ret; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub trim { |
51
|
3
|
|
|
3
|
0
|
8
|
my ($str, $limit) = @_; |
52
|
|
|
|
|
|
|
|
53
|
3
|
|
|
|
|
4
|
my $cnt = 0; |
54
|
3
|
|
|
|
|
222
|
my $ret = ''; |
55
|
3
|
|
|
|
|
21
|
while ($str =~ /(\p{InFullwidth})|(\p{InHalfwidth})/g) { |
56
|
9
|
100
|
|
|
|
3295
|
if ($1) { |
57
|
2
|
100
|
|
|
|
6
|
if ($cnt+2 <= $limit) { |
58
|
1
|
|
|
|
|
2
|
$ret .= $1; |
59
|
1
|
|
|
|
|
4
|
$cnt += 2; |
60
|
|
|
|
|
|
|
} else { |
61
|
1
|
|
|
|
|
2
|
last; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} else { |
64
|
7
|
50
|
|
|
|
16
|
if ($cnt+1 <= $limit) { |
65
|
7
|
|
|
|
|
10
|
$ret .= $2; |
66
|
7
|
|
|
|
|
25
|
$cnt += 1; |
67
|
|
|
|
|
|
|
} else { |
68
|
0
|
|
|
|
|
0
|
last; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
3
|
|
|
|
|
12
|
$ret; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
__END__ |