TruncateString truncates a string to maxLen runes (not bytes). If the string is longer than maxLen, it truncates to maxLen-3 and appends "...".
(s string, maxLen int)
| 287 | // TruncateString truncates a string to maxLen runes (not bytes). |
| 288 | // If the string is longer than maxLen, it truncates to maxLen-3 and appends "...". |
| 289 | func TruncateString(s string, maxLen int) string { |
| 290 | runes := []rune(s) |
| 291 | if len(runes) <= maxLen { |
| 292 | return s |
| 293 | } |
| 294 | return string(runes[0:maxLen-3]) + "..." |
| 295 | } |
no outgoing calls
no test coverage detected