| 56 | } |
| 57 | |
| 58 | fn parse_diff(&mut self, content: &str) { |
| 59 | let mut old_line: u32 = 0; |
| 60 | let mut new_line: u32 = 0; |
| 61 | |
| 62 | for line in content.lines() { |
| 63 | let (diff_line, _update_counts) = if let Some(stripped) = line.strip_prefix("@@ ") { |
| 64 | let header = stripped.to_string(); |
| 65 | old_line = Self::parse_hunk_start(&header, true); |
| 66 | new_line = Self::parse_hunk_start(&header, false); |
| 67 | ( |
| 68 | DiffLine { |
| 69 | content: line.to_string(), |
| 70 | line_type: DiffLineType::HunkHeader, |
| 71 | old_line_num: None, |
| 72 | new_line_num: None, |
| 73 | }, |
| 74 | false, |
| 75 | ) |
| 76 | } else if line.starts_with('+') && !line.starts_with("+++") { |
| 77 | let content = line[1..].to_string(); |
| 78 | let num = new_line; |
| 79 | new_line += 1; |
| 80 | ( |
| 81 | DiffLine { |
| 82 | content, |
| 83 | line_type: DiffLineType::Added, |
| 84 | old_line_num: None, |
| 85 | new_line_num: Some(num), |
| 86 | }, |
| 87 | true, |
| 88 | ) |
| 89 | } else if line.starts_with('-') && !line.starts_with("---") { |
| 90 | let content = line[1..].to_string(); |
| 91 | let num = old_line; |
| 92 | old_line += 1; |
| 93 | ( |
| 94 | DiffLine { |
| 95 | content, |
| 96 | line_type: DiffLineType::Removed, |
| 97 | old_line_num: Some(num), |
| 98 | new_line_num: None, |
| 99 | }, |
| 100 | true, |
| 101 | ) |
| 102 | } else if line.starts_with(' ') || line.is_empty() { |
| 103 | let content = if line.is_empty() { |
| 104 | " ".to_string() |
| 105 | } else { |
| 106 | line[1..].to_string() |
| 107 | }; |
| 108 | let o = old_line; |
| 109 | let n = new_line; |
| 110 | old_line += 1; |
| 111 | new_line += 1; |
| 112 | ( |
| 113 | DiffLine { |
| 114 | content, |
| 115 | line_type: DiffLineType::Context, |