void (*write_line)(void);
// CSV backend:
int always_quote;
+ // WS backend:
+ int strict_ws;
// regex backend:
pcre *pcre;
pcre_extra *pcre_extra;
ws++;
} else {
if (ws) {
- new_field(i);
+ if (!in_field->start_pos &&
+ !in_field->len &&
+ !in_format->strict_ws)
+ in_field->start_pos = i;
+ else
+ new_field(i);
ws = 0;
}
in_field->len++;
}
}
- if (ws)
+ if (ws && in_format->strict_ws)
new_field(n);
return 1;
}
-t, --tsv TAB-separated values (default)\n\
-c, --csv Comma-separated values\n\
-w, --ws Values separated by arbitrary whitespace\n\
+-W, --strict-ws Like --ws, but recognize empty columns at start/end\n\
-r, --regex=<rx> Separator given by Perl regular expression (input only)\n\
\n\
Format parameters:\n\
exit(1);
}
-static const char short_options[] = "cd:qr:tw";
+static const char short_options[] = "cd:qr:twW";
enum long_options {
OPT_HELP = 256,
{ "fs", 1, NULL, 'd' },
{ "quiet", 0, NULL, 'q' },
{ "regex", 1, NULL, 'r' },
+ { "strict-ws", 0, NULL, 'W' },
{ "trim", 0, NULL, OPT_TRIM },
{ "tsv", 0, NULL, 't' },
{ "ws", 0, NULL, 'w' },
case 'w':
set_format(FORM_WS);
break;
+ case 'W':
+ set_format(FORM_WS);
+ current_format()->strict_ws = 1;
+ break;
case OPT_ALWAYS_QUOTE:
if (current_format()->id != FORM_CSV)
bad_args("--always-quote makes sense only for CSV.");