예제 #1
0
        public int GetSourceMatchLength(int destIndex, int sourceIndex, int maxLength)
        {
            int matchCount;

            for (matchCount = 0; matchCount < maxLength; matchCount++)
            {
                if (dest.GetByIndex(destIndex + matchCount).CompareTo(source.GetByIndex(sourceIndex + matchCount)) != 0)
                {
                    break;
                }
            }
            return(matchCount);
        }
예제 #2
0
파일: Engine.cs 프로젝트: BlueSky007/Demo55
        //比如当前新文件的当前行为第1行,与老版本的每一行进行比较。
        private int GetSourceMatchLength(int destIndex, int sourceIndex, int maxLength)
        {
            int matchCount;

            for (matchCount = 0; matchCount < maxLength; matchCount++)
            {
                if (_dest.GetByIndex(destIndex + matchCount).CompareTo(_source.GetByIndex(sourceIndex + matchCount)) != 0)
                {
                    break;//如果比较:两个行不相同 就跳出循环
                }
            }
            return(matchCount);
        }
예제 #3
0
파일: FormMain.cs 프로젝트: Gvin/Diplom
        private void ShowResult(IDiffList source, IDiffList destination, ArrayList result)
        {
            int cnt = 1;
            int i;

            foreach (DiffResultSpan drs in result)
            {
                ListViewItem lviS;
                ListViewItem lviD;
                switch (drs.Status)
                {
                    case DiffResultSpanStatus.DeleteSource:
                        for (i = 0; i < drs.Length; i++)
                        {
                            lviS = new ListViewItem(cnt.ToString("00000"));
                            lviD = new ListViewItem(cnt.ToString("00000"));
                            lviS.BackColor = Color.Red;
                            lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line);
                            lviD.BackColor = Color.LightGray;
                            lviD.SubItems.Add("");

                            lvSource.Items.Add(lviS);
                            lvDest.Items.Add(lviD);
                            cnt++;
                        }

                        break;
                    case DiffResultSpanStatus.NoChange:
                        for (i = 0; i < drs.Length; i++)
                        {
                            lviS = new ListViewItem(cnt.ToString("00000"));
                            lviD = new ListViewItem(cnt.ToString("00000"));
                            lviS.BackColor = Color.White;
                            lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line);
                            lviD.BackColor = Color.White;
                            lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line);

                            lvSource.Items.Add(lviS);
                            lvDest.Items.Add(lviD);
                            cnt++;
                        }

                        break;
                    case DiffResultSpanStatus.AddDestination:
                        for (i = 0; i < drs.Length; i++)
                        {
                            lviS = new ListViewItem(cnt.ToString("00000"));
                            lviD = new ListViewItem(cnt.ToString("00000"));
                            lviS.BackColor = Color.LightGray;
                            lviS.SubItems.Add("");
                            lviD.BackColor = Color.LightGreen;
                            lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line);

                            lvSource.Items.Add(lviS);
                            lvDest.Items.Add(lviD);
                            cnt++;
                        }

                        break;
                    case DiffResultSpanStatus.Replace:
                        for (i = 0; i < drs.Length; i++)
                        {
                            lviS = new ListViewItem(cnt.ToString("00000"));
                            lviD = new ListViewItem(cnt.ToString("00000"));
                            lviS.BackColor = Color.Red;
                            lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line);
                            lviD.BackColor = Color.LightGreen;
                            lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line);

                            lvSource.Items.Add(lviS);
                            lvDest.Items.Add(lviD);
                            cnt++;
                        }

                        break;
                }
            }
        }
예제 #4
0
        public Results(IDiffList source, IDiffList destination, ArrayList DiffLines, double seconds)
        {
            InitializeComponent();
            this.Text = string.Format("Results: {0} secs.", seconds.ToString("#0.00"));
            ListViewItem lviS;
            ListViewItem lviD;
            int          cnt = 1;
            int          i;

            foreach (DiffResultSpan drs in DiffLines)
            {
                switch (drs.Status)
                {
                case DiffResultSpanStatus.DeleteSource:
                    for (i = 0; i < drs.Length; i++)
                    {
                        lviS           = new ListViewItem(cnt.ToString("00000"));
                        lviD           = new ListViewItem(cnt.ToString("00000"));
                        lviS.BackColor = Color.Red;
                        lviS.SubItems.Add((source.GetByIndex(drs.SourceIndex + i)).ToString());
                        lviD.BackColor = Color.LightGray;
                        lviD.SubItems.Add("");
                        lvSource.Items.Add(lviS);
                        lvDestination.Items.Add(lviD);
                        cnt++;
                    }
                    break;

                case DiffResultSpanStatus.NoChange:
                    for (i = 0; i < drs.Length; i++)
                    {
                        lviS           = new ListViewItem(cnt.ToString("00000"));
                        lviD           = new ListViewItem(cnt.ToString("00000"));
                        lviS.BackColor = Color.White;
                        lviS.SubItems.Add((source.GetByIndex(drs.SourceIndex + i)).ToString());
                        lviD.BackColor = Color.White;
                        lviD.SubItems.Add((destination.GetByIndex(drs.DestIndex + i)).ToString());
                        lvSource.Items.Add(lviS);
                        lvDestination.Items.Add(lviD);
                        cnt++;
                    }
                    break;

                case DiffResultSpanStatus.AddDestination:
                    for (i = 0; i < drs.Length; i++)
                    {
                        lviS           = new ListViewItem(cnt.ToString("00000"));
                        lviD           = new ListViewItem(cnt.ToString("00000"));
                        lviS.BackColor = Color.LightGray;
                        lviS.SubItems.Add("");
                        lviD.BackColor = Color.LightGreen;
                        lviD.SubItems.Add((destination.GetByIndex(drs.DestIndex + i)).ToString());
                        lvSource.Items.Add(lviS);
                        lvDestination.Items.Add(lviD);
                        cnt++;
                    }
                    break;

                case DiffResultSpanStatus.Replace:
                    for (i = 0; i < drs.Length; i++)
                    {
                        lviS           = new ListViewItem(cnt.ToString("00000"));
                        lviD           = new ListViewItem(cnt.ToString("00000"));
                        lviS.BackColor = Color.Red;
                        lviS.SubItems.Add((source.GetByIndex(drs.SourceIndex + i)).ToString());
                        lviD.BackColor = Color.LightGreen;
                        lviD.SubItems.Add((destination.GetByIndex(drs.DestIndex + i)).ToString());
                        lvSource.Items.Add(lviS);
                        lvDestination.Items.Add(lviD);
                        cnt++;
                    }
                    break;
                }
            }
        }