blob: 0b5c05aee2cb633f8a061d2cf6a3245e5ca47172 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
include gumbo_parser / gumbo
type
CArray {.unchecked.} [T] = array[0..0, T]
template len*(vector: var GumboVector): int =
vector.length.int
iterator values*[T](vector: var GumboVector): T =
let arr = cast[ptr CArray[T]](vector.data)
for idx in 0..len(vector)-1:
yield arr[idx]
iterator children*(document: var GumboDocument): ptr GumboNode =
for child in values[ptr GumboNode](document.children):
yield child
iterator children*(element: var GumboElement): ptr GumboNode =
for child in values[ptr GumboNode](element.children):
yield child
iterator children*(node: ptr GumboNode): ptr GumboNode =
case node.`type`
of GumboNodeDocument:
for child in children(node.v.document):
yield child
of GumboNodeElement:
for child in children(node.v.element):
yield child
else:
discard
iterator attributes*(element: var GumboElement): ptr GumboAttribute =
for attribute in values[ptr GumboAttribute](element.attributes):
yield attribute
|