publisher: Make the HTML element collector more robust

Fixes #8530
This commit is contained in:
Bjørn Erik Pedersen
2021-05-13 13:10:32 +02:00
parent abbc99d4c6
commit ef0f1a7269
3 changed files with 299 additions and 166 deletions

View File

@@ -45,3 +45,25 @@ func RemoveAccentsString(s string) string {
accentTransformerPool.Put(t)
return s
}
// Chunk splits s into strings of size.
func Chunk(s string, size int) []string {
if size >= len(s) {
return []string{s}
}
var chunks []string
chunk := make([]rune, size)
l := 0
for _, r := range s {
chunk[l] = r
l++
if l == size {
chunks = append(chunks, string(chunk))
l = 0
}
}
if l > 0 {
chunks = append(chunks, string(chunk[:l]))
}
return chunks
}