Skip to content

Commit

Permalink
Fix .comb(Str) to ensure non-overlapping results
Browse files Browse the repository at this point in the history
It is expected that .comb() returns non-overlapping results, and
.comb('aa') should yield the same results as .comb(/aa/).
  • Loading branch information
softmoth committed May 6, 2020
1 parent feb0367 commit 8d5a0f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/core.c/Str.pm6
Expand Up @@ -979,10 +979,12 @@ my class Str does Stringy { # declared in BOOTSTRAP
my class CombPat does Iterator {
has str $!str;
has str $!pat;
has int $!patsz;
has int $!pos;
method !SET-SELF(\string, \pat) {
$!str = nqp::unbox_s(string);
$!pat = nqp::unbox_s(pat);
$!patsz = nqp::chars($!pat);
self
}
method new(\string, \pat) { nqp::create(self)!SET-SELF(string,pat) }
Expand All @@ -992,7 +994,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
IterationEnd
}
else {
$!pos = $found + 1;
$!pos = $found + $!patsz;
nqp::p6box_s($!pat)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/core.c/Supply-factories.pm6
Expand Up @@ -622,6 +622,7 @@
?? supply {
my str $str;
my str $needle = $the-needle;
my int $len = nqp::chars($needle);
whenever self -> str $val {
$str = nqp::concat($str,$val);

Expand All @@ -631,7 +632,7 @@
nqp::isgt_i(($i = nqp::index($str,$needle,$pos)),-1),
nqp::stmts(
emit($the-needle),
($pos = $i + 1)
($pos = $i + $len)
)
);
$str = nqp::substr($str,$pos);
Expand Down

0 comments on commit 8d5a0f7

Please sign in to comment.