Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- [+] add regular expression support, closes #64 #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions compliance/functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@
"expression": "contains(decimals, `false`)",
"result": false
},
{
"expression": "matches('This and these', 't(his|h[eo]se)')",
"result": true
},
{
"expression": "matches('Those people', 't(his|h[eo]se)')",
"result": false
},
{
"expression": "matches('THOSE people', '(?i)t(his|h[eo]se)')",
"result": true
},
{
"expression": "ends_with(str, 'r')",
"result": true
Expand Down
18 changes: 18 additions & 0 deletions functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math"
"reflect"
"regexp"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -169,6 +170,14 @@ func newFunctionCaller() *functionCaller {
},
handler: jpfContains,
},
"matches": {
name: "matches",
arguments: []argSpec{
{types: []jpType{jpString}},
{types: []jpType{jpString}},
},
handler: jpfMatches,
},
"ends_with": {
name: "ends_with",
arguments: []argSpec{
Expand Down Expand Up @@ -458,6 +467,15 @@ func jpfContains(arguments []interface{}) (interface{}, error) {
}
return false, nil
}
func jpfMatches(arguments []interface{}) (interface{}, error) {
search := arguments[0].(string)
rgexp := arguments[1].(string)
r, err := regexp.Compile(rgexp)
if err != nil {
return false, err
}
return r.MatchString(search), nil
}
func jpfEndsWith(arguments []interface{}) (interface{}, error) {
search := arguments[0].(string)
suffix := arguments[1].(string)
Expand Down