/** * 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> patch_make(String text1, String text2) { if (text1 == null || text2 == null) { throw new IllegalArgumentException("Null inputs. (patch_make)"); } // No diffs provided, compute our own. LinkedList<Diff> diffs = diff_main(text1, text2, true); if (diffs.size() > 2) { diff_cleanupSemantic(diffs); diff_cleanupEfficiency(diffs); } return patch_make(text1, diffs); }
protected LinkedList<DiffMatchPatch.Diff> getDiffs(String first, String second) { LinkedList<DiffMatchPatch.Diff> diffs = diffMatchPatch.diff_main(cleanupValue(first), cleanupValue(second)); diffMatchPatch.diff_cleanupSemantic(diffs); return diffs; }
patches = patch_deepCopy(patches); String nullPadding = patch_addPadding(patches); text = nullPadding + text + nullPadding; patch_splitMax(patches); for (Patch aPatch : patches) { int expected_loc = aPatch.start2 + delta; String text1 = diff_text1(aPatch.diffs); int start_loc; int end_loc = -1; start_loc = match_main(text, text1.substring(0, this.Match_MaxBits), expected_loc); if (start_loc != -1) { end_loc = match_main(text, text1.substring(text1.length() - this.Match_MaxBits), expected_loc + text1.length() - this.Match_MaxBits); start_loc = match_main(text, text1, expected_loc); text = text.substring(0, start_loc) + diff_text2(aPatch.diffs) + text.substring(start_loc + text1.length()); } else { LinkedList<Diff> diffs = diff_main(text1, text2, false); if (text1.length() > this.Match_MaxBits && diff_levenshtein(diffs) / (float) text1.length() > this.Patch_DeleteThreshold) {
long deadline) { LinesToCharsResult b = diff_linesToChars(text1, text2); text1 = b.chars1; text2 = b.chars2; List<String> linearray = b.lineArray; LinkedList<Diff> diffs = diff_main(text1, text2, false, deadline); diff_charsToLines(diffs, linearray); diff_cleanupSemantic(diffs); pointer.remove(); for (Diff newDiff : diff_main(text_delete, text_insert, false, deadline)) { pointer.add(newDiff);
String[] hm = diff_halfMatch(text1, text2); if (hm != null) { String mid_common = hm[4]; LinkedList<Diff> diffs_a = diff_main(text1_a, text2_a, checklines, deadline); LinkedList<Diff> diffs_b = diff_main(text1_b, text2_b, checklines, deadline); return diff_lineMode(text1, text2, deadline); return diff_bisect(text1, text2, deadline);
int commonlength = diff_commonPrefix(text1, text2); String commonprefix = text1.substring(0, commonlength); text1 = text1.substring(commonlength); commonlength = diff_commonSuffix(text1, text2); String commonsuffix = text1.substring(text1.length() - commonlength); text1 = text1.substring(0, text1.length() - commonlength); diffs = diff_compute(text1, text2, checklines, deadline); diff_cleanupMerge(diffs); return diffs;
/** * Find the differences between two texts. * Run a faster, slightly less optimal diff. * This method allows the 'checklines' of diff_main() 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> diff_main(String text1, String text2) { return diff_main(text1, text2, true); }
diff_cleanupMerge(diffs); diff_cleanupSemanticLossless(diffs); String deletion = prevDiff.text; String insertion = thisDiff.text; int overlap_length1 = this.diff_commonOverlap(deletion, insertion); int overlap_length2 = this.diff_commonOverlap(insertion, deletion); if (overlap_length1 >= overlap_length2) { if (overlap_length1 >= deletion.length() / 2.0 ||
commonlength = diff_commonPrefix(text_insert, text_delete); if (commonlength != 0) { if (pointer.hasPrevious()) { commonlength = diff_commonSuffix(text_insert, text_delete); if (commonlength != 0) { thisDiff = pointer.next(); diff_cleanupMerge(diffs);
commonOffset = diff_commonSuffix(equality1, edit); if (commonOffset != 0) { commonString = edit.substring(edit.length() - commonOffset); bestEdit = edit; bestEquality2 = equality2; bestScore = diff_cleanupSemanticScore(equality1, edit) + diff_cleanupSemanticScore(edit, equality2); while (edit.length() != 0 && equality2.length() != 0 && edit.charAt(0) == equality2.charAt(0)) { edit = edit.substring(1) + equality2.charAt(0); equality2 = equality2.substring(1); score = diff_cleanupSemanticScore(equality1, edit) + diff_cleanupSemanticScore(edit, equality2);
if (x1 >= x2) { return diff_bisectSplit(text1, text2, x1, y1, deadline); if (x1 >= x2) { return diff_bisectSplit(text1, text2, x1, y1, deadline);
/** * 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> diff_main(String text1, String text2, boolean checklines) { // Set a deadline by which time the diff must be complete. long deadline; if (Diff_Timeout <= 0) { deadline = Long.MAX_VALUE; } else { deadline = System.currentTimeMillis() + (long) (Diff_Timeout * 1000); } return diff_main(text1, text2, checklines, deadline); }
/** * 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> diff_bisectSplit(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 = diff_main(text1a, text2a, false, deadline); LinkedList<Diff> diffsb = diff_main(text1b, text2b, false, deadline); diffs.addAll(diffsb); return diffs; }