Class SourceText
Represents MuLang source text indexed by Unicode scalar values.
public sealed class SourceText
- Inheritance
-
SourceText
- Inherited Members
Properties
Length
Gets the length in Unicode scalar values.
public int Length { get; }
Property Value
LineCount
Gets the number of source lines.
public int LineCount { get; }
Property Value
LineMap
Gets the source line map.
public TextLineMap LineMap { get; }
Property Value
Text
Gets the underlying MuLang source string.
public string Text { get; }
Property Value
Methods
From(string)
Creates source text from a MuLang source string.
public static SourceText From(string text)
Parameters
textstringThe source text.
Returns
- SourceText
The source-text representation.
Exceptions
- ArgumentNullException
Thrown when
textisnull.- ArgumentException
Thrown when
textcontains invalid UTF-16.
GetPosition(int)
Gets the line and column for a Unicode scalar offset.
public TextPosition GetPosition(int offset)
Parameters
offsetintThe Unicode scalar offset.
Returns
- TextPosition
The corresponding source position.
Exceptions
- ArgumentOutOfRangeException
Thrown when
offsetis outside the source-text bounds.
GetRune(int)
Gets the Unicode scalar value at an offset.
public Rune GetRune(int offset)
Parameters
offsetintThe Unicode scalar offset.
Returns
- Rune
The Unicode scalar value at the specified offset.
Exceptions
- ArgumentOutOfRangeException
Thrown when
offsetdoes not identify a scalar value.- InvalidOperationException
Thrown when the stored source text contains invalid UTF-16.
GetText(TextSpan)
Gets the text within a source span.
public string GetText(TextSpan span)
Parameters
spanTextSpanThe source span.
Returns
- string
The text contained in the span.
Exceptions
- ArgumentOutOfRangeException
Thrown when the span is outside the source-text bounds.
- OverflowException
Thrown when the span end exceeds MaxValue.
GetUtf16Offset(int)
Gets the UTF-16 code-unit offset for a Unicode scalar offset.
public int GetUtf16Offset(int offset)
Parameters
offsetintThe Unicode scalar offset.
Returns
- int
The corresponding zero-based UTF-16 code-unit offset.
Exceptions
- ArgumentOutOfRangeException
Thrown when
offsetis outside the source-text bounds.