Trailing whitespace in CSV cells broke the text to number conversion.
Trim the text content of cells before processing it. This is useful and
actually essential for data cells, and does not harm titles in header
lines, neither will it affect column format specs.
How to reproduce:
$ echo ' 3.14 , 2' | \
sigrok-cli -i - -I csv:header=false:column_formats=2a
sr: input/csv: Cannot parse analog text 3.14 in column 1 in line 1.
*/
static char **split_line(char *buf, struct context *inc)
{
- return g_strsplit(buf, inc->delimiter->str, 0);
+ char **fields, *f;
+ size_t l;
+
+ fields = g_strsplit(buf, inc->delimiter->str, 0);
+ if (!fields)
+ return NULL;
+
+ l = g_strv_length(fields);
+ while (l--) {
+ f = fields[l];
+ g_strchomp(f);
+ }
+
+ return fields;
}
/**