cwCsv.cpp : _parse_number_field() now skips over empty fields.
This commit is contained in:
parent
85d647562f
commit
4ffa2e7df7
25
cwCsv.cpp
25
cwCsv.cpp
@ -8,6 +8,7 @@
|
|||||||
#include "cwObject.h"
|
#include "cwObject.h"
|
||||||
#include "cwCsv.h"
|
#include "cwCsv.h"
|
||||||
#include "cwNumericConvert.h"
|
#include "cwNumericConvert.h"
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace cw
|
namespace cw
|
||||||
{
|
{
|
||||||
@ -263,6 +264,8 @@ namespace cw
|
|||||||
goto errLabel;
|
goto errLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fieldStr_Ref = p->lineBuf + p->colA[colIdx].char_idx;
|
fieldStr_Ref = p->lineBuf + p->colA[colIdx].char_idx;
|
||||||
|
|
||||||
errLabel:
|
errLabel:
|
||||||
@ -275,16 +278,28 @@ namespace cw
|
|||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
rc_t rc = kOkRC;
|
||||||
const char* fieldStr = nullptr;
|
const char* fieldStr = nullptr;
|
||||||
|
|
||||||
if((rc = _get_field_str(p,colIdx,fieldStr)) != kOkRC )
|
if((rc = _get_field_str(p,colIdx,fieldStr)) != kOkRC )
|
||||||
goto errLabel;
|
goto errLabel;
|
||||||
|
|
||||||
if((rc = string_to_number(fieldStr,valueRef)) != kOkRC )
|
if( fieldStr != nullptr )
|
||||||
{
|
{
|
||||||
rc = cwLogError(rc,"Numeric parse failed on column '%s' on line index:%i",cwStringNullGuard(p->colA[colIdx].title),p->curLineIdx);
|
// advance past white space
|
||||||
goto errLabel;
|
while( *fieldStr && isspace(*fieldStr) )
|
||||||
}
|
++fieldStr;
|
||||||
|
|
||||||
|
// the first char must be a number or decimal point
|
||||||
|
if( isdigit(*fieldStr) || (*fieldStr=='.' && std::is_floating_point<T>()) )
|
||||||
|
{
|
||||||
|
|
||||||
|
if((rc = string_to_number(fieldStr,valueRef)) != kOkRC )
|
||||||
|
{
|
||||||
|
rc = cwLogError(rc,"Numeric parse failed on column '%s' on line index:%i",cwStringNullGuard(p->colA[colIdx].title),p->curLineIdx);
|
||||||
|
goto errLabel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
errLabel:
|
errLabel:
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user