aboutsummaryrefslogtreecommitdiff
path: root/internal/strutil/strutil.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/strutil/strutil.go')
-rw-r--r--internal/strutil/strutil.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/internal/strutil/strutil.go b/internal/strutil/strutil.go
index 30fa260a..c1013959 100644
--- a/internal/strutil/strutil.go
+++ b/internal/strutil/strutil.go
@@ -54,3 +54,12 @@ func Ellipsis(str string, threshold int) string {
}
return str[:threshold] + "..."
}
+
+// Truncate returns a truncated string if its length is over the limit.
+// Otherwise, it returns the original string.
+func Truncate(str string, limit int) string {
+ if len(str) < limit {
+ return str
+ }
+ return str[:limit]
+}