2018-03-30 19:08:53 +00:00
|
|
|
package pad
|
|
|
|
|
2021-02-05 09:04:09 +00:00
|
|
|
import "unicode/utf8"
|
|
|
|
|
2018-03-30 19:08:53 +00:00
|
|
|
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
|
2018-03-30 19:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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))
|
2018-03-30 19:08:53 +00:00
|
|
|
}
|