File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package utils
2
2
3
3
import (
4
4
"encoding/hex"
5
+ "fmt"
5
6
"strings"
6
7
"unicode"
7
8
"unicode/utf16"
@@ -50,14 +51,15 @@ func EnsureTrailingNewline(s string) string {
50
51
51
52
// TruncateString shortens a string longer than n by replacing the middle part with "...<truncated>..."
52
53
func TruncateString (s string , n int ) string {
53
- if len (s ) <= n {
54
+ if len (s ) <= n || n < 30 {
54
55
return s
55
56
}
56
- const l = len ("...<truncated>..." )
57
- prefixLength := (n - l ) / 2
58
- suffixLength := n - prefixLength - l
57
+ suffix := fmt .Sprintf ("......<%d bytes truncated>" , len (s )- 30 )
58
+ if n < len (suffix ) {
59
+ return suffix
60
+ }
59
61
60
- truncated := s [:prefixLength ] + "...<truncated>..." + s [ len (s ) - suffixLength :]
62
+ truncated := s [:n - len (suffix )] + suffix
61
63
62
64
return truncated
63
65
}
You can’t perform that action at this time.
0 commit comments