Skip to content

Commit

Permalink
Implement :overlap for Any.match.
Browse files Browse the repository at this point in the history
  • Loading branch information
colomon committed May 18, 2010
1 parent da6b23e commit c515f5f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/core/Cool-str.pm
Expand Up @@ -177,7 +177,12 @@ augment class Cool {
self gt '' ?? self.substr(0,1).lc ~ self.substr(1) !! ""
}

our multi method match(Regex $pat, :c(:$continue), :g(:$global), :pos(:$p), Mu :$nth) {
our multi method match(Regex $pat,
:c(:$continue),
:g(:$global),
:pos(:$p),
Mu :$nth,
:ov(:$overlap)) {
if $continue ~~ Bool {
note ":c / :continue requires a position in the string";
fail ":c / :continue requires a position in the string";
Expand All @@ -186,7 +191,7 @@ augment class Cool {
%opts<p> = $p if defined $p;
%opts<c> = $continue // 0 unless defined $p;

if $global || $nth.defined {
if $global || $nth.defined || $overlap {
my $i = 1;
gather while my $m = Regex::Cursor.parse(self, :rule($pat), |%opts) {
my $m-copy = $m;
Expand All @@ -195,11 +200,17 @@ augment class Cool {
} else {
take $m-copy;
}
if $m.to == $m.from {
%opts<c> = $m.to + 1;

if ($overlap) {
%opts<c> = $m.from + 1;
} else {
%opts<c> = $m.to;
if $m.to == $m.from {
%opts<c> = $m.to + 1;
} else {
%opts<c> = $m.to;
}
}

$i++;
}
} else {
Expand Down

0 comments on commit c515f5f

Please sign in to comment.