Ejemplo n.º 1
0
        /// <summary>単一行の各文字を比較します</summary>
        /// <param name="textA">元テキスト</param>
        /// <param name="textB">変更テキスト</param>
        /// <param name="option">オプション指定</param>
        /// <returns>比較結果</returns>
        public static DiffResult[] DiffChar(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.SplitChar(textA, textB, option);
            }
            else
            {
                diff.isSwap = true;
                diff.SplitChar(textB, textA, option);
            }

            // ☆山内:一致判断匿名関数
            diff.isSame = delegate(int posA, int posB)
            {
                return(diff.dataA[posA] == diff.dataB[posB]);
            };

            return(diff.DetectDiff());
        }
Ejemplo n.º 2
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();

            return(diff.DiffCore(textA, textB, option));
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            #region テストデータ

            //      string textA = @"abc
            //defg
            //h
            //ij
            //";
            string textA = @"abc";
            string textB = @"acb";
            //string textA = @"綾金大学大学院";
            //string textB = @"大学院理工学研究科情報専攻";
            DiffOption option = new DiffOption();

            #endregion


            #region テスト001_SplitCharメソッド
#if TEST001
            // 文字コード数値変換静的メソッドテスト
            FastDiff.Test.TestSplitChar(textA, option);
#endif
            #endregion

            #region テスト002_SplitLineメソッド
#if TEST002
            // 行単位分離静的メソッドテスト
            FastDiff.Test.TestSplitLine(textA, option);
#endif
            #endregion

            #region テスト003_DiffCharメソッド
#if TEST003
            textBox1.AppendText("0123456789112345678921234567893123456789\r\n");
            textBox1.AppendText(textA.ToString() + "\r\n");
            textBox1.AppendText(textB.ToString() + "\r\n");
            textBox1.AppendText("-----------------------------\r\n");

            // 文字比較メソッドテスト
            DiffResult[] result = FastDiff.DiffChar(textA, textB);
            foreach (DiffResult x in result)
            {
                textBox1.AppendText(x.ToString() + "\r\n");
            }
#endif
            #endregion
        }