From fa0e9cd2792dd81acc7ddec5bba271d778231ad4 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Tue, 21 Aug 2012 20:59:02 +1000 Subject: [PATCH] exp/html: refactor the parser.read method. R=andybalholm CC=golang-dev https://golang.org/cl/6463070 --- src/pkg/exp/html/parse.go | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/pkg/exp/html/parse.go b/src/pkg/exp/html/parse.go index 2ef0241debd..2a93e2f26c1 100644 --- a/src/pkg/exp/html/parse.go +++ b/src/pkg/exp/html/parse.go @@ -398,20 +398,6 @@ func (p *parser) reconstructActiveFormattingElements() { } } -// read reads the next token from the tokenizer. -func (p *parser) read() error { - // CDATA sections are allowed only in foreign content. - n := p.oe.top() - p.tokenizer.AllowCDATA(n != nil && n.Namespace != "") - - p.tokenizer.Next() - p.tok = p.tokenizer.Token() - if p.tok.Type == ErrorToken { - return p.tokenizer.Err() - } - return nil -} - // Section 12.2.4. func (p *parser) acknowledgeSelfClosingTag() { p.hasSelfClosingToken = false @@ -2014,9 +2000,17 @@ func (p *parser) parse() error { // Iterate until EOF. Any other error will cause an early return. var err error for err != io.EOF { - err = p.read() - if err != nil && err != io.EOF { - return err + // CDATA sections are allowed only in foreign content. + n := p.oe.top() + p.tokenizer.AllowCDATA(n != nil && n.Namespace != "") + // Read and parse the next token. + p.tokenizer.Next() + p.tok = p.tokenizer.Token() + if p.tok.Type == ErrorToken { + err = p.tokenizer.Err() + if err != nil && err != io.EOF { + return err + } } p.parseCurrentToken() }