7ef20404a23038b61099344295dd592d1435850d kent Thu Aug 15 09:58:04 2019 -0700 Adding default to pick. diff --git src/lib/strex.doc src/lib/strex.doc index aceca45..e471d20 100644 --- src/lib/strex.doc +++ src/lib/strex.doc @@ -70,35 +70,36 @@ 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") example to give something a value if non is present fix(requiredField, "", "reasonable default value") -pick(query ? key1:val1, key2:val2, ... keyN:valN) +pick(query ? key1:val1, key2:val2, ... keyN:valN, default:defaultVal) Looks through keys for one that matches query, and returns associated value if - it finds it. Otherwise returns empty string. + it finds it. Otherwise it returns the empty string unless a default is specified. + The default key can appear in any position, but traditionally is last or first. Can be used to apply different expressions to parsing in different conditions: - pick(species, "human" : ethnicity, "mouse" : strain ) + pick(species, "human" : ethnicity, "mouse" : strain, default:"unknown") (boolean ? trueVal : falseVal) This is the trinary conditional expression found in C, Python and many other languages. If the boolean before the question mark is true, then the result is the trueVal before the colon, otherwise it's the falseVal after the colon. Empty strings and zeros as booleans are considered false, other strings and numbers true. in(string, query) - returns true if query is a substring of string, false otherwise same(a, b) - returns true if the two arguments are the same, false otherwise starts(prefix, string) - returns true if string starts with prefix ends(string, suffix) - returns true if string ends with suffix