Source File
transition.go
Belonging Package
github.com/google/safehtml/template
package template
import (
)
var transitionFunc = [...]func(context, []byte) (context, int){
stateText: tText,
stateSpecialElementBody: tSpecialTagEnd,
stateTag: tTag,
stateAttrName: tAttrName,
stateAfterName: tAfterName,
stateBeforeValue: tBeforeValue,
stateHTMLCmt: tHTMLCmt,
stateAttr: tAttr,
stateError: tError,
}
var commentStart = []byte("<!--")
var commentEnd = []byte("-->")
func ( context, []byte) (context, int) {
:= 0
for {
:= + bytes.IndexByte([:], '<')
if < || +1 == len() {
return , len()
} else if +4 <= len() && bytes.Equal(commentStart, [:+4]) {
return context{state: stateHTMLCmt}, + 4
}
++
:= false
if [] == '/' {
if +1 == len() {
return , len()
}
, = true, +1
}
, := eatTagName(, )
if ! {
.element =
}
return ,
}
=
}
}
:= eatWhiteSpace(, 0)
if == len() {
return , len()
}
if [] == '>' {
:= context{
state: stateText,
element: .element,
scriptType: .scriptType,
linkRel: .linkRel,
}
if specialElements[.element.name] {
.state = stateSpecialElementBody
}
.element = element{}
.scriptType = ""
.linkRel = ""
}
return , + 1
}
, := eatAttrName(, )
if != nil {
return context{state: stateError, err: }, len()
}
:= stateTag
if == {
return context{
state: stateError,
err: errorf(ErrBadHTML, nil, 0, "expected space, attr name, or end of tag, but got %q", [:]),
}, len()
}
if == len() {
= stateAttrName
} else {
= stateAfterName
}
return context{
state: ,
element: .element,
attr: attr{name: strings.ToLower(string([:]))},
linkRel: .linkRel,
},
}
func ( context, []byte) (context, int) {
, := eatAttrName(, 0)
if != nil {
return context{state: stateError, err: }, len()
} else if != len() {
.state = stateAfterName
}
return ,
}
:= eatWhiteSpace(, 0)
if == len() {
return , len()
return , + 1
}
:= delimSpaceOrTagEnd
switch [] {
case '\'':
, = delimSingleQuote, +1
case '"':
, = delimDoubleQuote, +1
}
.state, .delim = stateAttr,
return ,
}
func ( context, []byte) (context, int) {
if := bytes.Index(, commentEnd); != -1 {
return context{}, + 3
}
return , len()
}
var (
specialTagEndPrefix = []byte("</")
tagEndSeparators = []byte("> \t\n\f/")
)
func ( []byte, []byte) int {
:= 0
:= len(specialTagEndPrefix)
:= bytes.Index(, specialTagEndPrefix)
if == -1 {
return
}
if len() > 0 && bytes.IndexByte(tagEndSeparators, [0]) != -1 {
return +
}
+= len()
}
+= +
}
return -1
}
return -1, errorf(ErrBadHTML, nil, 0, "%q in attribute name: %.32q", [:+1], )
func ( byte) bool {
return asciiAlpha() || '0' <= && <= '9'
}
func ( []byte, int) (int, element) {
if == len() || !asciiAlpha([]) {
return , element{}
}
:= + 1
for < len() {
:= []
if asciiAlphaNum() {
++
continue
default:
return
}
}
return len()
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |