2018-11-10 12:11:36 +00:00
|
|
|
namespace Upsilon.Text
|
|
|
|
{
|
|
|
|
public struct TextSpan
|
|
|
|
{
|
2019-01-16 22:57:42 +00:00
|
|
|
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)
|
2018-11-10 12:11:36 +00:00
|
|
|
{
|
2019-01-16 22:57:42 +00:00
|
|
|
StartLine = startLine;
|
|
|
|
StartPosition = startPosition;
|
|
|
|
EndLine = endLine;
|
|
|
|
EndPosition = endPosition;
|
2018-11-10 12:11:36 +00:00
|
|
|
}
|
|
|
|
|
2018-11-17 13:37:41 +00:00
|
|
|
public override string ToString()
|
|
|
|
{
|
2019-01-16 22:57:42 +00:00
|
|
|
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)
|
|
|
|
{
|
2019-01-17 18:24:00 +00:00
|
|
|
if (StartLine == EndLine && linePosition == StartLine)
|
|
|
|
{
|
2019-01-18 15:09:25 +00:00
|
|
|
return characterPosition >= StartPosition && characterPosition <= EndPosition;
|
2019-01-17 18:24:00 +00:00
|
|
|
}
|
2019-01-17 17:34:58 +00:00
|
|
|
if (StartLine == linePosition && StartPosition <= characterPosition) return true;
|
|
|
|
if (StartLine < linePosition && EndLine > linePosition) return true;
|
|
|
|
if (EndLine == linePosition && EndPosition >= characterPosition) return true;
|
|
|
|
return false;
|
2018-11-17 13:37:41 +00:00
|
|
|
}
|
2018-11-10 12:11:36 +00:00
|
|
|
}
|
|
|
|
}
|