/// <summary> /// Entrypoint into the algorithm this class is all about. This method triggers that the /// differences between A and B are calculated in form of a list of edits. /// </summary> protected void calculateEdits() { edits = new EditList(); middle.initialize(0, a.size(), 0, b.size()); if (middle.beginA >= middle.endA && middle.beginB >= middle.endB) { return; } calculateEdits(middle.beginA, middle.endA, middle.beginB, middle.endB); }
private bool isEqual(EditList o) { if (Count != o.Count) { return(false); } for (int i = 0; i < Count; i++) { if (!this[i].Equals(o[i])) { return(false); } } return(true); }
public override bool Equals(object obj) { EditList e = (obj as EditList); if (e != null) { return(isEqual(e)); } string s = (obj as string); if (s != null) { return(isEqual(s)); } return(false); }
private void FormatEdits(Stream @out, RawText a, RawText b, EditList edits) { for (int curIdx = 0; curIdx < edits.Count; /* */) { Edit curEdit = edits.get(curIdx); int endIdx = FindCombinedEnd(edits, curIdx); Edit endEdit = edits.get(endIdx); int aCur = Math.Max(0, curEdit.BeginA - _context); int bCur = Math.Max(0, curEdit.BeginB - _context); int aEnd = Math.Min(a.size(), endEdit.EndA + _context); int bEnd = Math.Min(b.size(), endEdit.EndB + _context); WriteHunkHeader(@out, aCur, aEnd, bCur, bEnd); while (aCur < aEnd || bCur < bEnd) { if (aCur < curEdit.BeginA || endIdx + 1 < curIdx) { WriteLine(@out, ' ', a, aCur); aCur++; bCur++; } else if (aCur < curEdit.EndA) { WriteLine(@out, '-', a, aCur++); } else if (bCur < curEdit.EndB) { WriteLine(@out, '+', b, bCur++); } if (End(curEdit, aCur, bCur) && ++curIdx < edits.Count) { curEdit = edits.get(curIdx); } } } }