dominantFileEnding returns CRLF if CRLF endings outnumber LF in contentLines, LF otherwise (including ties and ending-less files).
(contentLines []string)
| 697 | // dominantFileEnding returns CRLF if CRLF endings outnumber LF in |
| 698 | // contentLines, LF otherwise (including ties and ending-less files). |
| 699 | func dominantFileEnding(contentLines []string) string { |
| 700 | var crlf, lf int |
| 701 | for _, l := range contentLines { |
| 702 | switch { |
| 703 | case strings.HasSuffix(l, "\r\n"): |
| 704 | crlf++ |
| 705 | case strings.HasSuffix(l, "\n"): |
| 706 | lf++ |
| 707 | } |
| 708 | } |
| 709 | if crlf > lf { |
| 710 | return "\r\n" |
| 711 | } |
| 712 | return "\n" |
| 713 | } |
| 714 | |
| 715 | // atNoNewlineEOF reports whether the matched region ends at a |
| 716 | // file that lacks a trailing newline. True when no non-empty lines |