textio.eh
Text I/O streams. More...
Types
Functions
Description
This header provides wrappers for I/O streams, allowing to process text
in different encodings.
Reader is a text input stream and
Writer is a text output stream. Their API copies that of
IStream
and
OStream
with the only difference that they
work with characters, not bytes.
To create new reader simply wrap IStream
with suitable reader function.
Wrappers are provided for the following encodings:
You can create a text stream for arbitrary encoding (even self made) using
Reader.new and
Writer.new providing encoding functions for
them.
UTF-8 is the default encoding used in Alchemy OS. It is used, for example,
in terminal.
Type details
Text input stream.
Text output stream.
Function details
Creates new reader using the specified input stream and decoding function.
On each call the decoding function should return a single character read from the given
input stream. If the end of the stream is reached, this function should return
EOF.
Reads next character from this reader.
If the end of the stream is reached then
EOF is returned.
Reads
len characters from the input stream and writes them to the character array
buf starting at index
ofs.
The function can end up in reading less characters if the end of the stream is reached.
Returns total number of actually read characters. If no characters can be read because
stream has reached its end then
EOF is returned.
Reads specified number of characters and returns them as the string.
The function can end up reading less characters if the end of the streas is reached.
If no characters can be read then
null
is returned.
def Reader.readline(): String;
|
Reads a single line of characters from this reader.
If the end of the stream is reached then
null
is returned.
Skips over and discards
num characters.
The function may, for a variety of reasons, end up skipping over some smaller number
of characters, possibly 0. Returns total number of actually skipped characters.
Closes this reader and frees associated resources.
Creates new writer using the specified output stream and encoding function.
On each call the encoding function should write the bytes representing given character
to the output stream.
def Writer.write(ch: Int);
|
Writes given character to the output.
def Writer.writearray(buf: [Char], ofs: Int, len: Int);
|
Writes
len characters from given character array starting from index
ofs to the output.
def Writer.print(str: String);
|
Writes given string to the output.
def Writer.println(str: String);
|
Writes given string to the output and terminates a line.
Writes formatted string to the output using given format string and arguments.
See
String.format description on how formatting is used.
Forces any buffered data to be written immediately.
Closes this writer and frees associated resources.
Wraps given stream in a reader that uses UTF-8 encoding.
Wraps given stream in a writer that uses UTF-8 encoding.
Wraps given stream in a reader that uses ISO 8859-1 encoding (also known as Latin-1).
Wraps given stream in a writer that uses ISO 8859-1 encoding (also known as Latin-1).
Wraps given stream in a reader that uses UTF-16 encoding (little ending).
Wraps given stream in a writer that uses UTF-16 encoding (little ending).