findLine finds the line that contains the given character offset and returns the line number and offset of the beginning of that line. Note that the last line is treated as if it contains all offsets beyond the end of the actual source.
(characterOffset int32)
| 182 | // Note that the last line is treated as if it contains all offsets |
| 183 | // beyond the end of the actual source. |
| 184 | func (s *sourceImpl) findLine(characterOffset int32) (int32, int32) { |
| 185 | var line int32 = 1 |
| 186 | for _, lineOffset := range s.lineOffsets { |
| 187 | if lineOffset > characterOffset { |
| 188 | break |
| 189 | } |
| 190 | line++ |
| 191 | } |
| 192 | if line == 1 { |
| 193 | return line, 0 |
| 194 | } |
| 195 | return line, s.lineOffsets[line-2] |
| 196 | } |