fix csv reader for null fields

This commit is contained in:
John Kerl 2015-05-09 13:52:01 -07:00
parent ddda357649
commit ba93969997
2 changed files with 11 additions and 8 deletions

View file

@ -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;

View file

@ -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