Merge pull request #540 from twpayne/export-is-container Export Node.IsContainer and add Node.IsLeaf
Russ Ross russ@russross.com
Sat, 29 Jun 2019 09:15:18 -0600
1 files changed,
9 insertions(+),
3 deletions(-)
jump to
M
node.go
→
node.go
@@ -199,7 +199,8 @@ sibling.Parent.FirstChild = sibling
} } -func (n *Node) isContainer() bool { +// IsContainer returns true if 'n' can contain children. +func (n *Node) IsContainer() bool { switch n.Type { case Document: fallthrough@@ -236,6 +237,11 @@ return true
default: return false } +} + +// IsLeaf returns true if 'n' is a leaf node. +func (n *Node) IsLeaf() bool { + return !n.IsContainer() } func (n *Node) canContain(t NodeType) bool {@@ -309,11 +315,11 @@ }
} func (nw *nodeWalker) next() { - if (!nw.current.isContainer() || !nw.entering) && nw.current == nw.root { + if (!nw.current.IsContainer() || !nw.entering) && nw.current == nw.root { nw.current = nil return } - if nw.entering && nw.current.isContainer() { + if nw.entering && nw.current.IsContainer() { if nw.current.FirstChild != nil { nw.current = nw.current.FirstChild nw.entering = true