Add -0 / --nul-output option for processing values containing newlines

Closes: https://github.com/stedolan/jq/issues/1271
This commit is contained in:
Paul Wise authored and Nico Williams committed 2019-12-30 15:37:14 -06:00
1 parent 707022b0e5
commit 24564b2d34
2 files changed
+12

No files matched your search

+7
View File
@@ -130,6 +130,7 @@ enum {
RAW_INPUT = 2,
PROVIDE_NULL = 4,
RAW_OUTPUT = 8,
RAW_NUL = 16,
ASCII_OUTPUT = 32,
COLOR_OUTPUT = 64,
NO_COLOR_OUTPUT = 128,
@@ -196,6 +197,8 @@ static int process(jq_state *jq, jv value, int flags, int dumpopts) {
}
if (!(options & RAW_NO_LF))
priv_fwrite("\n", 1, stdout, dumpopts & JV_PRINT_ISATTY);
if (options & RAW_NUL)
priv_fwrite("\0", 1, stdout, dumpopts & JV_PRINT_ISATTY);
if (options & UNBUFFERED_OUTPUT)
fflush(stdout);
}
@@ -394,6 +397,10 @@ int main(int argc, char* argv[]) {
options |= RAW_OUTPUT | RAW_NO_LF;
if (!short_opts) continue;
}
if (isoption(argv[i], '0', "nul-output", &short_opts)) {
options |= RAW_OUTPUT | RAW_NO_LF | RAW_NUL;
if (!short_opts) continue;
}
if (isoption(argv[i], 'b', "binary", &short_opts)) {
#ifdef WIN32
fflush(stdout);