-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff.py
More file actions
46 lines (37 loc) · 1.56 KB
/
diff.py
File metadata and controls
46 lines (37 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Main diff-match-patch implementation"""
from typing import List
from ._binding import PyDiffMatchPatch
from .types import Diff
class DiffMatchPatch:
"""A wrapper around the Rust DiffMatchPatch implementation"""
def __init__(self):
self._inner = PyDiffMatchPatch()
self._checklines = True # Default value from Rust
def diff_main(self, text1: str, text2: str) -> List[Diff]:
"""
Find the differences between two texts.
Args:
text1: The first text to compare
text2: The second text to compare
Returns:
A list of Diff objects representing the differences
"""
return [Diff.from_py_diff(d) for d in self._inner.diff_main(text1, text2)]
@property
def checklines(self) -> bool:
"""Returns true if line mode optimization is enabled"""
return self._checklines
@checklines.setter
def checklines(self, enable: bool):
"""Enable or disable line mode optimization"""
self._inner.set_checklines(enable)
self._checklines = enable
def set_edit_cost(self, cost: int):
"""Set the edit cost for efficiency cleanup"""
self._inner.set_edit_cost(cost)
def set_delete_threshold(self, threshold: float):
"""Set the delete threshold for patch application"""
self._inner.set_delete_threshold(threshold)
def set_match_threshold(self, threshold: float):
"""Set the match threshold for fuzzy matching"""
self._inner.set_match_threshold(threshold)