Faster please....
- Posted by "Euman" <euman at bellsouth.net> Jan 12, 2004
- 417 views
This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C3D89F.4EEED320 charset="iso-8859-1" Hello all, Two function for delimited data, one uses match( ) recursively and the other find( ). (The first came from an idea by Brian Broker the second, Ron Austin) Maybe someday, someone will test which one wins..? If there are faster ways, I would appreciate the hand up... global function sDelimited(sequence s, integer delimiter) -- returns: sequence containing indices of all matches -- if unsuccessful return empty sequence {} object found sequence dl, dseq integer start, endx dl = repeat(dl, 1) found = match(dl, s) if found then found &= found + sDelimited(s[found+1..length(s)], delimiter) else return {} end if dseq = {} start = 1 for i = 1 to length(found) do endx = found[i] dseq &= {s[start...endx]} start = endx + 1 end for return dseq end function global function sDelimited(sequence s, integer delimiter) integer len, start, endx sequence dseq len = length(s) dl = repeat(delimiter, 1) start = 1 for i = 1 to len do if equal(s[i..i],dl) then endx = i - 1 dseq &= {s[start..endx]} start = i + 1 end if end for return dseq end function Purpose: to return nested sequence using delimiter chars salted throughout a flat sequence. Regards, Euman ------=_NextPart_000_0005_01C3D89F.4EEED320 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 8bit <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2800.1276" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial size=2>Hello all,</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>Two function for delimited data, one uses match( ) recursively and the other find( ).</FONT></DIV> <DIV><FONT face=Arial size=2>(The first came from an idea by Brian Broker the second, Ron Austin)</FONT></DIV> <DIV><FONT face=Arial size=2><FONT size=3> </FONT></FONT></DIV> <DIV><FONT face=Arial size=2>Maybe someday, someone will test which one wins..?</FONT></DIV> <DIV><FONT face=Arial size=2>If there are faster ways, I would appreciate the hand up...</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>global function sDelimited(sequence s, integer delimiter)<BR>-- returns: sequence containing indices of all matches<BR>-- if unsuccessful return empty sequence {}<BR> object found <BR> sequence dl, dseq<BR> integer start, endx<BR> <BR> dl = repeat(dl, 1)<BR> found = match(dl, s)<BR> if found then<BR> found &= found + sDelimited(s[found+1..length(s)], delimiter)<BR> else<BR> return {}<BR> end if<BR> dseq = {}<BR> start = 1<BR> for i = 1 to length(found) do<BR> endx = found[i]<BR> dseq &= {s[start...endx]}<BR> start = endx + 1<BR> end for<BR> return dseq<BR>end function</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>global function sDelimited(sequence s, integer delimiter)<BR>integer len, start, endx</FONT></DIV> <DIV><FONT face=Arial size=2>sequence dseq</FONT></DIV><FONT face=Arial size=2> <DIV><BR> len = length(s)<BR> dl = repeat(delimiter, 1)<BR> start = 1<BR> for i = 1 to len do<BR> if equal(s[i..i],dl) then<BR> endx = i - 1<BR> dseq &= {s[start..endx]}<BR> start = i + 1<BR> end if<BR> end for<BR> return dseq<BR>end function</DIV> <DIV> </DIV> <DIV>Purpose: to return nested sequence using delimiter chars salted throughout a flat sequence.</DIV> <DIV> </DIV> <DIV>Regards,</DIV> ------=_NextPart_000_0005_01C3D89F.4EEED320--