catchCaretLineColumn returns the SQL without the caret marker and the 1-based line + 0-based column of the caret position. Handles multiline input.
(s string)
| 143 | // catchCaretLineColumn returns the SQL without the caret marker and the |
| 144 | // 1-based line + 0-based column of the caret position. Handles multiline input. |
| 145 | func catchCaretLineColumn(s string) (string, int, int) { |
| 146 | for i, c := range s { |
| 147 | if c == '|' { |
| 148 | text := s[:i] + s[i+1:] |
| 149 | line := 1 |
| 150 | col := 0 |
| 151 | for _, ch := range s[:i] { |
| 152 | if ch == '\n' { |
| 153 | line++ |
| 154 | col = 0 |
| 155 | } else { |
| 156 | col++ |
| 157 | } |
| 158 | } |
| 159 | return text, line, col |
| 160 | } |
| 161 | } |
| 162 | return s, 1, -1 |
| 163 | } |