MCPcopy Create free account
hub / github.com/JanSmrcka/differ / parseHunkHeader

Function parseHunkHeader

internal/ui/diff.go:125–144  ·  view source on GitHub ↗

parseHunkHeader extracts line numbers from @@ -old,count +new,count @@

(line string, oldNum, newNum *int)

Source from the content-addressed store, hash-verified

123
124// parseHunkHeader extracts line numbers from @@ -old,count +new,count @@
125func parseHunkHeader(line string, oldNum, newNum *int) {
126 parts := strings.SplitN(line, "@@", 3)
127 if len(parts) < 2 {
128 return
129 }
130 ranges := strings.TrimSpace(parts[1])
131 for _, r := range strings.Fields(ranges) {
132 if strings.HasPrefix(r, "-") {
133 nums := strings.SplitN(r[1:], ",", 2)
134 if n, err := strconv.Atoi(nums[0]); err == nil {
135 *oldNum = n
136 }
137 } else if strings.HasPrefix(r, "+") {
138 nums := strings.SplitN(r[1:], ",", 2)
139 if n, err := strconv.Atoi(nums[0]); err == nil {
140 *newNum = n
141 }
142 }
143 }
144}
145
146const lineNumWidth = 4
147

Callers 2

parseDiffLineFunction · 0.85
TestParseHunkHeaderFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseHunkHeaderFunction · 0.68