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

Function SetWildcard

wildcard.go:90–109  ·  view source on GitHub ↗

SetWildcard applies Set to every concrete path matched by [*]. Wildcards may appear at any array position and may be repeated. If a wildcard matches an empty array, data is returned unchanged. SYS-REQ-113

(data []byte, setValue []byte, keys ...string)

Source from the content-addressed store, hash-verified

88//
89// SYS-REQ-113
90func SetWildcard(data []byte, setValue []byte, keys ...string) ([]byte, error) {
91 if wildcardIndex(keys) == -1 {
92 return Set(data, setValue, keys...)
93 }
94
95 var paths [][]string
96 if err := expandWildcardPaths(data, nil, keys, &paths); err != nil {
97 return nil, err
98 }
99
100 result := data
101 for _, path := range paths {
102 var err error
103 result, err = Set(result, setValue, path...)
104 if err != nil {
105 return nil, err
106 }
107 }
108 return result, nil
109}
110
111// SYS-REQ-113
112func expandWildcardPaths(data []byte, concrete, remaining []string, paths *[][]string) error {

Callers 2

TestSetWildcardFunction · 0.85

Calls 3

wildcardIndexFunction · 0.85
SetFunction · 0.85
expandWildcardPathsFunction · 0.85

Tested by 2

TestSetWildcardFunction · 0.68