2
0
mirror of https://github.com/miguelmota/cointop synced 2024-11-16 21:25:38 +00:00
cointop/pkg/pad/pad.go

22 lines
508 B
Go
Raw Normal View History

package pad
2021-02-05 09:04:09 +00:00
import "unicode/utf8"
func times(str string, n int) (out string) {
for i := 0; i < n; i++ {
out += str
}
return
}
// Left left-pads the string with pad up to len runes
// len may be exceeded if
func Left(str string, length int, pad string) string {
2021-02-05 09:04:09 +00:00
return times(pad, length-utf8.RuneCountInString(str)) + str
}
// Right right-pads the string with pad up to len runes
func Right(str string, length int, pad string) string {
2021-02-05 09:04:09 +00:00
return str + times(pad, length-utf8.RuneCountInString(str))
}