From 198a0039f11037d4772b4a0c3ca89e5758a0e4bb Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 2 Mar 2016 18:48:51 -0500 Subject: [PATCH] cmCsv.h : Renamed cmCsvInsertTextColAfter() to cmCsvInsertQTestColAfter() to be clear that the output will be quoted. Added cmCsvInsertIdentColAfter() to insert non-quoted text. --- cmCsv.c | 40 +++++++++++++++++++++++++++++++++++++--- cmCsv.h | 6 ++++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/cmCsv.c b/cmCsv.c index 229df1f..8ece1ce 100644 --- a/cmCsv.c +++ b/cmCsv.c @@ -772,6 +772,24 @@ unsigned cmCsvInsertSymDouble( cmCsvH_t h, double v ) } +cmCsvRC_t cmCsvSetCellIdent( cmCsvH_t h, unsigned row, unsigned col, const char* text ) +{ + cmCsvCell_t* cp; + unsigned symId; + + if((cp = _cmCsvCellPtr(h,row,col)) == NULL ) + return cmErrLastRC(&_cmCsvHandleToPtr(h)->err); + + if((symId = cmCsvInsertSymText(h,text)) == cmInvalidId ) + return cmErrLastRC(&_cmCsvHandleToPtr(h)->err); + + cp->symId = symId; + cp->flags &= !kTypeTMask; + cp->flags |= kIdentCsvTFl; + + return kOkCsvRC; +} + cmCsvRC_t cmCsvSetCellText( cmCsvH_t h, unsigned row, unsigned col, const char* text ) { cmCsvCell_t* cp; @@ -1011,7 +1029,23 @@ cmCsvRC_t cmCsvInsertColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_ } -cmCsvRC_t cmCsvInsertTextColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* text, unsigned lexTId ) +cmCsvRC_t cmCsvInsertIdentColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* text, unsigned lexTId ) +{ + cmCsvRC_t rc; + cmCsvCell_t* ncp; + + if( cellPtrPtr != NULL ) + *cellPtrPtr = NULL; + + if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC ) + if((rc = cmCsvSetCellIdent(h, ncp->row, ncp->col, text )) == kOkCsvRC ) + if( cellPtrPtr != NULL ) + *cellPtrPtr = ncp; + + return rc; +} + +cmCsvRC_t cmCsvInsertQTextColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* text, unsigned lexTId ) { cmCsvRC_t rc; cmCsvCell_t* ncp; @@ -1137,12 +1171,12 @@ cmCsvRC_t cmCsvWrite( cmCsvH_t h, const char* fn ) if((tp = cmHashTblStr(p->htH,cp->symId)) == NULL ) return _cmCsvError(p,kHashTblErrCsvRC,"Unable to locate the symbol text for cell at row:%i col:%i.",cp->row,cp->col); - if( cmIsFlag(cp->flags,kTextTMask) ) + if( cmIsFlag(cp->flags,kStrCsvTFl) ) fprintf(fp,"\""); fputs(tp,fp); - if( cmIsFlag(cp->flags,kTextTMask) ) + if( cmIsFlag(cp->flags,kStrCsvTFl) ) fprintf(fp,"\""); cp = cp->rowPtr; diff --git a/cmCsv.h b/cmCsv.h index 3cef026..b90933d 100644 --- a/cmCsv.h +++ b/cmCsv.h @@ -117,7 +117,8 @@ extern "C" { // Set the value associated with a cell. - cmCsvRC_t cmCsvSetCellText( cmCsvH_t h, unsigned row, unsigned col, const char* text ); + cmCsvRC_t cmCsvSetCellIdent( cmCsvH_t h, unsigned row, unsigned col, const char* text ); + cmCsvRC_t cmCsvSetCellQText( cmCsvH_t h, unsigned row, unsigned col, const char* text ); cmCsvRC_t cmCsvSetCellInt( cmCsvH_t h, unsigned row, unsigned col, int v ); cmCsvRC_t cmCsvSetCellUInt( cmCsvH_t h, unsigned row, unsigned col, unsigned v ); cmCsvRC_t cmCsvSetCellHex( cmCsvH_t h, unsigned row, unsigned col, unsigned v ); @@ -138,7 +139,8 @@ extern "C" { // cmCsvCell_t.lexTId in the new cell. There are no constraints on its value. cmCsvRC_t cmCsvInsertColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned symId, unsigned flags, unsigned lexTId ); - cmCsvRC_t cmCsvInsertTextColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* val, unsigned lexTId ); + cmCsvRC_t cmCsvInsertIdentColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* val, unsigned lexTId ); + cmCsvRC_t cmCsvInsertQTextColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* val, unsigned lexTId ); cmCsvRC_t cmCsvInsertIntColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, int val, unsigned lexTId ); cmCsvRC_t cmCsvInsertUIntColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned val, unsigned lexTId ); cmCsvRC_t cmCsvInsertHexColAfter( cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned val, unsigned lexTId );