cwCsv.h/cpp : Fixed off-by-1 bug in _udpate_col_array().
Fixed bug in _get_field_str() where leading white space was not skipped.
This commit is contained in:
parent
95f26398e8
commit
c789d70ce2
10
cwCsv.cpp
10
cwCsv.cpp
@ -74,7 +74,7 @@ namespace cw
|
|||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
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);
|
rc = cwLogError(kSyntaxErrorRC,"Too many CSV columns on line index:%i",p->curLineIdx);
|
||||||
goto errLabel;
|
goto errLabel;
|
||||||
@ -131,7 +131,7 @@ namespace cw
|
|||||||
}
|
}
|
||||||
|
|
||||||
fieldN += 1;
|
fieldN += 1;
|
||||||
bi = i+1;
|
bi = i+1;
|
||||||
state = kBeforeField;
|
state = kBeforeField;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -266,8 +266,10 @@ namespace cw
|
|||||||
goto errLabel;
|
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;
|
fieldStr_Ref = p->lineBuf + p->colA[colIdx].char_idx;
|
||||||
|
|
||||||
errLabel:
|
errLabel:
|
||||||
|
1
cwCsv.h
1
cwCsv.h
@ -10,6 +10,7 @@ namespace cw
|
|||||||
typedef handle<struct csv_str> handle_t;
|
typedef handle<struct csv_str> handle_t;
|
||||||
|
|
||||||
// The first line of the CSV is expected to hold the column titles.
|
// 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.
|
// 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 );
|
rc_t create( handle_t& hRef, const char* fname, const char** titleA=nullptr, unsigned titleN=0 );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user