[pypy-svn] pypy default: Add java implementation of str.rsplit()

amauryfa commits-noreply at bitbucket.org
Wed Mar 30 19:54:03 CEST 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r43028:1c14a2e9dad8
Date: 2011-03-30 13:59 +0200
http://bitbucket.org/pypy/pypy/changeset/1c14a2e9dad8/

Log:	Add java implementation of str.rsplit()

diff --git a/pypy/translator/jvm/src/pypy/PyPy.java b/pypy/translator/jvm/src/pypy/PyPy.java
--- a/pypy/translator/jvm/src/pypy/PyPy.java
+++ b/pypy/translator/jvm/src/pypy/PyPy.java
@@ -761,6 +761,21 @@
         return list.toArray(new String[list.size()]);
     }
 
+    public static Object[] ll_rsplit_chr(String str, char c, int max) {
+        ArrayList list = new ArrayList();
+        int lastidx = str.length(), idx = 0;
+        while ((idx = str.lastIndexOf(c, lastidx - 1)) != -1)
+        {
+            if (max >= 0 && list.size() >= max)
+                break;
+            String sub = str.substring(idx + 1, lastidx);
+            list.add(0, sub);
+            lastidx = idx;
+        }
+        list.add(0, str.substring(0, lastidx));
+        return list.toArray(new String[list.size()]);
+    }
+
     public static String ll_substring(String str, int start, int cnt) {
         return str.substring(start,start+cnt);
     }


More information about the Pypy-commit mailing list