From 395c5ae4f154af28a76dd197960e4ebef4bbfc9d Mon Sep 17 00:00:00 2001 From: Tyler Heck Date: Thu, 14 Nov 2019 09:22:41 -0700 Subject: [PATCH 1/2] Update to delta method in diff match patch class to stop splitting surrogate pairs --- .../fraser/neil/plaintext/diff_match_patch.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Simperium/src/main/java/name/fraser/neil/plaintext/diff_match_patch.java b/Simperium/src/main/java/name/fraser/neil/plaintext/diff_match_patch.java index beea40ba..38cabd46 100644 --- a/Simperium/src/main/java/name/fraser/neil/plaintext/diff_match_patch.java +++ b/Simperium/src/main/java/name/fraser/neil/plaintext/diff_match_patch.java @@ -1429,7 +1429,22 @@ public int diff_levenshtein(LinkedList diffs) { */ public String diff_toDelta(LinkedList diffs) { StringBuilder text = new StringBuilder(); + char lastEnd = 0; + boolean isFirst = true; for (Diff aDiff : diffs) { + char thisTop = aDiff.text.charAt(0); + char thisEnd = aDiff.text.charAt(aDiff.text.length() - 1); + if (Character.isHighSurrogate(thisEnd)) { + aDiff.text = aDiff.text.substring(0, aDiff.text.length() - 1); + } + if (! isFirst && Character.isHighSurrogate(lastEnd) && Character.isLowSurrogate(thisTop)) { + aDiff.text = lastEnd + aDiff.text; + } + isFirst = false; + lastEnd = thisEnd; + if ( aDiff.text.isEmpty() ) { + continue; + } switch (aDiff.operation) { case INSERT: try { From 5ed3492d05e509f86955326b4201dea8a7b8baf2 Mon Sep 17 00:00:00 2001 From: Tyler Heck Date: Thu, 14 Nov 2019 10:19:33 -0700 Subject: [PATCH 2/2] Update version from 0.9.1 to 0.9.2 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index cbc76f4d..b30eb210 100644 --- a/build.gradle +++ b/build.gradle @@ -35,5 +35,5 @@ def gitDescribe() { } def static gitVersion() { - '0.9.1' + '0.9.2' }