non-last line's ending replaced by ending; the last line keeps its original ending. Used before pass 1 splicing to normalize the replacement to the file's ending style.
(lines []string, ending string)
| 871 | // its original ending. Used before pass 1 splicing to normalize |
| 872 | // the replacement to the file's ending style. |
| 873 | func rewriteInternalEnding(lines []string, ending string) string { |
| 874 | var b strings.Builder |
| 875 | for i, l := range lines { |
| 876 | body, e := splitEnding(l) |
| 877 | _, _ = b.WriteString(body) |
| 878 | isLast := i == len(lines)-1 |
| 879 | switch { |
| 880 | case isLast: |
| 881 | _, _ = b.WriteString(e) |
| 882 | case e == "": |
| 883 | // Non-last line without ending is only legal at EOF; |
| 884 | // leave the caller's shape alone. |
| 885 | default: |
| 886 | _, _ = b.WriteString(ending) |
| 887 | } |
| 888 | } |
| 889 | return b.String() |
| 890 | } |
| 891 | |
| 892 | // splitLineParts decomposes a line into its leading whitespace |
| 893 | // (spaces and tabs only), middle body, trailing whitespace |
no test coverage detected