Truncate truncates a string to a maximum length, adding "..." if truncated. If maxLen is 3 or less, the string is truncated without "...". This is a general-purpose utility for truncating any string to a configurable length. For domain-specific workflow command identifiers with newline handling, se
(s string, maxLen int)
| 18 | // length. For domain-specific workflow command identifiers with newline handling, |
| 19 | // see workflow.ShortenCommand instead. |
| 20 | func Truncate(s string, maxLen int) string { |
| 21 | if len(s) <= maxLen { |
| 22 | return s |
| 23 | } |
| 24 | if maxLen <= 3 { |
| 25 | stringutilLog.Printf("Truncate: hard-cut at maxLen=%d (no ellipsis)", maxLen) |
| 26 | return s[:maxLen] |
| 27 | } |
| 28 | stringutilLog.Printf("Truncate: shortened from %d to %d chars", len(s), maxLen) |
| 29 | return s[:maxLen-3] + "..." |
| 30 | } |
| 31 | |
| 32 | // NormalizeWhitespace normalizes trailing whitespace and newlines to reduce spurious conflicts. |
| 33 | // It trims trailing whitespace from each line and ensures exactly one trailing newline. |