Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implement .index and .rindex methods
The default values seem to not work yet, but I trust that jnthn++ will fix that in time
  • Loading branch information
moritz committed Jun 7, 2011
1 parent 25cd9f7 commit 6c01923
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/CORE.setting/Cool.pm
Expand Up @@ -61,4 +61,27 @@ my class Cool {
pir::box__PS(pir::repr_unbox_str__SP(self.Str)).reverse
);
}

proto method index(|$) {*}
multi method index(Cool \$needle, Cool $pos = 0) {
my $result := pir::perl6_box_int__PI(pir::index__ISSI(
pir::repr_unbox_str__SP(self.Str),
pir::repr_unbox_str__SP($needle.Str),
pir::repr_unbox_int__IP($pos.Int)
));
# TODO: fail() instead of returning Str
$result < 0 ?? Str !! $result;
}

proto method rindex(|$) {*}
multi method rindex(Cool \$needle, Cool $pos = self.chars) {
my $result := pir::perl6_box_int__PI(
pir::box__PS(pir::repr_unbox_str__SP(self.Str)).reverse_index(
pir::repr_unbox_str__SP($needle.Str),
pir::repr_unbox_int__IP($pos.Int)
)
);
# TODO: fail() instead of returning Str
$result < 0 ?? Str !! $result;
}
}

0 comments on commit 6c01923

Please sign in to comment.