Source File
escape.go
Belonging Package
golang.org/x/net/html
package html
import (
)
var replacementTable = [...]rune{
'\u20AC', // First entry is what 0x80 should be replaced with.
'\u0081',
'\u201A',
'\u0192',
'\u201E',
'\u2026',
'\u2020',
'\u2021',
'\u02C6',
'\u2030',
'\u0160',
'\u2039',
'\u0152',
'\u008D',
'\u017D',
'\u008F',
'\u0090',
'\u2018',
'\u2019',
'\u201C',
'\u201D',
'\u2022',
'\u2013',
'\u2014',
'\u02DC',
'\u2122',
'\u0161',
'\u203A',
'\u0153',
'\u009D',
'\u017E',
}
, := 1, [:]
if len() <= 1 {
[] = []
return + 1, + 1
}
if [] == '#' {
if len() <= 3 { // We need to have at least "&#.".
[] = []
return + 1, + 1
}
++
:= []
:= false
if == 'x' || == 'X' {
= true
++
}
:= '\x00'
for < len() {
= []
++
if {
if '0' <= && <= '9' {
= 16* + rune() - '0'
continue
} else if 'a' <= && <= 'f' {
= 16* + rune() - 'a' + 10
continue
} else if 'A' <= && <= 'F' {
= 16* + rune() - 'A' + 10
continue
}
} else if '0' <= && <= '9' {
= 10* + rune() - '0'
continue
}
if != ';' {
--
}
break
}
if <= 3 { // No characters matched.
[] = []
return + 1, + 1
}
= replacementTable[-0x80]
= '\uFFFD'
}
return + utf8.EncodeRune([:], ), +
}
for < len() {
:= []
if 'a' <= && <= 'z' || 'A' <= && <= 'Z' || '0' <= && <= '9' {
continue
}
if != ';' {
--
}
break
}
:= string([1:])
} else if := entity[]; != 0 {
return + utf8.EncodeRune([:], ), +
} else if := entity2[]; [0] != 0 {
:= + utf8.EncodeRune([:], [0])
return + utf8.EncodeRune([:], [1]), +
} else if ! {
:= len() - 1
if > longestEntityWithoutSemicolon {
= longestEntityWithoutSemicolon
}
for := ; > 1; -- {
if := entity[[:]]; != 0 {
return + utf8.EncodeRune([:], ), + + 1
}
}
}
, = +, +
copy([:], [:])
return ,
}
func ( []byte, bool) []byte {
for , := range {
if == '&' {
, := unescapeEntity(, , , )
for < len() {
:= []
if == '&' {
, = unescapeEntity(, , , )
} else {
[] =
, = +1, +1
}
}
return [0:]
}
}
return
}
func ( []byte) []byte {
for , := range {
if 'A' <= && <= 'Z' {
[] = + 'a' - 'A'
}
}
return
}
const escapedChars = "&'<>\"\r"
func ( writer, string) error {
:= strings.IndexAny(, escapedChars)
for != -1 {
if , := .WriteString([:]); != nil {
return
}
var string
switch [] {
case '&':
= "&"
= "'"
case '<':
= "<"
case '>':
= ">"
= """
case '\r':
= " "
default:
panic("unrecognized escape character")
}
= [+1:]
if , := .WriteString(); != nil {
return
}
= strings.IndexAny(, escapedChars)
}
, := .WriteString()
return
}
![]() |
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. |