line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::Prettify; |
2
|
3
|
|
|
3
|
|
101098
|
use Exporter; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
161
|
|
3
|
3
|
|
|
3
|
|
14
|
use vars qw($VERSION @EXPORT @ISA); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
392
|
|
4
|
|
|
|
|
|
|
@ISA=qw/Exporter/; |
5
|
|
|
|
|
|
|
@EXPORT = qw(prettify prettify_filename); |
6
|
3
|
|
|
3
|
|
21
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
84
|
|
7
|
3
|
|
|
3
|
|
13
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1144
|
|
8
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)/g; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub prettify { |
11
|
60
|
|
|
60
|
1
|
17029
|
my $string = shift; |
12
|
60
|
50
|
|
|
|
135
|
$string or croak("missing argument"); |
13
|
|
|
|
|
|
|
|
14
|
60
|
|
|
|
|
109
|
_depathify(\$string); |
15
|
60
|
|
|
|
|
115
|
_ampersand(\$string); |
16
|
60
|
|
|
|
|
112
|
_spacing(\$string); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
60
|
|
|
|
|
116
|
_cap(\$string); |
20
|
|
|
|
|
|
|
|
21
|
60
|
|
|
|
|
162
|
return $string; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub prettify_filename { |
25
|
8
|
|
|
8
|
1
|
5528
|
my $string = shift; |
26
|
8
|
50
|
|
|
|
24
|
$string or croak("missing argument"); |
27
|
|
|
|
|
|
|
|
28
|
8
|
|
|
|
|
38
|
$string=~s/^(.+\/+)//; |
29
|
8
|
|
|
|
|
23
|
my $loc = $1; |
30
|
|
|
|
|
|
|
|
31
|
8
|
|
|
|
|
19
|
my $ext = _ext(\$string); |
32
|
8
|
|
|
|
|
19
|
_spacing(\$string); |
33
|
|
|
|
|
|
|
|
34
|
8
|
|
|
|
|
30
|
$string=~s/ /_/g; |
35
|
|
|
|
|
|
|
#$string = lc $string; |
36
|
|
|
|
|
|
|
|
37
|
3
|
|
|
3
|
|
17
|
no warnings; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
2075
|
|
38
|
8
|
|
|
|
|
30
|
return "$loc$string$ext"; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# privates.... |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _cap { |
48
|
60
|
|
|
60
|
|
69
|
my $ref = shift; |
49
|
|
|
|
|
|
|
#my $string = lc($$_ref); |
50
|
|
|
|
|
|
|
|
51
|
60
|
|
|
|
|
204
|
$$ref=~s/\b([a-z])/uc($1)/ge; |
|
24
|
|
|
|
|
91
|
|
52
|
60
|
|
|
|
|
78
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _ext { |
56
|
68
|
|
|
68
|
|
76
|
my $_ref = shift; |
57
|
68
|
100
|
|
|
|
292
|
if( $$_ref=~s/(\.\w{1,8})$// ){ |
58
|
52
|
|
|
|
|
106
|
return $1; |
59
|
|
|
|
|
|
|
} |
60
|
16
|
|
|
|
|
23
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _depathify { |
65
|
60
|
|
|
60
|
|
65
|
my $r = shift; |
66
|
|
|
|
|
|
|
|
67
|
60
|
|
|
|
|
254
|
$$r=~s/^.+\/+//; |
68
|
|
|
|
|
|
|
|
69
|
60
|
|
|
|
|
106
|
_ext($r); |
70
|
|
|
|
|
|
|
|
71
|
60
|
|
|
|
|
70
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _spacing { |
75
|
68
|
|
|
68
|
|
80
|
my $ref = shift; |
76
|
|
|
|
|
|
|
|
77
|
68
|
|
|
|
|
478
|
$$ref=~s/[_\W]/ /g; |
78
|
|
|
|
|
|
|
|
79
|
68
|
|
|
|
|
215
|
$$ref=~s/([0-9])([a-zA-Z])/$1 $2/g; |
80
|
68
|
|
|
|
|
290
|
$$ref=~s/([a-zA-Z])([0-9])/$1 $2/g; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
68
|
|
|
|
|
148
|
$$ref=~s/([a-z])([A-Z])/$1 $2/g; |
84
|
68
|
|
|
|
|
202
|
$$ref=~s/ {2,}/ /g; |
85
|
68
|
|
|
|
|
487
|
$$ref=~s/^\s+|\s+$//g; |
86
|
68
|
|
|
|
|
100
|
return; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _ampersand { |
91
|
60
|
|
|
60
|
|
66
|
my $ref = shift; |
92
|
|
|
|
|
|
|
|
93
|
60
|
|
|
|
|
104
|
$$ref=~s/(\d)&(\d)/$1 $2/g; |
94
|
|
|
|
|
|
|
|
95
|
60
|
|
|
|
|
358
|
$$ref=~s/^&|&$/_and_/g; |
96
|
|
|
|
|
|
|
|
97
|
60
|
|
|
|
|
203
|
my $r = qr/[a-z ]{2,}|[[^a-z]\b]/i; |
98
|
|
|
|
|
|
|
|
99
|
60
|
|
|
|
|
683
|
$$ref=~s/($r)&($r)/$1_and_$2/g; |
100
|
|
|
|
|
|
|
|
101
|
60
|
|
|
|
|
193
|
$$ref=~s/&//g; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#$$ref=~s/(\W)&(\W)/$1_and_$2/g; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#$$ref=~s/(\b[a-z])&([a-z])\b/$1$2/ig; # H&R HR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#$$ref=~s/([^ a-z])&([^ a-z])/$1_$2/ig; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#$$ref=~s/\b&\b/_and_/g; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |