Re: reading strings

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hayden McKay wrote:
> }}}
<eucode>
> --==============================================--
> constant
>     --
>     TERMINATOR = 0,       -- the string terminator
>     MAXLENGTH = 256       -- maximum string length
>  	
> --------------------------------------------------
> -- changes...
> --         function now returns "{}" if the string
> --         is empty or the terminator is not found
> 
> global function string(atom lp)
> 
>     sequence chunk
>     integer loc
> 
>     chunk = peek({lp, MAXLENGTH})
> 
>     loc = find(TERMINATOR, chunk)
> 
> --  if loc then
>     if loc >= 1 then
>         chunk = chunk[1..(loc-1)]
>     else
>         chunk = {}   -- return empty string.
>     end if
> 
>     return chunk
> 
> end function
> </eucode>
{{{


Hayden:

    Try this one.

constant
TERMINATOR = 0,       -- the string terminator
MAXLENGTH = 256       -- maximum string length
--
global function string(object lp)
  if atom(lp) then
    return string(peek({lp, MAXLENGTH}))
  else
    return lp[1..find(TERMINATOR,lp)-1]
  end if
end function


Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu