[pypy-svn] r73085 - in pypy/branch/cpython-extension/pypy: module/cpyext rlib

xoraxax at codespeak.net xoraxax at codespeak.net
Mon Mar 29 17:20:05 CEST 2010


Author: xoraxax
Date: Mon Mar 29 17:20:02 2010
New Revision: 73085

Removed:
   pypy/branch/cpython-extension/pypy/rlib/string.py
Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
   pypy/branch/cpython-extension/pypy/rlib/rstring.py
Log:
Use rstring and move code.

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py	Mon Mar 29 17:20:02 2010
@@ -21,7 +21,7 @@
 from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr, PyTypeObject, \
         PyGetSetDef
 from pypy.module.cpyext.slotdefs import slotdefs
-from pypy.rlib.string import split
+from pypy.rlib.rstring import rsplit
 
 
 class W_GetSetPropertyEx(GetSetProperty):
@@ -98,7 +98,7 @@
         # XXX missing: convert_member_defs
 
         full_name = rffi.charp2str(pto.c_tp_name)
-        module_name, extension_name = split(full_name, ".", 1)
+        module_name, extension_name = rsplit(full_name, ".", 1)
         dict_w["__module__"] = space.wrap(module_name)
 
         W_TypeObject.__init__(self, space, extension_name,

Modified: pypy/branch/cpython-extension/pypy/rlib/rstring.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/rstring.py	(original)
+++ pypy/branch/cpython-extension/pypy/rlib/rstring.py	Mon Mar 29 17:20:02 2010
@@ -1,11 +1,49 @@
-
-""" String builder interface
+""" String builder interface and string functions
 """
 
 from pypy.rpython.extregistry import ExtRegistryEntry
 from pypy.annotation.model import SomeObject, SomeString, s_None,\
      SomeChar, SomeInteger, SomeUnicodeCodePoint, SomeUnicodeString
 
+
+# -------------- public API for string functions -----------------------
+def split(value, by, maxsplit=-1):
+    bylen = len(by)
+    if bylen == 0:
+        raise ValueError("empty separator")
+
+    res = []
+    start = 0
+    while maxsplit != 0:
+        next = value.find(by, start)
+        if next < 0:
+            break
+        res.append(value[start:next])
+        start = next + bylen
+        maxsplit -= 1   # NB. if it's already < 0, it stays < 0
+
+    res.append(value[start:len(value)])
+    return res
+
+def rsplit(value, by, maxsplit=-1):
+    res = []
+    end = len(value)
+    bylen = len(by)
+    if bylen == 0:
+        raise ValueError("empty separator")
+
+    while maxsplit != 0:
+        next = value.rfind(by, 0, end)
+        if next < 0:
+            break
+        res.append(value[next+bylen:end])
+        end = next
+        maxsplit -= 1   # NB. if it's already < 0, it stays < 0
+
+    res.append(value[:end])
+    res.reverse()
+    return res
+
 # -------------- public API ---------------------------------
 
 INIT_SIZE = 100 # XXX tweak



More information about the Pypy-commit mailing list