Beispiel #1
0
        private void GetLongestSourceMatch(DiffState curItem, int destIndex, int destEnd, int sourceStart, int sourceEnd)
        {
            int maxDestLength = (destEnd - destIndex) + 1,
                curLength     = 0,
                curBestLength = 0,
                curBestIndex  = -1,
                maxLength     = 0;

            for (int sourceIndex = sourceStart; sourceIndex <= sourceEnd; sourceIndex++)
            {
                maxLength = Math.Min(maxDestLength, (sourceEnd - sourceIndex) + 1);
                if (maxLength <= curBestLength)
                {
                    //No chance to find a longer one any more
                    break;
                }
                curLength = GetSourceMatchLength(destIndex, sourceIndex, maxLength);
                if (curLength > curBestLength)
                {
                    //This is the best match so far
                    curBestIndex  = sourceIndex;
                    curBestLength = curLength;
                }
                //jump over the match
                sourceIndex += curBestLength;
            }

            if (curBestIndex == -1)
            {
                curItem.SetStatusToNoMatch();
            }
            else
            {
                curItem.SetStatusToMatch(curBestIndex, curBestLength);
            }
        }