添加正则表达式的方法

This commit is contained in:
eson 2018-12-23 21:36:09 +08:00
parent fdedd9ddb2
commit 013383b188

View File

@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"errors"
"log"
"reflect"
"regexp"
"strconv"
@ -744,6 +745,7 @@ func parseArrayPath(path string) (r arrayPathResult) {
path[i] == '<' ||
path[i] == '>' ||
path[i] == '%' ||
path[i] == '~' ||
path[i] == ']' {
break
}
@ -779,7 +781,34 @@ func parseArrayPath(path string) (r arrayPathResult) {
break
}
}
s = i
s = i + 1
if r.query.op == "~" {
pair := path[i]
i++
GETREGEXPSTR:
for ; i < len(path); i++ {
if path[i] == pair {
for iend := i + 1; iend < len(path); iend++ {
if path[iend] == ' ' {
continue
}
if path[iend] == ']' {
if iend+1 < len(path) && path[iend+1] == '#' {
r.query.all = true
}
break GETREGEXPSTR
} else {
break
}
}
}
}
} else {
for ; i < len(path); i++ {
if path[i] == '"' {
i++
@ -811,6 +840,7 @@ func parseArrayPath(path string) (r arrayPathResult) {
}
break
}
} //
}
if i > len(path) {
i = len(path)
@ -1117,15 +1147,15 @@ func queryMatches(rp *arrayPathResult, value Result) bool {
case ">=":
return value.Str >= rpv
case "%":
return match.Match(value.Str, rpv)
case "!%":
return !match.Match(value.Str, rpv)
case "~":
log.Println(rpv)
if rp.re == nil {
rp.re = regexp.MustCompile(escapeRegexpString(rpv))
rp.re = regexp.MustCompile(rpv)
}
return rp.re.MatchString(value.Str)
case "!%":
if rp.re == nil {
rp.re = regexp.MustCompile(escapeRegexpString(rpv))
}
return !rp.re.MatchString(value.Str)
}
case Number:
rpvn, _ := strconv.ParseFloat(rpv, 64)