Splits content into lines (without trailing newlines).
(content: &[u8])
| 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 | } |