v0.0.477 add langext.StrWrap
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m4s

This commit is contained in:
2024-06-29 15:36:39 +02:00
parent dff8941bd3
commit cb95bb561c
3 changed files with 176 additions and 3 deletions

View File

@@ -88,12 +88,15 @@ func StrRunePadRight(str string, pad string, padlen int) string {
func Indent(str string, pad string) string {
eonl := strings.HasSuffix(str, "\n")
if eonl {
str = str[0 : len(str)-1]
}
r := ""
for _, v := range strings.Split(str, "\n") {
r += pad + v + "\n"
}
if eonl {
if !eonl {
r = r[0 : len(r)-1]
}
@@ -115,3 +118,21 @@ func StrRepeat(val string, count int) string {
}
return r
}
func StrWrap(val string, linelen int, seperator string) string {
res := ""
for iPos := 0; ; {
next := min(iPos+linelen, len(val))
res += val[iPos:next]
iPos = next
if iPos >= len(val) {
break
}
res += seperator
}
return res
}