diff options
Diffstat (limited to 'internal/strutil/strutil.go')
-rw-r--r-- | internal/strutil/strutil.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/internal/strutil/strutil.go b/internal/strutil/strutil.go index b1de241f..30fa260a 100644 --- a/internal/strutil/strutil.go +++ b/internal/strutil/strutil.go @@ -44,3 +44,13 @@ func RandomChars(n int) (string, error) { return string(buffer), nil } + +// Ellipsis returns a truncated string and appends "..." to the end of the +// string if the string length is larger than the threshold. Otherwise, the +// original string is returned. +func Ellipsis(str string, threshold int) string { + if len(str) <= threshold || threshold < 0 { + return str + } + return str[:threshold] + "..." +} |