Return a list of matching block Match triples describing matching subsequences of `a` in `b` starting from the `a_start` position in `a` up to the `a_end` position in `a`.
(a, b, a_start, a_end, *args, **kwargs)
| 64 | |
| 65 | |
| 66 | def match_blocks(a, b, a_start, a_end, *args, **kwargs): |
| 67 | """ |
| 68 | Return a list of matching block Match triples describing matching |
| 69 | subsequences of `a` in `b` starting from the `a_start` position in `a` up to |
| 70 | the `a_end` position in `a`. |
| 71 | """ |
| 72 | if TRACE: |
| 73 | logger_debug('a_start', a_start, 'a_end', a_end) |
| 74 | # convert sequences to strings |
| 75 | text1 = int2unicode(a[a_start:a_end]) |
| 76 | text2 = int2unicode(b) |
| 77 | |
| 78 | df = Differ(timeout=0.01) |
| 79 | diffs = df.difference(text1, text2) |
| 80 | diffs = trim(diffs) |
| 81 | |
| 82 | apos = a_start |
| 83 | bpos = 0 |
| 84 | matches = [] |
| 85 | for op, matched_text in diffs: |
| 86 | size = len(matched_text) |
| 87 | if not size: |
| 88 | continue |
| 89 | if op == DIFF_EQUAL: |
| 90 | matches.append(Match(apos, bpos, size)) |
| 91 | apos += size |
| 92 | bpos += size |
| 93 | elif op == DIFF_INSERT: |
| 94 | bpos += size |
| 95 | |
| 96 | elif op == DIFF_DELETE: |
| 97 | apos += size |
| 98 | |
| 99 | return matches |
| 100 | |
| 101 | |
| 102 | def int2unicode(nums): |
nothing calls this directly
no test coverage detected