forked from mirror/gjson
Remove the DisableChaining option
Chaining (pipe character) is now a part of the standard
This commit is contained in:
parent
6781e4ee59
commit
001444ea45
18
gjson.go
18
gjson.go
|
@ -716,14 +716,12 @@ type arrayPathResult struct {
|
||||||
|
|
||||||
func parseArrayPath(path string) (r arrayPathResult) {
|
func parseArrayPath(path string) (r arrayPathResult) {
|
||||||
for i := 0; i < len(path); i++ {
|
for i := 0; i < len(path); i++ {
|
||||||
if !DisableChaining {
|
|
||||||
if path[i] == '|' {
|
if path[i] == '|' {
|
||||||
r.part = path[:i]
|
r.part = path[:i]
|
||||||
r.pipe = path[i+1:]
|
r.pipe = path[i+1:]
|
||||||
r.piped = true
|
r.piped = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if path[i] == '.' {
|
if path[i] == '.' {
|
||||||
r.part = path[:i]
|
r.part = path[:i]
|
||||||
r.path = path[i+1:]
|
r.path = path[i+1:]
|
||||||
|
@ -849,9 +847,6 @@ func parseArrayPath(path string) (r arrayPathResult) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisableChaining will disable the chaining (pipe) syntax
|
|
||||||
var DisableChaining = false
|
|
||||||
|
|
||||||
type objectPathResult struct {
|
type objectPathResult struct {
|
||||||
part string
|
part string
|
||||||
path string
|
path string
|
||||||
|
@ -863,18 +858,16 @@ type objectPathResult struct {
|
||||||
|
|
||||||
func parseObjectPath(path string) (r objectPathResult) {
|
func parseObjectPath(path string) (r objectPathResult) {
|
||||||
for i := 0; i < len(path); i++ {
|
for i := 0; i < len(path); i++ {
|
||||||
if !DisableChaining {
|
|
||||||
if path[i] == '|' {
|
if path[i] == '|' {
|
||||||
r.part = path[:i]
|
r.part = path[:i]
|
||||||
r.pipe = path[i+1:]
|
r.pipe = path[i+1:]
|
||||||
r.piped = true
|
r.piped = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if path[i] == '.' {
|
if path[i] == '.' {
|
||||||
// peek at the next byte and see if it's a '@' modifier.
|
// peek at the next byte and see if it's a '@' modifier.
|
||||||
r.part = path[:i]
|
r.part = path[:i]
|
||||||
if !DisableModifiers && !DisableChaining &&
|
if !DisableModifiers &&
|
||||||
i < len(path)-1 && path[i+1] == '@' {
|
i < len(path)-1 && path[i+1] == '@' {
|
||||||
r.pipe = path[i+1:]
|
r.pipe = path[i+1:]
|
||||||
r.piped = true
|
r.piped = true
|
||||||
|
@ -906,7 +899,7 @@ func parseObjectPath(path string) (r objectPathResult) {
|
||||||
} else if path[i] == '.' {
|
} else if path[i] == '.' {
|
||||||
r.part = string(epart)
|
r.part = string(epart)
|
||||||
// peek at the next byte and see if it's a '@' modifier
|
// peek at the next byte and see if it's a '@' modifier
|
||||||
if !DisableModifiers && !DisableChaining &&
|
if !DisableModifiers &&
|
||||||
i < len(path)-1 && path[i+1] == '@' {
|
i < len(path)-1 && path[i+1] == '@' {
|
||||||
r.pipe = path[i+1:]
|
r.pipe = path[i+1:]
|
||||||
r.piped = true
|
r.piped = true
|
||||||
|
@ -2369,13 +2362,11 @@ func execModifier(json, path string) (pathOut, res string, ok bool) {
|
||||||
hasArgs = len(pathOut) > 0
|
hasArgs = len(pathOut) > 0
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if !DisableChaining {
|
|
||||||
if path[i] == '|' {
|
if path[i] == '|' {
|
||||||
pathOut = path[i:]
|
pathOut = path[i:]
|
||||||
name = path[1:i]
|
name = path[1:i]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if path[i] == '.' {
|
if path[i] == '.' {
|
||||||
pathOut = path[i:]
|
pathOut = path[i:]
|
||||||
name = path[1:i]
|
name = path[1:i]
|
||||||
|
@ -2396,10 +2387,7 @@ func execModifier(json, path string) (pathOut, res string, ok bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !parsedArgs {
|
if !parsedArgs {
|
||||||
idx := -1
|
idx := strings.IndexByte(pathOut, '|')
|
||||||
if !DisableChaining {
|
|
||||||
idx = strings.IndexByte(pathOut, '|')
|
|
||||||
}
|
|
||||||
if idx == -1 {
|
if idx == -1 {
|
||||||
args = pathOut
|
args = pathOut
|
||||||
pathOut = ""
|
pathOut = ""
|
||||||
|
|
Loading…
Reference in New Issue