Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Undo special tests for index/rindex/indices
The test should really live in nqp::unbox_i, as mentioned in
http://irclog.perlgeek.de/perl6/2015-08-15#i_11061969
  • Loading branch information
lizmat committed Aug 16, 2015
1 parent 76b71ca commit 8a7b83f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/core/Cool.pm
Expand Up @@ -196,10 +196,8 @@ my class Cool { # declared in BOOTSTRAP

proto method indices(|) {*}
multi method indices(Cool:D: Str(Cool) $needle, Int(Cool) $start = 0, :$overlap) {
my str $str = nqp::unbox_s(self.Str);
return () if $start < 0 || $start > nqp::chars($str);

my int $pos = $start;
my str $str = nqp::unbox_s(self.Str);
my str $need = nqp::unbox_s($needle);
my int $add = $overlap ?? 1 !! nqp::chars($need) || 1;

Expand All @@ -220,10 +218,11 @@ my class Cool { # declared in BOOTSTRAP
$i < 0 ?? Nil !! nqp::box_i($i,Int);
}
multi method index(Cool:D: Str(Cool) $needle, Int(Cool) $pos) {
my str $str = nqp::unbox_s(self.Str);
my int $i = $pos < 0 || $pos > nqp::chars($str)
?? -1
!! nqp::index($str, nqp::unbox_s($needle), nqp::unbox_i($pos));
my int $i = nqp::index(
nqp::unbox_s(self.Str),
nqp::unbox_s($needle),
nqp::unbox_i($pos)
);
$i < 0 ?? Nil !! nqp::box_i($i,Int);
}

Expand All @@ -233,10 +232,11 @@ my class Cool { # declared in BOOTSTRAP
$i < 0 ?? Nil !! nqp::box_i($i,Int);
}
multi method rindex(Cool:D: Str(Cool) $needle, Int(Cool) $pos) {
my str $str = nqp::unbox_s(self.Str);
my int $i = $pos < 0 || $pos > nqp::chars($str)
?? -1
!! nqp::rindex($str, nqp::unbox_s($needle), nqp::unbox_i($pos));
my int $i = nqp::rindex(
nqp::unbox_s(self.Str),
nqp::unbox_s($needle),
nqp::unbox_i($pos)
);
$i < 0 ?? Nil !! nqp::box_i($i,Int);
}

Expand Down

0 comments on commit 8a7b83f

Please sign in to comment.