ReadLine functionv0.1.0

Source
Appends the next line of standard input to builder, without its ending.
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

NameTypeDescription
builder&var StringBuilderreceives the line, appended to whatever it already holds

Returns: success when a line was read; IsEnd at the end of input with nothing appended

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.

Source

Parameters

NameTypeDescription
reader&var Readerwhere the bytes come from, borrowed for the call
builder&var StringBuilderreceives 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.

Source

Parameters

NameTypeDescription
reader&var BufferedReaderwhere the bytes come from
builder&var StringBuilderreceives the line, appended to whatever it already holds
limituintthe 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