mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-16 20:39:08 +08:00
19 lines
464 B
Go
19 lines
464 B
Go
package txtutil
|
|
|
|
// ToChunks returns the string as chunks of 255-octet strings (the last string being the remainder).
|
|
func ToChunks(s string) []string {
|
|
return splitChunks(s, 255)
|
|
}
|
|
|
|
func splitChunks(buf string, lim int) []string {
|
|
var chunk string
|
|
chunks := make([]string, 0, len(buf)/lim+1)
|
|
for len(buf) >= lim {
|
|
chunk, buf = buf[:lim], buf[lim:]
|
|
chunks = append(chunks, chunk)
|
|
}
|
|
if len(buf) > 0 {
|
|
chunks = append(chunks, buf[:])
|
|
}
|
|
return chunks
|
|
}
|