| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ABSTRACT: Common Methods for Operating on Strings |
|
2
|
|
|
|
|
|
|
package Bubblegum::Object::String; |
|
3
|
|
|
|
|
|
|
|
|
4
|
37
|
|
|
37
|
|
22331
|
use 5.10.0; |
|
|
37
|
|
|
|
|
102
|
|
|
|
37
|
|
|
|
|
1500
|
|
|
5
|
37
|
|
|
37
|
|
170
|
use namespace::autoclean; |
|
|
37
|
|
|
|
|
50
|
|
|
|
37
|
|
|
|
|
221
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
37
|
|
|
37
|
|
2076
|
use Bubblegum::Class 'with'; |
|
|
37
|
|
|
|
|
53
|
|
|
|
37
|
|
|
|
|
221
|
|
|
8
|
37
|
|
|
37
|
|
26564
|
use Bubblegum::Constraints -isas, -types; |
|
|
37
|
|
|
|
|
68
|
|
|
|
37
|
|
|
|
|
385
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
37
|
|
|
37
|
|
157325
|
use Carp 'confess'; |
|
|
37
|
|
|
|
|
67
|
|
|
|
37
|
|
|
|
|
2067
|
|
|
11
|
37
|
|
|
37
|
|
181
|
use Scalar::Util 'looks_like_number'; |
|
|
37
|
|
|
|
|
52
|
|
|
|
37
|
|
|
|
|
84359
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'Bubblegum::Object::Role::Defined'; |
|
14
|
|
|
|
|
|
|
with 'Bubblegum::Object::Role::Comparison'; |
|
15
|
|
|
|
|
|
|
with 'Bubblegum::Object::Role::Coercive'; |
|
16
|
|
|
|
|
|
|
with 'Bubblegum::Object::Role::Value'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @ISA = (); # non-object |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.45'; # VERSION |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub append { |
|
23
|
2
|
|
|
2
|
1
|
2354
|
return $_[0] = CORE::join ' ', map type_string($_), @_; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub codify { |
|
27
|
40
|
|
50
|
40
|
1
|
3428
|
my $self = CORE::shift || 'return(@_)'; |
|
28
|
40
|
|
|
|
|
909
|
my $vars = sprintf 'my (%s) = @_;', join ',', map "\$$_", 'a'..'z'; |
|
29
|
40
|
|
|
|
|
156
|
my $code = sprintf 'use gum; sub { %s return do { %s } }', $vars, $self; |
|
30
|
40
|
50
|
|
3
|
|
3783
|
my $ref = eval $code or confess $@; |
|
|
3
|
|
|
3
|
|
1840
|
|
|
|
3
|
|
|
3
|
|
7
|
|
|
|
3
|
|
|
3
|
|
17
|
|
|
|
3
|
|
|
3
|
|
17
|
|
|
|
3
|
|
|
3
|
|
4
|
|
|
|
3
|
|
|
2
|
|
15
|
|
|
|
3
|
|
|
2
|
|
16
|
|
|
|
3
|
|
|
2
|
|
4
|
|
|
|
3
|
|
|
|
|
14
|
|
|
|
3
|
|
|
|
|
18
|
|
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
14
|
|
|
|
3
|
|
|
|
|
19
|
|
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
16
|
|
|
|
3
|
|
|
|
|
18
|
|
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
16
|
|
|
|
2
|
|
|
|
|
12
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
12
|
|
|
|
2
|
|
|
|
|
16
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
13
|
|
|
|
2
|
|
|
|
|
13
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
12
|
|
|
31
|
40
|
|
|
|
|
1054
|
return $ref; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub concat { |
|
35
|
2
|
|
|
2
|
1
|
3025
|
return $_[0] = CORE::join '', map type_string($_), @_; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub contains { |
|
39
|
5
|
|
|
5
|
1
|
4185
|
my $self = CORE::shift; |
|
40
|
5
|
|
|
|
|
13
|
my $other = CORE::shift; |
|
41
|
|
|
|
|
|
|
|
|
42
|
5
|
100
|
|
|
|
17
|
if (isa_regexpref($other)) { |
|
43
|
3
|
100
|
|
|
|
32
|
return $self =~ $other ? 1 : 0; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
3
|
50
|
|
|
|
21
|
if (isa_string($other)) { |
|
47
|
3
|
100
|
|
|
|
18
|
return CORE::index($self, $other) < 0 ? 0 : 1; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
2
|
return 0; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub eq { |
|
54
|
3
|
|
|
3
|
1
|
3360
|
my $self = CORE::shift; |
|
55
|
3
|
|
|
|
|
50
|
my $other = type_string CORE::shift; |
|
56
|
|
|
|
|
|
|
|
|
57
|
3
|
100
|
|
|
|
83
|
return $self eq $other ? 1 : 0; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub eqtv { |
|
61
|
3
|
|
|
3
|
1
|
3368
|
my $self = CORE::shift; |
|
62
|
3
|
|
|
|
|
13
|
my $other = CORE::shift; |
|
63
|
|
|
|
|
|
|
|
|
64
|
3
|
50
|
|
|
|
8
|
return 0 unless CORE::defined $other; |
|
65
|
3
|
100
|
66
|
|
|
20
|
return ($self->type eq $other->type && $self eq $other) ? 1 : 0; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub format { |
|
69
|
3
|
|
|
3
|
1
|
3362
|
my $self = CORE::shift; |
|
70
|
3
|
|
|
|
|
8
|
my $format = type_string CORE::shift; |
|
71
|
|
|
|
|
|
|
|
|
72
|
3
|
|
|
|
|
77
|
return CORE::sprintf $format, $self, @_; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub gt { |
|
76
|
3
|
|
|
3
|
1
|
3241
|
my $self = CORE::shift; |
|
77
|
3
|
|
|
|
|
9
|
my $other = type_string CORE::shift; |
|
78
|
|
|
|
|
|
|
|
|
79
|
3
|
100
|
|
|
|
108
|
return $self gt $other ? 1 : 0; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub gte { |
|
83
|
3
|
|
|
4
|
1
|
3261
|
my $self = CORE::shift; |
|
84
|
3
|
|
|
|
|
12
|
my $other = type_string CORE::shift; |
|
85
|
|
|
|
|
|
|
|
|
86
|
3
|
100
|
|
|
|
106
|
return $self ge $other ? 1 : 0; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub lt { |
|
90
|
2
|
|
|
2
|
1
|
3281
|
my $self = CORE::shift; |
|
91
|
2
|
|
|
|
|
5
|
my $other = type_string CORE::shift; |
|
92
|
|
|
|
|
|
|
|
|
93
|
2
|
100
|
|
|
|
69
|
return $self lt $other ? 1 : 0; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub lte { |
|
97
|
3
|
|
|
3
|
1
|
3203
|
my $self = CORE::shift; |
|
98
|
3
|
|
|
|
|
10
|
my $other = type_string CORE::shift; |
|
99
|
|
|
|
|
|
|
|
|
100
|
3
|
100
|
|
|
|
101
|
return $self le $other ? 1 : 0; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub ne { |
|
104
|
2
|
|
|
2
|
1
|
3256
|
my $self = CORE::shift; |
|
105
|
2
|
|
|
|
|
6
|
my $other = type_string CORE::shift; |
|
106
|
|
|
|
|
|
|
|
|
107
|
2
|
100
|
|
|
|
101
|
return $self ne $other ? 1 : 0; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub camelcase { |
|
111
|
2
|
|
|
2
|
1
|
3228
|
$_[0] = CORE::ucfirst(CORE::lc("$_[0]")); |
|
112
|
2
|
|
|
|
|
17
|
$_[0] =~ s/[^a-zA-Z0-9]+([a-z])/\U$1/g; |
|
113
|
2
|
|
|
|
|
5
|
$_[0] =~ s/[^a-zA-Z0-9]+//g; |
|
114
|
2
|
|
|
|
|
12
|
return $_[0]; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub chomp { |
|
118
|
1
|
|
|
1
|
1
|
3284
|
CORE::chomp $_[0]; |
|
119
|
1
|
|
|
|
|
4
|
return $_[0]; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub chop { |
|
123
|
1
|
|
|
1
|
1
|
3201
|
CORE::chop $_[0]; |
|
124
|
1
|
|
|
|
|
4
|
return $_[0]; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub hex { |
|
128
|
1
|
|
|
1
|
1
|
3239
|
my $self = CORE::shift; |
|
129
|
1
|
|
|
|
|
6
|
return CORE::hex $self; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub index { |
|
133
|
6
|
|
|
6
|
1
|
3281
|
my ($self, $substr, $pos) = @_; |
|
134
|
6
|
|
|
|
|
16
|
type_string $substr; |
|
135
|
6
|
100
|
|
|
|
196
|
return CORE::index $self, $substr if scalar @_ == 2; |
|
136
|
|
|
|
|
|
|
|
|
137
|
4
|
|
|
|
|
10
|
type_number $pos; |
|
138
|
4
|
|
|
|
|
482
|
return CORE::index $self, $substr, $pos |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub lc { |
|
142
|
2
|
|
|
2
|
1
|
3262
|
my $self = CORE::shift; |
|
143
|
2
|
|
|
|
|
8
|
return CORE::lc $self; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub lcfirst { |
|
147
|
1
|
|
|
1
|
1
|
3307
|
my $self = CORE::shift; |
|
148
|
1
|
|
|
|
|
5
|
return CORE::lcfirst $self; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub length { |
|
152
|
1
|
|
|
1
|
1
|
3367
|
my $self = CORE::shift; |
|
153
|
1
|
|
|
|
|
5
|
return CORE::length $self; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub lines { |
|
157
|
1
|
|
|
1
|
1
|
3301
|
my $self = CORE::shift; |
|
158
|
1
|
|
|
|
|
13
|
return [CORE::split /\n+/, $self]; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub lowercase { |
|
162
|
1
|
|
|
1
|
1
|
3443
|
goto &lc |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub replace { |
|
166
|
4
|
|
|
4
|
1
|
3299
|
my ($self, $regexp, $other, $mods) = @_; |
|
167
|
|
|
|
|
|
|
|
|
168
|
4
|
100
|
|
|
|
13
|
$mods = CORE::defined $mods ? type_string $mods : ''; |
|
169
|
4
|
100
|
66
|
|
|
39
|
if (!isa_regexpref($regexp) && isa_string($regexp)) { |
|
170
|
2
|
|
|
|
|
20
|
$regexp = CORE::quotemeta $regexp; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
4
|
|
|
|
|
560
|
CORE::eval("sub { \$_[0] =~ s/$regexp/$other/$mods }")->($_[0]); |
|
174
|
4
|
|
|
|
|
61
|
return $self = $_[0]; |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub reverse { |
|
178
|
1
|
|
|
1
|
1
|
3317
|
my $self = CORE::shift; |
|
179
|
1
|
|
|
|
|
6
|
return CORE::reverse $self; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub rindex { |
|
183
|
10
|
|
|
10
|
1
|
4733
|
my ($self, $substr, $pos) = @_; |
|
184
|
10
|
|
|
|
|
34
|
type_string $substr; |
|
185
|
10
|
100
|
|
|
|
480
|
return CORE::rindex $self, $substr if !defined $pos; |
|
186
|
|
|
|
|
|
|
|
|
187
|
8
|
|
|
|
|
30
|
type_number $pos; |
|
188
|
8
|
|
|
|
|
305
|
return CORE::rindex $self, $substr, $pos; |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub snakecase { |
|
192
|
1
|
|
|
1
|
1
|
5090
|
$_[0] = CORE::lc("$_[0]"); |
|
193
|
1
|
|
|
|
|
11
|
$_[0] =~ s/[^a-zA-Z0-9]+([a-z])/\U$1/g; |
|
194
|
1
|
|
|
|
|
3
|
$_[0] =~ s/[^a-zA-Z0-9]+//g; |
|
195
|
1
|
|
|
|
|
3
|
return $_[0]; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub split { |
|
199
|
4
|
|
|
4
|
1
|
3375
|
my ($self, $regexp, $limit) = @_; |
|
200
|
|
|
|
|
|
|
|
|
201
|
4
|
100
|
66
|
|
|
10
|
if (!isa_regexpref($regexp) && isa_string($regexp)) { |
|
202
|
2
|
|
|
|
|
17
|
$regexp = CORE::quotemeta $regexp; |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
4
|
100
|
|
|
|
53
|
return [CORE::split /$regexp/, $self] if !defined $limit; |
|
206
|
|
|
|
|
|
|
|
|
207
|
2
|
|
|
|
|
5
|
type_number $limit; |
|
208
|
2
|
|
|
|
|
81
|
return [CORE::split /$regexp/, $self, $limit]; |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub strip { |
|
212
|
1
|
|
|
1
|
1
|
3632
|
$_[0] =~ s/\s{2,}/ /g; |
|
213
|
1
|
|
|
|
|
7
|
return $_[0]; |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub titlecase { |
|
217
|
1
|
|
|
1
|
1
|
3394
|
$_[0] =~ s/\b(\w)/\U$1/g; |
|
218
|
1
|
|
|
|
|
4
|
return $_[0]; |
|
219
|
|
|
|
|
|
|
} |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub trim { |
|
222
|
1
|
|
|
1
|
1
|
3356
|
$_[0] =~ s/^\s+|\s+$//g; |
|
223
|
1
|
|
|
|
|
4
|
return $_[0]; |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub uc { |
|
227
|
2
|
|
|
2
|
1
|
3461
|
my $self = CORE::shift; |
|
228
|
2
|
|
|
|
|
10
|
return CORE::uc $self; |
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub ucfirst { |
|
232
|
1
|
|
|
1
|
1
|
3369
|
my $self = CORE::shift; |
|
233
|
1
|
|
|
|
|
5
|
return CORE::ucfirst $self; |
|
234
|
|
|
|
|
|
|
} |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub uppercase { |
|
237
|
1
|
|
|
1
|
1
|
3400
|
goto &uc; |
|
238
|
|
|
|
|
|
|
} |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub words { |
|
241
|
2
|
|
|
2
|
1
|
4755
|
my $self = CORE::shift; |
|
242
|
2
|
|
|
|
|
17
|
return [CORE::split /\s+/, $self]; |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
1; |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
__END__ |