[pypy-svn] r8878 - in pypy/dist/pypy/objspace/std: . test

sanxiyn at codespeak.net sanxiyn at codespeak.net
Fri Feb 4 18:27:09 CET 2005


Author: sanxiyn
Date: Fri Feb  4 18:27:09 2005
New Revision: 8878

Modified:
   pypy/dist/pypy/objspace/std/stringobject.py
   pypy/dist/pypy/objspace/std/stringtype.py
   pypy/dist/pypy/objspace/std/test/test_stringobject.py
Log:
Implements optional argument of string.startswith method


Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py	(original)
+++ pypy/dist/pypy/objspace/std/stringobject.py	Fri Feb  4 18:27:09 2005
@@ -642,16 +642,16 @@
     return W_IntObject(space, found)
     
     
-#[optional arguments not supported now]    
-def str_startswith__String_String(space, w_self, w_start): 
+def str_startswith__String_String_ANY(space, w_self, w_prefix, w_start):
     u_self = w_self._value
-    u_start  = w_start._value
+    u_prefix  = w_prefix._value
+    u_start = space.int_w(w_start)
     
     found = 0
-    if u_start:
-        startlen = len(u_start)
-        if startlen <= len(u_self):
-           found = (u_start == u_self[:startlen]) 
+    if u_prefix:
+        plen = len(u_prefix)
+        if u_start + plen <= len(u_self):
+           found = (u_prefix == u_self[u_start:u_start+plen])
     else:
         found = 1
         

Modified: pypy/dist/pypy/objspace/std/stringtype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringtype.py	(original)
+++ pypy/dist/pypy/objspace/std/stringtype.py	Fri Feb  4 18:27:09 2005
@@ -33,7 +33,7 @@
 str_endswith   = MultiMethod('endswith', 2)   #[optional arguments not supported now]
 str_expandtabs = MultiMethod('expandtabs', 2, defaults=(8,))
 str_splitlines = MultiMethod('splitlines', 2, defaults=(0,))
-str_startswith = MultiMethod('startswith', 2) #[optional arguments not supported now]
+str_startswith = MultiMethod('startswith', 3, defaults=(0,))
 str_translate  = MultiMethod('translate', 3, defaults=('',)) #unicode mimic not supported now
 str_decode     = MultiMethod('decode', 3, defaults=(None, None))
 

Modified: pypy/dist/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_stringobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_stringobject.py	Fri Feb  4 18:27:09 2005
@@ -273,7 +273,11 @@
         assert ''.startswith('a') == 0
         assert 'x'.startswith('xx') == 0
         assert 'y'.startswith('xx') == 0
-                
+
+    def test_startswith_more(self):
+        assert 'ab'.startswith('a', 0) == 1
+        assert 'ab'.startswith('a', 1) == 0
+        assert 'ab'.startswith('b', 1) == 1
 
     def test_endswith(self):
         assert 'ab'.endswith('ab') == 1



More information about the Pypy-commit mailing list