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));
        }
        internal static List <Span> GetContiguousSpans(Span span, ITokenizedStringListInternal tokens)
        {
            List <Span> result = new List <Span>();
            int         start  = span.Start;

            for (int i = span.Start + 1; (i < span.End); ++i)
            {
                if (tokens.GetElementInOriginal(i - 1).End != tokens.GetElementInOriginal(i).Start)
                {
                    result.Add(Span.FromBounds(start, i));
                    start = i;
                }
            }

            if (start < span.End)
            {
                result.Add(Span.FromBounds(start, span.End));
            }

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Create a new hierarchical difference collection.
        /// </summary>
        /// <param name="differenceCollection">The underlying difference collection for this level
        /// of the hierarchy.</param>
        /// <param name="differenceService">The difference service to use for doing the next level of
        /// differencing</param>
        /// <param name="options">The options to use for the next level of differencing.
        /// If <see cref="StringDifferenceOptions.DifferenceType" /> is <c>0</c>, then
        /// no further differencing will take place.</param>
        public HierarchicalDifferenceCollection(IDifferenceCollection <string> differenceCollection,
                                                ITokenizedStringListInternal left,
                                                ITokenizedStringListInternal right,
                                                ITextDifferencingService differenceService,
                                                StringDifferenceOptions options)
        {
            if (differenceCollection == null)
            {
                throw new ArgumentNullException(nameof(differenceCollection));
            }
            if (left == null)
            {
                throw new ArgumentNullException(nameof(left));
            }
            if (right == null)
            {
                throw new ArgumentNullException(nameof(right));
            }
            if (!object.ReferenceEquals(left, differenceCollection.LeftSequence))
            {
                throw new ArgumentException("left must equal differenceCollection.LeftSequence");
            }
            if (!object.ReferenceEquals(right, differenceCollection.RightSequence))
            {
                throw new ArgumentException("right must equal differenceCollection.RightSequence");
            }

            this.left  = left;
            this.right = right;

            this.differenceCollection = differenceCollection;
            this.differenceService    = differenceService;
            this.options = options;

            containedDifferences = new ConcurrentDictionary <int, IHierarchicalDifferenceCollection>();
        }