progress
This commit is contained in:
parent
16e76d6b31
commit
484dbfc9d9
529 changed files with 113694 additions and 0 deletions
80
AspClassic.Parser/Span.cs
Normal file
80
AspClassic.Parser/Span.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
namespace AspClassic.Parser;
|
||||
|
||||
/// <summary>
|
||||
/// Stores the location of a span of text.
|
||||
/// </summary>
|
||||
/// <remarks>The end location is exclusive.</remarks>
|
||||
public struct Span
|
||||
{
|
||||
private readonly Location _Start;
|
||||
|
||||
private readonly Location _Finish;
|
||||
|
||||
/// <summary>
|
||||
/// The start location of the span.
|
||||
/// </summary>
|
||||
public Location Start => _Start;
|
||||
|
||||
/// <summary>
|
||||
/// The end location of the span.
|
||||
/// </summary>
|
||||
public Location Finish => _Finish;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the locations in the span are valid.
|
||||
/// </summary>
|
||||
public bool IsValid => Start.IsValid && Finish.IsValid;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new span with a specific start and end location.
|
||||
/// </summary>
|
||||
/// <param name="start">The beginning of the span.</param>
|
||||
/// <param name="finish">The end of the span.</param>
|
||||
public Span(Location start, Location finish)
|
||||
{
|
||||
this = default(Span);
|
||||
_Start = start;
|
||||
_Finish = finish;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two specified Span values to see if they are equal.
|
||||
/// </summary>
|
||||
/// <param name="left">One span to compare.</param>
|
||||
/// <param name="right">The other span to compare.</param>
|
||||
/// <returns>True if the spans are the same, False otherwise.</returns>
|
||||
public static bool operator ==(Span left, Span right)
|
||||
{
|
||||
return left.Start.Index == right.Start.Index && left.Finish.Index == right.Finish.Index;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two specified Span values to see if they are not equal.
|
||||
/// </summary>
|
||||
/// <param name="left">One span to compare.</param>
|
||||
/// <param name="right">The other span to compare.</param>
|
||||
/// <returns>True if the spans are not the same, False otherwise.</returns>
|
||||
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));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue