/// <summary>
        /// Calculates span that includes both supplied spans.
        /// </summary>
        public static LinearSpan Union(LinearSpan span1, LinearSpan span2)
        {
            var start = Math.Min(span1.Start, span2.Start);
            var end   = Math.Max(span1.End, span2.End);

            return(start <= end?FromBounds(start, end) : EmptySpan);
        }
        /// <summary>
        /// Calculates span that is an intersection of the supplied spans.
        /// </summary>
        /// <returns>Intersection or empty span if spans don't intersect</returns>
        public static LinearSpan Intersection(LinearSpan span1, int spanStart, int spanLength)
        {
            var start = Math.Max(span1.Start, spanStart);
            var end   = Math.Min(span1.End, spanStart + spanLength);

            return(start <= end?FromBounds(start, end) : EmptySpan);
        }
Beispiel #3
0
 public static LinearSpan ToLinearSpan(this Range range, PythonAst ast)
 => LinearSpan.FromBounds(ast.LocationToIndex(range.start), ast.LocationToIndex(range.end));
Beispiel #4
0
 public static LinearSpan ToLinearSpan(this SourceSpan span, PythonAst ast)
 => LinearSpan.FromBounds(ast.LocationToIndex(span.Start), ast.LocationToIndex(span.End));
 /// <summary>
 /// Creates span based on another span
 /// </summary>
 /// <param name="span">Span to use as position source</param>
 public LinearSpan(LinearSpan span) : this(span.Start, span.Length)
 {
 }
 public static bool Intersect(LinearSpan span1, int spanStart2, int spanLength2)
 => Intersect(span1.Start, span1.Length, spanStart2, spanLength2);
 public static bool Intersect(LinearSpan span1, LinearSpan span2)
 => Intersect(span1, span2.Start, span2.Length);
 public static bool Contains(LinearSpan span, LinearSpan other) => span.Contains(other.Start) && span.Contains(other.End);
 public static bool Contains(LinearSpan span, int position) => Contains(span.Start, span.Length, position);
 public static bool IsValid(LinearSpan span) => span != null && span.Length > 0;
 public virtual bool Contains(LinearSpan span) => Contains(span.Start) && Contains(span.End);
 public virtual bool Intersect(LinearSpan span) => Intersect(this, span.Start, span.Length);