Skip to content

Commit

Permalink
implement :p/:pos in Regex.match
Browse files Browse the repository at this point in the history
With help from colomon++
  • Loading branch information
moritz committed May 17, 2010
1 parent 816a4fc commit 2d0fc2b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/core/Cool-str.pm
Expand Up @@ -177,24 +177,27 @@ augment class Cool {
self gt '' ?? self.substr(0,1).lc ~ self.substr(1) !! ""
}

our multi method match(Regex $pat, :c(:$continue), :g(:$global)) {
our multi method match(Regex $pat, :c(:$continue), :g(:$global), :pos(:$p)) {
if $continue ~~ Bool {
note ":c / :continue requires a position in the string";
fail ":c / :continue requires a position in the string";
}
my %opts;
%opts<p> = $p if defined $p;
%opts<c> = $continue // 0 unless defined $p;

if $global {
my $cont = $continue;
gather while my $m = Regex::Cursor.parse(self, :rule($pat), :c($cont)) {
gather while my $m = Regex::Cursor.parse(self, :rule($pat), |%opts) {
my $m-copy = $m;
take $m-copy;
if $m.to == $m.from {
$cont = $m.to + 1;
%opts<c> = $m.to + 1;
} else {
$cont = $m.to;
%opts<c> = $m.to;
}
}
} else {
Regex::Cursor.parse(self, :rule($pat), :c($continue));
Regex::Cursor.parse(self, :rule($pat), |%opts);
}
}

Expand Down
1 change: 1 addition & 0 deletions t/spectest.data
Expand Up @@ -284,6 +284,7 @@ S05-modifier/global.t
# S05-modifier/perl5_2.t
# S05-modifier/perl5_7.t
# S05-modifier/perl5_8.t
S05-modifier/pos.t
S05-substitution/match.t
S05-substitution/subst.t
# S05-transliteration/trans.t
Expand Down

0 comments on commit 2d0fc2b

Please sign in to comment.