unquoteExecString

Unquote Exec value into an array of escaped arguments. If an argument was quoted then unescaping of quoted arguments is applied automatically. Note that unescaping of quoted argument is not the same as unquoting argument in general. Read more in specification.

@trusted pure
unquoteExecString
(
string value
)

Throws

DesktopExecException if string can't be unquoted (e.g. no pair quote). Note: Although Desktop Entry Specification says that arguments must be quoted by double quote, for compatibility reasons this implementation also recognizes single quotes.

Examples

assert(equal(unquoteExecString(``), string[].init));
assert(equal(unquoteExecString(`   `), string[].init));
assert(equal(unquoteExecString(`"" "  "`), [``, `  `]));

assert(equal(unquoteExecString(`cmd arg1  arg2   arg3   `), [`cmd`, `arg1`, `arg2`, `arg3`]));
assert(equal(unquoteExecString(`"cmd" arg1 arg2  `), [`cmd`, `arg1`, `arg2`]));

assert(equal(unquoteExecString(`"quoted cmd"   arg1  "quoted arg"  `), [`quoted cmd`, `arg1`, `quoted arg`]));
assert(equal(unquoteExecString(`"quoted \"cmd\"" arg1 "quoted \"arg\""`), [`quoted "cmd"`, `arg1`, `quoted "arg"`]));

assert(equal(unquoteExecString(`"\\\$" `), [`\$`]));
assert(equal(unquoteExecString(`"\\$" `), [`\$`]));
assert(equal(unquoteExecString(`"\$" `), [`$`]));
assert(equal(unquoteExecString(`"$"`), [`$`]));

assert(equal(unquoteExecString(`"\\" `), [`\`]));
assert(equal(unquoteExecString(`"\\\\" `), [`\\`]));

assert(equal(unquoteExecString(`'quoted cmd' arg`), [`quoted cmd`, `arg`]));

assertThrown!DesktopExecException(unquoteExecString(`cmd "quoted arg`));

Meta