TruncateStrWithEllipsis truncates s to at most n runes (including "..." suffix).
(s string, n int)
| 17 | |
| 18 | // TruncateStrWithEllipsis truncates s to at most n runes (including "..." suffix). |
| 19 | func TruncateStrWithEllipsis(s string, n int) string { |
| 20 | if n <= 0 { |
| 21 | return "" |
| 22 | } |
| 23 | r := []rune(s) |
| 24 | if len(r) <= n { |
| 25 | return s |
| 26 | } |
| 27 | if n < 3 { |
| 28 | return string(r[:n]) |
| 29 | } |
| 30 | return string(r[:n-3]) + "..." |
| 31 | } |
no outgoing calls