# New Ticket Created by Vasily Chekalkin # Please include the string: [perl #58310] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=58310 >
Hello. Trivial implementation of Str.rindex (depends on #58308) -- Bacek
commit bbd7144bee1648f4516d61a98b48177b1370fe78 Author: Vasily Chekalkin <[EMAIL PROTECTED](none)> Date: Sun Aug 24 20:51:41 2008 +1000 Implement rindex diff --git a/languages/perl6/src/builtins/any-str.pir b/languages/perl6/src/builtins/any-str.pir index 77bb24c..84a62c6 100644 --- a/languages/perl6/src/builtins/any-str.pir +++ b/languages/perl6/src/builtins/any-str.pir @@ -21,7 +21,7 @@ the size of that file down and to emphasize their generic, .namespace [] .sub 'onload' :anon :init :load $P0 = get_hll_namespace ['Any'] - '!EXPORT'('chars index substr', 'from'=>$P0) + '!EXPORT'('chars index rindex substr', 'from'=>$P0) .end @@ -75,6 +75,44 @@ the size of that file down and to emphasize their generic, .return ($P0) .end +=item rindex() + +=cut + +.namespace ['Any'] +.sub 'rindex' :method :multi(_) + .param string substring + .param int pos :optional + .param int has_pos :opt_flag + .local pmc retv + + if has_pos goto have_pos + pos = 0 + have_pos: + + .local string s + s = self + + check_substring: + if substring goto substring_search + $I0 = length s + if pos < $I0 goto done + pos = $I0 + goto done + + substring_search: + pos = rindex s, substring, pos + if pos < 0 goto fail + + done: + $P0 = new 'Int' + $P0 = pos + .return ($P0) + + fail: + $P0 = new 'Failure' + .return ($P0) +.end =item substr() =cut