optimize code

This commit is contained in:
xing 2024-04-10 22:31:08 +08:00
parent ee9ba3fcf0
commit 63591899bb
2 changed files with 48 additions and 45 deletions

View File

@ -61,7 +61,13 @@ func InitDigestCache() {
if len(c.DigestTagOccupyNum) <= 1 { if len(c.DigestTagOccupyNum) <= 1 {
return c return c
} }
c.specialSolve = map[string]digest.SpecialSolveConf{} c.specialSolve = ParseDigestConf(c)
return c
}, "digestConfig")
}
func ParseDigestConf(c DigestConfig) map[string]digest.SpecialSolveConf {
specialSolve := map[string]digest.SpecialSolveConf{}
for _, item := range c.DigestTagOccupyNum { for _, item := range c.DigestTagOccupyNum {
tags := strings.Split(strings.ReplaceAll(item.Tag, " ", ""), "<") tags := strings.Split(strings.ReplaceAll(item.Tag, " ", ""), "<")
for _, tag := range tags { for _, tag := range tags {
@ -99,9 +105,8 @@ func InitDigestCache() {
} }
} }
} }
} }
c.specialSolve[tag] = digest.SpecialSolveConf{ specialSolve[tag] = digest.SpecialSolveConf{
Num: item.Num, Num: item.Num,
ChuckOvered: item.ChuckOvered, ChuckOvered: item.ChuckOvered,
EscapeCharacter: ec, EscapeCharacter: ec,
@ -109,8 +114,7 @@ func InitDigestCache() {
} }
} }
} }
return c return specialSolve
}, "digestConfig")
} }
func RemoveWpBlock(s string) string { func RemoveWpBlock(s string) string {

View File

@ -26,8 +26,6 @@ type SpecialSolve struct {
ChuckOvered bool ChuckOvered bool
} }
var selfCloseTags = html.GetSelfCloseTags()
func StripTags(content, allowTag string) string { func StripTags(content, allowTag string) string {
content = strings.Trim(content, " \t\n\r\000\x0B") content = strings.Trim(content, " \t\n\r\000\x0B")
content = strings.Replace(content, "]]>", "]]&gt;", -1) content = strings.Replace(content, "]]>", "]]&gt;", -1)
@ -78,7 +76,7 @@ func Html(content string, limit int) (string, string) {
tagIn = false tagIn = false
continue continue
} }
if tagIn == false && ru[i] != '\n' { if tagIn == false {
end++ end++
} }
} }
@ -111,6 +109,7 @@ func CustomizeHtml(content string, limit int, m map[string]SpecialSolveConf) (st
runeTotal := len(runeContent) runeTotal := len(runeContent)
l, r := '<', '>' l, r := '<', '>'
i := -1 i := -1
selfCloseTags := html.GetSelfCloseTags()
var currentTag, parentTag string var currentTag, parentTag string
var allTags = []string{"<top>"} var allTags = []string{"<top>"}
var tag []rune var tag []rune