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)
| 895 | // splice to substitute the file's whitespace at each position |
| 896 | // when search and replace agree on what that position should be. |
| 897 | func 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, |
no test coverage detected