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

Method split_lines

atomic-core/src/record/workflow/crdt/line_ops/analyzer.rs:388–415  ·  view source on GitHub ↗

Splits content into lines (without trailing newlines).

(content: &[u8])

Source from the content-addressed store, hash-verified

386
387 /// Splits content into lines (without trailing newlines).
388 pub(crate) fn split_lines(content: &[u8]) -> Vec<&[u8]> {
389 if content.is_empty() {
390 return Vec::new();
391 }
392
393 let mut lines = Vec::new();
394 let mut start = 0;
395
396 for (i, &byte) in content.iter().enumerate() {
397 if byte == b'\n' {
398 lines.push(&content[start..i]);
399 start = i + 1;
400 }
401 }
402
403 // Handle final line without newline
404 if start < content.len() {
405 lines.push(&content[start..]);
406 } else if start == content.len()
407 && !content.is_empty()
408 && content[content.len() - 1] == b'\n'
409 {
410 // Trailing newline creates empty final line
411 lines.push(&content[start..start]);
412 }
413
414 lines
415 }
416}

Callers

nothing calls this directly

Calls 4

is_emptyMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected