[pypy-svn] rev 975 - in pypy/trunk/src/pypy/objspace/std: . test

tomek at codespeak.net tomek at codespeak.net
Mon Jun 23 11:07:32 CEST 2003


Author: tomek
Date: Mon Jun 23 11:07:32 2003
New Revision: 975

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 swapcase to stringobject


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 11:07:32 2003
@@ -53,7 +53,7 @@
 isupper           def str_isupper__String(space, w_self): def _isupper(ch):
 join              def str_join__String_ANY(space, w_self, w_list):
 ljust             def str_ljust__String_ANY(space, w_self, w_arg):
-lower      
+lower             OK
 lstrip            def str_lstrip__String(space, w_self):
 replace           *Tomek
 rfind             OK, nur noch tests
@@ -64,7 +64,7 @@
 splitlines        *Günter
 startswith        *Günter
 strip             def str_strip__String(space, w_self):
-swapcase
+swapcase          OK
 title             def str_title__String(space, w_self):
 translate
 upper             def str_upper__String(space, w_self):
@@ -183,6 +183,22 @@
 
     return space.wrap("".join(res))
 
+def str_swapcase__String(space, w_self):
+    self = space.unwrap(w_self)
+    res = [' '] * len(self)
+    for i in range(len(self)):
+        ch = self[i]
+        if _isupper(ch):
+            o = ord(ch) + 32
+            res[i] = chr(o)
+        elif _islower(ch):
+            o = ord(ch) - 32
+            res[i] = chr(o)
+        else:
+            res[i] = ch
+
+    return space.wrap("".join(res))
+
     
 def str_capitalize__String(space, w_self):
     input = space.unwrap(w_self)
@@ -262,7 +278,9 @@
         splitcount = maxsplit
 
     while splitcount:             
-        next = value.find(by, start)
+        next = _find(value, by, start, len(value), 1)
+        #next = value.find(by, start)    #of course we cannot use 
+                                         #the find method, 
         if next < 0:
             res.append(value[start:])
             start = len(value) + 1      

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 11:07:32 2003
@@ -20,6 +20,7 @@
     str_rjust      = MultiMethod('rjust', 2)
     str_upper      = MultiMethod('upper', 1)
     str_lower      = MultiMethod('lower', 1)
+    str_swapcase   = MultiMethod('swapcase', 1)
     str_capitalize = MultiMethod('capitalize', 1)
     str_title      = MultiMethod('title', 1)
     #XXX we need to have the possibility to specify, if the a parameter

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 11:07:32 2003
@@ -233,6 +233,10 @@
     def test_upper(self):
         self.assertEquals("aaa AAA".upper(), "AAA AAA")
         self.assertEquals("".upper(), "")
+    
+    def test_swapcase(self):
+        self.assertEquals("aaa AAA 111".swapcase(), "AAA aaa 111")
+        self.assertEquals("".swapcase(), "")
 
 if __name__ == '__main__':
     test.main()


More information about the Pypy-commit mailing list