internalLineEnding returns the shared line ending used across lines. An unterminated last line (EOF-no-newline) is excluded. Returns ("", false) if any non-last line has no ending, or if endings disagree.
(lines []string)
| 670 | // Returns ("", false) if any non-last line has no ending, or if |
| 671 | // endings disagree. |
| 672 | func internalLineEnding(lines []string) (string, bool) { |
| 673 | if len(lines) < 2 { |
| 674 | return "", false |
| 675 | } |
| 676 | var want string |
| 677 | for i, l := range lines { |
| 678 | isLast := i == len(lines)-1 |
| 679 | _, e := splitEnding(l) |
| 680 | if isLast && e == "" { |
| 681 | continue |
| 682 | } |
| 683 | if e == "" { |
| 684 | return "", false |
| 685 | } |
| 686 | if want == "" { |
| 687 | want = e |
| 688 | continue |
| 689 | } |
| 690 | if e != want { |
| 691 | return "", false |
| 692 | } |
| 693 | } |
| 694 | return want, want != "" |
| 695 | } |
| 696 | |
| 697 | // dominantFileEnding returns CRLF if CRLF endings outnumber LF in |
| 698 | // contentLines, LF otherwise (including ties and ending-less files). |
no test coverage detected