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])
| 882 | /// Returns a vector where index i contains the byte offset where line i starts. |
| 883 | /// Line 0 starts at offset 0. |
| 884 | fn calculate_line_offsets(content: &[u8]) -> Vec<usize> { |
| 885 | let mut offsets = vec![0]; |
| 886 | for (i, &byte) in content.iter().enumerate() { |
| 887 | if byte == b'\n' && i + 1 < content.len() { |
| 888 | offsets.push(i + 1); |
| 889 | } |
| 890 | } |
| 891 | offsets |
| 892 | } |
no test coverage detected