Skip to content

Commit cb41a1f

Browse files
authored
Merge pull request #213 from Simperium/stop-splitting-surrogates
Stop Splitting Surrogates
2 parents 8be64f6 + 5ed3492 commit cb41a1f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,22 @@ public int diff_levenshtein(LinkedList<Diff> diffs) {
14291429
*/
14301430
public String diff_toDelta(LinkedList<Diff> diffs) {
14311431
StringBuilder text = new StringBuilder();
1432+
char lastEnd = 0;
1433+
boolean isFirst = true;
14321434
for (Diff aDiff : diffs) {
1435+
char thisTop = aDiff.text.charAt(0);
1436+
char thisEnd = aDiff.text.charAt(aDiff.text.length() - 1);
1437+
if (Character.isHighSurrogate(thisEnd)) {
1438+
aDiff.text = aDiff.text.substring(0, aDiff.text.length() - 1);
1439+
}
1440+
if (! isFirst && Character.isHighSurrogate(lastEnd) && Character.isLowSurrogate(thisTop)) {
1441+
aDiff.text = lastEnd + aDiff.text;
1442+
}
1443+
isFirst = false;
1444+
lastEnd = thisEnd;
1445+
if ( aDiff.text.isEmpty() ) {
1446+
continue;
1447+
}
14331448
switch (aDiff.operation) {
14341449
case INSERT:
14351450
try {

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ def gitDescribe() {
3535
}
3636

3737
def static gitVersion() {
38-
'0.9.1'
38+
'0.9.2'
3939
}

0 commit comments

Comments
 (0)