Text

abstract class Text

The data structure for documents.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val children: List<Text>?

If this is a branch node, children will hold the Text objects that it is made up of. For leaf nodes, this holds null.

Link copied to clipboard

The position at the end of this document.

Link copied to clipboard

True if this document has no content.

Link copied to clipboard

True if this document has content.

Link copied to clipboard
abstract val length: Int

The length of the string.

Link copied to clipboard
abstract val lines: Int

The number of lines in the string (always >= 1).

Functions

Link copied to clipboard
fun append(other: Text): Text

Append another document to this one.

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

Retrieve a part of the document as a string using an IntRange.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun iter(dir: Int = 1): TextIterator

Iterate over the text. When dir is -1, iteration happens from end to start. This will return lines and the breaks between them as separate strings.

Link copied to clipboard
fun iterLines(from: LineNumber? = null, to: LineNumber? = null): TextIterator

Return a cursor that iterates over the given range of lines, without returning the line breaks between, and yielding empty strings for empty lines.

Link copied to clipboard
fun iterRange(from: DocPos, to: DocPos = endPos): TextIterator

Iterate over a range of the text. When from>to, the iterator will run in reverse.

Link copied to clipboard

Get the description for the given (1-based) line number.

Link copied to clipboard
fun lineAt(pos: DocPos): Line

Get the line description around the given position.

Link copied to clipboard

Return a sequence of lines in this document.

Link copied to clipboard
open fun replace(from: DocPos, to: DocPos, text: Text): Text

Replace a range of the text with the given content.

Link copied to clipboard
fun slice(from: DocPos, to: DocPos = endPos): Text

Retrieve the text between the given points.

Link copied to clipboard
abstract fun sliceString(from: DocPos, to: DocPos = endPos, lineSep: String = ""): String

Retrieve a part of the document as a string.

Link copied to clipboard

Convert the document to an array of lines (which can be deserialized again via Text.of).

Link copied to clipboard
open override fun toString(): String

Return the document as a string, using newline characters to separate lines.