ReadLine functionv0.1.0
pub func ReadLine(builder: &var StringBuilder) -> ! IoError
EndOfStream is reported only when the input ends with nothing before it; a stream failure is returned as
itself, with whatever was read so far left in the builder. The line must be UTF-8: a byte that does not belong
to a well-formed character, or a character cut short by the end of the input, is InvalidText, reported once
the rest of the line has been read through its ending so that the next call starts on the next line; the text
before the fault stays in the builder. Reads one byte at a time on purpose: standard input may be shared with
whatever runs next, and a buffer here would take bytes that were never this line's.
Parameters
| Name | Type | Description |
|---|---|---|
builder | &var StringBuilder | receives the line, appended to whatever it already holds |
Returns: success when a line was read; IsEnd at the end of input with nothing appended
Related
ReadLineFrom
pub func ReadLineFrom(
reader: &var Reader,
builder: &var StringBuilder
) -> ! IoError
Appends the next line of reader to builder, without its ending, reading one byte at a time.
This is ReadLine over any source: a line feed ends the line, a carriage return immediately before it belongs
to the ending, and EndOfStream is reported only when the source ends with nothing before it. A stream failure
is returned as itself, with whatever was read so far left in the builder. The line must be UTF-8: a byte that
does not belong to a well-formed character, or a character cut short by the end of the source, is
InvalidText, reported once the rest of the line has been read through its ending; the text before the fault
stays in the builder. No byte past the line's ending is read, which is what makes it safe on a shared stream;
a source that is not shared reads faster through ReadTextLine over a BufferedReader.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from, borrowed for the call |
builder | &var StringBuilder | receives the line, appended to whatever it already holds |
Returns: success when a line was read; IsEnd at the end of input with nothing appended
ReadTextLine
pub func ReadTextLine(
reader: &var BufferedReader,
builder: &var StringBuilder,
limit: uint
) -> ! IoError
Appends the next line of reader to builder, without its ending.
A line ends at a line feed; a carriage return immediately before it is part of the ending. The last line of a
stream needs no ending: what stands before the end is a line, and EndOfStream is reported only when the
stream ends with nothing before it, so a caller loops until exactly that.
The line must be UTF-8 — InvalidText otherwise, including a sequence cut short by the end of the stream --
and at most limit bytes, LimitExceeded otherwise. Only validated bytes ever reach the builder, and on
either failure it is cleared and the offending line consumed through its ending, so the caller can report the
line and read on. A scalar value split across the buffer's edge is completed from the next refill, not
condemned: where the buffer happens to end is not a property of the text.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var BufferedReader | where the bytes come from |
builder | &var StringBuilder | receives the line, appended to whatever it already holds |
limit | uint | the most bytes to accept before reporting the line too long |
Returns: success when a line was read; IsEnd at the end of input with nothing appended