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

Function rewriteInternalEnding

agent/agentfiles/files.go:873–890  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

871// its original ending. Used before pass 1 splicing to normalize
872// the replacement to the file's ending style.
873func 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

Callers 1

fuzzyReplaceFunction · 0.85

Calls 3

splitEndingFunction · 0.85
WriteStringMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected