Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implement :overlap in Str.match
  • Loading branch information
moritz committed Jul 23, 2011
1 parent a52ea8f commit 98fed2e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core/Str.pm
Expand Up @@ -248,7 +248,7 @@ my class Str does Stringy {
}


multi method match(Regex $pat, :continue(:$c), :pos(:$p), :global(:$g)) {
multi method match(Regex $pat, :continue(:$c), :pos(:$p), :global(:$g), :ov(:$overlap)) {
# XXX initialization is a workaround for a nom bug
my %opts := {};
if $c.defined {
Expand All @@ -257,7 +257,7 @@ my class Str does Stringy {
%opts<c> = 0;
}
%opts<p> = $p if $p.defined;
if $g {
if $g || $overlap {
gather while my $m = $pat(Cursor.'!cursor_init'(self, |%opts)).MATCH {
# XXX a bug in the regex engine means that we can
# match a zero-width match past the end of the string.
Expand All @@ -268,7 +268,9 @@ my class Str does Stringy {

# XXX should be %opts.delete('d'), but Hash.delete is NYI
%opts<d> = Any if %opts<d>;
%opts<c> = $m.to == $m.from ?? $m.to + 1 !! $m.to;
%opts<c> = $overlap
?? $m.from +1
!! ($m.to == $m.from ?? $m.to + 1 !! $m.to);
}
} else {
$pat(Cursor.'!cursor_init'(self, |%opts)).MATCH;
Expand Down

0 comments on commit 98fed2e

Please sign in to comment.