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

Function splitLineParts

agent/agentfiles/files.go:897–912  ·  view source on GitHub ↗

splitLineParts decomposes a line into its leading whitespace (spaces and tabs only), middle body, trailing whitespace (spaces and tabs only), and line ending. Used by the fuzzy splice to substitute the file's whitespace at each position when search and replace agree on what that position should be.

(line string)

Source from the content-addressed store, hash-verified

895// splice to substitute the file's whitespace at each position
896// when search and replace agree on what that position should be.
897func splitLineParts(line string) (lead, middle, trail, ending string) {
898 body, ending := splitEnding(line)
899 i := 0
900 for i < len(body) && (body[i] == ' ' || body[i] == '\t') {
901 i++
902 }
903 lead = body[:i]
904 rest := body[i:]
905 j := len(rest)
906 for j > 0 && (rest[j-1] == ' ' || rest[j-1] == '\t') {
907 j--
908 }
909 middle = rest[:j]
910 trail = rest[j:]
911 return lead, middle, trail, ending
912}
913
914// endingShapeEqual reports whether two line endings occupy the
915// same "position class" for the splice substitution: both empty,

Callers 3

leadOnlyFunction · 0.85
detectIndentUnitFunction · 0.85
buildReplacementLinesFunction · 0.85

Calls 1

splitEndingFunction · 0.85

Tested by

no test coverage detected