diff options
Diffstat (limited to 'modules/base')
-rw-r--r-- | modules/base/tool.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go index bc6ff81a14..45d0aea5bc 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -464,6 +464,15 @@ func EllipsisString(str string, length int) string { return str[:length-3] + "..." } +// TruncateString returns a truncated string with given limit, +// it returns input string if length is not reached limit. +func TruncateString(str string, limit int) string { + if len(str) < limit { + return str + } + return str[:limit] +} + // StringsToInt64s converts a slice of string to a slice of int64. func StringsToInt64s(strs []string) []int64 { ints := make([]int64, len(strs)) |