@@ -949,22 +949,20 @@ - (void)diff_cleanupMerge:(NSMutableArray *)diffs;
949949 }
950950 }
951951 // Delete the offending records and add the merged ones.
952- if (count_delete == 0 ) {
953- splice (diffs, thisPointer - count_insert,
954- count_delete + count_insert,
955- [NSMutableArray arrayWithObject: [Diff diffWithOperation: DIFF_INSERT andText: text_insert]]);
956- } else if (count_insert == 0 ) {
957- splice (diffs, thisPointer - count_delete,
958- count_delete + count_insert,
959- [NSMutableArray arrayWithObject: [Diff diffWithOperation: DIFF_DELETE andText: text_delete]]);
960- } else {
961- splice (diffs, thisPointer - count_delete - count_insert,
962- count_delete + count_insert,
963- [NSMutableArray arrayWithObjects: [Diff diffWithOperation: DIFF_DELETE andText: text_delete],
964- [Diff diffWithOperation: DIFF_INSERT andText: text_insert], nil ]);
952+ thisPointer -= count_delete + count_insert;
953+
954+ splice (diffs, thisPointer, count_delete + count_insert, nil );
955+ if ([text_delete length ] != 0 ) {
956+ splice (diffs, thisPointer, 0 ,
957+ [NSMutableArray arrayWithObject: [Diff diffWithOperation: DIFF_DELETE andText: text_delete]]);
958+ thisPointer++;
959+ }
960+ if ([text_insert length ] != 0 ) {
961+ splice (diffs, thisPointer, 0 ,
962+ [NSMutableArray arrayWithObject: [Diff diffWithOperation: DIFF_INSERT andText: text_insert]]);
963+ thisPointer++;
965964 }
966- thisPointer = thisPointer - count_delete - count_insert +
967- (count_delete != 0 ? 1 : 0 ) + (count_insert != 0 ? 1 : 0 ) + 1 ;
965+ thisPointer++;
968966 } else if (thisPointer != 0 && prevDiff.operation == DIFF_EQUAL) {
969967 // Merge this equality with the previous one.
970968 prevDiff.text = [prevDiff.text stringByAppendingString: thisDiff.text];
@@ -993,7 +991,10 @@ - (void)diff_cleanupMerge:(NSMutableArray *)diffs;
993991 if (prevDiff.operation == DIFF_EQUAL &&
994992 nextDiff.operation == DIFF_EQUAL) {
995993 // This is a single edit surrounded by equalities.
996- if ([thisDiff.text hasSuffix: prevDiff.text]) {
994+ if ([prevDiff.text length ] == 0 ) {
995+ splice (diffs, thisPointer - 1 , 1 , nil );
996+ changes = YES ;
997+ } else if ([thisDiff.text hasSuffix: prevDiff.text]) {
997998 // Shift the edit over the previous equality.
998999 thisDiff.text = [prevDiff.text stringByAppendingString:
9991000 [thisDiff.text substringWithRange: NSMakeRange (0 , thisDiff.text.length - prevDiff.text.length)]];
@@ -2048,7 +2049,7 @@ - (NSMutableArray *)patch_makeFromOldString:(NSString *)text1
20482049 [patches addObject: patch];
20492050 patch = [[Patch new ] autorelease ];
20502051 // Unlike Unidiff, our patch lists have a rolling context.
2051- // http ://code.google. com/p/ google- diff-match-patch/wiki/Unidiff
2052+ // https ://github. com/google/ diff-match-patch/wiki/Unidiff
20522053 // Update prepatch text & pos to reflect the application of the
20532054 // just completed patch.
20542055 [prepatch_text release ];
0 commit comments