1. Re: split function -- really. No, REALLY

--Boundary_(ID_a21s/AfLJCK2jgIrNtBleg)

OK, something is wrong with Topica.  The tops of my messages are getting 
cut.  It seems it is removing the 'function' line and a couple around it 
for some reason.

You can download a zip file of the program here:
<http://www.macalester.edu/~fines/split.zip>

Ted

--On Wednesday, September 17, 2003 9:25 AM -0500 Ted Fines 
<fines at Macalester.edu> wrote:

>
> I don't know how the top part of the function got truncated in my
> previous post, but here it is again.  Sorry...
>
> Ted
>
> -- cut here --
> include get.e
> include wildcard.e
>
> --
> -- empty values are returned too, e.g. given{".","...something..."}
> returns -- {{},{},{},{something},{},{},{}} because the nothing in front of
> -- the first "." and after the last "." is an empty sequence
>
>     sequence d,s,t,u,result,origs
>
>     if length(myargs) > 3 or length(myargs) < 2 then
>         return -1
>     end if
>     d = myargs[1]
>     s = myargs[2]
>     if length(myargs) = 3 then
>         ignorecase=0
>     else
>         ignorecase=1
>     end if
>
>     -- handle special cases...
>
>     -- d or s is empty
>     lengthofd=length(d)
>     if lengthofd = 0 or length(s) = 0 then
>         return s
>     end if
>
>     -- d and s are the same
>     if ignorecase=1 then
>         if equal(lower(s),lower(d)) then
>             return {{},{}}
>         end if
>     elsif equal(s,d) then
>         return {{},{}}
>     end if
>
>
>     result = {}
>     origs=s
>     while 1 do
>         if ignorecase then
>             i = match(lower(d),lower(s))
>         else
>             i = match(d,s)
>         end if
>         if i > 0 then
>             if (i+lengthofd) <= length(s) then
>                 t = s[i+lengthofd..length(s)]
>             elsif i+lengthofd-1 = length(s) then
>                 result = append(result,s[1..i-1])
>                 exit
>             end if
>             if i!= 1 then
>                 u = s[1..i-1]
>                 result = append(result,u)
>             else
>                 result = append(result,{})
>             end if
>             s = t
>         else
>             result = append(result,s)
>             exit
>         end if
>     end while
>     -- account for last portion of s=d
>     if ignorecase then
>         if lengthofd = 1 then
>             if
> match(lower(d),lower(sprintf("%s",{origs[length(origs)]}))) then
> result=append(result,{})
>             end if
>         else
>             if
> match(lower(d),lower(origs[length(origs)-lengthofd+1..length(origs)]))
> then                 result=append(result,{})
>             end if
>         end if
>     else
>         if lengthofd = 1 then
>             if match(d,sprintf("%s",{origs[length(origs)]})) then
>                 result=append(result,{})
>             end if
>         else
>             if match(d,origs[length(origs)-lengthofd+1..length(origs)])
> then                 result=append(result,{})
>             end if
>         end if
>     end if
>     return result
> end function
>
> procedure show_results(sequence t)
>     sequence d,s
<snip>

>
>



--Boundary_(ID_a21s/AfLJCK2jgIrNtBleg)
Content-type: application/octet-stream; name=split.zip

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu