optimize digest
This commit is contained in:
parent
08d3bca39c
commit
6209f2b5e5
|
@ -24,6 +24,14 @@ func Html(content string, limit int) (string, string) {
|
||||||
return content, ""
|
return content, ""
|
||||||
}
|
}
|
||||||
index := quto.FindAllStringIndex(content, -1)
|
index := quto.FindAllStringIndex(content, -1)
|
||||||
|
var runeIndex [][]int
|
||||||
|
if len(index) > 0 {
|
||||||
|
runeIndex = slice.Map(index, func(t []int) []int {
|
||||||
|
return slice.Map(t, func(i int) int {
|
||||||
|
return utf8.RuneCountInString(content[:i])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
end := 0
|
end := 0
|
||||||
ru := []rune(content)
|
ru := []rune(content)
|
||||||
tagIn := false
|
tagIn := false
|
||||||
|
@ -32,13 +40,11 @@ func Html(content string, limit int) (string, string) {
|
||||||
i := -1
|
i := -1
|
||||||
for {
|
for {
|
||||||
i++
|
i++
|
||||||
for len(index) > 0 {
|
for len(runeIndex) > 0 && i >= runeIndex[0][0] {
|
||||||
ints := slice.Map(index[0], func(t int) int {
|
ints := runeIndex[0]
|
||||||
return utf8.RuneCountInString(content[:t])
|
|
||||||
})
|
|
||||||
if ints[0] <= i {
|
if ints[0] <= i {
|
||||||
i = i + i - ints[0] + ints[1] - ints[0]
|
i = ints[1]
|
||||||
index = index[1:]
|
runeIndex = runeIndex[1:]
|
||||||
end++
|
end++
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user