Skip to content

Instantly share code, notes, and snippets.

@chakrit
Created April 25, 2013 09:00
Show Gist options
  • Save chakrit/5458462 to your computer and use it in GitHub Desktop.
Save chakrit/5458462 to your computer and use it in GitHub Desktop.
parse = (line) ->
stuff = line.split ' '
result = []
while stuff.length
item = stuff.shift()
if item[0] is '"' # begin quoted string
while item[item.length - 1] isnt '"' or (item[item.length - 2] is '\\' and item[item.length - 3] isnt '\\')
item += ' ' + stuff.shift()
item = item.substr 1, item.length - 2
item = item.replace /\\\"/g, '"'
item = item.replace /\\\\/g, '\\'
result.push item
return result
console.log '====='
result = parse 'test word "quoted words" and "quoted with \\"quote\\"marks\\" and \\\\ slashes" and "\\\\" "\\\\\"" slashed quotes'
console.log word for word in result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment