module

Bidi::TextSource

Abstract text source for bidi algorithms. In Crystal, we only implement this for String (UTF-8). This corresponds to Rust's TextSource trait.

Class methods

char_at(text : String, index : Int32) : Tuple(Char, Int32) | Nil

Get the character at a given byte index, along with its length in bytes. Returns nil if index is out of range or points inside a multi-byte character.

Source
char_indices(text : String) : Array(Tuple(Int32, Char))

Get an array of (byte_index, char) pairs for each character.

Source
char_len(char : Char) : Int32

Number of bytes a character uses in UTF-8.

Source
each_char_with_index(text : String, &block : Int32, Char, Int32 -> )

Iterate over characters with their byte indices and lengths. Yields (byte_index, char, char_length) for each character.

Source
indices_lengths(text : String) : Array(Tuple(Int32, Int32))

Get an array of (byte_index, char_length) pairs for each character.

Source