MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / normalizeWhitespace

Function normalizeWhitespace

internal/mailparse/parse.go:276–293  ·  view source on GitHub ↗

normalizeWhitespace collapses runs of blank lines and trims trailing spaces per line, so the parsed view is compact without losing paragraph structure.

(s string)

Source from the content-addressed store, hash-verified

274// normalizeWhitespace collapses runs of blank lines and trims trailing spaces
275// per line, so the parsed view is compact without losing paragraph structure.
276func normalizeWhitespace(s string) string {
277 lines := strings.Split(s, "\n")
278 out := make([]string, 0, len(lines))
279 blank := 0
280 for _, ln := range lines {
281 ln = strings.TrimRight(ln, " \t\r")
282 if ln == "" {
283 blank++
284 if blank > 1 {
285 continue // collapse 2+ blank lines into one
286 }
287 } else {
288 blank = 0
289 }
290 out = append(out, ln)
291 }
292 return strings.TrimSpace(strings.Join(out, "\n"))
293}

Callers 1

ParseFunction · 0.85

Calls 1

makeFunction · 0.85

Tested by

no test coverage detected