diff --git a/README.md b/README.md
index f75bedf..9fe8825 100644
--- a/README.md
+++ b/README.md
@@ -158,6 +158,10 @@ Accepts a time layout in golang [time format](http://golang.org/pkg/time/#pkg-co
###### strings
+**`$split(s string, separator string})`**
+
+Return an array of strings.
+
**`$contains(s string, substr string)`**
see [strings.Contains](http://golang.org/pkg/strings/#Contains)
@@ -190,4 +194,4 @@ evaluates a variable of type interface{} with a *TokenTree generated from `Parse
### changes
- **.0.1.1** addition of $bool, $~bool, $num, $str, $now, $fmtTime, $parseTime. Fix for non-alphanumeric characters in JSON keys.
-- **.0.1.0** initial release
\ No newline at end of file
+- **.0.1.0** initial release
diff --git a/jee.go b/jee.go
index 3737df8..7eb7e89 100644
--- a/jee.go
+++ b/jee.go
@@ -754,6 +754,26 @@ var binaryFuncs = map[string]func(interface{}, interface{}) (interface{}, error)
}
return float64(t.UnixNano() / 1000 / 1000), nil
},
+ "$split": func(val interface{}, b interface{}) (interface{}, error) {
+ sa, ok := val.(string)
+ if !ok {
+ return nil, nil
+ }
+
+ sb, ok := b.(string)
+ if !ok {
+ return nil, nil
+ }
+
+ var list []interface{}
+ stringList := strings.Split(sa, sb)
+
+ for _ , k := range stringList {
+ list = append(list, k)
+ }
+
+ return list, nil
+ },
"$fmtTime": func(a interface{}, b interface{}) (interface{}, error) {
layout, ok := a.(string)
if !ok {
@@ -826,6 +846,9 @@ var binaryFuncs = map[string]func(interface{}, interface{}) (interface{}, error)
if !ok {
return nil, nil
}
+ if b == nil {
+ return false, nil
+ }
for _, e := range s {
switch c := e.(type) {
diff --git a/jee_test.go b/jee_test.go
index 7d0b7a1..aca1697 100644
--- a/jee_test.go
+++ b/jee_test.go
@@ -403,6 +403,18 @@ var Tests = []Test{
exp: `$has($keys(.), "arrayString")`,
result: `true`,
},
+ Test{
+ exp: `$has($split("arrayString, arrayString2, arrayString3", ","), "arrayString")`,
+ result: `true`,
+ },
+ Test{
+ exp: `$has($split("arrayString, arrayString2, arrayString3", ","), "nope")`,
+ result: `false`,
+ },
+ Test{
+ exp: `$has($split("arrayString, arrayString2, arrayString3", ","), null)`,
+ result: `false`,
+ },
Test{
exp: `$has($keys(.), "nope")`,
result: `false`,