From d504289bb25af9253b4a922694a6eb2c30ec3818 Mon Sep 17 00:00:00 2001 From: Henrik Holst Date: Wed, 2 Apr 2025 16:19:27 +0200 Subject: [PATCH 1/7] Added support for @ssv in builtin.c Added support to write @ssv files (semicolon separated CSV files) --- src/builtin.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/builtin.c b/src/builtin.c index 7695fbb9aa..4fe53b8b9f 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -558,7 +558,7 @@ static jv f_format(jq_state *jq, jv input, jv fmt) { } else if (!strcmp(fmt_s, "text")) { jv_free(fmt); return f_tostring(jq, input); - } else if (!strcmp(fmt_s, "csv") || !strcmp(fmt_s, "tsv")) { + } else if (!strcmp(fmt_s, "csv") || !strcmp(fmt_s, "ssv") || !strcmp(fmt_s, "tsv")) { const char *quotes, *sep, *escapings; const char *msg; if (!strcmp(fmt_s, "csv")) { @@ -566,6 +566,11 @@ static jv f_format(jq_state *jq, jv input, jv fmt) { quotes = "\""; sep = ","; escapings = "\"\"\"\0"; + } else if (!strcmp(fmt_s, "ssv")) { + msg = "cannot be ssv-formatted, only array"; + quotes = "\""; + sep = ";"; + escapings = "\"\"\"\0"; } else { msg = "cannot be tsv-formatted, only array"; assert(!strcmp(fmt_s, "tsv")); From a42a18a31dd469c95e844c04a5cac623d3ffbc62 Mon Sep 17 00:00:00 2001 From: Henrik Holst Date: Wed, 2 Apr 2025 16:22:49 +0200 Subject: [PATCH 2/7] Added info about the @ssv format Added info in the man page about the @ssv format and also clarified that @csv is comma separated. --- jq.1.prebuilt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jq.1.prebuilt b/jq.1.prebuilt index 8c21b18680..dc6bb93fd3 100644 --- a/jq.1.prebuilt +++ b/jq.1.prebuilt @@ -2340,7 +2340,13 @@ The inverse of \fB@uri\fR, applies percent\-decoding, by mapping all \fB%XX\fR s \fB@csv\fR: . .IP -The input must be an array, and it is rendered as CSV with double quotes for strings, and quotes escaped by repetition\. +The input must be an array, and it is rendered as comma separated CSV with double quotes for strings, and quotes escaped by repetition\. +. +.TP +\fB@ssv\fR: +. +.IP +The input must be an array, and it is rendered as semicolon separated CSV with double quotes for strings, and quotes escaped by repetition\. . .TP \fB@tsv\fR: From 292216007cd7aca928e897d3403b4b192187e2a3 Mon Sep 17 00:00:00 2001 From: Henrik Holst Date: Wed, 2 Apr 2025 16:26:36 +0200 Subject: [PATCH 3/7] Added info about the @ssv format Added info about the @ssv format in the manual and also clarified that @csv is comma separated. --- docs/content/manual/dev/manual.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/content/manual/dev/manual.yml b/docs/content/manual/dev/manual.yml index 12e1837cf2..e93d6caa9d 100644 --- a/docs/content/manual/dev/manual.yml +++ b/docs/content/manual/dev/manual.yml @@ -2151,9 +2151,15 @@ sections: * `@csv`: - The input must be an array, and it is rendered as CSV - with double quotes for strings, and quotes escaped by - repetition. + The input must be an array, and it is rendered as comma + separated CSV with double quotes for strings, and quotes + escaped by repetition. + + * `@ssv`: + + The input must be an array, and it is rendered as semicolon + separated CSV with double quotes for strings, and quotes + escaped by repetition. * `@tsv`: From 08da6a24a97e659d0168830df0dca2de96574837 Mon Sep 17 00:00:00 2001 From: Henrik Holst Date: Wed, 2 Apr 2025 16:34:45 +0200 Subject: [PATCH 4/7] Added test for @ssv format Added a test case for the @ssv format --- tests/jq.test | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/jq.test b/tests/jq.test index e25558d2d4..30861f5b7d 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -61,11 +61,12 @@ null null "interpolation" -@text,@json,([1,.]|@csv,@tsv),@html,(@uri|.,@urid),@sh,(@base64|.,@base64d) +@text,@json,([1,.]|@csv,@ssv,@tsv),@html,(@uri|.,@urid),@sh,(@base64|.,@base64d) "!()<>&'\"\t" "!()<>&'\"\t" "\"!()<>&'\\\"\\t\"" "1,\"!()<>&'\"\"\t\"" +"1;\"!()<>&'\"\"\t\"" "1\t!()<>&'\"\\t" "!()<>&'"\t" "%21%28%29%3C%3E%26%27%22%09" From 82923642ec2054f2eb88ea0fc3867de3728ad6cd Mon Sep 17 00:00:00 2001 From: Henrik Holst Date: Tue, 15 Apr 2025 20:12:13 +0200 Subject: [PATCH 5/7] Changed from ssv to scsv --- src/builtin.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/builtin.c b/src/builtin.c index 4fe53b8b9f..e5501fca9c 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -558,7 +558,7 @@ static jv f_format(jq_state *jq, jv input, jv fmt) { } else if (!strcmp(fmt_s, "text")) { jv_free(fmt); return f_tostring(jq, input); - } else if (!strcmp(fmt_s, "csv") || !strcmp(fmt_s, "ssv") || !strcmp(fmt_s, "tsv")) { + } else if (!strcmp(fmt_s, "csv") || !strcmp(fmt_s, "scsv") || !strcmp(fmt_s, "tsv")) { const char *quotes, *sep, *escapings; const char *msg; if (!strcmp(fmt_s, "csv")) { @@ -566,8 +566,8 @@ static jv f_format(jq_state *jq, jv input, jv fmt) { quotes = "\""; sep = ","; escapings = "\"\"\"\0"; - } else if (!strcmp(fmt_s, "ssv")) { - msg = "cannot be ssv-formatted, only array"; + } else if (!strcmp(fmt_s, "scsv")) { + msg = "cannot be scsv-formatted, only array"; quotes = "\""; sep = ";"; escapings = "\"\"\"\0"; From cc3284693782e6989d7e9d0e687b686ada2dcb85 Mon Sep 17 00:00:00 2001 From: Henrik Holst Date: Tue, 15 Apr 2025 20:13:59 +0200 Subject: [PATCH 6/7] Change from ssv to csv in jq.test --- tests/jq.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/jq.test b/tests/jq.test index 30861f5b7d..9d31a68316 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -61,7 +61,7 @@ null null "interpolation" -@text,@json,([1,.]|@csv,@ssv,@tsv),@html,(@uri|.,@urid),@sh,(@base64|.,@base64d) +@text,@json,([1,.]|@csv,@scsv,@tsv),@html,(@uri|.,@urid),@sh,(@base64|.,@base64d) "!()<>&'\"\t" "!()<>&'\"\t" "\"!()<>&'\\\"\\t\"" From feb5353e6d2cd3d0cb61f7bc8c21bb362aa5cc6d Mon Sep 17 00:00:00 2001 From: Henrik Holst Date: Tue, 15 Apr 2025 20:14:51 +0200 Subject: [PATCH 7/7] Changed from ssv to csv in the manual --- docs/content/manual/dev/manual.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/manual/dev/manual.yml b/docs/content/manual/dev/manual.yml index e93d6caa9d..cceb8b821e 100644 --- a/docs/content/manual/dev/manual.yml +++ b/docs/content/manual/dev/manual.yml @@ -2155,7 +2155,7 @@ sections: separated CSV with double quotes for strings, and quotes escaped by repetition. - * `@ssv`: + * `@scsv`: The input must be an array, and it is rendered as semicolon separated CSV with double quotes for strings, and quotes