TextSpan Struct

Represents a contiguous character range in text.

public readonly struct TextSpan : IComparable<TextSpan>, IEquatable<TextSpan>

Example

var span = new TextSpan(start: 5, length: 3);
var sameSpan = TextSpan.FromBounds(5, 8);
Assert.Equal(span, sameSpan);
Assert.Equal(8, span.End);
Implements

Constructors

NameDescription
TextSpan(int, int)

TextSpan(int, int)

TextSpan.cs
public TextSpan(int start, int length)

Parameters

start int
length int

No documentation is available.

Properties

NameDescription
End
IsEmptyGets a value indicating whether the span is zero-length.
Length
Start
public int End { get; }

Property value

int

No documentation is available.

Gets a value indicating whether the span is zero-length.

public bool IsEmpty { get; }

Property value

bool

public int Length { get; }

Property value

int

No documentation is available.

public int Start { get; }

Property value

int

No documentation is available.

Methods

NameDescription
CompareTo(TextSpan)Orders spans by TextSpan.Start, then by TextSpan.Length.
Contains(TextSpan)Determines whether the span contains all of span.
Contains(int)Determines whether the span contains position. The end of the span is exclusive.
Equals(TextSpan)
Equals(object?)
FromBounds(int, int)
GetHashCode()
Intersection(TextSpan)Returns the intersection of the two spans, or null when they do not intersect. Two spans that only touch intersect in an empty span.
IntersectsWith(TextSpan)Determines whether the two spans share at least one character or touch at an endpoint.
IntersectsWith(int)Determines whether position is inside the span or at its end.
Overlap(TextSpan)Returns the overlap of the two spans, or null when they do not overlap.
OverlapsWith(TextSpan)Determines whether the two spans share at least one character. Empty spans never overlap.
ToString()

CompareTo(TextSpan)

TextSpan.cs

Orders spans by TextSpan.Start, then by TextSpan.Length.

public int CompareTo(TextSpan other)

Parameters

other TextSpan

Returns

int

Contains overloads

Contains(TextSpan)

TextSpan.cs

Determines whether the span contains all of span.

public bool Contains(TextSpan span)
Parameters
span TextSpan
Returns

bool

Contains(int)

TextSpan.cs

Determines whether the span contains position. The end of the span is exclusive.

public bool Contains(int position)
Parameters
position int
Returns

bool

Equals overloads

Equals(TextSpan)

TextSpan.cs
public bool Equals(TextSpan other)
Parameters
other TextSpan
Returns

bool

No documentation is available.

Equals(object?)

TextSpan.cs
public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

FromBounds(int, int)

TextSpan.cs
public static TextSpan FromBounds(int start, int end)

Parameters

start int
end int

Returns

TextSpan

No documentation is available.

GetHashCode()

TextSpan.cs
public override int GetHashCode()

Returns

int

No documentation is available.

Intersection(TextSpan)

TextSpan.cs

Returns the intersection of the two spans, or null when they do not intersect. Two spans that only touch intersect in an empty span.

public TextSpan? Intersection(TextSpan span)

Parameters

span TextSpan

Returns

TextSpan?

IntersectsWith overloads

IntersectsWith(TextSpan)

TextSpan.cs

Determines whether the two spans share at least one character or touch at an endpoint.

public bool IntersectsWith(TextSpan span)
Parameters
span TextSpan
Returns

bool

IntersectsWith(int)

TextSpan.cs

Determines whether position is inside the span or at its end.

public bool IntersectsWith(int position)
Parameters
position int
Returns

bool

Overlap(TextSpan)

TextSpan.cs

Returns the overlap of the two spans, or null when they do not overlap.

public TextSpan? Overlap(TextSpan span)

Parameters

span TextSpan

Returns

TextSpan?

OverlapsWith(TextSpan)

TextSpan.cs

Determines whether the two spans share at least one character. Empty spans never overlap.

public bool OverlapsWith(TextSpan span)

Parameters

span TextSpan

Returns

bool

ToString()

TextSpan.cs
public override string ToString()

Returns

string

No documentation is available.

Operators

NameDescription
operator ==(TextSpan, TextSpan)
operator >(TextSpan, TextSpan)
operator >=(TextSpan, TextSpan)
operator !=(TextSpan, TextSpan)
operator <(TextSpan, TextSpan)
operator <=(TextSpan, TextSpan)

operator ==(TextSpan, TextSpan)

TextSpan.cs
public static bool operator ==(TextSpan left, TextSpan right)

Parameters

left TextSpan
right TextSpan

Returns

bool

No documentation is available.

operator >(TextSpan, TextSpan)

TextSpan.cs
public static bool operator >(TextSpan left, TextSpan right)

Parameters

left TextSpan
right TextSpan

Returns

bool

No documentation is available.

operator >=(TextSpan, TextSpan)

TextSpan.cs
public static bool operator >=(TextSpan left, TextSpan right)

Parameters

left TextSpan
right TextSpan

Returns

bool

No documentation is available.

operator !=(TextSpan, TextSpan)

TextSpan.cs
public static bool operator !=(TextSpan left, TextSpan right)

Parameters

left TextSpan
right TextSpan

Returns

bool

No documentation is available.

operator <(TextSpan, TextSpan)

TextSpan.cs
public static bool operator <(TextSpan left, TextSpan right)

Parameters

left TextSpan
right TextSpan

Returns

bool

No documentation is available.

operator <=(TextSpan, TextSpan)

TextSpan.cs
public static bool operator <=(TextSpan left, TextSpan right)

Parameters

left TextSpan
right TextSpan

Returns

bool

No documentation is available.