forked from mirror/gjson
query matching with %
This commit is contained in:
parent
6fd75099ef
commit
90669a0cbe
3
gjson.go
3
gjson.go
|
@ -647,6 +647,7 @@ func parseArrayPath(path string) (r arrayPathResult) {
|
||||||
for ; i < len(path); i++ {
|
for ; i < len(path); i++ {
|
||||||
if path[i] <= ' ' || path[i] == '=' ||
|
if path[i] <= ' ' || path[i] == '=' ||
|
||||||
path[i] == '<' || path[i] == '>' ||
|
path[i] == '<' || path[i] == '>' ||
|
||||||
|
path[i] == '%' ||
|
||||||
path[i] == ']' {
|
path[i] == ']' {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -997,6 +998,8 @@ func queryMatches(rp *arrayPathResult, value Result) bool {
|
||||||
return value.Str > rpv
|
return value.Str > rpv
|
||||||
case ">=":
|
case ">=":
|
||||||
return value.Str >= rpv
|
return value.Str >= rpv
|
||||||
|
case "%":
|
||||||
|
return match.Match(value.Str, rpv)
|
||||||
}
|
}
|
||||||
case Number:
|
case Number:
|
||||||
rpvn, _ := strconv.ParseFloat(rpv, 64)
|
rpvn, _ := strconv.ParseFloat(rpv, 64)
|
||||||
|
|
|
@ -205,6 +205,10 @@ func TestBasic(t *testing.T) {
|
||||||
t.Fatalf("expected %v, got %v", "1002.3", mtok.String())
|
t.Fatalf("expected %v, got %v", "1002.3", mtok.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mtok = get(basicJSON, `loggy.programmers.#[firstName % "Bre*"].email`)
|
||||||
|
if mtok.String() != "aaaa" {
|
||||||
|
t.Fatalf("expected %v, got %v", "aaaa", mtok.String())
|
||||||
|
}
|
||||||
mtok = get(basicJSON, `loggy.programmers.#[firstName == "Brett"].email`)
|
mtok = get(basicJSON, `loggy.programmers.#[firstName == "Brett"].email`)
|
||||||
if mtok.String() != "aaaa" {
|
if mtok.String() != "aaaa" {
|
||||||
t.Fatalf("expected %v, got %v", "aaaa", mtok.String())
|
t.Fatalf("expected %v, got %v", "aaaa", mtok.String())
|
||||||
|
|
Loading…
Reference in New Issue