Home > @gglib/utils > TextReader

TextReader class

A wrapper around a string. Simplifies reading arbitrary formatted text data.


export declare class TextReader 


Constructor Modifiers Description
(constructor)(text) Creates a new instance of TextReader


Property Modifiers Type Description
canRead boolean Checks whether the readers position has not reached the end of the string
char string Gets the character at the current readers position.
rest string Gets a substring until the end of the string.
whitespaces string Characters that identify a white space. Default is ' \t\r\n\f'.


Method Modifiers Description
acceptToken(value) Consumes the next token only if it matches the given value. Otherwise leaves the state untouched.
consumeToken(value) Reads the next token but throws an error if it does not match the given value
next() Advances the readers position to the next character.
nextBlock(start, end, cb) Skips until next occurrence of start character and then reads the text until the end character
nextLine(cb) Reads until next occurrence of a new line character
nextToken() Skips whites paces at current position and then reads until next whitespace character
peek() Returns the next character but does not advance the reader position.
peekLine() Returns the current line but does not advance the reader position
peekToken() Returns the next token but does not advance the reader position.
skipUntil(char, andBeyond) Skips characters until occurrence of one in the given string
skipWhile(char) Skips all characters in given string
skipWhitespace() Skips all whitespace characters