[pypy-svn] rev 663 - pypy/trunk/src/pypy/objspace/std

alex at codespeak.net alex at codespeak.net
Thu May 29 14:30:19 CEST 2003


Author: alex
Date: Thu May 29 14:30:19 2003
New Revision: 663

Modified:
   pypy/trunk/src/pypy/objspace/std/stringobject.py
Log:
need to fix split by spaces...



Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/stringobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/stringobject.py	Thu May 29 14:30:19 2003
@@ -51,15 +51,13 @@
         else:
             return W_StringObject(w_self.space, "")
 
-    def split(w_self, w_by=None):
+    def splitByWhitespace(w_self):
         res = []
         inword = 0
         for ch in w_self.value:
-            if ch==w_by.value or w_by is None and ch.isspace():
+            if ch.isspace():
                 if inword:
                     inword = 0
-                elif w_by is not None:
-                    res.append('')
             else:
                 if inword:
                     res[-1] += ch
@@ -70,6 +68,21 @@
             res[i] = W_StringObject(w_self.space, res[i])
         return W_ListObject(w_self.space, res)
 
+    def split(w_self, w_by=None):
+        if w_by is None: return w_self.splitByWhiteSpace
+        res = []
+        start = 0
+        while 1:
+            next = w_self.value.find(w_by.value, start)
+            if next < 0:
+                res.append(w_self.value[start:])
+                break
+            res.append(w_self.value[start:next])
+            start = next + len(w_by.value)
+        for i in range(len(res)):
+            res[i] = W_StringObject(w_self.space, res[i])
+        return W_ListObject(w_self.space, res)
+
 def getattr_str(space, w_list, w_attr):
     if space.is_true(space.eq(w_attr, space.wrap('join'))):
         w_builtinfn = make_builtin_func(space, W_StringObject.join)


More information about the Pypy-commit mailing list