PathFrom returns the path to this node from the given parent node, using [Node.Name]s separated by / delimeters. Any existing / characters in names are escaped to \\ The paths that it returns exclude the name of the parent and the leading slash; for example, in the tree a/b/c/d/e, the result of d.P
(parent Node)
| 248 | // automatically gets the [NodeBase.This] version of the given parent, |
| 249 | // so a base type can be passed in without manually accessing [NodeBase.This]. |
| 250 | func (n *NodeBase) PathFrom(parent Node) string { |
| 251 | if n.This == parent { |
| 252 | return "" |
| 253 | } |
| 254 | // critical to get `This` |
| 255 | parent = parent.AsTree().This |
| 256 | // we bail a level below the parent so it isn't in the path |
| 257 | if n.Parent == nil || n.Parent == parent { |
| 258 | return EscapePathName(n.Name) |
| 259 | } |
| 260 | ppath := n.Parent.AsTree().PathFrom(parent) |
| 261 | return ppath + "/" + EscapePathName(n.Name) |
| 262 | |
| 263 | } |
| 264 | |
| 265 | // FindPath returns the node at the given path from this node. |
| 266 | // FindPath only works correctly when names are unique. |