Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: Changeset: r64905:b89e2ccc4560 Date: 2013-06-13 23:47 +0200 http://bitbucket.org/pypy/pypy/changeset/b89e2ccc4560/
Log: use rstring.split diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py --- a/pypy/objspace/std/unicodeobject.py +++ b/pypy/objspace/std/unicodeobject.py @@ -16,7 +16,7 @@ from rpython.rlib.rarithmetic import ovfcheck from rpython.rlib.objectmodel import ( compute_hash, compute_unique_id, specialize) -from rpython.rlib.rstring import UnicodeBuilder +from rpython.rlib.rstring import UnicodeBuilder, split, rsplit from rpython.rlib.runicode import make_unicode_escape_function from rpython.tool.sourcetools import func_with_new_name @@ -688,7 +688,7 @@ if delim_len == 0: raise OperationError(space.w_ValueError, space.wrap('empty separator')) - parts = _split_with(self, delim, maxsplit) + parts = split(self, delim, maxsplit) return space.newlist_unicode(parts) @@ -727,15 +727,13 @@ res.reverse() return space.newlist_unicode(res) -def sliced(space, s, start, stop, orig_obj): - assert start >= 0 - assert stop >= 0 - if start == 0 and stop == len(s) and space.is_w(space.type(orig_obj), space.w_unicode): - return orig_obj - return space.wrap( s[start:stop]) - -unicode_rsplit__Unicode_Unicode_ANY = make_rsplit_with_delim('unicode_rsplit__Unicode_Unicode_ANY', - sliced) +def unicode_rsplit__Unicode_Unicode_ANY(space, w_self, w_by, w_maxsplit=-1): + maxsplit = space.int_w(w_maxsplit) + value = w_self._value + by = w_by._value + if not by: + raise OperationError(space.w_ValueError, space.wrap("empty separator")) + return space.newlist_unicode(rsplit(value, by, maxsplit)) def _split_into_chars(self, maxsplit): if maxsplit == 0: @@ -753,21 +751,6 @@ parts.append(self[index:]) return parts -def _split_with(self, with_, maxsplit=-1): - parts = [] - start = 0 - end = len(self) - length = len(with_) - while maxsplit != 0: - index = self.find(with_, start, end) - if index < 0: - break - parts.append(self[start:index]) - start = index + length - maxsplit -= 1 - parts.append(self[start:]) - return parts - def unicode_replace__Unicode_Unicode_Unicode_ANY(space, w_self, w_old, w_new, w_maxsplit): return _unicode_replace(space, w_self, w_old._value, w_new._value, @@ -787,7 +770,7 @@ def _unicode_replace(space, w_self, old, new, w_maxsplit): if len(old): - parts = _split_with(w_self._value, old, space.int_w(w_maxsplit)) + parts = split(w_self._value, old, space.int_w(w_maxsplit)) else: self = w_self._value maxsplit = space.int_w(w_maxsplit) @@ -848,7 +831,7 @@ def unicode_expandtabs__Unicode_ANY(space, w_self, w_tabsize): self = w_self._value tabsize = space.int_w(w_tabsize) - parts = _split_with(self, u'\t') + parts = self.split(self, u'\t') result = [parts[0]] prevsize = 0 for ch in parts[0]: _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit