Actually, I don't think split can do it in the general case, because the interactions of quotes and backslashes are non-obvious.
The purpose of the tokenizer is to recognize that:
Code:
a = b <= 3 tokens, <a> <=> <b>
"a = b" <= 1 token, <a = b>
a = "b = c" <= 3 tokens, <a> <=> <b = c>
x = \"hello, world!\" <= 3 tokens, <x> <=> <"hello, world!">
Currently it just ignores single quotes, but is otherwise basically like Unix shell command line semantics -- which is intentional, that's why LibGetOpt has it.
So you can have
Code:
/mycommand -a 3 -b "this is a test" -c more words
come out to:
Code:
{
a = 3,
b = 'this is a test',
leftover_args = { 'more', 'words' },
leftover = 'more words'
} I use this in my addons because it's a heck of a lot easier to write "/goofball -g" and just check for args.g in my slashcommand function than it would be to actually do the string parsing.
Bookmarks