d4228428913bd26a1031a2acc156a0b0d777ea45
kent
  Mon Jun 26 08:11:31 2017 -0700
Improving comments in csv.h.  Make eraseTrailingSpaces keep track of number of spaces erased, and using this to keep a dyString->stringSize accurate.

diff --git src/lib/csv.c src/lib/csv.c
index 4f9914e..2ae0db3 100644
--- src/lib/csv.c
+++ src/lib/csv.c
@@ -61,31 +61,31 @@
 char c;
 while ((c = *val++) != 0)
     {
     if (c == '"')
 	fputc('"', f);
     fputc(c, f);
     }
 fputc('"', f);
 }
 
 char *csvParseNext(char **pos, struct dyString *scratch)
 /* Return next value starting at pos, putting results into scratch and
  * returning scratch->string or NULL if no values left. Will update *pos
  * to after trailing comma if any. This will tolerate and ignore leading
  * and trailing white space.  
- *     Since an empty or all-white string is will return NULL, if you
+ *     Since an empty or all-white string will return NULL, if you
  * want empty strings to be a legitimate value then they have to be quoted
  * or followed by a comma. */
 {
 // Return NULL at end of string
 char *s = skipLeadingSpaces(*pos);
 if (isEmpty(s))
     return NULL;
 
 // Clear scratch pad and get first character
 dyStringClear(scratch);
 char c = *s;
 
 // If we start with a quote then fall into logic that goes to next quote,
 // treating internal "" as a single " so that can have internal quotes
 if (c == '"')
@@ -127,31 +127,34 @@
     char lastC = 0;
     for (;;)
        {
        if (c == 0)
            break;
        if (c == ',')
            {
 	   ++s;  // skip over trailing comma.
 	   break;
 	   }
 	dyStringAppendC(scratch, c);
 	lastC = c;
 	c = *(++s);
 	}
     if (isspace(lastC))
-        eraseTrailingSpaces(scratch->string);
+	{
+        int erased = eraseTrailingSpaces(scratch->string);
+	scratch->stringSize -= erased;
+	}
     }
 
 // Update position to start reading next one from and return scratchpad
 *pos = s;
 return scratch->string;
 }
 
 boolean csvNeedsParsing(char *s)
 /* Return TRUE if s is something that needs parsing through the csv parser.  That
  * is it either starts with a quote or has a comma */
 {
 if (strchr(s, ','))
     return TRUE;
 return *s == '"';
 }