[pypy-svn] r65734 - pypy/trunk/pypy/translator/jvm/src/pypy

benjamin at codespeak.net benjamin at codespeak.net
Wed Jun 10 20:41:54 CEST 2009


Author: benjamin
Date: Wed Jun 10 20:41:51 2009
New Revision: 65734

Modified:
   pypy/trunk/pypy/translator/jvm/src/pypy/PyPy.java
Log:
implement splitlines() for jvm

Modified: pypy/trunk/pypy/translator/jvm/src/pypy/PyPy.java
==============================================================================
--- pypy/trunk/pypy/translator/jvm/src/pypy/PyPy.java	(original)
+++ pypy/trunk/pypy/translator/jvm/src/pypy/PyPy.java	Wed Jun 10 20:41:51 2009
@@ -746,6 +746,36 @@
         return str.substring(start, end);
     }
 
+    public static Object[] ll_splitlines(String str, boolean keep_newlines) {
+        ArrayList lines = new ArrayList();
+        int i = 0, j = 0;
+        int length = str.length();
+        while (i < length) {
+            int eol;
+            while (i < length && str.charAt(i) != '\n' && str.charAt(i) != '\r') {
+                i++;
+            }
+            eol = i;
+            if (i < length) {
+                if (str.charAt(i) == '\r' && i + 1 < length &&
+                    str.charAt(i + 1) == '\n') {
+                    i += 2;
+                } else {
+                    i++;
+                }
+                if (keep_newlines) {
+                    eol = i;
+                }
+            }
+            lines.add(str.substring(j, eol));
+            j = i;
+        }
+        if (j < length) {
+            lines.add(str.substring(j, length));
+        }
+        return lines.toArray(new String[lines.size()]);
+    }
+        
     public static Object[] ll_split_chr(String str, char c) {
         ArrayList list = new ArrayList();
         int lastidx = 0, idx = 0;



More information about the Pypy-commit mailing list