Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Regexp/Common/delimited.pm |
Statements | Executed 12 statements in 222µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 8µs | 29µs | BEGIN@3 | Regexp::Common::delimited::
1 | 1 | 1 | 4µs | 6µs | BEGIN@5 | Regexp::Common::delimited::
1 | 1 | 1 | 4µs | 15µs | BEGIN@8 | Regexp::Common::delimited::
1 | 1 | 1 | 4µs | 7µs | BEGIN@6 | Regexp::Common::delimited::
0 | 0 | 0 | 0s | 0s | __ANON__[:49] | Regexp::Common::delimited::
0 | 0 | 0 | 0s | 0s | __ANON__[:55] | Regexp::Common::delimited::
0 | 0 | 0 | 0s | 0s | _croak | Regexp::Common::delimited::
0 | 0 | 0 | 0s | 0s | gen_delimited | Regexp::Common::delimited::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Regexp::Common::delimited; | ||||
2 | |||||
3 | 2 | 17µs | 2 | 29µs | # spent 29µs (8+21) within Regexp::Common::delimited::BEGIN@3 which was called:
# once (8µs+21µs) by Regexp::Common::import at line 3 # spent 29µs making 1 call to Regexp::Common::delimited::BEGIN@3
# spent 21µs making 1 call to Regexp::Common::import, recursion: max depth 1, sum of overlapping time 21µs |
4 | |||||
5 | 2 | 12µs | 2 | 7µs | # spent 6µs (4+1) within Regexp::Common::delimited::BEGIN@5 which was called:
# once (4µs+1µs) by Regexp::Common::import at line 5 # spent 6µs making 1 call to Regexp::Common::delimited::BEGIN@5
# spent 1µs making 1 call to strict::import |
6 | 2 | 13µs | 2 | 10µs | # spent 7µs (4+3) within Regexp::Common::delimited::BEGIN@6 which was called:
# once (4µs+3µs) by Regexp::Common::import at line 6 # spent 7µs making 1 call to Regexp::Common::delimited::BEGIN@6
# spent 3µs making 1 call to warnings::import |
7 | |||||
8 | 2 | 173µs | 2 | 26µs | # spent 15µs (4+11) within Regexp::Common::delimited::BEGIN@8 which was called:
# once (4µs+11µs) by Regexp::Common::import at line 8 # spent 15µs making 1 call to Regexp::Common::delimited::BEGIN@8
# spent 11µs making 1 call to vars::import |
9 | 1 | 300ns | $VERSION = '2010010201'; | ||
10 | |||||
11 | sub gen_delimited { | ||||
12 | |||||
13 | my ($dels, $escs) = @_; | ||||
14 | # return '(?:\S*)' unless $dels =~ /\S/; | ||||
15 | if (length $escs) { | ||||
16 | $escs .= substr ($escs, -1) x (length ($dels) - length ($escs)); | ||||
17 | } | ||||
18 | my @pat = (); | ||||
19 | my $i; | ||||
20 | for ($i=0; $i < length $dels; $i++) { | ||||
21 | my $del = quotemeta substr ($dels, $i, 1); | ||||
22 | my $esc = length($escs) ? quotemeta substr ($escs, $i, 1) : ""; | ||||
23 | if ($del eq $esc) { | ||||
24 | push @pat, | ||||
25 | "(?k:$del)(?k:[^$del]*(?:(?:$del$del)[^$del]*)*)(?k:$del)"; | ||||
26 | } | ||||
27 | elsif (length $esc) { | ||||
28 | push @pat, | ||||
29 | "(?k:$del)(?k:[^$esc$del]*(?:$esc.[^$esc$del]*)*)(?k:$del)"; | ||||
30 | } | ||||
31 | else { | ||||
32 | push @pat, "(?k:$del)(?k:[^$del]*)(?k:$del)"; | ||||
33 | } | ||||
34 | } | ||||
35 | my $pat = join '|', @pat; | ||||
36 | return "(?k:$pat)"; | ||||
37 | } | ||||
38 | |||||
39 | sub _croak { | ||||
40 | require Carp; | ||||
41 | goto &Carp::croak; | ||||
42 | } | ||||
43 | |||||
44 | pattern name => [qw( delimited -delim= -esc=\\ )], | ||||
45 | create => sub {my $flags = $_[1]; | ||||
46 | _croak 'Must specify delimiter in $RE{delimited}' | ||||
47 | unless length $flags->{-delim}; | ||||
48 | return gen_delimited (@{$flags}{-delim, -esc}); | ||||
49 | }, | ||||
50 | 1 | 3µs | 1 | 48µs | ; # spent 48µs making 1 call to Regexp::Common::pattern |
51 | |||||
52 | pattern name => [qw( quoted -esc=\\ )], | ||||
53 | create => sub {my $flags = $_[1]; | ||||
54 | return gen_delimited (q{"'`}, $flags -> {-esc}); | ||||
55 | }, | ||||
56 | 1 | 1µs | 1 | 18µs | ; # spent 18µs making 1 call to Regexp::Common::pattern |
57 | |||||
58 | |||||
59 | 1 | 3µs | 1; | ||
60 | |||||
61 | __END__ |