Skip to content

Commit

Permalink
re-enable Cool.rindex
Browse files Browse the repository at this point in the history
requires rewriting the reverse_index opcode with the same method on the
parrot String. Also enable rindex.t
  • Loading branch information
moritz committed Jun 28, 2010
1 parent c18d372 commit cccc121
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
25 changes: 11 additions & 14 deletions src/core/Cool-str.pm
Expand Up @@ -220,21 +220,18 @@ augment class Cool {
# .tailcall '!FAIL'("Attempt to index from negative position")
}


# S32/Str says that this should always return a StrPos object
# our Int multi method rindex($substring, $pos?) is export {
# if ($substring.chars == 0) {
# my $string_length = self.chars;
# return $pos.defined && $pos < $string_length ?? $pos !! $string_length;
# }
#
# my $result = pir::reverse_index__ISSi(self, $substring, $pos);
# fail("Substring '$substring' not found in '{self}'") if $result < 0;
# return $result;
#
# # also used to be a the following error message, but the condition
# # was never checked:
# # .tailcall '!FAIL'("Attempt to index from negative position")
# }
our Int multi method rindex($substring, $pos?) is export {
if ($substring.chars == 0) {
my $string_length = self.chars;
return $pos.defined && $pos < $string_length ?? $pos !! $string_length;
}

my $result = (~self).reverse_index($substring, $pos);
fail("Substring '$substring' not found in '{self}'") if $result < 0;
return $result;
}

our Str multi method chop() is export {
self.substr(0, -1)
Expand Down
2 changes: 1 addition & 1 deletion t/spectest.data
Expand Up @@ -560,7 +560,7 @@ S32-str/lc.t # icu
# S32-str/p5chomp.t
S32-str/p5chop.t
S32-str/pos.t
# S32-str/rindex.t
S32-str/rindex.t
S32-str/samecase.t # icu
# S32-str/split-simple.t
S32-str/split-simple2.t # CHEAT! simplified version of split-simple.t
Expand Down

0 comments on commit cccc121

Please sign in to comment.