From: Gerhard Sittig Date: Mon, 5 Jun 2017 11:09:16 +0000 (+0200) Subject: input/csv: Concentrate text line encoding in a single spot X-Git-Tag: libsigrok-0.5.0~20 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=492dfa90255e95b143b7a0ba9c78b6e022e7b115 input/csv: Concentrate text line encoding in a single spot Factor out a magic string literal which held a delimiter set yet could be mistaken for an (assumed) fixed termination string. Concentrate the determination of the end-of-line text encoding as well as the resulting set of possible deliminters in one nearby location. The symbolic name for the delimiter set eliminates the doubt on its purpose. --- diff --git a/src/input/csv.c b/src/input/csv.c index db6f4676..fa1d51fd 100644 --- a/src/input/csv.c +++ b/src/input/csv.c @@ -447,6 +447,8 @@ static int init(struct sr_input *in, GHashTable *options) return SR_OK; } +static const char *delim_set = "\r\n"; + static const char *get_line_termination(GString *buf) { const char *term; @@ -476,7 +478,7 @@ static int initial_parse(const struct sr_input *in, GString *buf) columns = NULL; line_number = 0; - lines = g_strsplit_set(buf->str, "\r\n", 0); + lines = g_strsplit_set(buf->str, delim_set, 0); for (l = 0; lines[l]; l++) { line_number++; line = lines[l]; @@ -651,7 +653,7 @@ static int process_buffer(struct sr_input *in) max_columns = 1; ret = SR_OK; - lines = g_strsplit_set(in->buf->str, "\r\n", 0); + lines = g_strsplit_set(in->buf->str, delim_set, 0); for (l = 0; lines[l]; l++) { inc->line_number++; line = lines[l];