forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1410.go
33 lines (31 loc) · 762 Bytes
/
1410.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
func entityParser(text string) string {
entity := map[string]byte {
""": '"',
"&apos": '\'',
">": '>',
"<": '<',
"&frasl": '/',
"&": '&',
}
n, i := len(text), 0
var res strings.Builder
for i < n {
if text[i] == '&' {
var t strings.Builder
for text[i] != ';' {
t.WriteByte(text[i])
i++
}
if v, ok := entity[t.String()]; ok {
res.WriteByte(v)
} else {
res.WriteString(t.String())
res.WriteByte(';')
}
} else {
res.WriteByte(text[i])
}
i++
}
return res.String()
}