MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / calculate_line_offsets

Function calculate_line_offsets

atomic-core/src/record/workflow/record/mod.rs:896–904  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

894/// Returns a vector where index i contains the byte offset where line i starts.
895/// Line 0 starts at offset 0.
896fn 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}

Callers 1

record_modified_fileFunction · 0.85

Calls 3

iterMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected