-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsyntax_node_identifier_child_wildcard.go
70 lines (52 loc) · 1.56 KB
/
syntax_node_identifier_child_wildcard.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package jsonpath
type syntaxChildWildcardIdentifier struct {
*syntaxBasicNode
}
func (i *syntaxChildWildcardIdentifier) retrieve(
root, current interface{}, container *bufferContainer) error {
childErrorMap := make(map[error]struct{}, 1)
var lastError error
switch typedNodes := current.(type) {
case map[string]interface{}:
lastError = i.retrieveMap(root, typedNodes, container, childErrorMap)
case []interface{}:
lastError = i.retrieveList(root, typedNodes, container, childErrorMap)
}
if len(container.result) == 0 {
switch len(childErrorMap) {
case 0:
return ErrorMemberNotExist{path: i.text}
case 1:
return lastError
default:
return ErrorNoneMatched{path: i.next.getConnectedText()}
}
}
return nil
}
func (i *syntaxChildWildcardIdentifier) retrieveMap(
root interface{}, srcMap map[string]interface{}, container *bufferContainer,
childErrorMap map[error]struct{}) error {
var lastError error
sortKeys := container.getSortedKeys(srcMap)
for _, key := range *sortKeys {
if err := i.retrieveMapNext(root, srcMap, key, container); err != nil {
childErrorMap[err] = struct{}{}
lastError = err
}
}
container.putSortSlice(sortKeys)
return lastError
}
func (i *syntaxChildWildcardIdentifier) retrieveList(
root interface{}, srcList []interface{}, container *bufferContainer,
childErrorMap map[error]struct{}) error {
var lastError error
for index := range srcList {
if err := i.retrieveListNext(root, srcList, index, container); err != nil {
childErrorMap[err] = struct{}{}
lastError = err
}
}
return lastError
}