MCPcopy Create free account
hub / github.com/github/gh-aw / Truncate

Function Truncate

pkg/stringutil/stringutil.go:20–30  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

18// length. For domain-specific workflow command identifiers with newline handling,
19// see workflow.ShortenCommand instead.
20func 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.

Callers 15

formatFieldValueWithTagFunction · 0.92
generateFindingsFunction · 0.92
renderLogsTSVVerboseFunction · 0.92
renderLogsCompactFunction · 0.92
TestTruncateFunction · 0.92
downloadRunArtifactsFunction · 0.92
ListWorkflowMCPFunction · 0.92

Calls 1

PrintfMethod · 0.45

Tested by 10

TestTruncateFunction · 0.74
TestTruncateStringFunction · 0.74
TestTruncateFunction · 0.68
BenchmarkTruncateFunction · 0.68
TestTruncate_UnicodeFunction · 0.68
BenchmarkTruncate_ShortFunction · 0.68
BenchmarkTruncate_LongFunction · 0.68