Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #510 from skids/glr2
Handle :0x and :nth(*) correctly and always return Positional
  • Loading branch information
moritz committed Aug 22, 2015
2 parents b9a76ce + acd1af9 commit c4742a6
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/core/Str.pm
Expand Up @@ -604,12 +604,12 @@ my class Str does Stringy { # declared in BOOTSTRAP
# Translate :nth lists to monotonic 0-based indices
my sub nthidx($n is copy) {

if nqp::istype($n, Callable) {
# Whatevers force us to remember early
if nqp::istype($n, Callable) or nqp::istype($n, Whatever) {
# WhateverCode forces us to remember early
once @matches := $matches.list;
once $matches := Nil;
# Whatevers are 1-based
$n = $n(+@matches)
# WhateverCode is 1-based
$n = nqp::istype($n, Whatever) ?? +@matches !! $n(+@matches);
}

state $max = -Inf;
Expand Down Expand Up @@ -649,11 +649,11 @@ my class Str does Stringy { # declared in BOOTSTRAP
X::Str::Match::x.new(:got($x)).fail;
}
$clip := 0..($clip.max) if $clip.min < 0;
return Slip.new() if $clip.max < $clip.min;
return Slip.new() if $clip.max < 1 or $clip.max < $clip.min;

if $nth.defined {
$idxs := $nth.map(&nthidx).Array;
return Nil
return Slip.new()
if $clip.min and not $idxs.EXISTS-POS($clip.min - 1);
}
else {
Expand All @@ -667,7 +667,6 @@ my class Str does Stringy { # declared in BOOTSTRAP
@matches := ();
}


# Just "list $matches.grep", once we have True.last
@matches := (gather do for $matches -> $m {
state $i = 0;
Expand Down

0 comments on commit c4742a6

Please sign in to comment.