summaryrefslogtreecommitdiff
path: root/funcs/strings.go
diff options
context:
space:
mode:
Diffstat (limited to 'funcs/strings.go')
-rw-r--r--funcs/strings.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/funcs/strings.go b/funcs/strings.go
index d14223d6..93b0bd9b 100644
--- a/funcs/strings.go
+++ b/funcs/strings.go
@@ -40,6 +40,7 @@ func AddStringFuncs(f map[string]interface{}) {
f["toLower"] = StrNS().ToLower
f["trimSpace"] = StrNS().TrimSpace
f["indent"] = StrNS().Indent
+ f["sort"] = StrNS().Sort
// these are legacy aliases with non-pipelinable arg order
f["contains"] = strings.Contains
@@ -108,6 +109,23 @@ func (f *StringFuncs) Repeat(count int, s interface{}) (string, error) {
return strings.Repeat(str, count), nil
}
+// Sort -
+func (f *StringFuncs) Sort(list interface{}) ([]string, error) {
+ switch v := list.(type) {
+ case []string:
+ return gompstrings.Sort(v), nil
+ case []interface{}:
+ l := len(v)
+ b := make([]string, len(v))
+ for i := 0; i < l; i++ {
+ b[i] = conv.ToString(v[i])
+ }
+ return gompstrings.Sort(b), nil
+ default:
+ return nil, errors.Errorf("wrong type for value; expected []string; got %T", list)
+ }
+}
+
// Split -
func (f *StringFuncs) Split(sep string, s interface{}) []string {
return strings.Split(conv.ToString(s), sep)