Table of Contents

Class SourceText

Namespace
MuLang.Core.Text
Assembly
MuLang.Core.dll

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

int

LineCount

Gets the number of source lines.

public int LineCount { get; }

Property Value

int

LineMap

Gets the source line map.

public TextLineMap LineMap { get; }

Property Value

TextLineMap

Text

Gets the underlying MuLang source string.

public string Text { get; }

Property Value

string

Methods

From(string)

Creates source text from a MuLang source string.

public static SourceText From(string text)

Parameters

text string

The source text.

Returns

SourceText

The source-text representation.

Exceptions

ArgumentNullException

Thrown when text is null.

ArgumentException

Thrown when text contains invalid UTF-16.

GetPosition(int)

Gets the line and column for a Unicode scalar offset.

public TextPosition GetPosition(int offset)

Parameters

offset int

The Unicode scalar offset.

Returns

TextPosition

The corresponding source position.

Exceptions

ArgumentOutOfRangeException

Thrown when offset is outside the source-text bounds.

GetRune(int)

Gets the Unicode scalar value at an offset.

public Rune GetRune(int offset)

Parameters

offset int

The Unicode scalar offset.

Returns

Rune

The Unicode scalar value at the specified offset.

Exceptions

ArgumentOutOfRangeException

Thrown when offset does 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

span TextSpan

The 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

offset int

The Unicode scalar offset.

Returns

int

The corresponding zero-based UTF-16 code-unit offset.

Exceptions

ArgumentOutOfRangeException

Thrown when offset is outside the source-text bounds.