4c1592ae46d1272a7d1ed5785e9df07e6dbb59e2 galt Tue Jul 10 14:41:42 2012 -0700 fixing subtle problem with tabs and empty strings in b2bb input parsing diff --git src/lib/common.c src/lib/common.c index c71badc..559ab3b 100644 --- src/lib/common.c +++ src/lib/common.c @@ -1840,58 +1840,63 @@ break; if (c == 0) break; ++count; } return count; } /* int chopString(in, sep, outArray, outSize); */ /* This chops up the input string (cannabilizing it) * into an array of zero terminated strings in * outArray. It returns the number of strings. * If you pass in NULL for outArray, it will just * return the number of strings that it *would* - * chop. */ + * chop. + * GOTCHA: since multiple separators are skipped + * and treated as one, it is impossible to parse + * a list with an empty string. + * e.g. cat\t\tdog returns only cat and dog but no empty string */ int chopString(char *in, char *sep, char *outArray[], int outSize) { int recordCount = 0; for (;;) { if (outArray != NULL && recordCount >= outSize) break; /* Skip initial separators. */ in += strspn(in, sep); if (*in == 0) break; if (outArray != NULL) outArray[recordCount] = in; recordCount += 1; in += strcspn(in, sep); if (*in == 0) break; if (outArray != NULL) *in = 0; in += 1; } return recordCount; } int chopByWhite(char *in, char *outArray[], int outSize) -/* Like chopString, but specialized for white space separators. */ +/* Like chopString, but specialized for white space separators. + * See the GOTCHA in chopString */ { int recordCount = 0; char c; for (;;) { if (outArray != NULL && recordCount >= outSize) break; /* Skip initial separators. */ while (isspace(*in)) ++in; if (*in == 0) break; /* Store start of word and look for end of word. */ if (outArray != NULL)