Calculate 1-indexed line number at byte offset in source.
(source: &str, offset: usize)
| 50 | |
| 51 | /// Calculate 1-indexed line number at byte offset in source. |
| 52 | fn line_number_at(source: &str, offset: usize) -> usize { |
| 53 | source[..offset.min(source.len())] |
| 54 | .bytes() |
| 55 | .filter(|&b| b == b'\n') |
| 56 | .count() |
| 57 | + 1 |
| 58 | } |
| 59 | |
| 60 | /// Get content bounds (start, end byte offsets) of a quoted string literal, |
| 61 | /// excluding prefix characters and quote delimiters. |