[pypy-svn] r58933 - pypy/branch/2.5-merge/pypy/objspace/std
iko at codespeak.net
iko at codespeak.net
Fri Oct 10 20:02:55 CEST 2008
Author: iko
Date: Fri Oct 10 20:02:54 2008
New Revision: 58933
Modified:
pypy/branch/2.5-merge/pypy/objspace/std/stringobject.py
Log:
(iko, cfbolz)
_split_helper didn't work out, revert a bit
Modified: pypy/branch/2.5-merge/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/objspace/std/stringobject.py (original)
+++ pypy/branch/2.5-merge/pypy/objspace/std/stringobject.py Fri Oct 10 20:02:54 2008
@@ -260,30 +260,25 @@
return space.newlist(res_w)
-def _split_helper(space, value, sep, maxsplit):
+def str_split__String_String_ANY(space, w_self, w_by, w_maxsplit=-1):
+ maxsplit = space.int_w(w_maxsplit)
+ value = w_self._value
+ by = w_by._value
+ bylen = len(by)
+ if bylen == 0:
+ raise OperationError(space.w_ValueError, space.wrap("empty separator"))
+
res_w = []
start = 0
- seplen = len(sep)
-
while maxsplit != 0:
- next = value.find(sep, start)
+ next = value.find(by, start)
if next < 0:
break
res_w.append(sliced(space, value, start, next))
- start = next + seplen
+ start = next + bylen
maxsplit -= 1 # NB. if it's already < 0, it stays < 0
res_w.append(sliced(space, value, start, len(value)))
-
-def str_split__String_String_ANY(space, w_self, w_by, w_maxsplit=-1):
- maxsplit = space.int_w(w_maxsplit)
- value = w_self._value
- by = w_by._value
- bylen = len(by)
- if bylen == 0:
- raise OperationError(space.w_ValueError, space.wrap("empty separator"))
-
- res_w = _split_helper(space, value, by, maxsplit)
return space.newlist(res_w)
def str_rsplit__String_None_ANY(space, w_self, w_none, w_maxsplit=-1):
@@ -494,8 +489,20 @@
substrings_w.append(c)
substrings_w.append(input[upper:])
else:
- substrings_w = _split_helper(space, input, sub, maxsplit)
-
+ start = 0
+ sublen = len(sub)
+ substrings_w = []
+
+ while maxsplit != 0:
+ next = input.find(sub, start)
+ if next < 0:
+ break
+ substrings_w.append(input[start:next])
+ start = next + sublen
+ maxsplit -= 1 # NB. if it's already < 0, it stays < 0
+
+ substrings_w.append(input[start:])
+
try:
# XXX conservative estimate. If your strings are that close
# to overflowing, bad luck.
More information about the Pypy-commit
mailing list