Files
playlet-piped/playlet-lib/src/source/utils/NodePathUtils.bs
T
Brahim Hadriche f3aeb58b38 Misc. (#281)
* Logger

* etag cache fix

* xml refactor

* whitespace

* NodePathUtils

* Http2
2024-02-05 09:56:22 -05:00

36 lines
863 B
Plaintext

namespace NodePathUtils
function FindNodeFromPath(root as object, path as string) as object
node = root
if path.StartsWith("/")
node = node.getScene()
path = path.Mid(1)
end if
pathParts = path.Tokenize("/")
for i = 0 to pathParts.Count() - 1
if node = invalid
return invalid
end if
if pathParts[i] = "."
continue for
end if
if pathParts[i] = ".."
node = node.getParent()
continue for
end if
node = node.findNode(pathParts[i])
end for
if root.isSameNode(node)
' if a node is referencing itself, it's probably a mistake
return invalid
end if
return node
end function
end namespace