catchCaret finds the | marker in the input and returns: - the text with the marker removed - the 1-based line number where the marker was - the 0-based column offset on that line
(s string)
| 103 | // - the 1-based line number where the marker was |
| 104 | // - the 0-based column offset on that line |
| 105 | func catchCaret(s string) (string, int, int) { |
| 106 | line := 1 |
| 107 | col := 0 |
| 108 | for i, c := range s { |
| 109 | if c == '|' { |
| 110 | return s[:i] + s[i+1:], line, col |
| 111 | } |
| 112 | if c == '\n' { |
| 113 | line++ |
| 114 | col = 0 |
| 115 | } else { |
| 116 | col++ |
| 117 | } |
| 118 | } |
| 119 | return s, -1, -1 |
| 120 | } |