Lyricdev
GitHub

class TextReader

pub class TextReader<R :: [Reader]>

A reader of UTF-8 text: a BufReader and a decoder. A codepoint split between two reads of the inner reader waits in the buffer for its rest; bytes that are no UTF-8 throw InvalidData, a Utf8Error as the cause with the offset counted from the reader's start. A byte order mark is text like any other, unless skipBom drops it from the front. It throws what its inner reader may (Reader).

Methods

pub static fn new(inner: R, skipBom: bool = false): TextReader<R>
pub mut fn readLine(): ?string throws [IoError, Cancelled]

Reads the next line without its end — a \n or a \r\n —; returns null at the end. A last line without an end is a line; the end of the last one starts none.

Errors

Throws InvalidData for bytes that are no UTF-8, and what the inner reader throws.

pub fn lines(): TextLinesIter<R>

Returns the lines to the end, as readLine gives them.

pub fn chars(): TextCharsIter<R>

Returns the characters to the end, one codepoint at a time.

pub mut fn readToEnd(): string throws [IoError, Cancelled]

Reads everything to the end and returns it as text.

Errors

Throws InvalidData for bytes that are no UTF-8, and what the inner reader throws.