summaryrefslogtreecommitdiffstats
path: root/modules/base
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-01-11 20:41:43 +0800
committerUnknwon <u@gogs.io>2016-01-11 20:41:43 +0800
commitf43cc908411a62c9252eb42484e5096810272369 (patch)
tree32220fed52d2f9c416dd94d26ebaf267caebca23 /modules/base
parenta2ef9a2b648422610a7f2cc6211e1f7a9549575f (diff)
downloadgitea-f43cc908411a62c9252eb42484e5096810272369.tar.gz
gitea-f43cc908411a62c9252eb42484e5096810272369.zip
#2287 Truncate repository name if too long
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/tool.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 255c34ef5a..6bfd912d32 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -453,6 +453,15 @@ func Subtract(left interface{}, right interface{}) interface{} {
}
}
+// EllipsisString returns a truncated short string,
+// it appends '...' in the end of the length of string is too large.
+func EllipsisString(str string, length int) string {
+ if len(str) < length {
+ return str
+ }
+ return str[:length-3] + "..."
+}
+
// StringsToInt64s converts a slice of string to a slice of int64.
func StringsToInt64s(strs []string) []int64 {
ints := make([]int64, len(strs))