From: Gerhard Sittig Date: Sun, 4 Oct 2020 17:48:42 +0000 (+0200) Subject: input/csv: trim cell content before conversion X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cd11e33c5de58edb0340fd9f25115aa4509f4767;p=libsigrok.git 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. --- diff --git a/src/input/csv.c b/src/input/csv.c index 1c4a5d7f..66cf4bb3 100644 --- a/src/input/csv.c +++ b/src/input/csv.c @@ -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; } /**