Re: Looking for the best "Parse"...
- Posted by Igor Kachan <kinz at peterlink.ru> Oct 28, 2001
- 397 views
Ýòî ñîîáùåíèå â ôîðìàòå MIME ñîñòîèò èç íåñêîëüêèõ ÷àñòåé. ------=_NextPart_000_01C15FF0.2DDE07C0 Derek wrote: > Thank you, Robert. That is a useful bit of information. > I'm will now be more inclined to do try this. Maybe then, > a mention in the documentation for this > special case might be in order. Hi Derek, I have tested the jparse4() with that extremly fast loop just now. Loop while 1 do . . . end while really works as I want, so I do not want new loop in Euphoria now. Thanks, Robert, from me, sorry, I didn't know about this feature. My results with jparse2(), jparse3(), jparse4() are below: (times of 10000 iterations in plain Dos-32 mode on a 386) jparse2() jparse3() jparse4() 21.58 21.48 21.31 21.59 21.47 21.37 21.59 21.48 21.31 21.59 21.48 21.36 But remember please, I don't know any algorithms, implemented in these functions, and thanks to Cassidy for such useful his task and for his working solution. Regards, Igor Kachan kinz at peterlink.ru ------=_NextPart_000_01C15FF0.2DDE07C0 Content-Type: application/octet-stream; name="Parse2.ex" Content-Transfer-Encoding: 7bit Content-Description: Parse2.ex (EX ) Content-Disposition: attachment; filename="Parse2.ex" include wildcard.e function jparse2(sequence s, sequence s1, sequence s2) -- replace every occurrence of s1 in s by s2 -- case insensitive search sequence os,u,v integer i,j,m os = {} u = lower(s) v = lower(s1) m = length(s1) i = match(v, u) j = 1 while i do os &= s[j..j+i-2] & s2 j += i+m-1 u = u[i+m..length(u)] i = match(v, u) end while return os & s[j..length(s)] end function integer k,i,j,m sequence os,u,v function jparse3(sequence s, sequence s1, sequence s2) -- replace every occurrence of s1 in s by s2 -- case insensitive search -- sequence os,u,v -- integer k,i,j,m os = {} u = lower(s) v = lower(s1) m = length(s1) j = 1 for t=1 to 111111111 do i = match(v, u) if not i then exit end if k = i+m os &= s[j..j+i-2] & s2 j += k-1 u = u[k..length(u)] end for return os & s[j..length(s)] end function function jparse4(sequence s, sequence s1, sequence s2) -- replace every occurrence of s1 in s by s2 -- case insensitive search -- sequence os,u,v -- integer k,i,j,m os = {} u = lower(s) v = lower(s1) m = length(s1) j = 1 while 1 do i = match(v, u) if not i then exit end if k = i+m os &= s[j..j+i-2] & s2 j += k-1 u = u[k..length(u)] end while return os & s[j..length(s)] end function sequence text text = jparse3 ("The $A jumped over the lazy dog.","$A","quick brown fox") puts (1, text & "\n") atom T T=time() for p=0 to 10000 do text = jparse2 ("The $A jumped over the lazy dog.","$A","quick brown fox") end for T=time()-T ? T T=time() for p=0 to 10000 do text = jparse3 ("The $A jumped over the lazy dog.","$A","quick brown fox") end for T=time()-T ?T T=time() for p=0 to 10000 do text = jparse4 ("The $A jumped over the lazy dog.","$A","quick brown fox") end for T=time()-T ?T ------=_NextPart_000_01C15FF0.2DDE07C0--