MCPcopy Create free account
hub / github.com/aws-cloudformation/rain / RemoveFromMap

Function RemoveFromMap

internal/node/node.go:199–226  ·  view source on GitHub ↗

Remove a map key-value pair from node.Content

(node *yaml.Node, name string)

Source from the content-addressed store, hash-verified

197
198// Remove a map key-value pair from node.Content
199func RemoveFromMap(node *yaml.Node, name string) error {
200
201 if len(node.Content) == 0 {
202 return nil
203 }
204
205 idx := -1
206
207 for i, n := range node.Content {
208 if n.Value == name {
209 idx = i
210 break
211 }
212 }
213
214 if idx == -1 {
215 return fmt.Errorf("unable to remove %v from map", name)
216 }
217
218 newContent := make([]*yaml.Node, 0)
219 newContent = append(newContent, node.Content[:idx]...)
220 // Remove 2 elements, since the key and value are consecutive elements in the Content array
221 newContent = append(newContent, node.Content[idx+2:]...)
222
223 node.Content = newContent
224
225 return nil
226}
227
228// Add or replace a map value
229func SetMapValue(parent *yaml.Node, name string, val *yaml.Node) {

Callers 13

RemoveSectionMethod · 0.92
RemoveEmptySectionsMethod · 0.92
processPackagesFunction · 0.92
FnInvokeMethod · 0.92
omitIfsFunction · 0.92
processMapsFunction · 0.92
processConstantsFunction · 0.92
ProcessOverridesMethod · 0.92
addScalarAttributeFunction · 0.92
moduleFunction · 0.92
ProcessConditionsMethod · 0.92
UnCDKFunction · 0.92

Calls

no outgoing calls

Tested by 1

TestRemoveFromMapFunction · 0.74