[svn:parrot] r49084 - in trunk: runtime/parrot/library t/library

fperrad at svn.parrot.org fperrad at svn.parrot.org
Fri Sep 17 15:19:32 UTC 2010


Author: fperrad
Date: Fri Sep 17 15:19:32 2010
New Revision: 49084
URL: https://trac.parrot.org/parrot/changeset/49084

Log:
[osutils] add rindex()

Modified:
   trunk/runtime/parrot/library/osutils.pir
   trunk/t/library/osutils.t

Modified: trunk/runtime/parrot/library/osutils.pir
==============================================================================
--- trunk/runtime/parrot/library/osutils.pir	Fri Sep 17 14:00:48 2010	(r49083)
+++ trunk/runtime/parrot/library/osutils.pir	Fri Sep 17 15:19:32 2010	(r49084)
@@ -851,6 +851,29 @@
     .return (volume, directories, file)
 .end
 
+=item rindex
+
+=cut
+
+.sub 'rindex'
+    .param string str
+    .param string sstr
+    .param int pos              :optional
+    .param int has_pos          :opt_flag
+    if has_pos goto L1
+    pos = 0
+  L1:
+    $I0 = index str, sstr, pos
+    unless $I0 < 0 goto L2
+    .return ($I0)
+  L2:
+    $I1 = $I0
+    inc $I0
+    $I0 = index str, sstr, $I0
+    unless $I0 < 0 goto L2
+    .return ($I1)
+.end
+
 =back
 
 =head1 AUTHOR

Modified: trunk/t/library/osutils.t
==============================================================================
--- trunk/t/library/osutils.t	Fri Sep 17 14:00:48 2010	(r49083)
+++ trunk/t/library/osutils.t	Fri Sep 17 15:19:32 2010	(r49084)
@@ -21,12 +21,13 @@
 
     load_bytecode 'osutils.pir'
 
-    plan(17)
+    plan(19)
     test_basename()
     test_dirname()
     test_catfile()
     test_splitpath()
     test_newer()
+    test_rindex()
 .end
 
 .sub 'test_basename'
@@ -80,6 +81,13 @@
     nok($I0, "newer('osutils.pir', ['osutils.pir', 'stat.pasm'])")
 .end
 
+.sub 'test_rindex'
+    $I0 = rindex('abc', '.')
+    is($I0, -1, "rindex('abc', '.')")
+    $I0 = rindex('abc.def.ghi', '.')
+    is($I0, 7, "rindex('abc.def.ghi', '.')")
+.end
+
 
 # Local Variables:
 #   mode: pir


More information about the parrot-commits mailing list