From: Mike Samuel Date: Tue, 20 Sep 2011 03:52:14 +0000 (-0700) Subject: exp/template/html: change transition functions to return indices X-Git-Tag: weekly.2011-09-21~21 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3a013f117566fa58300a6f1c8f6e5d0b481315ec;p=gostls13.git exp/template/html: change transition functions to return indices Formulaic changes to transition functions in preparation for CL 5074041. This should be completely semantics preserving. R=nigeltao CC=golang-dev https://golang.org/cl/5091041 --- diff --git a/src/pkg/exp/template/html/escape.go b/src/pkg/exp/template/html/escape.go index b859751140..6490c5f9e0 100644 --- a/src/pkg/exp/template/html/escape.go +++ b/src/pkg/exp/template/html/escape.go @@ -547,22 +547,22 @@ var delimEnds = [...]string{ // escapeText escapes a text template node. func (e *escaper) escapeText(c context, n *parse.TextNode) context { - s, written := n.Text, 0 - var b bytes.Buffer - for len(s) > 0 { - c1, s1 := contextAfterText(c, s) + s, written, i, b := n.Text, 0, 0, new(bytes.Buffer) + for i != len(s) { + c1, nread := contextAfterText(c, s[i:]) + i1 := i + nread if c.state == c1.state && (c.state == stateText || c.state == stateRCDATA) { - i0, i1 := len(n.Text)-len(s), len(n.Text)-len(s1) - for i := i0; i < i1; i++ { - if n.Text[i] == '<' { - b.Write(n.Text[written:i]) + for j := i; j < i1; j++ { + if s[j] == '<' { + b.Write(s[written:j]) b.WriteString("<") - written = i + 1 + written = j + 1 } } } - c, s = c1, s1 + c, i = c1, i1 } + if written != 0 && c.state != stateError { b.Write(n.Text[written:]) e.editTextNode(n, b.Bytes()) @@ -572,7 +572,7 @@ func (e *escaper) escapeText(c context, n *parse.TextNode) context { // contextAfterText starts in context c, consumes some tokens from the front of // s, then returns the context after those tokens and the unprocessed suffix. -func contextAfterText(c context, s []byte) (context, []byte) { +func contextAfterText(c context, s []byte) (context, int) { if c.delim == delimNone { return transitionFunc[c.state](c, s) } @@ -584,9 +584,10 @@ func contextAfterText(c context, s []byte) (context, []byte) { //