From 47092488288de0bf1ce4d70b82f633f03c22fe6a Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Thu, 13 Nov 2025 20:53:07 +0100 Subject: [PATCH] string builtin: strUpper() and strLower() added --- builtin-string.go | 26 ++++++++++++++++++++++++++ t_builtin-string_test.go | 2 ++ 2 files changed, 28 insertions(+) diff --git a/builtin-string.go b/builtin-string.go index 6a9df5c..a139452 100644 --- a/builtin-string.go +++ b/builtin-string.go @@ -200,6 +200,24 @@ func splitStrFunc(ctx ExprContext, name string, args map[string]any) (result any return } +func upperStrFunc(ctx ExprContext, name string, args map[string]any) (result any, err error) { + if source, ok := args[ParamSource].(string); ok { + result = strings.ToUpper(source) + } else { + err = ErrWrongParamType(name, ParamSource, TypeString, args[ParamSource]) + } + return +} + +func lowerStrFunc(ctx ExprContext, name string, args map[string]any) (result any, err error) { + if source, ok := args[ParamSource].(string); ok { + result = strings.ToLower(source) + } else { + err = ErrWrongParamType(name, ParamSource, TypeString, args[ParamSource]) + } + return +} + // --- End of function definitions // Import above functions in the context @@ -236,6 +254,14 @@ func ImportStringFuncs(ctx ExprContext) { NewFuncParam(ParamSuffix), NewFuncParamFlag(strParamOther, PfRepeat), }) + + ctx.RegisterFunc("strUpper", NewGolangFunctor(upperStrFunc), TypeBoolean, []ExprFuncParam{ + NewFuncParam(ParamSource), + }) + + ctx.RegisterFunc("strLower", NewGolangFunctor(lowerStrFunc), TypeBoolean, []ExprFuncParam{ + NewFuncParam(ParamSource), + }) } // Register the import function in the import-register. diff --git a/t_builtin-string_test.go b/t_builtin-string_test.go index 99e0a47..46500c0 100644 --- a/t_builtin-string_test.go +++ b/t_builtin-string_test.go @@ -31,6 +31,8 @@ func TestFuncString(t *testing.T) { /* 17 */ {`builtin "string"; strSplit("one-two-three", "-")`, newListA("one", "two", "three"), nil}, /* 18 */ {`builtin "string"; strJoin("-", [1, "two", "three"])`, nil, `strJoin(): expected string, got integer (1)`}, /* 19 */ {`builtin "string"; strJoin()`, nil, `strJoin(): too few params -- expected 1 or more, got 0`}, + /* 20 */ {`builtin "string"; strUpper("StOp")`, "STOP", nil}, + /* 21 */ {`builtin "string"; strLower("StOp")`, "stop", nil}, /* 69 */ /*{`builtin "string"; $$global`, `vars: { }