[pypy-svn] r54523 - in pypy/branch/io-improvements/pypy/rlib: . test

fijal at codespeak.net fijal at codespeak.net
Wed May 7 13:10:37 CEST 2008


Author: fijal
Date: Wed May  7 13:10:37 2008
New Revision: 54523

Added:
   pypy/branch/io-improvements/pypy/rlib/rstring.py   (contents, props changed)
   pypy/branch/io-improvements/pypy/rlib/test/test_rstring.py   (contents, props changed)
Log:
add string builder interface


Added: pypy/branch/io-improvements/pypy/rlib/rstring.py
==============================================================================
--- (empty file)
+++ pypy/branch/io-improvements/pypy/rlib/rstring.py	Wed May  7 13:10:37 2008
@@ -0,0 +1,19 @@
+
+""" String builder interface
+"""
+
+INIT_SIZE = 100 # XXX tweak
+
+class StringBuilder(object):
+    def __init__(self, init_size=INIT_SIZE):
+        self.l = []
+
+    def append(self, s):
+        self.l.append(s)
+
+    def append_char(self, c):
+        self.l.append(c)
+
+    def build(self):
+        return "".join(self.l)
+

Added: pypy/branch/io-improvements/pypy/rlib/test/test_rstring.py
==============================================================================
--- (empty file)
+++ pypy/branch/io-improvements/pypy/rlib/test/test_rstring.py	Wed May  7 13:10:37 2008
@@ -0,0 +1,9 @@
+
+from pypy.rlib.rstring import StringBuilder
+
+def test_string_builder():
+    s = StringBuilder()
+    s.append("a")
+    s.append("abc")
+    s.append_char("a")
+    assert s.build() == "aabca"



More information about the Pypy-commit mailing list