line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
# String::Gsub::Matcher |
3
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
4
|
|
|
|
|
|
|
# Mastering programmed by YAMASHINA Hio |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright 2006 YAMASHINA Hio |
7
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
8
|
|
|
|
|
|
|
# $Id$ |
9
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
10
|
|
|
|
|
|
|
package String::Gsub::Matcher; |
11
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
107
|
|
12
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
129
|
|
13
|
4
|
|
|
4
|
|
7539
|
use overload q|""| => \&stringy; |
|
4
|
|
|
|
|
4362
|
|
|
4
|
|
|
|
|
27
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
1; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
# $matcher = $pkg->new($str); |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
sub new |
21
|
|
|
|
|
|
|
{ |
22
|
34
|
|
|
34
|
1
|
70
|
my $pkg = shift; |
23
|
34
|
|
|
|
|
120
|
my $this = bless { origref=>\$_[0], }, $pkg; |
24
|
34
|
|
|
|
|
259
|
$this->{st} = [@-]; |
25
|
34
|
|
|
|
|
148
|
$this->{ed} = [@+]; |
26
|
34
|
|
|
|
|
138
|
$this; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
30
|
|
|
|
|
|
|
# $str = $matcher->expand($tmpl); |
31
|
|
|
|
|
|
|
# evaluate string-template by match results. |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
sub expand |
34
|
|
|
|
|
|
|
{ |
35
|
14
|
|
|
14
|
1
|
18
|
my $this = shift; |
36
|
14
|
|
|
|
|
28
|
my $tmpl = shift; |
37
|
|
|
|
|
|
|
|
38
|
14
|
|
|
|
|
84
|
$tmpl =~ s{\\(\d+)|\\([&`'])} |
39
|
|
|
|
|
|
|
{ |
40
|
14
|
100
|
|
|
|
64
|
if( defined($1) ) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
41
|
|
|
|
|
|
|
{ |
42
|
6
|
50
|
|
|
|
7
|
$1<=$#{$this->{st}} ? substr(${$this->{origref}}, $this->{st}[$1], $this->{ed}[$1] - $this->{st}[$1]) : ''; |
|
6
|
|
|
|
|
24
|
|
|
6
|
|
|
|
|
57
|
|
43
|
|
|
|
|
|
|
}elsif( $2 eq '&' ) |
44
|
|
|
|
|
|
|
{ |
45
|
4
|
|
|
|
|
6
|
substr(${$this->{origref}}, $this->{st}[0], $this->{ed}[0] - $this->{st}[0]); |
|
4
|
|
|
|
|
21
|
|
46
|
|
|
|
|
|
|
}elsif( $2 eq '`' ) |
47
|
|
|
|
|
|
|
{ |
48
|
2
|
|
|
|
|
3
|
substr(${$this->{origref}}, 0, $this->{st}[0]); |
|
2
|
|
|
|
|
9
|
|
49
|
|
|
|
|
|
|
}elsif( $2 eq "\'" ) |
50
|
|
|
|
|
|
|
{ |
51
|
2
|
|
|
|
|
2
|
substr(${$this->{origref}}, $this->{ed}[0]); |
|
2
|
|
|
|
|
9
|
|
52
|
|
|
|
|
|
|
}else |
53
|
|
|
|
|
|
|
{ # never reach here. |
54
|
0
|
|
|
|
|
0
|
''; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
}xmse; |
57
|
14
|
|
|
|
|
127
|
$tmpl; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
61
|
|
|
|
|
|
|
# $str = $matcher->stringy(); |
62
|
|
|
|
|
|
|
# overloading of "". |
63
|
|
|
|
|
|
|
# returns whole of match ($&). |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
sub stringy |
66
|
|
|
|
|
|
|
{ |
67
|
2
|
|
|
2
|
1
|
9
|
my $this = shift; |
68
|
2
|
|
|
|
|
4
|
substr(${$this->{origref}},$this->{st}[0], $this->{ed}[0]-$this->{st}[0]); |
|
2
|
|
|
|
|
22
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |