Browse Source

cmCsv.h : Renamed cmCsvInsertTextColAfter() to cmCsvInsertQTestColAfter() to be clear that the output will be quoted.

Added cmCsvInsertIdentColAfter() to insert non-quoted text.
master
kevin 8 years ago
parent
commit
198a0039f1
2 changed files with 41 additions and 5 deletions
  1. 37
    3
      cmCsv.c
  2. 4
    2
      cmCsv.h

+ 37
- 3
cmCsv.c View File

@@ -772,6 +772,24 @@ unsigned   cmCsvInsertSymDouble( cmCsvH_t h, double v )
772 772
 
773 773
 }
774 774
 
775
+cmCsvRC_t  cmCsvSetCellIdent(   cmCsvH_t h, unsigned row, unsigned col, const char* text )
776
+{
777
+  cmCsvCell_t* cp;
778
+  unsigned     symId;
779
+
780
+  if((cp = _cmCsvCellPtr(h,row,col)) == NULL )
781
+    return cmErrLastRC(&_cmCsvHandleToPtr(h)->err);
782
+
783
+  if((symId = cmCsvInsertSymText(h,text)) == cmInvalidId )
784
+    return cmErrLastRC(&_cmCsvHandleToPtr(h)->err);
785
+  
786
+  cp->symId = symId;
787
+  cp->flags &= !kTypeTMask;
788
+  cp->flags |= kIdentCsvTFl;
789
+
790
+  return kOkCsvRC;  
791
+}
792
+
775 793
 cmCsvRC_t  cmCsvSetCellText(   cmCsvH_t h, unsigned row, unsigned col, const char* text )
776 794
 {
777 795
   cmCsvCell_t* cp;
@@ -1011,7 +1029,23 @@ cmCsvRC_t cmCsvInsertColAfter(  cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_
1011 1029
   
1012 1030
 }
1013 1031
 
1014
-cmCsvRC_t  cmCsvInsertTextColAfter(   cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* text, unsigned lexTId )
1032
+cmCsvRC_t  cmCsvInsertIdentColAfter(   cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* text, unsigned lexTId )
1033
+{
1034
+  cmCsvRC_t    rc;
1035
+  cmCsvCell_t* ncp;
1036
+
1037
+  if( cellPtrPtr != NULL )
1038
+    *cellPtrPtr = NULL;
1039
+
1040
+  if((rc = cmCsvInsertColAfter(h, leftCellPtr, &ncp, cmInvalidId, 0, lexTId )) == kOkCsvRC )
1041
+    if((rc = cmCsvSetCellIdent(h, ncp->row, ncp->col, text )) == kOkCsvRC )
1042
+      if( cellPtrPtr != NULL )
1043
+        *cellPtrPtr = ncp;
1044
+  
1045
+  return rc;
1046
+}
1047
+
1048
+cmCsvRC_t  cmCsvInsertQTextColAfter(   cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* text, unsigned lexTId )
1015 1049
 {
1016 1050
   cmCsvRC_t    rc;
1017 1051
   cmCsvCell_t* ncp;
@@ -1137,12 +1171,12 @@ cmCsvRC_t  cmCsvWrite( cmCsvH_t h, const char* fn )
1137 1171
         if((tp = cmHashTblStr(p->htH,cp->symId)) == NULL )
1138 1172
           return _cmCsvError(p,kHashTblErrCsvRC,"Unable to locate the symbol text for cell at row:%i col:%i.",cp->row,cp->col);
1139 1173
 
1140
-        if( cmIsFlag(cp->flags,kTextTMask) )
1174
+        if( cmIsFlag(cp->flags,kStrCsvTFl) )
1141 1175
           fprintf(fp,"\"");
1142 1176
 
1143 1177
         fputs(tp,fp);
1144 1178
 
1145
-        if( cmIsFlag(cp->flags,kTextTMask) )
1179
+        if( cmIsFlag(cp->flags,kStrCsvTFl) )
1146 1180
           fprintf(fp,"\"");
1147 1181
 
1148 1182
         cp = cp->rowPtr;

+ 4
- 2
cmCsv.h View File

@@ -117,7 +117,8 @@ extern "C" {
117 117
 
118 118
 
119 119
   // Set the value associated with a cell.
120
-  cmCsvRC_t  cmCsvSetCellText(   cmCsvH_t h, unsigned row, unsigned col, const char* text );
120
+  cmCsvRC_t  cmCsvSetCellIdent(  cmCsvH_t h, unsigned row, unsigned col, const char* text );
121
+  cmCsvRC_t  cmCsvSetCellQText(  cmCsvH_t h, unsigned row, unsigned col, const char* text );
121 122
   cmCsvRC_t  cmCsvSetCellInt(    cmCsvH_t h, unsigned row, unsigned col, int v );
122 123
   cmCsvRC_t  cmCsvSetCellUInt(   cmCsvH_t h, unsigned row, unsigned col, unsigned v );
123 124
   cmCsvRC_t  cmCsvSetCellHex(    cmCsvH_t h, unsigned row, unsigned col, unsigned v );
@@ -138,7 +139,8 @@ extern "C" {
138 139
   // cmCsvCell_t.lexTId in the new cell. There are no constraints on its value.
139 140
   cmCsvRC_t  cmCsvInsertColAfter(  cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned symId, unsigned flags, unsigned lexTId );
140 141
 
141
-  cmCsvRC_t  cmCsvInsertTextColAfter(   cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* val, unsigned lexTId );
142
+  cmCsvRC_t  cmCsvInsertIdentColAfter(  cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* val, unsigned lexTId );
143
+  cmCsvRC_t  cmCsvInsertQTextColAfter(  cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, const char* val, unsigned lexTId );
142 144
   cmCsvRC_t  cmCsvInsertIntColAfter(    cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, int val,         unsigned lexTId );
143 145
   cmCsvRC_t  cmCsvInsertUIntColAfter(   cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned val,    unsigned lexTId );
144 146
   cmCsvRC_t  cmCsvInsertHexColAfter(    cmCsvH_t h, cmCsvCell_t* leftCellPtr, cmCsvCell_t** cellPtrPtr, unsigned val,    unsigned lexTId );

Loading…
Cancel
Save