Parse the content of a patch string and return a list of modified intervals >>> parse_patch(example_patch) [[2, 8], [13, 21]]
(text)
| 23 | platforms darwin""" |
| 24 | |
| 25 | def parse_patch(text): |
| 26 | """Parse the content of a patch string and return a list of modified intervals |
| 27 | |
| 28 | >>> parse_patch(example_patch) |
| 29 | [[2, 8], [13, 21]] |
| 30 | """ |
| 31 | re_chunk_header = re.compile("""\@\@\s* |
| 32 | \-(?P<old_start_line>\d+),(?P<old_num_lines>\d+)\s* |
| 33 | \+(?P<new_start_line>\d+),(?P<new_num_lines>\d+)\s* |
| 34 | \@\@ |
| 35 | """, re.VERBOSE) |
| 36 | modified_intervals = [] |
| 37 | for m in re_chunk_header.finditer(text): |
| 38 | old_start_line, old_num_lines, _, _ = m.groups() |
| 39 | modified_intervals.append([int(old_start_line), int(old_start_line) + int(old_num_lines) - 1]) |
| 40 | |
| 41 | return modified_intervals |
| 42 | |
| 43 | if __name__ == "__main__": |
| 44 | import doctest |