/// <summary>
        /// Initializes a new instance of a <see cref="NormalizedSnapshotSpanCollection"/> from a list of <see cref="SnapshotSpan"/> objects.
        /// </summary>
        /// <param name="snapshotSpans">An arbitrary set of <see cref="SnapshotSpan"/> objects.</param>
        /// <exception cref="ArgumentNullException"><paramref name="snapshotSpans"/> is null.</exception>
        /// <exception cref="ArgumentException">A <see cref="SnapshotSpan"/> is uninitialized, or it
        /// does not refer to the same <see cref="ITextSnapshot"/> as the other snapshot spans, or it refers to an uninitialized <see cref="ITextSnapshot"/>.</exception>
        public NormalizedSnapshotSpanCollection(IList <SnapshotSpan> snapshotSpans)
        {
            // TODO: possibly eliminate based on slight usage?
            if (snapshotSpans == null)
            {
                throw new ArgumentNullException(nameof(snapshotSpans));
            }

            if (snapshotSpans.Count == 0)
            {
                // empty collection
            }
            else
            {
                this.snapshot = snapshotSpans[0].Snapshot;
                if (this.snapshot == null)
                {
                    throw new ArgumentException(Strings.UninitializedSnapshotSpan);
                }
                if (snapshotSpans.Count == 1)
                {
                    // length one
                    this.span = snapshotSpans[0].Span;
                }
                else
                {
                    // length at least two
                    bool        alreadyNormalized = true;
                    List <Span> spans             = new List <Span>(snapshotSpans.Count);
                    Span        currentSpan       = snapshotSpans[0].Span;
                    spans.Add(currentSpan);
                    int lastEnd = currentSpan.End;
                    for (int s = 1; s < snapshotSpans.Count; ++s)
                    {
                        if (snapshotSpans[s].Snapshot != this.snapshot)
                        {
                            if (snapshotSpans[s].Snapshot == null)
                            {
                                throw new ArgumentException(Strings.UninitializedSnapshotSpan);
                            }
                            else
                            {
                                throw new ArgumentException(Strings.InvalidSnapshot);
                            }
                        }
                        currentSpan = snapshotSpans[s].Span;
                        spans.Add(currentSpan);
                        if (currentSpan.Start <= lastEnd)
                        {
                            alreadyNormalized = false;
                        }
                        lastEnd = currentSpan.End;
                    }
                    this.spans = alreadyNormalized
                                    ? NormalizedSpanCollection.CreateFromNormalizedSpans(spans)
                                    : new NormalizedSpanCollection(spans);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of a <see cref="NormalizedSnapshotSpanCollection"/> from a list of <see cref="SnapshotSpan"/> objects.
        /// </summary>
        /// <param name="snapshotSpans">An arbitrary set of <see cref="SnapshotSpan"/> objects.</param>
        /// <exception cref="ArgumentNullException"><paramref name="snapshotSpans"/> is null.</exception>
        /// <exception cref="ArgumentException">A <see cref="SnapshotSpan"/> is uninitialized, or it
        /// does not refer to the same <see cref="ITextSnapshot"/> as the other snapshot spans, or it refers to an uninitialized <see cref="ITextSnapshot"/>.</exception>
        public NormalizedSnapshotSpanCollection(IEnumerable <SnapshotSpan> snapshotSpans)
        {
            if (snapshotSpans == null)
            {
                throw new ArgumentNullException(nameof(snapshotSpans));
            }

            using (IEnumerator <SnapshotSpan> spanEnumerator = snapshotSpans.GetEnumerator())
            {
                if (!spanEnumerator.MoveNext())
                {
                    // empty
                }
                else
                {
                    SnapshotSpan firstSpan = spanEnumerator.Current;
                    this.snapshot = firstSpan.Snapshot;
                    if (!spanEnumerator.MoveNext())
                    {
                        // length one
                        this.span = firstSpan.Span;
                    }
                    else
                    {
                        // length at least two
                        bool        alreadyNormalized = true;
                        List <Span> spans             = new List <Span>();
                        Span        currentSpan       = firstSpan.Span;
                        spans.Add(currentSpan);
                        int lastEnd = currentSpan.End;
                        do
                        {
                            SnapshotSpan snapshotSpan = spanEnumerator.Current;
                            if (snapshotSpan.Snapshot != this.snapshot)
                            {
                                if (snapshotSpan.Snapshot == null)
                                {
                                    throw new ArgumentException(Strings.UninitializedSnapshotSpan);
                                }
                                else
                                {
                                    throw new ArgumentException(Strings.InvalidSnapshot);
                                }
                            }
                            currentSpan = snapshotSpan.Span;
                            spans.Add(currentSpan);
                            if (currentSpan.Start <= lastEnd)
                            {
                                alreadyNormalized = false;
                            }
                            lastEnd = currentSpan.End;
                        } while (spanEnumerator.MoveNext());
                        this.spans = alreadyNormalized
                                        ? NormalizedSpanCollection.CreateFromNormalizedSpans(spans)
                                        : new NormalizedSpanCollection(spans);
                    }
                }
            }
        }