v0.0.477 add langext.StrWrap
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m4s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m4s
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user