Return the byte slice of `content` covering `len` lines starting at line `start` (0-indexed), where lines are delimited by `\n` (the newline is included with the line it terminates). Used to extract the replacement slice for a Replace hunk so that `globalize_replace` only creates per-line vertices for the lines it actually replaces.
(content: &[u8], start: usize, len: usize)
| 615 | /// slice for a Replace hunk so that `globalize_replace` only creates |
| 616 | /// per-line vertices for the lines it actually replaces. |
| 617 | fn slice_lines(content: &[u8], start: usize, len: usize) -> &[u8] { |
| 618 | if len == 0 { |
| 619 | return &[]; |
| 620 | } |
| 621 | let mut line = 0usize; |
| 622 | let mut byte_start: Option<usize> = None; |
| 623 | let mut byte_end = content.len(); |
| 624 | if start == 0 { |
| 625 | byte_start = Some(0); |
| 626 | } |
| 627 | for (i, &b) in content.iter().enumerate() { |
| 628 | if b == b'\n' { |
| 629 | line += 1; |
| 630 | if byte_start.is_none() && line == start { |
| 631 | byte_start = Some(i + 1); |
| 632 | } |
| 633 | if byte_start.is_some() && line == start + len { |
| 634 | byte_end = i + 1; |
| 635 | break; |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | match byte_start { |
| 640 | Some(s) if s <= byte_end => &content[s..byte_end], |
| 641 | _ => &[], |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | /// Enrich FileOps with content ranges for a FileAdd operation. |
| 646 | /// |
no test coverage detected