gilo/internal/gilo/fn.go
Timothy J. Warren 3672c5c3e9
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
Complete kilo chapter 5, fix backspace and delete behavior
2021-04-06 10:30:12 -04:00

30 lines
360 B
Go

// Helper functions
package gilo
import "strings"
// Truncate a string to a length
func Truncate(s string, length int) string {
if length < 1 {
return ""
}
if len(s) < length {
return s
}
var buf strings.Builder
count := 0
for _, char := range s {
if count == length {
break
}
buf.WriteRune(char)
count++
}
return buf.String()
}