[pypy-svn] r28772 - in pypy/dist/pypy/rpython: lltypesystem test
pedronis at codespeak.net
pedronis at codespeak.net
Wed Jun 14 17:07:58 CEST 2006
Author: pedronis
Date: Wed Jun 14 17:07:56 2006
New Revision: 28772
Modified:
pypy/dist/pypy/rpython/lltypesystem/rstr.py
pypy/dist/pypy/rpython/test/test_rstr.py
Log:
fix finding of empty strings in rpython. May fix the problems of test_*str* for pypy-c
Modified: pypy/dist/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rstr.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/rstr.py Wed Jun 14 17:07:56 2006
@@ -347,10 +347,15 @@
def ll_find(cls, s1, s2, start, end):
"""Knuth Morris Prath algorithm for substring match"""
+ len1 = len(s1.chars)
+ if end > len1:
+ end = len1
len2 = len(s2.chars)
if len2 == 1:
return cls.ll_find_char(s1, s2.chars[0], start, end)
if len2 == 0:
+ if (end-start) < 0:
+ return -1
return start
# Construct the array of possible restarting positions
# T = Array_of_ints [-1..len2]
@@ -396,6 +401,9 @@
if len2 == 1:
return cls.ll_rfind_char(s1, s2.chars[0], start, end)
if len2 == 0:
+ len1 = len(s1.chars)
+ if end > len(s1.chars):
+ return len1
return end
# Construct the array of possible restarting positions
T = malloc( SIGNED_ARRAY, len2 )
Modified: pypy/dist/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rstr.py (original)
+++ pypy/dist/pypy/rpython/test/test_rstr.py Wed Jun 14 17:07:56 2006
@@ -255,12 +255,39 @@
res = self.interpret(fn, [i, j])
assert res == fn(i, j)
+ def test_find_empty_string(self):
+ def f():
+ s = "abc"
+ x = s.find('')
+ x+= s.find('', 1)*10
+ x+= s.find('', 2)*100
+ x+= s.find('', 3)*1000
+ x+= s.find('', 4)*10000
+ x+= s.find('', 5)*100000
+ return x
+ res = self.interpret(f, [])
+ assert res == f()
+
def test_rfind(self):
def fn():
return 'aaa'.rfind('a') + 'aaa'.rfind('a', 1) + 'aaa'.rfind('a', 1, 2)
res = self.interpret(fn, [])
assert res == 2 + 2 + 1
+ def test_rfind_empty_string(self):
+ def f():
+ s = "abc"
+ x = s.rfind('', 0 ,0)
+ x+= s.rfind('', 0, 1)*10
+ x+= s.rfind('', 0, 2)*100
+ x+= s.rfind('', 0, 3)*1000
+ x+= s.rfind('', 0, 4)*10000
+ x+= s.rfind('', 0, 5)*100000
+ return x
+ res = self.interpret(f, [])
+ assert res == f()
+
+
def test_find_char(self):
def fn(ch):
pos1 = 'aiuwraz 483'.find(ch)
More information about the Pypy-commit
mailing list