[pypy-svn] rev 889 - in pypy/trunk/src/pypy/objspace/std: . test
tomek at codespeak.net
tomek at codespeak.net
Sat Jun 21 19:55:46 CEST 2003
Author: tomek
Date: Sat Jun 21 19:55:46 2003
New Revision: 889
Modified:
pypy/trunk/src/pypy/objspace/std/rarray.py
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 two methods, title and capitalize, and the tests
Modified: pypy/trunk/src/pypy/objspace/std/rarray.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/rarray.py (original)
+++ pypy/trunk/src/pypy/objspace/std/rarray.py Sat Jun 21 19:55:46 2003
@@ -44,6 +44,10 @@
"""returns char at the index"""
return self._value[idx]
+ def setcharat(self, idx, ch):
+ """sets char at the index"""
+ self._value[idx] = ch
+
def setsize(self, size):
"""set size of the buffer to size"""
self._value = array.array('c', ' ' * size)
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 Sat Jun 21 19:55:46 2003
@@ -86,6 +86,44 @@
def str_istitle(space, w_self):
pass
+def str_upper__String(space, w_self):
+ up = W_StringObject(space, w_self._value.value())
+ for i in range(up._value.len):
+ ch = up._value.charat(i)
+ if _islower(ch):
+ o = ord(ch) - 32
+ up._value.setcharat(i, chr(o))
+
+ return up
+
+def str_capitalize__String(space, w_self):
+ w_str = W_StringObject(space, space.unwrap(w_self))
+ buffer = w_str._value
+ if buffer.len > 0:
+ ch = buffer.charat(0)
+ if _islower(ch):
+ o = ord(ch) - 32
+ buffer.setcharat(0, chr(o))
+ return w_str
+
+def str_title__String(space, w_self):
+ w_str = W_StringObject(space, space.unwrap(w_self))
+ buffer = w_str._value
+ inword = 0
+
+ for pos in range(0, buffer.len):
+ ch = buffer.charat(pos)
+ if ch.isspace():
+ if inword:
+ inword = 0
+ else:
+ if not inword:
+ if _islower(ch):
+ o = ord(ch) - 32
+ buffer.setcharat(pos, chr(o))
+ inword = 1
+ return w_str
+
def str_split__String_None_Int(space, w_self, w_none, w_maxsplit=-1):
res = []
inword = 0
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 Sat Jun 21 19:55:46 2003
@@ -9,15 +9,20 @@
str_join = MultiMethod('join', 2)
str_split = MultiMethod('split', 3, defaults=(None,-1))
- str_isdigit = MultiMethod('isdigit', 1)
- str_isalpha = MultiMethod('isalpha', 1)
- str_isspace = MultiMethod('isspace', 1)
- str_isupper = MultiMethod('isupper', 1)
- str_islower = MultiMethod('islower', 1)
- str_istitle = MultiMethod('istitle', 1)
- str_isalnum = MultiMethod('isalnum', 1)
- str_ljust = MultiMethod('ljust', 2)
- str_rjust = MultiMethod('rjust', 2)
+ str_isdigit = MultiMethod('isdigit', 1)
+ str_isalpha = MultiMethod('isalpha', 1)
+ str_isspace = MultiMethod('isspace', 1)
+ str_isupper = MultiMethod('isupper', 1)
+ str_islower = MultiMethod('islower', 1)
+ str_istitle = MultiMethod('istitle', 1)
+ str_isalnum = MultiMethod('isalnum', 1)
+ str_ljust = MultiMethod('ljust', 2)
+ str_rjust = MultiMethod('rjust', 2)
+ str_upper = MultiMethod('upper', 1)
+ str_capitalize = MultiMethod('capitalize', 1)
+ str_title = MultiMethod('title', 1)
+
+
# XXX we'll worry about the __new__/__init__ distinction later
def new__StringType_ANY_ANY(space, w_stringtype, w_args, w_kwds):
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 Sat Jun 21 19:55:46 2003
@@ -135,6 +135,12 @@
def test_split_splitchar(self):
self.assertEquals("/a/b/c".split('/'), ['','a','b','c'])
+ def test_title(self):
+ self.assertEquals("brown fox".title(), "Brown Fox")
+
+ def test_capitalize(self):
+ self.assertEquals("brown fox".capitalize(), "Brown fox")
+
def test_rjust(self):
s = "abc"
self.assertEquals(s.rjust(2), s)
More information about the Pypy-commit
mailing list