| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Rakudo
Revision: 30856
Author: moritz
Date: 07 Sep 2008 09:09:35
Changes:[rakudo] implement Str.rindex, bacek++. Closes RT #58308
Patch courtesy by Vasily Chekalkin
| ... | ...@@ -21,7 +21,7 @@ | |
| 21 | 21 | .namespace [] |
| 22 | 22 | .sub 'onload' :anon :init :load |
| 23 | 23 | $P0 = get_hll_namespace ['Any'] |
| 24 | '!EXPORT'('chars index substr', 'from'=>$P0) | |
| 24 | '!EXPORT'('chars index rindex substr', 'from'=>$P0) | |
| 25 | 25 | .end |
| 26 | 26 | |
| 27 | 27 | |
| ... | ...@@ -75,6 +75,48 @@ | |
| 75 | 75 | .return ($P0) |
| 76 | 76 | .end |
| 77 | 77 | |
| 78 | =item rindex() | |
| 79 | ||
| 80 | =cut | |
| 81 | ||
| 82 | .namespace ['Any'] | |
| 83 | .sub 'rindex' :method :multi(_, _) | |
| 84 | .param string substring | |
| 85 | .param int pos :optional | |
| 86 | .param int has_pos :opt_flag | |
| 87 | .local pmc retv | |
| 88 | ||
| 89 | check_substring: | |
| 90 | if substring goto substring_search | |
| 91 | ||
| 92 | # we do not have substring return pos or length | |
| 93 | ||
| 94 | .local string s | |
| 95 | s = self | |
| 96 | $I0 = length s | |
| 97 | ||
| 98 | if has_pos goto have_pos | |
| 99 | pos = $I0 | |
| 100 | goto done | |
| 101 | have_pos: | |
| 102 | if pos < $I0 goto done | |
| 103 | pos = $I0 | |
| 104 | goto done | |
| 105 | ||
| 106 | substring_search: | |
| 107 | pos = self.'reverse_index'(substring, pos) | |
| 108 | if pos < 0 goto fail | |
| 109 | ||
| 110 | done: | |
| 111 | $P0 = new 'Int' | |
| 112 | $P0 = pos | |
| 113 | .return ($P0) | |
| 114 | ||
| 115 | fail: | |
| 116 | $P0 = new 'Failure' | |
| 117 | .return ($P0) | |
| 118 | .end | |
| 119 | ||
| 78 | 120 | =item substr() |
| 79 | 121 | |
| 80 | 122 | =cut |