[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: quoting unquoted token?
- From: Martijn Hoekstra <martijnhoekstra@...>
- Date: Wed, 5 Oct 2011 22:29:24 +0200
Depends on how much sophistication you want. Something like this could
probably be done fastest with a quick simple parser. Runtime
performance wouldn't be great, but it would be fairly straightforward.
something like
function parse_string(mystring)
var tokens = {}
do
next_token, mystring = consume_token(mystring)
table.add(tokens, next_token)
until next_token = nil
return tokens
end
and write the consume_token ad hoc (switch on first character ",
consume and add all letters to the returnvalue until you find a ",
and return your value, and stripped string.
The back and forth stringwalking here is horrible, as wikll runtime
complexity be, but for shortish tokens it should be doable.
On Wed, Oct 5, 2011 at 8:02 PM, Petite Abeille <petite.abeille@gmail.com> wrote:
> Hello,
>
> What would be a reasonable way to, hmmm, quote unquoted tokens?
>
> Say a token is an uninterrupted sequence of alphanumeric characters (%w) or a quoted token. A quoted token is any sequence of characters inside quotes, minus any quote characters.
>
> For example:
>
> 'foo "hello world" bar'
>
> How to turn the above into:
>
> '"foo" "hello world" "bar"'
>
> Thoughts?
>
>
>
>
>