public ReadOnlyTextRangeCollection(TextRangeCollection <T> collection) { _collection = collection; }
/// <summary> /// Compares two collections and calculates 'changed' range. In case this collection /// or comparand are empty, uses lowerBound and upperBound values as range /// delimiters. Typically lowerBound is 0 and upperBound is lentgh of the file. /// </summary> /// <param name="otherCollection">Collection to compare to</param> public virtual ITextRange RangeDifference(IEnumerable <ITextRange> otherCollection, int lowerBound, int upperBound) { if (otherCollection == null) { return(TextRange.FromBounds(lowerBound, upperBound)); } var other = new TextRangeCollection <ITextRange>(otherCollection); if (this.Count == 0 && other.Count == 0) { return(TextRange.EmptyRange); } if (this.Count == 0) { return(TextRange.FromBounds(lowerBound, upperBound)); } if (other.Count == 0) { return(TextRange.FromBounds(lowerBound, upperBound)); } int minCount = Math.Min(this.Count, other.Count); int start = 0; int end = 0; int i, j; for (i = 0; i < minCount; i++) { start = Math.Min(this[i].Start, other[i].Start); if (this[i].Start != other[i].Start || this[i].Length != other[i].Length) { break; } } if (i == minCount) { if (this.Count == other.Count) { return(TextRange.EmptyRange); } if (this.Count > other.Count) { return(TextRange.FromBounds(Math.Min(upperBound, other[minCount - 1].Start), upperBound)); } else { return(TextRange.FromBounds(Math.Min(this[minCount - 1].Start, upperBound), upperBound)); } } for (i = this.Count - 1, j = other.Count - 1; i >= 0 && j >= 0; i--, j--) { end = Math.Max(this[i].End, other[j].End); if (this[i].Start != other[j].Start || this[i].Length != other[j].Length) { break; } } if (start < end) { return(TextRange.FromBounds(start, end)); } return(TextRange.FromBounds(lowerBound, upperBound)); }