-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsyntax_node_identifier_recursive_child.go
47 lines (37 loc) · 1.16 KB
/
syntax_node_identifier_recursive_child.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package jsonpath
type syntaxRecursiveChildIdentifier struct {
*syntaxBasicNode
nextMapRequired bool
nextListRequired bool
}
func (i *syntaxRecursiveChildIdentifier) retrieve(
root, current interface{}, container *bufferContainer) error {
targetNodes := make([]interface{}, 1, 5)
targetNodes[0] = current
for len(targetNodes) > 0 {
currentNode := targetNodes[len(targetNodes)-1]
targetNodes = targetNodes[:len(targetNodes)-1]
switch typedNodes := currentNode.(type) {
case map[string]interface{}:
if i.nextMapRequired {
i.retrieveAnyValueNext(root, typedNodes, container)
}
sortKeys := container.getSortedKeys(typedNodes)
defer func() { container.putSortSlice(sortKeys) }()
for index := len(typedNodes) - 1; index >= 0; index-- {
targetNodes = append(targetNodes, typedNodes[(*sortKeys)[index]])
}
case []interface{}:
if i.nextListRequired {
i.retrieveAnyValueNext(root, typedNodes, container)
}
for index := len(typedNodes) - 1; index >= 0; index-- {
targetNodes = append(targetNodes, typedNodes[index])
}
}
}
if len(container.result) == 0 {
return ErrorNoneMatched{path: i.getConnectedText()}
}
return nil
}