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

fijal at codespeak.net fijal at codespeak.net
Sat May 10 22:05:51 CEST 2008


Author: fijal
Date: Sat May 10 22:05:50 2008
New Revision: 54637

Modified:
   pypy/branch/io-improvements/pypy/rlib/rstring.py
   pypy/branch/io-improvements/pypy/rlib/test/test_rstring.py
Log:
add to string builder operation append_slice which takes a source string,
start and end of slice to add


Modified: pypy/branch/io-improvements/pypy/rlib/rstring.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rlib/rstring.py	(original)
+++ pypy/branch/io-improvements/pypy/rlib/rstring.py	Sat May 10 22:05:50 2008
@@ -14,6 +14,9 @@
     def append(self, s):
         self.l.append(s)
 
+    def append_slice(self, s, start, end):
+        self.l.append(s[start:end])
+
 class StringBuilder(AbstractStringBuilder):
     def build(self):
         return "".join(self.l)

Modified: pypy/branch/io-improvements/pypy/rlib/test/test_rstring.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rlib/test/test_rstring.py	(original)
+++ pypy/branch/io-improvements/pypy/rlib/test/test_rstring.py	Sat May 10 22:05:50 2008
@@ -6,12 +6,13 @@
     s.append("a")
     s.append("abc")
     s.append("a")
-    assert s.build() == "aabca"
+    s.append_slice("abc", 1, 2)
+    assert s.build() == "aabcab"
 
 def test_unicode_builder():
     s = UnicodeBuilder()
     s.append(u'a')
     s.append(u'abc')
-    s.append(u'abcdef')
-    assert s.build() == 'aabcabcdef'
+    s.append_slice(u'abcdef', 1, 2)
+    assert s.build() == 'aabcb'
     assert isinstance(s.build(), unicode)



More information about the Pypy-commit mailing list