/// <summary>
        /// Returns the difference between two sets of lines
        /// </summary>
        public DiffResult GetDiff(IList <HtmlLine> newLines, IList <HtmlLine> oldLines, bool ignoreSmallChanges)
        {
            IList <LineDiff> changes = GetDiffLines(newLines, oldLines);

            IList <LineDiff> addedDiffs    = new List <LineDiff>();
            IList <LineDiff> removedDiffs  = new List <LineDiff>();
            ISet <string>    uniqueInserts = new HashSet <string>();
            ISet <string>    uniqueDeletes = new HashSet <string>();

            foreach (LineDiff change in changes)
            {
                HtmlLine textLine = change.Line;

                string origText = textLine.Text?.Trim();

                if (string.IsNullOrWhiteSpace(origText))
                {
                    continue;
                }

                if (change.Operation == DiffType.Insert)
                {
                    // ensure no duplication
                    if (!uniqueInserts.Add(origText))
                    {
                        continue;
                    }

                    if (ignoreSmallChanges)
                    {
                        // ignore short change
                        if (origText.Length < 10)
                        {
                            continue;
                        }
                    }

                    addedDiffs.Add(change);
                }
                else if (change.Operation == DiffType.Delete)
                {
                    // ensure no duplication
                    if (!uniqueDeletes.Add(origText))
                    {
                        continue;
                    }

                    if (ignoreSmallChanges)
                    {
                        // ignore short change
                        if (origText.Length < 10)
                        {
                            continue;
                        }
                    }

                    removedDiffs.Add(change);
                }
            }

            return(new DiffResult(addedDiffs, removedDiffs));
        }
Beispiel #2
0
 public LineDiff(DiffType operation, HtmlLine line)
 {
     Operation = operation;
     Line      = line;
 }