From cd11e33c5de58edb0340fd9f25115aa4509f4767 Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Sun, 4 Oct 2020 19:48:42 +0200 Subject: [PATCH] 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. --- src/input/csv.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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; } /** -- 2.30.2