all repos — grayfriday @ 3e56bb68c8876389c631e9e318ce3c092a0906db

blackfriday fork with a few changes

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
commit

3e56bb68c8876389c631e9e318ce3c092a0906db

parent

792d13404204e12d4c292c77184f47ad325fcfdc

1 files changed, 9 insertions(+), 3 deletions(-)

jump to
M node.gonode.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