コード例 #1
0
        public static IEnumerable <DiffHunk> GetDiff(this IReadonlyTextDocument document, IReadonlyTextDocument changedDocument, bool includeEol = true)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            if (changedDocument == null)
            {
                throw new ArgumentNullException("changedDocument");
            }
            var codeDictionary = new Dictionary <string, int>();
            int codeCounter    = 0;
            var options        = new DiffOptions(includeEol);

            return(Diff.GetDiff <int>(GetDiffCodes(document, ref codeCounter, codeDictionary, options),
                                      GetDiffCodes(changedDocument, ref codeCounter, codeDictionary, options)));
        }
コード例 #2
0
        static int[] GetDiffCodes(IReadonlyTextDocument document, ref int codeCounter, Dictionary <string, int> codeDictionary, DiffOptions options)
        {
            int i      = 0;
            var result = new int[document.LineCount];

            foreach (var line in document.GetLinesStartingAt(1))
            {
                string lineText = document.GetTextAt(line.Offset, options.IncludeEol ? line.LengthIncludingDelimiter : line.Length);
                if (options.TrimLines)
                {
                    lineText = lineText.Trim();
                }
                int curCode;
                if (!codeDictionary.TryGetValue(lineText, out curCode))
                {
                    codeDictionary[lineText] = curCode = ++codeCounter;
                }
                result[i] = curCode;
                i++;
            }
            return(result);
        }