-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparser_whitespace.go
More file actions
102 lines (91 loc) · 2.06 KB
/
parser_whitespace.go
File metadata and controls
102 lines (91 loc) · 2.06 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package helium
import (
"context"
"github.com/lestrrat-go/helium/internal/strcursor"
"github.com/lestrrat-go/pdebug"
)
func (pctx *parserCtx) skipBlanks(ctx context.Context) bool {
i := 0
if pdebug.Enabled {
g := pdebug.IPrintf("START skipBlanks")
defer func() {
g.IRelease("END skipBlanks (skipped %d)", i)
}()
}
cur := pctx.getCursor()
if cur == nil {
return false
}
for c := cur.PeekAt(i); isBlankByte(c) && !cur.Done(); c = cur.PeekAt(i) {
i++
}
if i > 0 {
if err := cur.Advance(i); err != nil {
return false
}
if cur.Peek() == '%' {
pdebug.Printf("Found possible parameter entity reference")
if err := pctx.handlePEReference(ctx); err != nil {
return false
}
}
return true
}
return false
}
func (pctx *parserCtx) skipBlankBytes(ctx context.Context, cur *strcursor.ByteCursor) bool {
i := 0
if pdebug.Enabled {
g := pdebug.IPrintf("START skipBlankBytes")
defer func() {
g.IRelease("END skipBlankBytes (skipped %d)", i)
}()
}
for c := cur.PeekAt(i); c != 0 && isBlankByte(c); c = cur.PeekAt(i) {
i++
}
if i > 0 {
if err := cur.Advance(i); err != nil {
return false
}
if cur.Peek() == '%' {
pdebug.Printf("Found possible parameter entity reference")
if err := pctx.handlePEReference(ctx); err != nil {
return false
}
}
return true
}
return false
}
// note: unlike libxml2, we can't differentiate between SAX handlers
// that uses the same IgnorableWhitespace and Character handlers
// areBlanksBytes is like areBlanks but operates on []byte to avoid string
// allocation on the hot path.
func (ctx *parserCtx) areBlanksBytes(s []byte, blankChars bool) bool {
if ctx.spaceTab[len(ctx.spaceTab)-1] == 1 {
return false
}
if !blankChars {
for _, b := range s {
if !isBlankCh(rune(b)) {
return false
}
}
}
if ctx.peekNode() == nil {
return false
}
if ctx.doc != nil {
ok, _ := ctx.doc.IsMixedElement(ctx.peekNode().Name())
return !ok
}
cur := ctx.getCursor()
if cur == nil {
return false
}
if c := cur.Peek(); c != '<' && c != 0xD {
return false
}
return true
}