splitargs icon indicating copy to clipboard operation
splitargs copied to clipboard

Ignore escaped separators

Open gausie opened this issue 10 years ago • 6 comments

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

gausie avatar Aug 16 '15 18:08 gausie

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?

elgs avatar Aug 16 '15 18:08 elgs

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" [email protected] 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.

gausie avatar Aug 16 '15 19:08 gausie

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

elgs avatar Aug 16 '15 19:08 elgs

Not sure if this works but here's my attempt

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

greggman avatar Jan 11 '19 08:01 greggman

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

elgs avatar Jan 11 '19 09:01 elgs

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

Flamenco avatar May 25 '19 21:05 Flamenco