Add mitems and mpairs where it makes sense

This commit is contained in:
def 2015-01-28 02:21:54 +01:00
commit 46cf40c40d
5 changed files with 117 additions and 0 deletions

View file

@ -115,11 +115,21 @@ proc `[]`* (n: XmlNode, i: int): XmlNode {.inline.} =
assert n.k == xnElement
result = n.s[i]
proc mget* (n: var XmlNode, i: int): var XmlNode {.inline.} =
## returns the `i`'th child of `n` so that it can be modified
assert n.k == xnElement
result = n.s[i]
iterator items*(n: XmlNode): XmlNode {.inline.} =
## iterates over any child of `n`.
assert n.k == xnElement
for i in 0 .. n.len-1: yield n[i]
iterator mitems*(n: var XmlNode): var XmlNode {.inline.} =
## iterates over any child of `n`.
assert n.k == xnElement
for i in 0 .. n.len-1: yield mget(n, i)
proc attrs*(n: XmlNode): XmlAttributes {.inline.} =
## gets the attributes belonging to `n`.
## Returns `nil` if attributes have not been initialised for this node.