1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
--- SimpleParse-2.1.0a1/stt/TextTools/TextTools.py~ 2006-02-19 00:33:56.000000000 +0100
+++ SimpleParse-2.1.0a1/stt/TextTools/TextTools.py 2008-01-26 17:07:18.000000000 +0100
@@ -167,7 +167,7 @@
# Extra stuff useful in combination with the C functions
#
-def replace(text,what,with,start=0,stop=None,
+def replace(text,what,withwhat,start=0,stop=None,
SearchObject=TextSearch,join=join,joinlist=joinlist,tag=tag,
string_replace=string.replace,type=type,
@@ -188,11 +188,11 @@
what = so.match
if stop is None:
if start == 0 and len(what) < 2:
- return string_replace(text,what,with)
+ return string_replace(text,what,withwhat)
stop = len(text)
t = ((text,sWordStart,so,+2),
# Found something, replace and continue searching
- (with,Skip+AppendTagobj,len(what),-1,-1),
+ (withwhat,Skip+AppendTagobj,len(what),-1,-1),
# Rest of text
(text,Move,ToEOF)
)
@@ -203,13 +203,13 @@
# Alternative (usually slower) versions using different techniques:
-def _replace2(text,what,with,start=0,stop=None,
+def _replace2(text,what,withwhat,start=0,stop=None,
join=join,joinlist=joinlist,tag=tag,
TextSearchType=TextSearchType,TextSearch=TextSearch):
"""Analogon to string.replace; returns a string with all occurences
- of what in text[start:stop] replaced by with.
+ of what in text[start:stop] replaced by withwhat.
This version uses a one entry tag-table and a
Boyer-Moore-Search-object. what can be a string or a
@@ -226,13 +226,13 @@
stop = len(text)
if type(what) is not TextSearchType:
what=TextSearch(what)
- t = ((with,sFindWord,what,+1,+0),)
+ t = ((withwhat,sFindWord,what,+1,+0),)
found,taglist,last = tag(text,t,start,stop)
if not found:
return text
return join(joinlist(text,taglist))
-def _replace3(text,what,with,
+def _replace3(text,what,withwhat,
join=string.join,TextSearch=TextSearch,
TextSearchType=TextSearchType):
@@ -245,12 +245,12 @@
l = []
x = 0
for left,right in slices:
- l.append(text[x:left] + with)
+ l.append(text[x:left] + withwhat)
x = right
l.append(text[x:])
return join(l,'')
-def _replace4(text,what,with,
+def _replace4(text,what,withwhat,
join=join,joinlist=joinlist,tag=tag,TextSearch=TextSearch,
TextSearchType=TextSearchType):
@@ -262,7 +262,7 @@
return text
repl = [None]*len(slices)
for i in range(len(slices)):
- repl[i] = (with,)+slices[i]
+ repl[i] = (withwhat,)+slices[i]
return join(joinlist(text,repl))
def multireplace(text,replacements,start=0,stop=None,
@@ -569,16 +569,16 @@
print 'Replacing strings'
print '-'*72
print
- for what,with in (('m','M'),('mx','MX'),('mxText','MXTEXT'),
+ for what,withwhat in (('m','M'),('mx','MX'),('mxText','MXTEXT'),
('hmm','HMM'),('hmmm','HMM'),('hmhmm','HMM')):
- print 'Replace "%s" with "%s"' % (what,with)
+ print 'Replace "%s" with "%s"' % (what,withwhat)
t.start()
for i in range(100):
- rtext = string.replace(text,what,with)
+ rtext = string.replace(text,what,withwhat)
print 'with string.replace:',t.stop(),'sec.'
t.start()
for i in range(100):
- ttext = replace(text,what,with)
+ ttext = replace(text,what,withwhat)
print 'with tag.replace:',t.stop(),'sec.'
if ttext != rtext:
print 'results are NOT ok !'
@@ -586,7 +586,7 @@
mismatch(rtext,ttext)
t.start()
for i in range(100):
- ttext = _replace2(text,what,with)
+ ttext = _replace2(text,what,withwhat)
print 'with tag._replace2:',t.stop(),'sec.'
if ttext != rtext:
print 'results are NOT ok !'
@@ -594,7 +594,7 @@
print rtext
t.start()
for i in range(100):
- ttext = _replace3(text,what,with)
+ ttext = _replace3(text,what,withwhat)
print 'with tag._replace3:',t.stop(),'sec.'
if ttext != rtext:
print 'results are NOT ok !'
@@ -602,7 +602,7 @@
print rtext
t.start()
for i in range(100):
- ttext = _replace4(text,what,with)
+ ttext = _replace4(text,what,withwhat)
print 'with tag._replace4:',t.stop(),'sec.'
if ttext != rtext:
print 'results are NOT ok !'
|