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

Commit df810f7

Browse files
committed
Updates from review feedback
1 parent 08de57e commit df810f7

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

java/src/name/fraser/neil/plaintext/diff_match_patch.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,9 @@ public String diff_toDelta(List<Diff> diffs) {
14471447

14481448
isFirst = false;
14491449
lastEnd = thisEnd;
1450+
if ( aDiff.text.isEmpty() ) {
1451+
continue;
1452+
}
14501453

14511454
switch (aDiff.operation) {
14521455
case INSERT:

javascript/diff_match_patch_uncompressed.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,9 @@ diff_match_patch.prototype.diff_toDelta = function(diffs) {
13751375
}
13761376

13771377
lastEnd = thisEnd;
1378+
if ( 0 === thisDiff[1].length ) {
1379+
continue;
1380+
}
13781381

13791382
switch (diffs[x][0]) {
13801383
case DIFF_INSERT:

objectivec/DiffMatchPatch.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ - (NSString *)diff_text2:(NSMutableArray *)diffs;
12991299
- (NSString *)diff_toDelta:(NSMutableArray *)diffs;
13001300
{
13011301
NSMutableString *delta = [NSMutableString string];
1302-
UniChar lastEnd;
1302+
UniChar lastEnd = 0;
13031303
for (Diff *aDiff in diffs) {
13041304

13051305
UniChar thisTop = [aDiff.text characterAtIndex:0];
@@ -1309,11 +1309,14 @@ - (NSString *)diff_toDelta:(NSMutableArray *)diffs;
13091309
aDiff.text = [aDiff.text substringToIndex:([aDiff.text length] - 1)];
13101310
}
13111311

1312-
if (nil != lastEnd && CFStringIsSurrogateHighCharacter(lastEnd) && CFStringIsSurrogateLowCharacter(thisTop)) {
1313-
aDiff.text = [[NSString stringWithFormat:@"%C", lastEnd] stringByAppendingString:aDiff.text];
1312+
if (0 != lastEnd && CFStringIsSurrogateHighCharacter(lastEnd) && CFStringIsSurrogateLowCharacter(thisTop)) {
1313+
aDiff.text = [NSString stringWithFormat:@"%C%@", lastEnd, stringByAppendingString:aDiff.text];
13141314
}
13151315

13161316
lastEnd = thisEnd;
1317+
if (0 == [aDiff.text length]) {
1318+
continue;
1319+
}
13171320

13181321
switch (aDiff.operation) {
13191322
case DIFF_INSERT:

objectivec/Tests/DiffMatchPatchTest.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,18 @@ - (void)test_diff_deltaTest {
752752

753753
XCTAssertEqualObjects(diffs, [dmp diff_fromDeltaWithText:text1 andDelta:delta error:NULL], @"diff_fromDelta: Unicode 2.");
754754

755+
diffs = [dmp diff_mainOfOldString:@"☺️🖖🏿" andNewString:@"☺️😃🖖🏿"];
756+
delta = [dmp diff_toDelta:diffs];
757+
758+
XCTAssertEqualObjects(delta, @"=2\t+%F0%9F%98%83\t=4", @"Delta should match the expected string");
759+
760+
diffs = [dmp diff_mainOfOldString:@"☺️🖖🏿" andNewString:@"☺️😃🖖🏿"];
761+
patches = [dmp patch_makeFromDiffs:diffs];
762+
expectedResult = [dmp patch_apply:patches toString:@"☺️🖖🏿"];
763+
764+
expectedString = [result firstObject];
765+
XCTAssertEqualObjects(edited, expectedString, @"Output String should match the Edited one!");
766+
755767
// Verify pool of unchanged characters.
756768
diffs = [NSMutableArray arrayWithObject:
757769
[Diff diffWithOperation:DIFF_INSERT andText:@"A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # "]];

python2/diff_match_patch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,8 @@ def diff_toDelta(self, diffs):
11731173

11741174
data = encoded.decode('utf-16be')
11751175
last_end = this_end
1176+
if 0 == len(encoded):
1177+
continue
11761178

11771179
if op == self.DIFF_INSERT:
11781180
# High ascii will raise UnicodeDecodeError. Use Unicode instead.

python3/diff_match_patch.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,6 @@ def diff_toDelta(self, diffs):
11471147
Delta text.
11481148
"""
11491149
text = []
1150-
last_end = None
11511150
for (op, data) in diffs:
11521151
if op == self.DIFF_INSERT:
11531152
# High ascii will raise UnicodeDecodeError. Use Unicode instead.

0 commit comments

Comments
 (0)