# New Ticket Created by Vasily Chekalkin
# Please include the string: [perl #58308]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=58308 >
Hello.
There is almost copy-pasted version of rindex.
--
Bacek.
commit e23d65f77c2e0963d5647a9ccf585c6484c8323b
Author: Vasily Chekalkin <[EMAIL PROTECTED](none)>
Date: Sun Aug 24 20:40:35 2008 +1000
Implement op rindex
diff --git a/src/ops/ops.num b/src/ops/ops.num
index 24e25fb..18329c8 100644
--- a/src/ops/ops.num
+++ b/src/ops/ops.num
@@ -1224,3 +1224,16 @@ stm_commit_ic 1193
stm_wait_ic 1194
stm_abort 1195
stm_depth_i 1196
+rindex_i_s_s 1197
+rindex_i_sc_s 1198
+rindex_i_s_sc 1199
+rindex_i_sc_sc 1200
+rindex_i_s_s_i 1201
+rindex_i_sc_s_i 1202
+rindex_i_s_sc_i 1203
+rindex_i_sc_sc_i 1204
+rindex_i_s_s_ic 1205
+rindex_i_sc_s_ic 1206
+rindex_i_s_sc_ic 1207
+rindex_i_sc_sc_ic 1208
+
diff --git a/src/ops/string.ops b/src/ops/string.ops
index 066186b..bf483cb 100644
--- a/src/ops/string.ops
+++ b/src/ops/string.ops
@@ -273,6 +273,29 @@ inline op index(out INT, in STR, in STR, in INT) :base_core {
}
+=item B<rindex>(out INT, in STR, in STR)
+
+=item B<rindex>(out INT, in STR, in STR, in INT)
+
+The B<rindex> function searches for a substring within target string, but
+without the wildcard-like behavior of a full regular-expression pattern match.
+It returns the position of the last occurrence of substring $3
+in target string $2 at or after zero-based position $4.
+If $4 is omitted, B<index> starts searching from the beginning of the string.
+The return value is based at "0".
+If the string is null, or the substring is not found or is null,
+B<index> returns "-1".
+
+=cut
+
+inline op rindex(out INT, in STR, in STR) :base_core {
+ $1 = ($2 && $3) ? string_str_rindex(interp, $2, $3, 0) : -1;
+}
+
+inline op rindex(out INT, in STR, in STR, in INT) :base_core {
+ $1 = ($2 && $3) ? string_str_rindex(interp, $2, $3, $4) : -1;
+}
+
=item B<sprintf>(out STR, in STR, invar PMC)
=item B<sprintf>(out PMC, invar PMC, invar PMC)
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