NormalizeWhitespace normalizes trailing whitespace and newlines to reduce spurious conflicts. It trims trailing whitespace from each line and ensures exactly one trailing newline.
(content string)
| 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. |
| 34 | func NormalizeWhitespace(content string) string { |
| 35 | // Split into lines and trim trailing whitespace from each line |
| 36 | lines := strings.Split(content, "\n") |
| 37 | for i, line := range lines { |
| 38 | lines[i] = strings.TrimRight(line, " \t") |
| 39 | } |
| 40 | |
| 41 | // Join back and ensure exactly one trailing newline if content is not empty |
| 42 | normalized := strings.Join(lines, "\n") |
| 43 | normalized = strings.TrimRight(normalized, "\n") |
| 44 | if normalized != "" { |
| 45 | normalized += "\n" |
| 46 | } |
| 47 | |
| 48 | return normalized |
| 49 | } |
| 50 | |
| 51 | // ParseVersionValue converts version values of various types to strings. |
| 52 | // Supports string, int, int64, uint64, and float64 types. |
no outgoing calls