MCPcopy Index your code
hub / github.com/coder/coder / internalLineEnding

Function internalLineEnding

agent/agentfiles/files.go:672–695  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

670// Returns ("", false) if any non-last line has no ending, or if
671// endings disagree.
672func 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).

Callers 1

fuzzyReplaceFunction · 0.85

Calls 1

splitEndingFunction · 0.85

Tested by

no test coverage detected