FindPath returns the node at the given path from this node. FindPath only works correctly when names are unique. The given path must be consistent with the format produced by [NodeBase.PathFrom]. There is also support for index-based access (ie: [0] for the first child) for cases where indexes are m
(path string)
| 270 | // are more useful than names. It returns nil if no node is found |
| 271 | // at the given path. |
| 272 | func (n *NodeBase) FindPath(path string) Node { |
| 273 | curn := n.This |
| 274 | pels := strings.Split(strings.Trim(strings.TrimSpace(path), "\""), "/") |
| 275 | for _, pe := range pels { |
| 276 | if len(pe) == 0 { |
| 277 | continue |
| 278 | } |
| 279 | idx := findPathChild(curn, UnescapePathName(pe)) |
| 280 | if idx < 0 { |
| 281 | return nil |
| 282 | } |
| 283 | curn = curn.AsTree().Children[idx] |
| 284 | } |
| 285 | return curn |
| 286 | } |
| 287 | |
| 288 | // findPathChild finds the child with the given string representation in [NodeBase.FindPath]. |
| 289 | func findPathChild(n Node, child string) int { |