Beispiel #1
0
        /// <summary>複数行の文字列を行単位で比較します</summary>
        /// <param name="textA">元テキスト</param>
        /// <param name="textB">変更テキスト</param>
        /// <param name="option">オプション指定</param>
        /// <returns>比較結果</returns>
        public static DiffResult[] Diff(string textA, string textB, DiffOption option)
        {
            if (string.IsNullOrEmpty(textA) || string.IsNullOrEmpty(textB))
                return StringNullOrEmpty(textA, textB);

            FastDiff diff = new FastDiff();
            if (textA.Length <= textB.Length) {
                diff.SplitHash(textA, textB, option);
            }
            else {
                diff.isSwap = true;
                diff.SplitHash(textB, textA, option);
            }
            return diff.DetectDiff();
        }
Beispiel #2
0
 /// <summary>複数行の文字列を行単位で比較します</summary>
 /// <param name="textA">元テキスト</param>
 /// <param name="textB">変更テキスト</param>
 /// <returns>比較結果</returns>
 public static DiffResult[] Diff(string textA, string textB)
 {
     DiffOption option = new DiffOption();
     return Diff(textA, textB, option);
 }
Beispiel #3
0
        private static int[] SplitHash(string text, DiffOption option)
        {
            if (option.IgnoreCase)
                text = text.ToUpperInvariant();

            string[] lines = text.Split('\n');

            // TODO: FIXME! Optimize this
            if (option.IgnoreSpace)
                for (int i = 0; i < lines.Length; ++i)
                    lines[i] = Regex.Replace(lines[i], @"\s+", " ");

            if (option.TrimSpace)
                for (int i = 0; i < lines.Length; ++i)
                    lines[i] = lines[i].Trim();

            int[] hashs = new int[lines.Length];

            for (int i = 0; i < lines.Length; ++i)
                hashs[i] = lines[i].GetHashCode();

            return hashs;
        }
Beispiel #4
0
 private void SplitHash(string textA, string textB, DiffOption option)
 {
     if (option.TrimSpace || option.IgnoreSpace) {
         this.dataA = SplitHash(textA, option);
         this.dataB = SplitHash(textB, option);
     }
     else {
         this.dataA = SplitHash(textA, option.IgnoreCase);
         this.dataB = SplitHash(textB, option.IgnoreCase);
     }
 }
Beispiel #5
0
        private static int[] SplitChar(string text, DiffOption option)
        {
            if (option.IgnoreCase)
                text = text.ToUpperInvariant();

            // TODO: FIXME! Optimize this
            if (option.IgnoreSpace)
                text = Regex.Replace(text, @"\s+", " ");

            if (option.TrimSpace)
                text = text.Trim();

            int[] result = new int[text.Length];
            for (int i = 0; i < text.Length; i++)
                result[i] = text[i];
            return result;
        }
Beispiel #6
0
 private void SplitChar(string textA, string textB, DiffOption option)
 {
     this.dataA = SplitChar(textA, option);
     this.dataB = SplitChar(textB, option);
 }