Table of Contents

Struct SourceRange

Namespace
RDCore.SDK.Model.Source
Assembly
RDCore.SDK.Protocol.dll

A contiguous span in a source document, from a Start position (inclusive) to an End position (exclusive).

public readonly record struct SourceRange : IComparable<SourceRange>, IEquatable<SourceRange>
Implements
Inherited Members

Remarks

IComparable compares source location start.

Constructors

SourceRange(SourcePosition, SourcePosition)

A contiguous span in a source document, from a Start position (inclusive) to an End position (exclusive).

public SourceRange(SourcePosition Start, SourcePosition End)

Parameters

Start SourcePosition

The inclusive start position of the range.

End SourcePosition

The exclusive end position of the range.

Remarks

IComparable compares source location start.

SourceRange(int, int, int, int)

Creates a SourceRange from zero-based start/end line numbers and character offsets.

public SourceRange(int startLine, int startCharacter, int endLine, int endCharacter)

Parameters

startLine int
startCharacter int
endLine int
endCharacter int

Properties

Empty

Gets an empty range at position L0C0.

public static SourceRange Empty { get; }

Property Value

SourceRange

End

The exclusive end position of the range.

public SourcePosition End { get; init; }

Property Value

SourcePosition

IsEmpty

true if this range spans no characters (Start and End are the same position).

public bool IsEmpty { get; }

Property Value

bool

Start

The inclusive start position of the range.

public SourcePosition Start { get; init; }

Property Value

SourcePosition

Methods

CompareTo(SourceRange)

Compares two ranges by where they start, in document order.

public int CompareTo(SourceRange other)

Parameters

other SourceRange

The range to compare with.

Returns

int

Less than zero when this range starts before other, zero when they start at the same position, greater than zero when it starts after.

Contains(SourcePosition)

Whether a position is in the range: at its Start, or after it and before its End, which is not in it.

public bool Contains(SourcePosition position)

Parameters

position SourcePosition

The position.

Returns

bool

true when the position is in the range; always false for an empty range.

Contains(SourceRange)

Whether another range is within this one: it starts at or after Start, and ends at or before End.

public bool Contains(SourceRange range)

Parameters

range SourceRange

The other range.

Returns

bool

true when every character of range is in this range. An empty range is within this one when its position is from Start to End, both included; a range is within itself.

Intersects(SourceRange)

Whether this range and another share a character: each starts before the other ends.

public bool Intersects(SourceRange range)

Parameters

range SourceRange

The other range.

Returns

bool

true when at least one character is in both ranges. A range that ends where the other starts shares no character with it, and an empty range shares none with any range.