diff options
author | Paul Wise <pabs3@bonedaddy.net> | 2019-10-14 12:55:30 +0800 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2019-12-30 15:37:14 -0600 |
commit | 24564b2d345398a818eb74a194faf3733655d73a (patch) | |
tree | 4d2ecea17b37e2f9f4aa614419d850cc9a1e0219 | |
parent | 707022b0e5d2b1c7b8a55e3c4f4ab539e05a9086 (diff) |
Add -0 / --nul-output option for processing values containing newlines
Closes: https://github.com/stedolan/jq/issues/1271
-rw-r--r-- | docs/content/manual/manual.yml | 5 | ||||
-rw-r--r-- | src/main.c | 7 |
2 files changed, 12 insertions, 0 deletions
diff --git a/docs/content/manual/manual.yml b/docs/content/manual/manual.yml index 578517be..f50f0e62 100644 --- a/docs/content/manual/manual.yml +++ b/docs/content/manual/manual.yml @@ -199,6 +199,11 @@ sections: Like `-r` but jq won't print a newline after each output. + * `--nul-output` / `-0`: + + Like `-r` but jq will print NUL instead of newline after each output. + This can be useful when the values being output can contain newlines. + * `-f filename` / `--from-file filename`: Read filter from the file rather than from a command line, like @@ -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); |