MCPcopy Create free account
hub / github.com/buger/jsonparser / expandWildcardPaths

Function expandWildcardPaths

wildcard.go:112–148  ·  view source on GitHub ↗

SYS-REQ-113

(data []byte, concrete, remaining []string, paths *[][]string)

Source from the content-addressed store, hash-verified

110
111// SYS-REQ-113
112func expandWildcardPaths(data []byte, concrete, remaining []string, paths *[][]string) error {
113 wildcard := wildcardIndex(remaining)
114 if wildcard == -1 {
115 path := make([]string, len(concrete)+len(remaining))
116 copy(path, concrete)
117 copy(path[len(concrete):], remaining)
118 *paths = append(*paths, path)
119 return nil
120 }
121
122 arrayPath := make([]string, len(concrete)+wildcard)
123 copy(arrayPath, concrete)
124 copy(arrayPath[len(concrete):], remaining[:wildcard])
125
126 array, valueType, _, err := Get(data, arrayPath...)
127 if err != nil {
128 return err
129 }
130 if valueType != Array {
131 return MalformedArrayError
132 }
133
134 index := 0
135 _, err = ArrayEachErr(array, func(_ []byte, _ ValueType, _ int, parseErr error) error {
136 if parseErr != nil {
137 return parseErr
138 }
139
140 nextPath := make([]string, len(arrayPath)+1)
141 copy(nextPath, arrayPath)
142 nextPath[len(arrayPath)] = "[" + strconv.Itoa(index) + "]"
143 index++
144
145 return expandWildcardPaths(data, nextPath, remaining[wildcard+1:], paths)
146 })
147 return err
148}
149
150// SYS-REQ-113
151func wildcardIndex(path []string) int {

Callers 1

SetWildcardFunction · 0.85

Calls 3

wildcardIndexFunction · 0.85
GetFunction · 0.85
ArrayEachErrFunction · 0.85

Tested by

no test coverage detected