CreateReplace() public static method

public static CreateReplace ( int destIndex, int sourceIndex, int length ) : DiffResultSpan
destIndex int
sourceIndex int
length int
return DiffResultSpan
Exemplo n.º 1
0
        private bool AddChanges(
            List <DiffResultSpan> report,
            int curDest,
            int nextDest,
            int curSource,
            int nextSource)
        {
            var retval     = false;
            var diffDest   = nextDest - curDest;
            var diffSource = nextSource - curSource;
            var minDiff    = 0;

            if (diffDest > 0)
            {
                if (diffSource > 0)
                {
                    minDiff = Math.Min(diffDest, diffSource);
                    report.Add(DiffResultSpan.CreateReplace(curDest, curSource, minDiff));
                    if (diffDest > diffSource)
                    {
                        curDest += minDiff;
                        report.Add(DiffResultSpan.CreateAddDestination(curDest, diffDest - diffSource));
                    }
                    else
                    {
                        if (diffSource > diffDest)
                        {
                            curSource += minDiff;
                            report.Add(DiffResultSpan.CreateDeleteSource(curSource, diffSource - diffDest));
                        }
                    }
                }
                else
                {
                    report.Add(DiffResultSpan.CreateAddDestination(curDest, diffDest));
                }
                retval = true;
            }
            else
            {
                if (diffSource > 0)
                {
                    report.Add(DiffResultSpan.CreateDeleteSource(curSource, diffSource));
                    retval = true;
                }
            }
            return(retval);
        }