4a3c4b8969e55de992c22ca6e2ec1ba807910bc6 kent Wed Aug 14 19:06:15 2019 -0700 Adding info about symbol function. Improving docs on 'or' diff --git src/lib/strex.doc src/lib/strex.doc index 756729c..8990903 100644 --- src/lib/strex.doc +++ src/lib/strex.doc @@ -1,32 +1,33 @@ The strex language is a small string expression evaluation language. This document describes its built in functions and operators: + - returns the concatenation of the surrounding strings or the addition of surrounding numbers. Will convert a number to a string in mixed expressions or - logical or operation extended to strings and numbers. for logic - if any or-separated-values are true, return true, else false for numbers - if any or-separated non-zero numbers exist, return first one else 0 for strings - if any or-separated non-empty strings exists, return first one else "" In mixed operations result is converted to strings if strings are involved or the values "" and "true" if no strings are involved. For the pure string case this can be useful for setting defaults as well. For instance presuming you might or might not have filled in values for the city or country variables in the given expression that would return a location of some sort - city or country or "somewhere in the universe" - + (city or country or "somewhere in the universe") + Note the parenthesis around the ors is good to have because of the very low + precedence of the logical operators. and - logical and operation extended to strings and numbers for logic - if all and-separated-values are tru, return true, else false for numbers - if all numbers are non-zero return true else false for strings - if all and-separated strings are nonempty, return true, else "" In mixed operations result is converted to strings if strings are involved or the values "" and "true" if no strings are involved. returns first nonempty string or non-zero number on either side of | or "" if all empty & - returns first empty string or zero on either side of & or right side if all non-empty [index] - selects a character from string given an integer zero based index. As in Python if index is negative it selects characters from the end of the string. -1 corresponds to the last character of string, as 0 corresponds to first. @@ -62,30 +63,37 @@ [3] = "3" - the fourth character (the fun of zero based indexes [-3] = "7" - the third character from the end [-3:] = "789" - last three characters of string [:-3] = "0123456" - everything up to the last three Python actually goes further than this and allows a third, step, specification that strex has not implemented. untsv(string, index) - separate by tab. Synonym for separate(string, '\t', index) uncsv(string, index) - do comma separated value extraction of string. Includes quote escaping. trim(string) - returns copy of string with leading and trailing spaces removed strip(string, toRemove) - remove all occurrences of any character in toRemove from string +symbol(prefix, string) - turn string into a computer usable symbol that starts with the given + prefix. To create the rest of the symbol, the string is mangled. First the + spaces, tabs, and newlines are all turned into _ chars, then any remaining + characters that aren't ascii letters or numerical digits are removed. If the result + is 32 characters or less it's used, but if it's longer it's converted into an MD5 + sum. + replace(string, oldPart, newPart) - returns string with all instances of old replaced by new. The cases where either old or new are empty string are useful special cases. If new is "", then all instances of the old string will be deleted. If old is "", then empty strings will be replaced by new strings, useful in setting a default value for a field. fix(string, target, newString) - similar to replace but works at the whole string level. Returns string unchanged except for the case where string matches target exactly. In that case it returns newString instead. The name "fix" comes from it being used generally to replace one constant, fixed, string with another. Also, a lot of the time when you do this it is to fix a small inconsistency in the metadata. In general fix is faster to execute and quicker to type than replace and the effects are more specific. example to help clean up minor variations in vocabulary fix(fix(fix(fix( sex, "M","male"), "F","female"), "Male","male") "Female","female")