1b20a1774021cdcb07303801d55b7ca3fa6cff09 braney Wed Jan 8 05:54:20 2025 -0800 fix up chop functions so they don't call ArraySize with NULL diff --git src/inc/common.h src/inc/common.h index dee94e2..8e3b146 100644 --- src/inc/common.h +++ src/inc/common.h @@ -990,51 +990,59 @@ * If you pass in NULL for outArray, it will just * return the number of strings that it *would* * chop. * NOTE: unlike chopByChar, this skips empty words between separators! */ extern char crLfChopper[]; extern char whiteSpaceChopper[]; /* Some handy predefined separators. */ int chopByWhite(char *in, char *outArray[], int outSize); /* Like chopString, but specialized for white space separators. */ #define chopLine(line, words) chopByWhite(line, words, ArraySize(words)) /* Chop line by white space. */ +#define chopLineLen(line) chopByWhite(line, NULL, 0) +/* Return the number of elements if you were to chop line by white space. */ + int chopByWhiteRespectDoubleQuotes(char *in, char *outArray[], int outSize); /* Like chopString, but specialized for white space separators. * Further, any doubleQuotes (") are respected. * If doubleQuote encloses whole string, then they are removed: * "Fred and Ethyl" results in word [Fred and Ethyl] * If doubleQuotes exist inside string they are retained: * Fred "and Ethyl" results in word [Fred "and Ethyl"] * Special note "" is a valid, though empty word. */ int chopByCharRespectDoubleQuotes(char *in, char sep, char *outArray[], int outSize); /* Chop a string into sep delimited strings but honor double quotes */ int chopByChar(char *in, char chopper, char *outArray[], int outSize); /* Chop based on a single character. */ #define chopTabs(string, words) chopByChar(string, '\t', words, ArraySize(words)) /* Chop string by tabs. */ +#define chopTabsLen(string) chopByChar(string, '\t', NULL, 0) +/* Return the number of elements if you were to chop string by tab. */ + #define chopCommas(string, words) chopByChar(string, ',', words, ArraySize(words)) /* Chop string by commas. */ +#define chopCommasLen(string) chopByChar(string, ',', NULL, 0) +/* Return the number of elements if you were to chop string by comma. */ char *skipBeyondDelimit(char *s,char delimit); /* Returns NULL or pointer to first char beyond one (or more contiguous) delimit char. If delimit is ' ' then skips beyond first patch of whitespace. */ char *skipLeadingSpaces(const char *s); /* Return first white space or NULL if none.. */ char *skipToSpaces(const char *s); /* Return first white space. */ int eraseTrailingSpaces(char *s); /* Replace trailing white space with zeroes. Returns number of * spaces erased. */