Created
April 25, 2013 09:00
-
-
Save chakrit/5458462 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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