output.go: make htmlOut.str faster
This commit is contained in:
parent
e40db066f3
commit
fa865c7dbc
32
output.go
32
output.go
@ -80,28 +80,42 @@ func (w *htmlOut) s(s string) *htmlOut {
|
|||||||
/* print string, escaping for HTML
|
/* print string, escaping for HTML
|
||||||
* If obfuscate selected, convert characters to hex or decimal entities at random
|
* If obfuscate selected, convert characters to hex or decimal entities at random
|
||||||
*/
|
*/
|
||||||
func (w *htmlOut) str(hs string, obfuscate bool) *htmlOut {
|
func (w *htmlOut) str(s string, obfuscate bool) *htmlOut {
|
||||||
for _, r := range hs {
|
var ws string
|
||||||
|
var i0 = 0
|
||||||
|
|
||||||
|
for i, r := range s {
|
||||||
switch r {
|
switch r {
|
||||||
case '&':
|
case '&':
|
||||||
w.s("&")
|
ws = "&"
|
||||||
case '<':
|
case '<':
|
||||||
w.s("<")
|
ws = "<"
|
||||||
case '>':
|
case '>':
|
||||||
w.s(">")
|
ws = ">"
|
||||||
case '"':
|
case '"':
|
||||||
w.s(""")
|
ws = """
|
||||||
default:
|
default:
|
||||||
if obfuscate {
|
if obfuscate {
|
||||||
if rand.Intn(1) == 0 {
|
if rand.Intn(1) == 0 {
|
||||||
w.s(fmt.Sprintf("&#%d;", r))
|
ws = fmt.Sprintf("&#%d;", r)
|
||||||
} else {
|
} else {
|
||||||
w.s(fmt.Sprintf("&#%x;", r))
|
ws = fmt.Sprintf("&#%x;", r)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
w.WriteRune(r)
|
if i0 == -1 {
|
||||||
|
i0 = i
|
||||||
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if i0 != -1 {
|
||||||
|
w.WriteString(s[i0:i])
|
||||||
|
i0 = -1
|
||||||
|
}
|
||||||
|
w.WriteString(ws)
|
||||||
|
}
|
||||||
|
if i0 != -1 {
|
||||||
|
w.WriteString(s[i0:])
|
||||||
}
|
}
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user