1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Fix error message for @tsv

This commit is contained in:
Nicolas Williams
2015-05-21 18:20:05 -05:00
parent 4b258f7d31
commit a50e548cc5

View File

@@ -375,11 +375,14 @@ static jv f_format(jq_state *jq, jv input, jv fmt) {
return f_tostring(jq, input); return f_tostring(jq, input);
} else if (!strcmp(fmt_s, "csv") || !strcmp(fmt_s, "tsv")) { } else if (!strcmp(fmt_s, "csv") || !strcmp(fmt_s, "tsv")) {
const char *quotes, *sep, *escapings; const char *quotes, *sep, *escapings;
const char *msg;
if (!strcmp(fmt_s, "csv")) { if (!strcmp(fmt_s, "csv")) {
msg = "cannot be csv-formatted, only array";
quotes = "\""; quotes = "\"";
sep = ","; sep = ",";
escapings = "\"\"\"\0"; escapings = "\"\"\"\0";
} else { } else {
msg = "cannot be tsv-formatted, only array";
assert(!strcmp(fmt_s, "tsv")); assert(!strcmp(fmt_s, "tsv"));
quotes = ""; quotes = "";
sep = "\t"; sep = "\t";
@@ -387,7 +390,7 @@ static jv f_format(jq_state *jq, jv input, jv fmt) {
} }
jv_free(fmt); jv_free(fmt);
if (jv_get_kind(input) != JV_KIND_ARRAY) if (jv_get_kind(input) != JV_KIND_ARRAY)
return type_error(input, "cannot be csv-formatted, only array"); return type_error(input, msg);
jv line = jv_string(""); jv line = jv_string("");
jv_array_foreach(input, i, x) { jv_array_foreach(input, i, x) {
if (i) line = jv_string_append_str(line, sep); if (i) line = jv_string_append_str(line, sep);