Timothy J. Warren
787166df3a
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
30 lines
362 B
Go
30 lines
362 B
Go
// Helper functions
|
|
package editor
|
|
|
|
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()
|
|
}
|