Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --command line matching
- local line = [[mycmd hey arg2 arg3 "non space separated arg" 'arg with a quote " ']]
- local args = {}
- local temp = ""
- local q = false
- line = line .. " "
- for char in line:gmatch("(.)") do
- local write = false
- if
- char == [[']] or
- char == [["]]
- then
- if not q then
- q = char
- char = ""
- elseif q == char then
- q = false
- write = true
- char = ""
- end
- end
- if q then
- temp = temp .. char
- elseif char:find("%s") then
- write = true
- char = ""
- else
- temp = temp .. char
- end
- if write and temp ~= "" then
- table.insert(args, temp)
- temp = ""
- end
- end
- table.foreach(args, print)
Advertisement
Add Comment
Please, Sign In to add comment