mirror of https://github.com/mpv-player/mpv
input.conf syntax: support custom quotes !XstringX!
Where X is any ASCII char chosen by the user. An argument is only interpreted as custom-quoted if it starts with '!' and the line doesn't end right after it. Custom quotes don't interpret backslash-escape. This change only affects command arguments which mpv parses (not array commands), and not tokens before the arguments (where applicable - key name, input section, command prefixes, command name).
This commit is contained in:
parent
bb439efe0d
commit
4f129a3eca
|
@ -63,7 +63,7 @@ command.
|
|||
|
||||
``<command>`` is the command itself. It consists of the command name and
|
||||
multiple (or none) arguments, all separated by whitespace. String arguments
|
||||
need to be quoted with ``"``. Details see ``Flat command syntax``.
|
||||
should be quoted, typically with ``"``. See ``Flat command syntax``.
|
||||
|
||||
You can bind multiple commands to one key. For example:
|
||||
|
||||
|
@ -162,18 +162,28 @@ a number of other places.
|
|||
|
||||
|
|
||||
| ``<command> ::= [<prefixes>] <command_name> (<argument>)*``
|
||||
| ``<argument> ::= (<string> | " <quoted_string> ")``
|
||||
| ``<argument> ::= (<unquoted> | " <double_quoted> " | !X <custom_quoted> X!)``
|
||||
|
||||
``command_name`` is an unquoted string with the command name itself. See
|
||||
`List of Input Commands`_ for a list.
|
||||
|
||||
Arguments are separated by whitespace. This applies even to string arguments.
|
||||
For this reason, string arguments should be quoted with ``"``. If a string
|
||||
argument contains spaces or certain special characters, quoting and possibly
|
||||
escaping is mandatory, or the command cannot be parsed correctly.
|
||||
Arguments are separated by whitespaces even if the command expects only one
|
||||
argument. Arguments with whitespaces or other special characters must be quoted,
|
||||
or the command cannot be parsed correctly.
|
||||
|
||||
Inside quotes, C-style escaping can be used. JSON escapes according to RFC 8259,
|
||||
minus surrogate pair escapes, should be a safe subset that can be used.
|
||||
Double quoted arguments start and end with ``"``. Custom quotes start with ``!``
|
||||
(exclamation mark) followed by any ASCII character, and end in the same pair in
|
||||
reverse order, e.g. ``!'foo'!`` or ``!-bar-!``. The final pair sequence is not
|
||||
allowed inside the string - in these examples ``'!`` and ``-!`` respectively.
|
||||
|
||||
Custom quotes take their content literally, while inside double quotes
|
||||
JSON/C-style escaping can be used. JSON escapes according to RFC 8259, minus
|
||||
surrogate pair escapes, should be a safe subset that can be used.
|
||||
|
||||
Note that argument parsing and property expansion happen at different stages.
|
||||
First, arguments are determined as described above, and then, where applicable,
|
||||
properties are expanded - regardless of argument quoting. However, expansion
|
||||
can still be prevented with ``$>``. See `Property Expansion`_.
|
||||
|
||||
Commands specified as arrays
|
||||
----------------------------
|
||||
|
|
13
input/cmd.c
13
input/cmd.c
|
@ -341,6 +341,19 @@ static int pctx_read_token(struct parse_ctx *ctx, bstr *out)
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
if (ctx->start.len > 1 && bstr_eatstart0(&ctx->str, "!")) {
|
||||
char endquote[2] = {ctx->str.start[0], '!'};
|
||||
ctx->str = bstr_cut(ctx->str, 1);
|
||||
int next = bstr_find(ctx->str, (bstr){endquote, 2});
|
||||
if (next < 0) {
|
||||
MP_ERR(ctx, "Unterminated custom quote: ...>%.*s<.\n", BSTR_P(start));
|
||||
return -1;
|
||||
}
|
||||
*out = bstr_splice(ctx->str, 0, next);
|
||||
ctx->str = bstr_cut(ctx->str, next+2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return read_token(ctx->str, &ctx->str, out) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue