/// <summary>
 /// Constructs a <see cref="StringDifferenceOptions"/> from a given <see cref="StringDifferenceOptions"/>.
 /// </summary>
 /// <param name="other">The <see cref="StringDifferenceOptions"/> to use in constructing a new <see cref="StringDifferenceOptions"/>.</param>
 public StringDifferenceOptions(StringDifferenceOptions other) : this()
 {
     this.differenceType              = other.DifferenceType;
     this.locality                    = other.Locality;
     this.ignoreTrimWhiteSpace        = other.IgnoreTrimWhiteSpace;
     this.WordSplitBehavior           = other.WordSplitBehavior;
     this.DetermineLocalityCallback   = other.DetermineLocalityCallback;
     this.ContinueProcessingPredicate = other.ContinueProcessingPredicate;
 }
Example #2
0
        private StringDifferenceOptions GetDifferenceOptions(TextDifferenceTypes differenceTypes)
        {
            StringDifferenceTypes stringDifferenceTypes = default;

            if (differenceTypes.HasFlag(TextDifferenceTypes.Line))
            {
                stringDifferenceTypes |= StringDifferenceTypes.Line;
            }

            if (differenceTypes.HasFlag(TextDifferenceTypes.Word))
            {
                stringDifferenceTypes |= StringDifferenceTypes.Word;
            }

            if (differenceTypes.HasFlag(TextDifferenceTypes.Character))
            {
                stringDifferenceTypes |= StringDifferenceTypes.Character;
            }

            return(new StringDifferenceOptions()
            {
                DifferenceType = stringDifferenceTypes
            });
        }
 static IDifferenceCollection <string> ComputeMatches(StringDifferenceTypes differenceType, StringDifferenceOptions differenceOptions,
                                                      IList <string> leftSequence, IList <string> rightSequence,
                                                      IList <string> originalLeftSequence, IList <string> originalRightSequence)
 {
     return(MaximalSubsequenceAlgorithm.DifferenceSequences(leftSequence, rightSequence, originalLeftSequence, originalRightSequence, differenceOptions.ContinueProcessingPredicate));
 }
 static IDifferenceCollection <string> ComputeMatches(StringDifferenceTypes differenceType, StringDifferenceOptions differenceOptions,
                                                      IList <string> leftSequence, IList <string> rightSequence)
 {
     return(ComputeMatches(differenceType, differenceOptions, leftSequence, rightSequence, leftSequence, rightSequence));
 }
        IHierarchicalDifferenceCollection DiffText(ITokenizedStringListInternal left, ITokenizedStringListInternal right, StringDifferenceTypes type, StringDifferenceOptions differenceOptions)
        {
            StringDifferenceOptions nextOptions = new StringDifferenceOptions(differenceOptions);

            nextOptions.DifferenceType &= ~type;

            var diffCollection = ComputeMatches(type, differenceOptions, left, right);

            return(new HierarchicalDifferenceCollection(diffCollection, left, right, this, nextOptions));
        }
 /// <summary>
 /// Constructs a <see cref="StringDifferenceOptions"/>.
 /// </summary>
 /// <param name="differenceType">The type of string differencing to do, as a combination of line, word, and character differencing.</param>
 /// <param name="locality">The greatest distance a differencing element (line, span, or character) can move and still be considered part of the same source.  A value of 0 disables locality checking.</param>
 /// <param name="ignoreTrimWhiteSpace">Determines whether whitespace should be ignored.</param>
 public StringDifferenceOptions(StringDifferenceTypes differenceType, int locality, bool ignoreTrimWhiteSpace) : this()
 {
     this.differenceType       = differenceType;
     this.locality             = locality;
     this.ignoreTrimWhiteSpace = ignoreTrimWhiteSpace;
 }
        IHierarchicalDifferenceCollection DiffText(DecompositionListMaker left, DecompositionListMaker right, StringDifferenceOptions differenceOptions)
        {
            if (left == null)
            {
                throw new ArgumentNullException("left");
            }
            if (right == null)
            {
                throw new ArgumentNullException("right");
            }

            StringDifferenceTypes differenceType = differenceOptions.DifferenceType;

            if (differenceType == 0)
            {
                throw new ArgumentOutOfRangeException("differenceOptions");
            }

            if ((differenceType & StringDifferenceTypes.Line) != 0)
            {
                //The DecompositionListMaker creates a new copy of the list so make sure we only ask once
                var leftUnfilteredLineList  = left.UnfilteredLineList;
                var rightUnfilteredLineList = right.UnfilteredLineList;

                var diffCollection = ComputeMatches(differenceType, differenceOptions, left.FilteredLineList, right.FilteredLineList, leftUnfilteredLineList, rightUnfilteredLineList);

                //Try to clean up the differences so things align better with the block structure of typical languages.
                diffCollection = FinessedDifferenceCollection.FinesseLineDifferences(diffCollection, leftUnfilteredLineList, rightUnfilteredLineList);

                StringDifferenceOptions nextOptions = new StringDifferenceOptions(differenceOptions);
                nextOptions.DifferenceType &= ~StringDifferenceTypes.Line;

                return(new HierarchicalDifferenceCollection(diffCollection, leftUnfilteredLineList, rightUnfilteredLineList, this, nextOptions));
            }
            else if ((differenceType & StringDifferenceTypes.Word) != 0)
            {
                var leftWords  = left.WordList;
                var rightWords = right.WordList;

                var diffCollection = ComputeMatches(StringDifferenceTypes.Word, differenceOptions, leftWords, rightWords);

                StringDifferenceOptions nextOptions = new StringDifferenceOptions(differenceOptions);
                nextOptions.DifferenceType &= ~StringDifferenceTypes.Word;

                return(new HierarchicalDifferenceCollection(diffCollection, leftWords, rightWords, this, nextOptions));
            }
            else if ((differenceType & StringDifferenceTypes.Character) != 0)
            {
                var leftChars  = left.CharacterList;
                var rightChars = right.CharacterList;

                var diffCollection = ComputeMatches(StringDifferenceTypes.Character, differenceOptions, leftChars, rightChars);

                // This should always be 0.
                StringDifferenceOptions nextOptions = new StringDifferenceOptions(differenceOptions);
                nextOptions.DifferenceType &= ~StringDifferenceTypes.Character;

                Debug.Assert(nextOptions.DifferenceType == 0,
                             "After character differencing, the difference type should be empty (invalid).");

                return(new HierarchicalDifferenceCollection(diffCollection, leftChars, rightChars, this, nextOptions));
            }
            else
            {
                throw new ArgumentOutOfRangeException("differenceOptions");
            }
        }