[string] Allow string escape to handle NULs

TODO: This currently only works for the "script" escaping style.

Work towards #4605.
This commit is contained in:
Fabian Homborg 2018-01-02 16:00:38 +01:00
parent a229f703ae
commit aedb8dc327

View File

@ -123,6 +123,18 @@ class arg_iterator_t {
}
return string_get_arg_argv(&argidx_, argv_);
}
const wcstring *nextstr() {
if (string_args_from_stdin(streams_)) {
return get_arg_stdin() ? &storage_ : NULL;
}
if (auto arg = string_get_arg_argv(&argidx_, argv_)) {
storage_ = arg;
return &storage_;
} else {
return NULL;
}
}
};
}
@ -488,8 +500,9 @@ static int string_escape_script(options_t &opts, int optind, wchar_t **argv,
if (opts.no_quoted) flags |= ESCAPE_NO_QUOTED;
arg_iterator_t aiter(argv, optind, streams);
while (const wchar_t *arg = aiter.next()) {
streams.out.append(escape_string(arg, flags, STRING_STYLE_SCRIPT));
while (auto arg = aiter.nextstr()) {
// Use the wcstring here because of embedded NULs.
streams.out.append(escape_string(*arg, flags, STRING_STYLE_SCRIPT));
streams.out.append(L'\n');
nesc++;
}