31 lines
672 B
Go
31 lines
672 B
Go
package strings
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
"github.com/zclconf/go-cty/cty/function"
|
|
)
|
|
|
|
func Trim() function.Function {
|
|
return function.New(&function.Spec{
|
|
Description: "Trim strings",
|
|
Params: []function.Parameter{
|
|
{
|
|
Name: "toTrim",
|
|
Description: "string to trim",
|
|
Type: cty.String,
|
|
},
|
|
{
|
|
Name: "cutset",
|
|
Description: "Characters to trim",
|
|
Type: cty.String,
|
|
},
|
|
},
|
|
Type: function.StaticReturnType(cty.String),
|
|
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
|
|
return cty.StringVal(strings.Trim(args[0].AsString(), args[1].AsString())), nil
|
|
},
|
|
})
|
|
}
|