public ArrayList DiffReport() { ArrayList report = new ArrayList(); int num1 = this._dest.Count(); int num2 = this._source.Count(); if (num1 == 0) { if (num2 > 0) { report.Add((object)DiffResultSpan.CreateDeleteSource(0, num2)); } return(report); } if (num2 == 0) { report.Add((object)DiffResultSpan.CreateAddDestination(0, num1)); return(report); } this._matchList.Sort(); int curDest = 0; int curSource = 0; DiffResultSpan diffResultSpan = (DiffResultSpan)null; foreach (DiffResultSpan match in this._matchList) { if (!this.AddChanges(report, curDest, match.DestIndex, curSource, match.SourceIndex) && diffResultSpan != null) { diffResultSpan.AddLength(match.Length); } else { report.Add((object)match); } curDest = match.DestIndex + match.Length; curSource = match.SourceIndex + match.Length; diffResultSpan = match; } this.AddChanges(report, curDest, num1, curSource, num2); return(report); }
private bool AddChanges(ArrayList report, int curDest, int nextDest, int curSource, int nextSource) { bool flag = false; int num1 = nextDest - curDest; int num2 = nextSource - curSource; if (num1 > 0) { if (num2 > 0) { int length = Math.Min(num1, num2); report.Add((object)DiffResultSpan.CreateReplace(curDest, curSource, length)); if (num1 > num2) { curDest += length; report.Add((object)DiffResultSpan.CreateAddDestination(curDest, num1 - num2)); } else if (num2 > num1) { curSource += length; report.Add((object)DiffResultSpan.CreateDeleteSource(curSource, num2 - num1)); } } else { report.Add((object)DiffResultSpan.CreateAddDestination(curDest, num1)); } flag = true; } else if (num2 > 0) { report.Add((object)DiffResultSpan.CreateDeleteSource(curSource, num2)); flag = true; } return(flag); }
private void ProcessRange(int destStart, int destEnd, int sourceStart, int sourceEnd) { int destIndex = -1; int length = -1; DiffState diffState = (DiffState)null; for (int index = destStart; index <= destEnd; ++index) { int maxPossibleDestLength = destEnd - index + 1; if (maxPossibleDestLength > length) { DiffState byIndex = this._stateList.GetByIndex(index); if (!byIndex.HasValidLength(sourceStart, sourceEnd, maxPossibleDestLength)) { this.GetLongestSourceMatch(byIndex, index, destEnd, sourceStart, sourceEnd); } if (byIndex.Status == DiffStatus.Matched) { switch (this._level) { case DiffEngineLevel.FastImperfect: if (byIndex.Length > length) { destIndex = index; length = byIndex.Length; diffState = byIndex; } index += byIndex.Length - 1; break; case DiffEngineLevel.Medium: if (byIndex.Length > length) { destIndex = index; length = byIndex.Length; diffState = byIndex; index += byIndex.Length - 1; break; } break; default: if (byIndex.Length > length) { destIndex = index; length = byIndex.Length; diffState = byIndex; break; } break; } } } else { break; } } if (destIndex < 0) { return; } int startIndex = diffState.StartIndex; this._matchList.Add((object)DiffResultSpan.CreateNoChange(destIndex, startIndex, length)); if (destStart < destIndex && sourceStart < startIndex) { this.ProcessRange(destStart, destIndex - 1, sourceStart, startIndex - 1); } int destStart1 = destIndex + length; int sourceStart1 = startIndex + length; if (destEnd > destStart1 && sourceEnd > sourceStart1) { this.ProcessRange(destStart1, destEnd, sourceStart1, sourceEnd); } }