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])
| 863 | /// Returns a vector where index i contains the byte offset where line i starts. |
| 864 | /// Line 0 starts at offset 0. |
| 865 | fn calculate_line_offsets(content: &[u8]) -> Vec<usize> { |
| 866 | let mut offsets = vec![0]; |
| 867 | for (i, &byte) in content.iter().enumerate() { |
| 868 | if byte == b'\n' && i + 1 < content.len() { |
| 869 | offsets.push(i + 1); |
| 870 | } |
| 871 | } |
| 872 | offsets |
| 873 | } |
no test coverage detected