Пример #1
0
 private void AddChangeType(List <Diff3Change> changes, Diff3Change change)
 {
     AddChangeType(changes, change.ChangeType, change.Base, change.From1, change.From2, change.IsBaseEqualFrom1, change.IsBaseEqualFrom2);
 }
Пример #2
0
        private void AddChangeType(List <Diff3Change> changes, Diff3ChangeType changeType, Span baseSpan, Span v1Index, Span v2Index, bool?baseEqualFrom1, bool?baseEqualFrom2)
        {
            bool addNew = changes.Count == 0;

            if (!addNew)
            {
                var previousChange = changes[changes.Count - 1];
                if (previousChange.ChangeType == changeType)
                {
                    bool keepPrevious = false;

                    if (previousChange.Base == baseSpan && (previousChange.From1 != Span.Invalid || previousChange.From2 != Span.Invalid))
                    {
                        if (previousChange.From1.CanMergeWith(v1Index) && (!previousChange.IsBaseEqualFrom1.HasValue || baseEqualFrom1 == previousChange.IsBaseEqualFrom1))
                        {
                            previousChange.From1            = Span.Merge(previousChange.From1, v1Index);
                            previousChange.IsBaseEqualFrom1 = baseEqualFrom1;
                            keepPrevious = true;
                        }

                        if (previousChange.From2.CanMergeWith(v2Index) && (!previousChange.IsBaseEqualFrom2.HasValue || baseEqualFrom2 == previousChange.IsBaseEqualFrom2))
                        {
                            previousChange.From2            = Span.Merge(previousChange.From2, v2Index);
                            previousChange.IsBaseEqualFrom2 = baseEqualFrom2;
                            keepPrevious = true;
                        }
                    }
                    else
                    {
                        if (previousChange.Base.CanMergeWith(baseSpan))
                        {
                            keepPrevious = true;
                        }

                        if (previousChange.From1.CanMergeWith(v1Index))
                        {
                            previousChange.From1            = Span.Merge(previousChange.From1, v1Index);
                            previousChange.IsBaseEqualFrom1 = null;
                            keepPrevious = true;
                        }

                        if (previousChange.From2.CanMergeWith(v2Index))
                        {
                            previousChange.From2            = Span.Merge(previousChange.From2, v2Index);
                            previousChange.IsBaseEqualFrom2 = null;
                            keepPrevious = true;
                        }
                    }

                    if (keepPrevious)
                    {
                        previousChange.Base = Span.Merge(previousChange.Base, baseSpan);
                    }
                    else
                    {
                        addNew = true;
                    }
                }
                else
                {
                    addNew = true;
                }
            }

            if (addNew)
            {
                var diff3 = new Diff3Change()
                {
                    Base       = baseSpan,
                    From1      = v1Index,
                    From2      = v2Index,
                    ChangeType = changeType
                };
                if (baseEqualFrom1.HasValue)
                {
                    diff3.IsBaseEqualFrom1 = baseEqualFrom1.Value;
                }

                if (baseEqualFrom2.HasValue)
                {
                    diff3.IsBaseEqualFrom2 = baseEqualFrom2.Value;
                }


                changes.Add(diff3);
            }
        }