MCPcopy Index your code
hub / github.com/AI45Lab/Code / parse_hunk_header

Function parse_hunk_header

core/src/tools/builtin/patch.rs:95–121  ·  view source on GitHub ↗

Parse @@ -old_start,old_count +new_start,new_count @@ line

(header: &str)

Source from the content-addressed store, hash-verified

93
94/// Parse @@ -old_start,old_count +new_start,new_count @@ line
95fn parse_hunk_header(header: &str) -> Result<usize, String> {
96 // Example: @@ -1,3 +1,3 @@
97 let stripped = header
98 .strip_prefix("@@")
99 .and_then(|s| s.find("@@").map(|end| &s[..end]))
100 .ok_or_else(|| format!("Invalid hunk header: {}", header))?
101 .trim();
102
103 // Parse -old_start part
104 let parts: Vec<&str> = stripped.split_whitespace().collect();
105 if parts.is_empty() {
106 return Err(format!("Invalid hunk header: {}", header));
107 }
108
109 let old_part = parts[0]
110 .strip_prefix('-')
111 .ok_or_else(|| format!("Invalid old range in hunk header: {}", header))?;
112
113 let old_start: usize = old_part
114 .split(',')
115 .next()
116 .unwrap_or("1")
117 .parse()
118 .map_err(|_| format!("Invalid old start line in hunk header: {}", header))?;
119
120 Ok(old_start)
121}
122
123/// Apply hunks to file content. Hunks are applied bottom-to-top to preserve line numbers.
124fn apply_hunks(content: &str, hunks: &[Hunk]) -> Result<String, String> {

Callers 1

parse_single_hunkFunction · 0.85

Calls 3

is_emptyMethod · 0.45
parseMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected