Created
January 18, 2012 07:18
-
-
Save cablehead/1631761 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from diffmatchpatch import diff_match_patch | |
DMP = diff_match_patch() | |
def diff(a, b): | |
diffs = DMP.diff_main(a, b) | |
if len(diffs) > 2: | |
DMP.diff_cleanupEfficiency(diffs) | |
if len(diffs) > 0: | |
delta = DMP.diff_toDelta(diffs) | |
return delta | |
def patch(a, d): | |
diffs = DMP.diff_fromDelta(a, d) | |
patches = DMP.patch_make(a, diffs) | |
result = DMP.patch_apply(patches, a) | |
return result[0] | |
def diffpatch(a, b): | |
d = diff(a, b) | |
print d | |
end = patch(a, d) | |
print repr(d), end == b | |
# diffpatch(u'\ud83d\udc7f y', u'\ud83d\udc7f x') | |
# diffpatch(u"\U0001f47f y", u"\U0001f47f x") | |
diffpatch(u"\U0001f47f y".encode('utf-8'), u"\U0001f47f x".encode('utf-8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment