Skip to content
This repository was archived by the owner on Aug 5, 2024. It is now read-only.

Commit 4fc0073

Browse files
committed
Add fixes for Python3 and fix counter in Python2
1 parent aafbd58 commit 4fc0073

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

python2/diff_match_patch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,9 +1179,9 @@ def diff_toDelta(self, diffs):
11791179
data = data.encode("utf-8")
11801180
text.append("+" + urllib.quote(data, "!~*'();/?:@&=+$,# "))
11811181
elif op == self.DIFF_DELETE:
1182-
text.append("-%d" % len(data))
1182+
text.append("-%d" % (len(data.encode('utf-16be')) // 2))
11831183
elif op == self.DIFF_EQUAL:
1184-
text.append("=%d" % len(data))
1184+
text.append("=%d" % (len(data.encode('utf-16be')) // 2))
11851185
return "\t".join(text)
11861186

11871187
def diff_fromDelta(self, text1, delta):

python3/diff_match_patch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,9 +1176,9 @@ def diff_toDelta(self, diffs):
11761176
data = data.encode("utf-8")
11771177
text.append("+" + urllib.parse.quote(data, "!~*'();/?:@&=+$,# "))
11781178
elif op == self.DIFF_DELETE:
1179-
text.append("-%d" % len(data))
1179+
text.append("-%d" % (len(data.encode('utf-16-be')) // 2))
11801180
elif op == self.DIFF_EQUAL:
1181-
text.append("=%d" % len(data))
1181+
text.append("=%d" % (len(data.encode('utf-16-be')) // 2))
11821182
return "\t".join(text)
11831183

11841184
def diff_fromDelta(self, text1, delta):

python3/tests/diff_match_patch_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def testDiffDelta(self):
447447

448448
diffs = [(self.dmp.DIFF_EQUAL, "\ud83d\ude4b\ud83d"), (self.dmp.DIFF_INSERT, "\ude4c\ud83d"), (self.dmp.DIFF_EQUAL, "\ude4b")]
449449
delta = self.dmp.diff_toDelta(diffs)
450-
self.assertEquals("=2\t+%F0%9F%99%8C\t=2", delta)
450+
self.assertEqual("=2\t+%F0%9F%99%8C\t=2", delta)
451451

452452
# Verify pool of unchanged characters.
453453
diffs = [(self.dmp.DIFF_INSERT, "A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # ")]

0 commit comments

Comments
 (0)