[pypy-svn] r13954 - in pypy/dist/pypy: annotation rpython rpython/test
tismer at codespeak.net
tismer at codespeak.net
Sun Jun 26 15:49:09 CEST 2005
Author: tismer
Date: Sun Jun 26 15:49:07 2005
New Revision: 13954
Modified:
pypy/dist/pypy/annotation/unaryop.py
pypy/dist/pypy/rpython/rstr.py
pypy/dist/pypy/rpython/test/test_rstr.py
Log:
string.replace(char, char) done
Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py (original)
+++ pypy/dist/pypy/annotation/unaryop.py Sun Jun 26 15:49:07 2005
@@ -321,6 +321,9 @@
getbookkeeper().count("str_split", str, patt)
return getbookkeeper().newlist(SomeString())
+ def method_replace(str, s1, s2):
+ return SomeString()
+
class __extend__(SomeChar):
Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py (original)
+++ pypy/dist/pypy/rpython/rstr.py Sun Jun 26 15:49:07 2005
@@ -121,7 +121,11 @@
v_str, v_chr = hop.inputargs(string_repr, char_repr)
c = hop.inputconst(Void, hop.r_result.lowleveltype)
return hop.gendirectcall(ll_split_chr, c, v_str, v_chr)
-
+
+ def rtype_method_replace(_, hop):
+ v_str, v_c1, v_c2 = hop.inputargs(string_repr, char_repr, char_repr)
+ return hop.gendirectcall(ll_replace_chr_chr, v_str, v_c1, v_c2)
+
def ll_str(s, r):
if typeOf(s) == Char:
return ll_chr2str(s)
@@ -434,7 +438,7 @@
return s.chars[i]
def ll_stritem(s, i):
- if i<0:
+ if i < 0:
i += len(s.chars)
return s.chars[i]
@@ -646,6 +650,20 @@
return res
+def ll_replace_chr_chr(s, c1, c2):
+ length = len(s.chars)
+ newstr = malloc(STR, length)
+ src = s.chars
+ dst = newstr.chars
+ j = 0
+ while j < length:
+ c = src[j]
+ if c == c1:
+ c = c2
+ dst[j] = c
+ j += 1
+ return newstr
+
def ll_contains(s, c):
chars = s.chars
strlen = len(chars)
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 Sun Jun 26 15:49:07 2005
@@ -306,6 +306,20 @@
s = 'Hello world'
return chr(i) in s
for i in range(256):
- res = interpret(fn, [i])
+ res = interpret(fn, [i])#, view=i==42)
assert res == fn(i)
+def test_replace():
+ def fn(c1, c2):
+ s = 'abbccc'
+ s = s.replace(c1, c2)
+ res = 0
+ for c in s:
+ if c == c2:
+ res += 1
+ return res
+ res = interpret(fn, ['a', 'c'])
+ assert res == 4
+ res = interpret(fn, ['c', 'b'])
+ assert res == 5
+
More information about the Pypy-commit
mailing list