[pypy-svn] rev 986 - in pypy/trunk/src/pypy/objspace/std: . test
tomek at codespeak.net
tomek at codespeak.net
Mon Jun 23 13:49:40 CEST 2003
Author: tomek
Date: Mon Jun 23 13:49:39 2003
New Revision: 986
Modified:
pypy/trunk/src/pypy/objspace/std/stringobject.py
pypy/trunk/src/pypy/objspace/std/stringtype.py
pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py
Log:
I added zfill method and string x int multiplikation
Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/stringobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/stringobject.py Mon Jun 23 13:49:39 2003
@@ -42,8 +42,8 @@
encode !Unicode not supported now
endswith str_endswith__String_String [optional arguments not supported now]
expandtabs str_expandtabs__String_Int
-find OK, nur noch tests
-index OK, nur noch tests
+find OK
+index OK
isalnum def str_isalnum__String(space, w_self): def _isalnum(ch):
isalpha def str_isalpha__String(space, w_self): def _isalpha(ch):
isdigit def str_isdigit__String(space, w_self): def _isdigit(ch):
@@ -68,7 +68,7 @@
title def str_title__String(space, w_self):
translate
upper def str_upper__String(space, w_self):
-zfill
+zfill *Tomek
"""
from pypy.objspace.std.objspace import *
@@ -582,7 +582,34 @@
u_expanded += " " * u_tabsize
return W_StringObject(space, u_expanded)
-
+
+def str_zfill__String_Int(space, w_self, w_width):
+ u = space.unwrap
+ input = u(w_self)
+ width = u(w_width)
+
+ if len(input) >= width:
+ return w_self
+
+ b = width - len(input)
+
+ buf = [' '] * width
+ if len(input) > 0 and (input[0] == '+' or input[0] == '-'):
+ buf[0] = input[0]
+ start = 1
+ middle = width - len(input) + 1
+ else:
+ start = 0
+ middle = width - len(input)
+
+ for i in range(start, middle):
+ buf[i] = '0'
+
+ for i in range(middle, width):
+ buf[i] = input[start]
+ start = start + 1
+
+ return space.wrap("".join(buf))
def unwrap__String(space, w_str):
return w_str._value
@@ -707,6 +734,21 @@
w_empty = space.newstring([])
return str_join(space, w_empty, w_r)
+def mul__String_Int(space, w_str, w_mul):
+ u = space.unwrap
+ input = u(w_str)
+ mul = u(w_mul)
+
+ buffer = [' '] * (mul*len(input))
+
+ pos = 0
+ for i in range(mul):
+ for j in range(len(input)):
+ buffer[pos] = input[j]
+ pos = pos + 1
+
+ return space.wrap("".join(buffer))
+
def add__String_String(space, w_left, w_right):
u = space.unwrap
right = u(w_right)
Modified: pypy/trunk/src/pypy/objspace/std/stringtype.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/stringtype.py (original)
+++ pypy/trunk/src/pypy/objspace/std/stringtype.py Mon Jun 23 13:49:39 2003
@@ -29,6 +29,7 @@
str_rfind = MultiMethod('rfind', 4, defaults=(None, None))
str_index = MultiMethod('index', 4, defaults=(None, None))
str_rindex = MultiMethod('rindex', 4, defaults=(None, None))
+ str_zfill = MultiMethod('zfill', 2)
str_strip = MultiMethod('strip', 1)
str_rstrip = MultiMethod('rstrip', 1)
Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Mon Jun 23 13:49:39 2003
@@ -212,7 +212,7 @@
self.assertEquals('xyzzyhelloxyzzy'.lstrip('xyz'), 'helloxyzzy')
self.assertEquals('xyzzyhelloxyzzy'.rstrip('xyz'), 'xyzzyhello')
- def _test_zfill(self):
+ def test_zfill(self):
self.assertEquals('123'.zfill(2), '123')
self.assertEquals('123'.zfill(3), '123')
self.assertEquals('123'.zfill(4), '0123')
More information about the Pypy-commit
mailing list