forked from AsaiYusuke/jsonpath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax_node_identifier_child_wildcard.go
90 lines (70 loc) · 1.94 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package jsonpath
import (
"reflect"
)
type syntaxChildWildcardIdentifier struct {
*syntaxBasicNode
}
func (i *syntaxChildWildcardIdentifier) retrieve(
root, current interface{}, container *bufferContainer) errorRuntime {
switch typedNodes := current.(type) {
case map[string]interface{}:
return i.retrieveMap(root, typedNodes, container)
case []interface{}:
return i.retrieveList(root, typedNodes, container)
default:
foundType := msgTypeNull
if current != nil {
foundType = reflect.TypeOf(current).String()
}
return ErrorTypeUnmatched{
errorBasicRuntime: i.errorRuntime,
expectedType: msgTypeObjectOrArray,
foundType: foundType,
}
}
}
func (i *syntaxChildWildcardIdentifier) retrieveMap(
root interface{}, srcMap map[string]interface{}, container *bufferContainer) errorRuntime {
var deepestTextLen int
var deepestError errorRuntime
sortKeys := getSortedKeys(srcMap)
for _, key := range *sortKeys {
if err := i.retrieveMapNext(root, srcMap, key, container); err != nil {
if len(container.result) == 0 {
deepestTextLen, deepestError = i.addDeepestError(err, deepestTextLen, deepestError)
}
}
}
putSortSlice(sortKeys)
if len(container.result) > 0 {
return nil
}
if deepestError == nil {
return ErrorMemberNotExist{
errorBasicRuntime: i.errorRuntime,
}
}
return deepestError
}
func (i *syntaxChildWildcardIdentifier) retrieveList(
root interface{}, srcList []interface{}, container *bufferContainer) errorRuntime {
var deepestTextLen int
var deepestError errorRuntime
for index := range srcList {
if err := i.retrieveListNext(root, srcList, index, container); err != nil {
if len(container.result) == 0 {
deepestTextLen, deepestError = i.addDeepestError(err, deepestTextLen, deepestError)
}
}
}
if len(container.result) > 0 {
return nil
}
if deepestError == nil {
return ErrorMemberNotExist{
errorBasicRuntime: i.errorRuntime,
}
}
return deepestError
}