Calculate byte offsets for each line in content. Returns a vector where index i contains the byte offset where line i starts. Line 0 starts at offset 0.
(content: &[u8])
| 894 | /// Returns a vector where index i contains the byte offset where line i starts. |
| 895 | /// Line 0 starts at offset 0. |
| 896 | fn calculate_line_offsets(content: &[u8]) -> Vec<usize> { |
| 897 | let mut offsets = vec![0]; |
| 898 | for (i, &byte) in content.iter().enumerate() { |
| 899 | if byte == b'\n' && i + 1 < content.len() { |
| 900 | offsets.push(i + 1); |
| 901 | } |
| 902 | } |
| 903 | offsets |
| 904 | } |
no test coverage detected