34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
namespace Upsilon.Text
|
|
{
|
|
public struct TextSpan
|
|
{
|
|
public int StartLine { get; }
|
|
public int StartPosition { get; }
|
|
public int EndLine { get; }
|
|
public int EndPosition { get; }
|
|
|
|
public TextSpan(int startLine, int startPosition, int endLine, int endPosition)
|
|
{
|
|
StartLine = startLine;
|
|
StartPosition = startPosition;
|
|
EndLine = endLine;
|
|
EndPosition = endPosition;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"({StartLine}, {StartPosition}) - ({EndLine}, {EndPosition})";
|
|
}
|
|
|
|
public static TextSpan Between(TextSpan start, TextSpan end)
|
|
{
|
|
return new TextSpan(start.StartLine, start.StartPosition, end.EndLine, end.EndPosition);
|
|
}
|
|
|
|
public bool Contains(int linePosition, int characterPosition)
|
|
{
|
|
return StartLine >= linePosition && EndLine <= linePosition && characterPosition >= StartPosition &&
|
|
characterPosition <= EndPosition;
|
|
}
|
|
}
|
|
} |