16d50b66c01e686c4d0d457e44536446f55b8bfe kent Thu Aug 8 11:29:11 2019 -0700 Renaming two built in functions. diff --git src/lib/strex.c src/lib/strex.c index 5fb8b91..4991b53 100644 --- src/lib/strex.c +++ src/lib/strex.c @@ -36,34 +36,34 @@ enum strexType /* A type */ { strexTypeBoolean = 1, strexTypeString = 2, strexTypeInt = 3, strexTypeDouble = 4, }; enum strexBuiltInFunc /* One of these for each builtIn. We'll just do a switch to implement */ { strexBuiltInTrim, strexBuiltInBetween, - strexBuiltInSpaced, + strexBuiltInSplit, strexBuiltInNow, strexBuiltInMd5, - strexBuiltInSplit, + strexBuiltInSeparate, }; struct strexBuiltIn /* A built in function */ { char *name; enum strexBuiltInFunc func; int paramCount; enum strexType *paramTypes; }; union strexVal /* Some value of arbirary type that can be of any type corresponding to strexType */ { @@ -127,34 +127,34 @@ /* Input to the strex parser */ { struct tokenizer *tkz; /* Get next text input from here */ struct hash *builtInHash; /* Hash of built in functions */ }; static enum strexType oneString[] = {strexTypeString}; // static enum strexType twoStrings[] = {strexTypeString, strexTypeString}; static enum strexType threeStrings[] = {strexTypeString, strexTypeString, strexTypeString}; static enum strexType stringInt[] = {strexTypeString, strexTypeInt}; static enum strexType stringStringInt[] = {strexTypeString, strexTypeString, strexTypeInt}; static struct strexBuiltIn builtins[] = { { "trim", strexBuiltInTrim, 1, oneString, }, { "between", strexBuiltInBetween, 3, threeStrings, }, - { "spaced", strexBuiltInSpaced, 2, stringInt }, + { "split", strexBuiltInSplit, 2, stringInt }, { "now", strexBuiltInNow, 0, NULL }, { "md5", strexBuiltInMd5, 1, oneString }, - { "split", strexBuiltInSplit, 3, stringStringInt }, + { "separate", strexBuiltInSeparate, 3, stringStringInt }, }; static struct hash *hashBuiltIns() /* Build a hash of builtins keyed by name */ { struct hash *hash = hashNew(0); int i; for (i=0; ichildren; struct strexParse *index = array->next; struct strexEval arrayVal = strexLocalEval(array, record, lookup, lm); struct strexEval indexVal = strexLocalEval(index, record, lookup, lm); struct strexEval res; struct dyString *scratch = dyStringNew(0); char *val = emptyForNull(csvParseOneOut(arrayVal.val.s, indexVal.val.i, scratch)); res.val.s = cloneString(val); res.type = strexTypeString; return res; } -static char *wordInString(char *words, int ix, struct lm *lm) -/* Return the word delimited string of index ix as clone into lm */ +static char *splitString(char *words, int ix, struct lm *lm) +/* Return the space-delimited word of index ix as clone into lm */ { char *s = words; int i; for (i=0; ; ++i) { s = skipLeadingSpaces(s); if (isEmpty(s)) errAbort("There aren't %d words in %s", ix+1, words); char *end = skipToSpaces(s); if (i == ix) { if (end == NULL) return lmCloneString(lm, s); else return lmCloneMem(lm, s, end - s); } s = end; } } -static char *splitString(char *string, char *splitter, int ix, struct lm *lm) +static char *separateString(char *string, char *splitter, int ix, struct lm *lm) /* Return the ix'th part of string as split apart by splitter */ { int splitterSize = strlen(splitter); if (splitterSize != 1) errAbort("Separator parameter to split must be a single character, not %s", splitter); int count = chopByChar(string, splitter[0], NULL, 0); if (ix >= count) errAbort("There aren't %d fields separated by %s in %s", ix+1, splitter, string); char **row; lmAllocArray(lm, row, count); char *scratch = lmCloneString(lm, string); chopByChar(scratch, splitter[0], row, count); return row[ix]; } @@ -856,58 +856,58 @@ { struct strexEval a = strexLocalEval(p->children, record, lookup, lm); res.val.s = trimSpaces(a.val.s); break; } case strexBuiltInBetween: { struct strexEval a = strexLocalEval(p->children, record, lookup, lm); struct strexEval b = strexLocalEval(p->children->next, record, lookup, lm); struct strexEval c = strexLocalEval(p->children->next->next, record, lookup, lm); char *between = stringBetween(a.val.s, c.val.s, b.val.s); res.val.s = lmCloneString(lm, between); freeMem(between); break; } - case strexBuiltInSpaced: + case strexBuiltInSplit: { struct strexEval a = strexLocalEval(p->children, record, lookup, lm); struct strexEval b = strexLocalEval(p->children->next, record, lookup, lm); - res.val.s = wordInString(a.val.s, b.val.i, lm); + res.val.s = splitString(a.val.s, b.val.i, lm); break; } case strexBuiltInNow: { time_t now = time(NULL); res.val.s = lmCloneString(lm, ctime(&now)); eraseTrailingSpaces(res.val.s); break; } case strexBuiltInMd5: { struct strexEval a = strexLocalEval(p->children, record, lookup, lm); char *md5 = hmacMd5("", a.val.s); res.val.s = lmCloneString(lm, md5); freez(&md5); break; } - case strexBuiltInSplit: + case strexBuiltInSeparate: { struct strexEval a = strexLocalEval(p->children, record, lookup, lm); struct strexEval b = strexLocalEval(p->children->next, record, lookup, lm); struct strexEval c = strexLocalEval(p->children->next->next, record, lookup, lm); - res.val.s = splitString(a.val.s, b.val.s, c.val.i, lm); + res.val.s = separateString(a.val.s, b.val.s, c.val.i, lm); break; } } return res; } static struct strexEval strexLocalEval(struct strexParse *p, void *record, StrexEvalLookup lookup, struct lm *lm) /* Evaluate self on parse tree, allocating memory if needed from lm. */ { struct strexEval res; switch (p->op) { case strexOpLiteral: