Пример #1
0
        //Start Diff betwween two files parsed into 2 objects
        public void StartDiff(CompareText source, CompareText dest)
        {
            if (source.Count() <= 0 && dest.Count() <= 0)
            {
                return;
            }

            //Save to Local vars for later use
            sourceList = source;
            destList   = dest;

            matchList = new ArrayList();

            compareStateList = new CompareStateList(destList.Count());
            RecursiveComparer(0, destList.Count() - 1, 0, sourceList.Count() - 1);
        }
Пример #2
0
        public ArrayList DiffResult()
        {
            ArrayList retval = new ArrayList();
            int       dcount = destList.Count();
            int       scount = sourceList.Count();

            //Deal with the special case of empty files
            if (dcount == 0)
            {
                if (scount > 0)
                {
                    retval.Add(CompareResultSpan.CreateDeleteSource(0, scount));
                }
                return(retval);
            }

            if (scount == 0)
            {
                retval.Add(CompareResultSpan.CreateAddDestination(0, dcount));
                return(retval);
            }

            matchList.Sort();
            int curDest            = 0;
            int curSource          = 0;
            CompareResultSpan last = null;

            //Process each match record
            foreach (CompareResultSpan drs in matchList)
            {
                if ((!AddChanges(retval, curDest, drs.DestinationIndex, curSource, drs.SourceIndex)) &&
                    (last != null))
                {
                    last.AddLength(drs.Length);
                }
                else
                {
                    retval.Add(drs);
                }
                curDest   = drs.DestinationIndex + drs.Length;
                curSource = drs.SourceIndex + drs.Length;
                last      = drs;
            }

            //Process any tail end data
            AddChanges(retval, curDest, dcount, curSource, scount);

            return(retval);
        }