mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
parent
0f5603eca2
commit
4dcbc48159
16 changed files with 660 additions and 3 deletions
28
irc/utils/chunks.go
Normal file
28
irc/utils/chunks.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package utils
|
||||
|
||||
import "iter"
|
||||
|
||||
func ChunkifyParams(params iter.Seq[string], maxChars int) [][]string {
|
||||
var chunked [][]string
|
||||
|
||||
var acc []string
|
||||
var length = 0
|
||||
|
||||
for p := range params {
|
||||
length = length + len(p) + 1 // (accounting for the space)
|
||||
|
||||
if length > maxChars {
|
||||
chunked = append(chunked, acc)
|
||||
acc = []string{}
|
||||
length = 0
|
||||
}
|
||||
|
||||
acc = append(acc, p)
|
||||
}
|
||||
|
||||
if len(acc) != 0 {
|
||||
chunked = append(chunked, acc)
|
||||
}
|
||||
|
||||
return chunked
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue