namespace AspClassic.Parser; /// /// Stores the location of a span of text. /// /// The end location is exclusive. public struct Span { private readonly Location _Start; private readonly Location _Finish; /// /// The start location of the span. /// public Location Start => _Start; /// /// The end location of the span. /// public Location Finish => _Finish; /// /// Whether the locations in the span are valid. /// public bool IsValid => Start.IsValid && Finish.IsValid; /// /// Constructs a new span with a specific start and end location. /// /// The beginning of the span. /// The end of the span. public Span(Location start, Location finish) { this = default(Span); _Start = start; _Finish = finish; } /// /// Compares two specified Span values to see if they are equal. /// /// One span to compare. /// The other span to compare. /// True if the spans are the same, False otherwise. public static bool operator ==(Span left, Span right) { return left.Start.Index == right.Start.Index && left.Finish.Index == right.Finish.Index; } /// /// Compares two specified Span values to see if they are not equal. /// /// One span to compare. /// The other span to compare. /// True if the spans are not the same, False otherwise. public static bool operator !=(Span left, Span right) { return left.Start.Index != right.Start.Index || left.Finish.Index != right.Finish.Index; } public override string ToString() { return Start.ToString() + " - " + Finish.ToString(); } public override bool Equals(object obj) { if (obj is Span) { return this == (Span)obj; } return false; } public override int GetHashCode() { return checked((int)((Start.Index ^ Finish.Index) & 0xFFFFFFFFu)); } }