Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-05-13 14:10:32 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-05-17 18:15:32 +0300
commitef0f1a726901d6c614040cfc2d7e8f9a2ca97816 (patch)
treeae56b2ac4b307d421bfbebc3efaa83abb16e0f59 /common
parentabbc99d4c60b102e2779e4362ceb433095719384 (diff)
publisher: Make the HTML element collector more robust
Fixes #8530
Diffstat (limited to 'common')
-rw-r--r--common/text/transform.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/common/text/transform.go b/common/text/transform.go
index f59577803..2d51f6c33 100644
--- a/common/text/transform.go
+++ b/common/text/transform.go
@@ -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
+}