input/csv: trim cell content before conversion

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.
This commit is contained in:
Gerhard Sittig 2020-10-04 19:48:42 +02:00
parent d999f2b61e
commit cd11e33c5d
1 changed files with 14 additions and 1 deletions

View File

@ -756,7 +756,20 @@ static void strip_comment(char *buf, const GString *prefix)
*/
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;
}
/**