aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/xml/xml.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/xml/xml.go')
-rw-r--r--libgo/go/xml/xml.go27
1 files changed, 23 insertions, 4 deletions
diff --git a/libgo/go/xml/xml.go b/libgo/go/xml/xml.go
index 4d9c672..691c13a 100644
--- a/libgo/go/xml/xml.go
+++ b/libgo/go/xml/xml.go
@@ -163,7 +163,7 @@ type Parser struct {
// "quot": `"`,
Entity map[string]string
- r io.ReadByter
+ r io.ByteReader
buf bytes.Buffer
saved *bytes.Buffer
stk *stack
@@ -191,7 +191,7 @@ func NewParser(r io.Reader) *Parser {
// Assume that if reader has its own
// ReadByte, it's efficient enough.
// Otherwise, use bufio.
- if rb, ok := r.(io.ReadByter); ok {
+ if rb, ok := r.(io.ByteReader); ok {
p.r = rb
} else {
p.r = bufio.NewReader(r)
@@ -541,17 +541,36 @@ func (p *Parser) RawToken() (Token, os.Error) {
}
// Probably a directive: <!DOCTYPE ...>, <!ENTITY ...>, etc.
- // We don't care, but accumulate for caller.
+ // We don't care, but accumulate for caller. Quoted angle
+ // brackets do not count for nesting.
p.buf.Reset()
p.buf.WriteByte(b)
+ inquote := uint8(0)
+ depth := 0
for {
if b, ok = p.mustgetc(); !ok {
return nil, p.err
}
- if b == '>' {
+ if inquote == 0 && b == '>' && depth == 0 {
break
}
p.buf.WriteByte(b)
+ switch {
+ case b == inquote:
+ inquote = 0
+
+ case inquote != 0:
+ // in quotes, no special action
+
+ case b == '\'' || b == '"':
+ inquote = b
+
+ case b == '>' && inquote == 0:
+ depth--
+
+ case b == '<' && inquote == 0:
+ depth++
+ }
}
return Directive(p.buf.Bytes()), nil
}