MCPcopy Index your code
hub / github.com/larksuite/cli / TruncateStrWithEllipsis

Function TruncateStrWithEllipsis

internal/util/strings.go:19–31  ·  view source on GitHub ↗

TruncateStrWithEllipsis truncates s to at most n runes (including "..." suffix).

(s string, n int)

Source from the content-addressed store, hash-verified

17
18// TruncateStrWithEllipsis truncates s to at most n runes (including "..." suffix).
19func 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}

Callers 3

httpStatusErrorFunction · 0.92
inlineClauseFunction · 0.92

Calls

no outgoing calls

Tested by 1