diff --git a/cwCsv.cpp b/cwCsv.cpp index 3e389f6..2d3a0c1 100644 --- a/cwCsv.cpp +++ b/cwCsv.cpp @@ -74,7 +74,7 @@ namespace cw { rc_t rc = kOkRC; - if( col_idx > p->colN ) + if( col_idx >= p->colN ) { rc = cwLogError(kSyntaxErrorRC,"Too many CSV columns on line index:%i",p->curLineIdx); goto errLabel; @@ -131,7 +131,7 @@ namespace cw } fieldN += 1; - bi = i+1; + bi = i+1; state = kBeforeField; } break; @@ -266,8 +266,10 @@ namespace cw goto errLabel; } - - + // skip leading white space + while( isspace(p->lineBuf[ p->colA[colIdx].char_idx ]) && p->lineBuf[ p->colA[colIdx].char_idx ] ) + p->colA[colIdx].char_idx++; + fieldStr_Ref = p->lineBuf + p->colA[colIdx].char_idx; errLabel: diff --git a/cwCsv.h b/cwCsv.h index b4c935a..22048ad 100644 --- a/cwCsv.h +++ b/cwCsv.h @@ -10,6 +10,7 @@ namespace cw typedef handle handle_t; // The first line of the CSV is expected to hold the column titles. + // Every column must have a title. // If titlesA and titleN are valid then these will be verified to exist when the CSV file is opened. rc_t create( handle_t& hRef, const char* fname, const char** titleA=nullptr, unsigned titleN=0 );