|
|
|
@@ -84,6 +84,40 @@ func ExFuncTrimSuffix(ctx ExpanderContext, varValue string, args []string) (resu
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ExFuncTrim(ctx ExpanderContext, varValue string, args []string) (result string, err error) {
|
|
|
|
|
result = strings.TrimSpace(varValue)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ExFuncMap(ctx ExpanderContext, varValue string, args []string) (result string, err error) {
|
|
|
|
|
sep := args[0]
|
|
|
|
|
for _, pairSpec := range args[1:] {
|
|
|
|
|
pair := strings.SplitN(pairSpec, sep, 2)
|
|
|
|
|
if pair[0] == varValue {
|
|
|
|
|
if len(pair) == 2 {
|
|
|
|
|
result = pair[1]
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ExFuncMapNC(ctx ExpanderContext, varValue string, args []string) (result string, err error) {
|
|
|
|
|
sep := args[0]
|
|
|
|
|
varValue = strings.ToLower(varValue)
|
|
|
|
|
for _, pairSpec := range args[1:] {
|
|
|
|
|
pair := strings.SplitN(pairSpec, sep, 2)
|
|
|
|
|
if strings.ToLower(pair[0]) == varValue {
|
|
|
|
|
if len(pair) == 2 {
|
|
|
|
|
result = pair[1]
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func AddBaseFuncs(ctx ExpanderContext) ExpanderContext {
|
|
|
|
|
ctx.AddFunc("__default", ExFuncDefault, 0, -1, "Returns the flow value if not empty, else all args joined; first arg is used as separator.")
|
|
|
|
|
ctx.AddFunc("__get", ExFuncGet, 0, 2, "Returns the value of the specified variable (arg1). With no arguments it returns the value of the variable having the flow value as name (same as __get ${.}). Arg2 is the default value. ")
|
|
|
|
@@ -91,6 +125,9 @@ func AddBaseFuncs(ctx ExpanderContext) ExpanderContext {
|
|
|
|
|
ctx.AddFunc("__join", ExFuncJoin, 1, -1, "Joins its args starting from the second. The first one (arg1) is the separator")
|
|
|
|
|
ctx.AddFunc("__lower", ExFuncLower, 0, 0, "Changes the flow value to lower case.")
|
|
|
|
|
ctx.AddFunc("__upper", ExFuncUpper, 0, 0, "Changes the flow value to upper case.")
|
|
|
|
|
ctx.AddFunc("__trim", ExFuncTrim, 0, 0, "Removes blanks on the left and on the right of the flow.")
|
|
|
|
|
ctx.AddFunc("__trim-suffix", ExFuncTrimSuffix, 1, 1, "Removes the specified suffix (arg1) from the flow.")
|
|
|
|
|
ctx.AddFunc("__map", ExFuncMap, 1, 1, "Returns the value mapped by the flow value as a key; e.g. two __map : 'one:1' 'two:2' 'six:6' returns 2")
|
|
|
|
|
ctx.AddFunc("__map-nc", ExFuncMapNC, 1, 1, "Same as __map but this comapares keys ignoring case differencies; e.g. two __map-nc : 'ONE:1' 'Two:2' 'sIX:6' returns 2")
|
|
|
|
|
return ctx
|
|
|
|
|
}
|
|
|
|
|