KeyIndex finds the index of the given key or -1 if not found. Note that it will only return an index if index + 1 also exists.
(key string)
| 53 | // KeyIndex finds the index of the given key or -1 if not found. Note that it |
| 54 | // will only return an index if index + 1 also exists. |
| 55 | func (n *Node) KeyIndex(key string) int { |
| 56 | for i := 0; i+1 < len(n.Content); i += 2 { |
| 57 | if n.Content[i].Kind == yaml.ScalarNode && n.Content[i].Value == key { |
| 58 | return i |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return -1 |
| 63 | } |
| 64 | |
| 65 | // ValueNode returns the given value node for a key, or nil if not found. |
| 66 | func (n *Node) ValueNode(key string) *Node { |