diff --git a/c/containers/lrec_parsers.c b/c/containers/lrec_parsers.c index 8cf5929ee..feea138fa 100644 --- a/c/containers/lrec_parsers.c +++ b/c/containers/lrec_parsers.c @@ -145,19 +145,22 @@ lrec_t* lrec_parse_csv(hdr_keeper_t* phdr_keeper, char* data_line, char ifs, int // xxx needs pe-non-null (hdr-empty) check: sllse_t* pe = phdr_keeper->pkeys->phead; - for (char* p = data_line; *p; p++) { + for (char* p = data_line; *p; ) { if (*p == ifs) { *p = 0; + + key = pe->value; + lrec_put_no_free(prec, key, value); + p++; - // xxx hoist loop invariant at the cost of some code duplication if (allow_repeat_ifs) { while (*p == ifs) p++; } - key = pe->value; - lrec_put_no_free(prec, key, value); value = p; pe = pe->pnext; + } else { + p++; } } key = pe->value; diff --git a/c/test/output/out b/c/test/output/out index 99b7bbfde..d4fc038a4 100644 --- a/c/test/output/out +++ b/c/test/output/out @@ -1319,10 +1319,10 @@ NULL-FIELD INPUT ./test/../mlr --icsv --odkvp cat test/input/null-fields.csv a=1,b=2,c=3,d=4,e=5 -a=6,b=,,c=,10 -a=,b=,,c=11,d=12 -a=13,b=14,c=,,d= -a=,b=,,c=, +a=6,b=,c=,d=,e=10 +a=,b=,c=,d=11,e=12 +a=13,b=14,c=,d=,e= +a=,b=,c=,d=,e= ./test/../mlr --inidx --odkvp cat test/input/null-fields.nidx 1=a,2=b,3=c,4=d,5=e