Compare commits
No commits in common. "main" and "v0.1.1" have entirely different histories.
@ -102,7 +102,7 @@ func (ctx *DictSetContext) Handle(spec string, scanFlags ScannerFlag) (value str
|
|||||||
origVarFound := found
|
origVarFound := found
|
||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
var expandedPart string
|
var expandedPart string
|
||||||
// ctx.varStores[0][pipeValueKey] = rawValue
|
ctx.varStores[0][pipeValueKey] = rawValue
|
||||||
ctx.SetVar(pipeValueKey, rawValue)
|
ctx.SetVar(pipeValueKey, rawValue)
|
||||||
if expandedPart, err = Scan(ctx, part); err != nil {
|
if expandedPart, err = Scan(ctx, part); err != nil {
|
||||||
break
|
break
|
||||||
|
@ -35,10 +35,6 @@ func TestNewDictSetContext(t *testing.T) {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
yday := now.Add(-24 * time.Hour)
|
yday := now.Add(-24 * time.Hour)
|
||||||
inputs := []inputType{
|
inputs := []inputType{
|
||||||
{ctx1, "${|__default ' abc cba '|__trim}", "abc cba", nil},
|
|
||||||
{ctx1, "${|__default two|__map ':' 'one:1' 'two:2' 'six:6'}", "2", nil},
|
|
||||||
{ctx1, "${|__default two|__map ':' 'one:1' 'TWO:2' 'six:6'}", "", nil},
|
|
||||||
{ctx1, "${|__default two|__map-nc ':' 'one:1' 'TWO:2' 'six:6'}", "2", nil},
|
|
||||||
{ctx2, `form: ${|__time-fmt now ""}`, fmt.Sprintf("form: %d-%02d-%02d %02d:%02d:%02d", now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second()), nil},
|
{ctx2, `form: ${|__time-fmt now ""}`, fmt.Sprintf("form: %d-%02d-%02d %02d:%02d:%02d", now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second()), nil},
|
||||||
{ctx2, `form: ${|__time-fmt now "%-D"}`, fmt.Sprintf("form: %d-%d-%d", now.Year(), now.Month(), now.Day()), nil},
|
{ctx2, `form: ${|__time-fmt now "%-D"}`, fmt.Sprintf("form: %d-%d-%d", now.Year(), now.Month(), now.Day()), nil},
|
||||||
{ctx2, `form: ${|__time-fmt now "%:T"}`, fmt.Sprintf("form: %d:%d:%d", now.Hour(), now.Minute(), now.Second()), nil},
|
{ctx2, `form: ${|__time-fmt now "%:T"}`, fmt.Sprintf("form: %d:%d:%d", now.Hour(), now.Minute(), now.Second()), nil},
|
||||||
|
@ -84,40 +84,6 @@ func ExFuncTrimSuffix(ctx ExpanderContext, varValue string, args []string) (resu
|
|||||||
return
|
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 {
|
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("__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. ")
|
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. ")
|
||||||
@ -125,9 +91,6 @@ 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("__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("__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("__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("__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
|
return ctx
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user