elgs / splitargs

Splits strings into tokens by given separator, treating quoted part as a single token.
17 stars 6 forks source link

Ignore escaped separators #3

Open gausie opened 9 years ago

gausie commented 9 years ago

If my separator is " ", I'd like "\ " not to be considered a separator.

elgs commented 9 years ago

I don't think it works that way. Anything inside the quotes, either single or double, will not be considered as a separator. The only things need to be escaped are the single quote ' and the double quote ". If you don't want some of the white spaces being considered as separator, why not put them in a pair of quotes?

gausie commented 9 years ago

I'm in a situation where I cannot control the input, unfortunately. Escaped spaces are accepted in shell and I'm trying to parse shell arguments. On 16 Aug 2015 7:45 pm, "Elgs Qian Chen" notifications@github.com wrote:

I don't think it works that way. Anything inside the quotes, either single or double, will not be considered as a separator. The only things need to be escaped are the single quote ' and the double quote ". If you don't want some of the white spaces being considered as separator, why not put them in a pair of quotes?

— Reply to this email directly or view it on GitHub https://github.com/elgs/splitargs/issues/3#issuecomment-131599625.

elgs commented 9 years ago

I see. Let me think about how to implement it.

greggman commented 5 years ago

Not sure if this works but here's my attempt

http://jsfiddle.net/greggman/c69au3oh/

elgs commented 5 years ago

Thanks @greggman. The results look pretty good. I will do more test.

Flamenco commented 5 years ago

I needed to escape spaces outside of my quotes, and also quotes inside my quotes.

Single Argument hello\ world

Quotes of same type inside. 'hello\'world\''

See PR: https://github.com/elgs/splitargs/pull/6