mirror of https://github.com/tidwall/gjson.git
added != comparison operator
This commit is contained in:
parent
90669a0cbe
commit
7afd24f7a2
21
gjson.go
21
gjson.go
|
@ -645,8 +645,11 @@ func parseArrayPath(path string) (r arrayPathResult) {
|
||||||
}
|
}
|
||||||
s := i
|
s := i
|
||||||
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] == '%' ||
|
||||||
path[i] == ']' {
|
path[i] == ']' {
|
||||||
break
|
break
|
||||||
|
@ -661,7 +664,11 @@ func parseArrayPath(path string) (r arrayPathResult) {
|
||||||
}
|
}
|
||||||
if i < len(path) {
|
if i < len(path) {
|
||||||
s = i
|
s = i
|
||||||
if path[i] == '<' || path[i] == '>' {
|
if path[i] == '!' {
|
||||||
|
if i < len(path)-1 && path[i+1] == '=' {
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
} else if path[i] == '<' || path[i] == '>' {
|
||||||
if i < len(path)-1 && path[i+1] == '=' {
|
if i < len(path)-1 && path[i+1] == '=' {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
@ -990,6 +997,8 @@ func queryMatches(rp *arrayPathResult, value Result) bool {
|
||||||
switch rp.query.op {
|
switch rp.query.op {
|
||||||
case "=":
|
case "=":
|
||||||
return value.Str == rpv
|
return value.Str == rpv
|
||||||
|
case "!=":
|
||||||
|
return value.Str != rpv
|
||||||
case "<":
|
case "<":
|
||||||
return value.Str < rpv
|
return value.Str < rpv
|
||||||
case "<=":
|
case "<=":
|
||||||
|
@ -1006,6 +1015,8 @@ func queryMatches(rp *arrayPathResult, value Result) bool {
|
||||||
switch rp.query.op {
|
switch rp.query.op {
|
||||||
case "=":
|
case "=":
|
||||||
return value.Num == rpvn
|
return value.Num == rpvn
|
||||||
|
case "!=":
|
||||||
|
return value.Num == rpvn
|
||||||
case "<":
|
case "<":
|
||||||
return value.Num < rpvn
|
return value.Num < rpvn
|
||||||
case "<=":
|
case "<=":
|
||||||
|
@ -1019,6 +1030,8 @@ func queryMatches(rp *arrayPathResult, value Result) bool {
|
||||||
switch rp.query.op {
|
switch rp.query.op {
|
||||||
case "=":
|
case "=":
|
||||||
return rpv == "true"
|
return rpv == "true"
|
||||||
|
case "!=":
|
||||||
|
return rpv != "true"
|
||||||
case ">":
|
case ">":
|
||||||
return rpv == "false"
|
return rpv == "false"
|
||||||
case ">=":
|
case ">=":
|
||||||
|
@ -1028,6 +1041,8 @@ func queryMatches(rp *arrayPathResult, value Result) bool {
|
||||||
switch rp.query.op {
|
switch rp.query.op {
|
||||||
case "=":
|
case "=":
|
||||||
return rpv == "false"
|
return rpv == "false"
|
||||||
|
case "!=":
|
||||||
|
return rpv != "false"
|
||||||
case "<":
|
case "<":
|
||||||
return rpv == "true"
|
return rpv == "true"
|
||||||
case "<=":
|
case "<=":
|
||||||
|
|
|
@ -204,7 +204,10 @@ func TestBasic(t *testing.T) {
|
||||||
if mtok.String() != "1002.3" {
|
if mtok.String() != "1002.3" {
|
||||||
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 != "Brett"].firstName`)
|
||||||
|
if mtok.String() != "Jason" {
|
||||||
|
t.Fatalf("expected %v, got %v", "Jason", mtok.String())
|
||||||
|
}
|
||||||
mtok = get(basicJSON, `loggy.programmers.#[firstName % "Bre*"].email`)
|
mtok = get(basicJSON, `loggy.programmers.#[firstName % "Bre*"].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