line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::Trim::More; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2017-01-27'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
20964
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
7
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
717
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
ltrim |
14
|
|
|
|
|
|
|
rtrim |
15
|
|
|
|
|
|
|
trim |
16
|
|
|
|
|
|
|
ltrim_lines |
17
|
|
|
|
|
|
|
rtrim_lines |
18
|
|
|
|
|
|
|
trim_lines |
19
|
|
|
|
|
|
|
trim_blank_lines |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
ellipsis |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub ltrim { |
25
|
6
|
|
|
6
|
1
|
521
|
my $str = shift; |
26
|
6
|
|
|
|
|
17
|
$str =~ s/\A\s+//s; |
27
|
6
|
|
|
|
|
17
|
$str; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub rtrim { |
31
|
6
|
|
|
6
|
1
|
911
|
my $str = shift; |
32
|
6
|
|
|
|
|
20
|
$str =~ s/\s+\z//s; |
33
|
6
|
|
|
|
|
21
|
$str; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub trim { |
37
|
6
|
|
|
6
|
1
|
850
|
my $str = shift; |
38
|
6
|
|
|
|
|
16
|
$str =~ s/\A\s+//s; |
39
|
6
|
|
|
|
|
15
|
$str =~ s/\s+\z//s; |
40
|
6
|
|
|
|
|
15
|
$str; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub ltrim_lines { |
44
|
6
|
|
|
6
|
1
|
834
|
my $str = shift; |
45
|
6
|
|
|
|
|
20
|
$str =~ s/^[ \t]+//mg; # XXX other unicode non-newline spaces |
46
|
6
|
|
|
|
|
16
|
$str; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub rtrim_lines { |
50
|
6
|
|
|
6
|
1
|
816
|
my $str = shift; |
51
|
6
|
|
|
|
|
23
|
$str =~ s/[ \t]+$//mg; |
52
|
6
|
|
|
|
|
18
|
$str; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub trim_lines { |
56
|
6
|
|
|
6
|
1
|
831
|
my $str = shift; |
57
|
6
|
|
|
|
|
20
|
$str =~ s/^[ \t]+//mg; |
58
|
6
|
|
|
|
|
13
|
$str =~ s/[ \t]+$//mg; |
59
|
6
|
|
|
|
|
17
|
$str; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub trim_blank_lines { |
63
|
2
|
|
|
2
|
1
|
545
|
local $_ = shift; |
64
|
2
|
100
|
|
|
|
9
|
return $_ unless defined; |
65
|
1
|
|
|
|
|
5
|
s/\A(?:\n\s*)+//; |
66
|
1
|
|
|
|
|
5
|
s/(?:\n\s*){2,}\z/\n/; |
67
|
1
|
|
|
|
|
4
|
$_; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub ellipsis { |
71
|
6
|
|
|
6
|
1
|
8
|
my ($str, $maxlen, $ellipsis) = @_; |
72
|
6
|
|
50
|
|
|
12
|
$maxlen //= 80; |
73
|
6
|
|
100
|
|
|
22
|
$ellipsis //= "..."; |
74
|
|
|
|
|
|
|
|
75
|
6
|
100
|
|
|
|
10
|
if (length($str) <= $maxlen) { |
76
|
3
|
|
|
|
|
9
|
return $str; |
77
|
|
|
|
|
|
|
} else { |
78
|
3
|
|
|
|
|
13
|
return substr($str, 0, $maxlen-length($ellipsis)) . $ellipsis; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
# ABSTRACT: Various string trimming utilities |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |