/** * Compute a list of patches to turn text1 into text2. * A set of diffs will be computed. * * @param text1 Old text. * @param text2 New text. * @return LinkedList of Patch objects. */ public LinkedList<Patch> patchMake(String text1, String text2) { if (text1 == null || text2 == null) { throw new IllegalArgumentException("Null inputs. (patchMake)"); } // No diffs provided, compute our own. LinkedList<Diff> diffs = diffMain(text1, text2, true); if (diffs.size() > 2) { diff_cleanupSemantic(diffs); diffCleanupEfficiency(diffs); } return patchMake(text1, diffs); }
public DiffMatchPatch build() { return new DiffMatchPatch(this); }
/** * Compute a list of patches to turn text1 into text2. * text1 will be derived from the provided diffs. * * @param diffs Array of Diff objects for text1 to text2. * @return LinkedList of Patch objects. */ public LinkedList<Patch> patchMake(LinkedList<Diff> diffs) { if (diffs == null) { throw new IllegalArgumentException("Null inputs. (patchMake)"); } // No origin string provided, compute our own. String text1 = diffText1(diffs); return patchMake(text1, diffs); }
patches = patch_deepCopy(patches); String nullPadding = patchAddPadding(patches); text = nullPadding + text + nullPadding; patchSplitMax(patches); for (Patch aPatch : patches) { int expected_loc = aPatch.start2 + delta; String text1 = diffText1(aPatch.diffs); int start_loc; int end_loc = -1; start_loc = matchMain(text, text1.substring(0, this.matchMaxbits), expected_loc); if (start_loc != -1) { end_loc = matchMain(text, text1.substring(text1.length() - this.matchMaxbits), expected_loc + text1.length() - this.matchMaxbits); start_loc = matchMain(text, text1, expected_loc); text = text.substring(0, start_loc) + diffText2(aPatch.diffs) + text.substring(start_loc + text1.length()); } else { LinkedList<DiffMatchPatch.Diff> diffs = diffMain(text1, text2, false); if (text1.length() > this.matchMaxbits && diffLevenshtein(diffs) / (float) text1.length() > this.patchDeleteThreshold) {
LinesToCharsResult b = diffLinesToChars(text1, text2); text1 = b.chars1; text2 = b.chars2; List<String> linearray = b.lineArray; LinkedList<Diff> diffs = diffMain(text1, text2, false, deadline); diffCharsToLines(diffs, linearray); diff_cleanupSemantic(diffs); pointer.remove(); for (Diff newDiff : diffMain(text_delete, text_insert, false, deadline)) { pointer.add(newDiff);
String[] hm = diffHalfMatch(text1, text2); if (hm != null) { String mid_common = hm[4]; LinkedList<Diff> diffs_a = diffMain(text1_a, text2_a, checklines, deadline); LinkedList<Diff> diffs_b = diffMain(text1_b, text2_b, checklines, deadline); return diffLineMode(text1, text2, deadline); return diffBisect(text1, text2, deadline);
@Override public DiffMatchPatchEdit clientDiff(final Document<String> document, final ShadowDocument<String> shadowDocument) { final String shadowText = shadowDocument.document().content(); final LinkedList<DiffMatchPatch.Diff> diffs = diffMatchPatch.diffMain(document.content(), shadowText); return DiffMatchPatchEdit.withChecksum(checksum(shadowText)).diffs(asAeroGearDiffs(diffs)).build(); }
/** * Find the differences between two texts. * Run a faster, slightly less optimal diff. * This method allows the 'checklines' of diffMain() to be optional. * Most of the time checklines is wanted, so default to true. * * @param text1 Old string to be diffed. * @param text2 New string to be diffed. * @return Linked List of Diff objects. */ public LinkedList<Diff> diffMain(String text1, String text2) { return diffMain(text1, text2, true); }
/** * Compute a list of patches to turn text1 into text2. * text2 is ignored, diffs are the delta between text2 and text2. * * @param text1 Old text * @param text2 Ignored. * @param diffs Array of Diff objects for text1 to text2. * @return LinkedList of Patch objects. * @deprecated Prefer {@link #patchMake(java.lang.String, java.util.LinkedList) }. */ public LinkedList<Patch> patchMake(String text1, String text2, LinkedList<Diff> diffs) { return patchMake(text1, diffs); }
public DiffMatchPatchServerSynchronizer() { this(builder().build()); }
private static LinkedList<DiffMatchPatch.Diff> asDiffUtilDiffs(final LinkedList<DiffMatchPatchDiff> diffs) { final LinkedList<DiffMatchPatch.Diff> dsf = new LinkedList<DiffMatchPatch.Diff>(); for (DiffMatchPatchDiff d : diffs) { dsf.add(DiffMatchPatch.diff(diffutilOp(d.operation()), d.text())); } return dsf; }
if (x1 >= x2) { return diffBisectSplit(text1, text2, x1, y1, deadline); if (x1 >= x2) { return diffBisectSplit(text1, text2, x1, y1, deadline);
@Override public DiffMatchPatchEdit serverDiff(final Document<String> document, final ShadowDocument<String> shadowDocument) { final String shadowText = shadowDocument.document().content(); final LinkedList<DiffMatchPatch.Diff> diffs = diffMatchPatch.diffMain(shadowText, document.content()); return DiffMatchPatchEdit.withChecksum(checksum(shadowText)) .serverVersion(shadowDocument.serverVersion()) .clientVersion(shadowDocument.clientVersion()) .diffs(asAeroGearDiffs(diffs)) .build(); }
/** * Find the differences between two texts. * * @param text1 Old string to be diffed. * @param text2 New string to be diffed. * @param checklines Speedup flag. If false, then don't run a * line-level diff first to identify the changed areas. * If true, then run a faster slightly less optimal diff. * @return Linked List of Diff objects. */ public LinkedList<Diff> diffMain(String text1, String text2, boolean checklines) { // Set a deadline by which time the diff must be complete. long deadline; if (diffTimeout <= 0) { deadline = Long.MAX_VALUE; } else { deadline = System.currentTimeMillis() + (long) (diffTimeout * 1000); } return diffMain(text1, text2, checklines, deadline); }
private LinkedList<Patch> patchesFrom(final DiffMatchPatchEdit edit) { return diffMatchPatch.patchMake(asDiffUtilDiffs(edit.diff().diffs())); }
/** * Given the location of the 'middle snake', split the diff in two parts * and recurse. * * @param text1 Old string to be diffed. * @param text2 New string to be diffed. * @param x Index of split point in text1. * @param y Index of split point in text2. * @param deadline Time at which to bail if not yet complete. * @return LinkedList of Diff objects. */ private LinkedList<Diff> diffBisectSplit(String text1, String text2, int x, int y, long deadline) { String text1a = text1.substring(0, x); String text2a = text2.substring(0, y); String text1b = text1.substring(x); String text2b = text2.substring(y); // Compute both diffs serially. LinkedList<Diff> diffs = diffMain(text1a, text2a, false, deadline); LinkedList<Diff> diffsb = diffMain(text1b, text2b, false, deadline); diffs.addAll(diffsb); return diffs; }