| 1 | package String::Trim::More; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | our $DATE = '2017-01-27'; # DATE | |||||||||||
| 4 | 2 | our $VERSION = '0.03'; # VERSION | |||||||||||
| 5 | |||||||||||||
| 6 | 2 | ▶ | use 5.010001; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 2 | ▶ | use Exporter; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 2 | our @ISA = qw(Exporter); | |||||||||||
| 12 | 2 | 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 | 6 | ▶ | sub ltrim { | ||||||||||
|
Subroutine
ltrim: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 25 | 6 | my $str = shift; | |||||||||||
| 26 | 6 | $str =~ s/\A\s+//s; | |||||||||||
| 27 | 6 | $str; | |||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | 6 | ▶ | sub rtrim { | ||||||||||
|
Subroutine
rtrim: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 31 | 6 | my $str = shift; | |||||||||||
| 32 | 6 | $str =~ s/\s+\z//s; | |||||||||||
| 33 | 6 | $str; | |||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | 6 | ▶ | sub trim { | ||||||||||
|
Subroutine
trim: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 37 | 6 | my $str = shift; | |||||||||||
| 38 | 6 | $str =~ s/\A\s+//s; | |||||||||||
| 39 | 6 | $str =~ s/\s+\z//s; | |||||||||||
| 40 | 6 | $str; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | 6 | ▶ | sub ltrim_lines { | ||||||||||
|
Subroutine
ltrim_lines: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 44 | 6 | my $str = shift; | |||||||||||
| 45 | 6 | $str =~ s/^[ \t]+//mg; # XXX other unicode non-newline spaces | |||||||||||
| 46 | 6 | $str; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 6 | ▶ | sub rtrim_lines { | ||||||||||
|
Subroutine
rtrim_lines: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 50 | 6 | my $str = shift; | |||||||||||
| 51 | 6 | $str =~ s/[ \t]+$//mg; | |||||||||||
| 52 | 6 | $str; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | 6 | ▶ | sub trim_lines { | ||||||||||
|
Subroutine
trim_lines: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 56 | 6 | my $str = shift; | |||||||||||
| 57 | 6 | $str =~ s/^[ \t]+//mg; | |||||||||||
| 58 | 6 | $str =~ s/[ \t]+$//mg; | |||||||||||
| 59 | 6 | $str; | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 2 | ▶ | sub trim_blank_lines { | ||||||||||
|
Subroutine
trim_blank_lines: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 63 | 2 | local $_ = shift; | |||||||||||
| 64 | 2 | ▶ | return $_ unless defined; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 1 | s/\A(?:\n\s*)+//; | |||||||||||
| 66 | 1 | s/(?:\n\s*){2,}\z/\n/; | |||||||||||
| 67 | 1 | $_; | |||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | 6 | ▶ | sub ellipsis { | ||||||||||
|
Subroutine
ellipsis: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 71 | 6 | my ($str, $maxlen, $ellipsis) = @_; | |||||||||||
| 72 | 6 | ▶ | $maxlen //= 80; | ||||||||||
|
Condition50%1/2
$maxlen //= 80
MC/DC0%0/1
$maxlen //= 80
$maxlen
Truth table50%1/2
A
A= $maxlen
| |||||||||||||
| 73 | 6 | ▶ | $ellipsis //= "..."; | ||||||||||
|
Condition100%2/2
$ellipsis //= "..."
MC/DC100%1/1
$ellipsis //= "..."
$ellipsis
Truth table100%2/2
A
A= $ellipsis
| |||||||||||||
| 74 | |||||||||||||
| 75 | 6 | ▶ | if (length($str) <= $maxlen) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | 3 | return $str; | |||||||||||
| 77 | } else { | ||||||||||||
| 78 | 3 | return substr($str, 0, $maxlen-length($ellipsis)) . $ellipsis; | |||||||||||
| 79 | } | ||||||||||||
| 80 | } | ||||||||||||
| 81 | |||||||||||||
| 82 | 2 | 1; | |||||||||||
| 83 | # ABSTRACT: Various string trimming utilities | ||||||||||||
| 84 | |||||||||||||
| 85 | __END__ | ||||||||||||