| 38 | self.deletions.append([self.del_start, self.cur - 1]) |
| 39 | |
| 40 | def parse(self, text): |
| 41 | self.clean() |
| 42 | for line in text.split('\n'): |
| 43 | line = line.strip() |
| 44 | if not self.in_chunk: |
| 45 | if line.startswith('@@'): |
| 46 | self.in_chunk = True |
| 47 | else: |
| 48 | continue |
| 49 | |
| 50 | if line.startswith('@@'): |
| 51 | m = self.re_chunk_header.search(line) |
| 52 | self.cur = max(int(m.groups()[0]), 1) |
| 53 | elif line.startswith('-'): |
| 54 | # print("in minus") |
| 55 | if self.in_add: |
| 56 | self.finish_add() |
| 57 | self.start_del() |
| 58 | elif self.in_del: |
| 59 | pass |
| 60 | else: |
| 61 | self.start_del() |
| 62 | self.cur += 1 # always increment in minus |
| 63 | elif line.startswith('+'): |
| 64 | # print("in plus") |
| 65 | if self.in_add: |
| 66 | self.add_num_lines += 1 |
| 67 | elif self.in_del: |
| 68 | self.finish_del() |
| 69 | self.start_add() |
| 70 | else: |
| 71 | self.start_add() |
| 72 | else: |
| 73 | # print("in blank") |
| 74 | if self.in_add: |
| 75 | self.finish_add() |
| 76 | elif self.in_del: |
| 77 | self.finish_del() |
| 78 | else: |
| 79 | pass |
| 80 | self.cur += 1 # always increment in blank |
| 81 | |
| 82 | if self.in_add: |
| 83 | self.finish_add() |
| 84 | elif self.in_del: |
| 85 | self.finish_del() |
| 86 | |
| 87 | return self.additions, self.deletions |