forked from lestrrat-go/libxml2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
63 lines (52 loc) · 1.69 KB
/
util.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package xpath
import "github.com/wayf-dk/go-libxml2/types"
// String returns the string component of the result, and as a side effect
// releases the Result by calling Free() on it. Use this if you do not
// really care about the error value from Find()
func String(r types.XPathResult, err error) string {
if err != nil {
return ""
}
defer r.Free()
return r.String()
}
// Bool returns the boolean component of the result, and as a side effect
// releases the Result by calling Free() on it. Use this if you do not
// really care about the error value from Find()
func Bool(r types.XPathResult, err error) bool {
if err != nil {
return false
}
defer r.Free()
return r.Bool()
}
// Number returns the numeric component of the result, and as a side effect
// releases the Result by calling Free() on it. Use this if you do not
// really care about the error value from Find()
func Number(r types.XPathResult, err error) float64 {
if err != nil {
return 0
}
defer r.Free()
return r.Number()
}
// NodeList returns the nodes associated with this result, and as a side effect
// releases the result by calling Free() on it. Use this if you do not
// really care about the error value from Find().
func NodeList(r types.XPathResult, err error) types.NodeList {
if err != nil {
return nil
}
defer r.Free()
return r.NodeList()
}
// NodeIter returns an iterator that will return the nodes assocaied with
// this reult, and as a side effect releases the result by calling Free()
// on it. Use this if you do not really care about the error value from Find().
func NodeIter(r types.XPathResult, err error) types.NodeIter {
if err != nil {
return NewNodeIterator(nil)
}
defer r.Free()
return r.NodeIter()
}