SourceText

class SourceText(val text: String, val id: String? = null, val origin: SourcePosition = SourcePosition(0, 0, 0)) : Source

Immutable source text together with an optional diagnostic identifier.

origin is non-zero for a materialized fragment of a streamed source. The text property then contains only that fragment, while every position returned by this class remains absolute.

val fragment = SourceText("foo\nbar", "fragment", SourcePosition(100, 7, 11))
check(fragment.positionAt(104) == SourcePosition(104, 8, 0))

Constructors

Link copied to clipboard
constructor(text: String, id: String? = null, origin: SourcePosition = SourcePosition(0, 0, 0))

Properties

Link copied to clipboard
open override val endExclusive: SourcePosition

First position after the text retained by this view.

Link copied to clipboard
open override val id: String?

optional diagnostic source identifier

Link copied to clipboard

absolute position corresponding to text[0]

Link copied to clipboard
open override val start: SourcePosition

First position whose text is retained by this view.

Link copied to clipboard

complete retained fragment

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Compares retained text, source identifier, and origin.

Link copied to clipboard
open override fun hashCode(): Int

Returns a hash derived from retained text, source identifier, and origin.

Link copied to clipboard
open override fun positionAt(offset: Int): SourcePosition

Converts an absolute UTF-16 string offset into a zero-based line and column.

Link copied to clipboard
open fun span(startOffset: Int, endExclusiveOffset: Int): SourceSpan

Creates a span from two absolute offsets.

Link copied to clipboard
open fun text(span: SourceSpan): String

Returns text covered by span.

open override fun text(startOffset: Int = start.offset, endExclusiveOffset: Int = endExclusive.offset): String
Link copied to clipboard
open override fun toString(): String

Returns id, or <source> when this source is anonymous.