-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtext.go
More file actions
58 lines (49 loc) · 1.15 KB
/
text.go
File metadata and controls
58 lines (49 loc) · 1.15 KB
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
package helium
import "github.com/lestrrat-go/pdebug"
// Text represents an XML text node (libxml2: xmlNode with type XML_TEXT_NODE).
type Text struct {
node
}
func newText(b []byte) *Text {
t := Text{}
t.etype = TextNode
t.content = make([]byte, len(b))
copy(t.content, b)
t.name = "(text)"
return &t
}
func (n *Text) AddChild(cur Node) error {
if t, ok := cur.(*Text); ok {
return n.AppendText(t.content)
}
return ErrInvalidOperation
}
func (n *Text) AppendText(b []byte) error {
if pdebug.Enabled {
g := pdebug.IPrintf("START Text.AppendText '%s' (%p)", b, n)
defer func() {
g.IRelease("END Text.AppendText '%s'", n.content)
}()
}
n.content = append(n.content, b...)
return nil
}
func (n *Text) AddSibling(cur Node) error {
if pdebug.Enabled {
g := pdebug.IPrintf("START Text.AddSibling '%s'", cur.Content())
defer g.IRelease("END Text.AddSibling")
}
if cur.Type() == TextNode {
return n.AppendText(cur.Content())
}
return addSibling(n, cur)
}
func (n Text) Content() []byte {
return n.content
}
func (n *Text) Replace(cur Node) error {
return replaceNode(n, cur)
}
func (n *Text) SetTreeDoc(doc *Document) {
setTreeDoc(n, doc)
}