Re: Faster lower() command
- Posted by jacques deschĂȘnes <desja at globetrotter.net> Jan 19, 2007
- 554 views
here is the power of euphoria
function lower(object o) return o + (o>='A' and o<='Z')*32 -- work as well with atom or sequence end function
regards, Jacques D. Jesse Adkins wrote: > > It's been a while since i've posted here. I recently put this together, from > code inside of the guru.ex file, and the current lower() command. > > The one inside of guru.ex is used to handle sequence lowering, and atom > lowering is handled by the current function. I chose to use the current > command for atom lowering using the guru.ex method is quite slow with atoms. > }}} <eucode> > function lower1( sequence x ) > integer c > for i = 1 to length(x) do > c = x[i] > if c <= 'Z' then > if c >= 'A' then > x[i] = c + 32 > end if > end if > end for > return x > end function > > function lower(object x) > if sequence(x) then > return lower1(x) > else > return x + (x >= 'A' and x <= 'Z') * TO_LOWER > end if > end function > </eucode> {{{ > > I put the sequence first, since I expect that lower() will mostly be used on > sequences. > > Any comments/questions/etc.?