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)
| 88 | // |
| 89 | // SYS-REQ-113 |
| 90 | func 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 |
| 112 | func expandWildcardPaths(data []byte, concrete, remaining []string, paths *[][]string) error { |