Re: A Puzzle in Eu -- what would you do?

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

D. Newhall wrote:
> 
> I didn't feel like using match so I wrote this. This is one of the few times
> I'll agree
> that GOTOs could be useful...
> 
> 
> function strip_comments(sequence code)
> 
>     integer index,     -- index of letter in code
>             in_string  -- "boolean"
>             
>     in_string = 0
> 
>     -- Replicate for loop
>     index = 1
> 
>     while length(code) >= index do
> 
>         if code[index] = '\"' and code[index - 1] != '\\' then
>             if in_string then
>                 in_string = not in_string
>             else
>                 in_string = 1
>             end if
>         end if
> 
>         if not in_string
>           -- What you search for goes here
>           and code[index] = '-' and code[index + 1] = '-' then
>             return code[1..index - 1]
>         end if
> 
>         index += 1
> 
>     end while
>     
>     return code
> 
> end function

Oops! Ddid it backwards.

          and code[index] = '-' and code[index + 1] = '-' then
            return code[1..index - 1]

should instead be 

          and code[index] = '-' and code[index + 1] = '-' then
            return code[index + 2..$]


The Euphoria Standard Library project :
    http://esl.sourceforge.net/
The Euphoria Standard Library mailing list :
    https://lists.sourceforge.net/lists/listinfo/esl-discussion

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

Search



Quick Links

User menu

Not signed in.

Misc Menu