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

Commit 8d2a5f8

Browse files
committed
Add fixes for ObjectiveC
1 parent 71646fb commit 8d2a5f8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

objectivec/DiffMatchPatch.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,22 @@ - (NSString *)diff_text2:(NSMutableArray *)diffs;
12991299
- (NSString *)diff_toDelta:(NSMutableArray *)diffs;
13001300
{
13011301
NSMutableString *delta = [NSMutableString string];
1302+
UniChar lastEnd;
13021303
for (Diff *aDiff in diffs) {
1304+
1305+
UniChar thisTop = [aDiff.text characterAtIndex:0];
1306+
UniChar thisEnd = [aDiff.text characterAtIndex:([aDiff.text length]-1)];
1307+
1308+
if (CFStringIsSurrogateHighCharacter(thisEnd)) {
1309+
aDiff.text = [aDiff.text substringToIndex:([aDiff.text length] - 1)];
1310+
}
1311+
1312+
if (nil != lastEnd && CFStringIsSurrogateHighCharacter(lastEnd) && CFStringIsSurrogateLowCharacter(thisTop)) {
1313+
aDiff.text = [[NSString stringWithFormat:@"%C", lastEnd] stringByAppendingString:aDiff.text];
1314+
}
1315+
1316+
lastEnd = thisEnd;
1317+
13031318
switch (aDiff.operation) {
13041319
case DIFF_INSERT:
13051320
[delta appendFormat:@"+%@\t", [[aDiff.text diff_stringByAddingPercentEscapesForEncodeUriCompatibility]

0 commit comments

Comments
 (0)