1#!/usr/bin/env python3 2""" 3# Created: Tue Aug 8 09:25:09 2023 (-0400) 4# @author: Jacob Faibussowitsch 5""" 6from __future__ import annotations 7 8import re 9 10from .._typing import * 11 12class Addline: 13 diff_line_re: ClassVar[re.Pattern[str]] = re.compile(r'^@@ -([0-9,]+) \+([0-9,]+) @@') 14 __slots__ = ('offset',) 15 16 offset: int 17 18 def __init__(self, offset: int) -> None: 19 r"""Construct an `Addline` 20 21 Parameters 22 ---------- 23 offset : 24 the integer offset to add to the line number for the diff 25 """ 26 self.offset = offset 27 return 28 29 def __call__(self, re_match: re.Match[str]) -> str: 30 r"""Apply the offset to the regex match 31 32 Parameters 33 ---------- 34 re_match : 35 the regex match object for the line 36 37 Returns 38 ------- 39 ret : 40 the same matched string, but with the line numbers bumped up by `self.offset` 41 """ 42 ll, lr = re_match.group(1).split(',') 43 rl, rr = re_match.group(2).split(',') 44 return f'@@ -{self.offset + int(ll)},{lr} +{self.offset + int(rl)},{rr} @@' 45