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

Function calculate_line_offsets

atomic-core/src/record/workflow/record/mod.rs:884–892  ·  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

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

Callers 1

record_modified_fileFunction · 0.85

Calls 3

iterMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected