diff options
| author | jean-dao <1405645+jean-dao@users.noreply.github.com> | 2017-09-10 17:10:55 +0200 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-09-10 11:10:55 -0400 |
| commit | 0f7544cfca63fc5b49790974e6b01097365bb18c (patch) | |
| tree | 39d9d8ac69e20b940847588f9b656dbc422ebc45 /std | |
| parent | b00b7bd29037f25ee155f07e74fcb5de44918926 (diff) | |
| download | zig-0f7544cfca63fc5b49790974e6b01097365bb18c.tar.gz zig-0f7544cfca63fc5b49790974e6b01097365bb18c.zip | |
std.io.InStream: add readLine function (#458)
Diffstat (limited to 'std')
| -rw-r--r-- | std/io.zig | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/std/io.zig b/std/io.zig index 2f0305b43f..1054e002f0 100644 --- a/std/io.zig +++ b/std/io.zig @@ -419,6 +419,19 @@ pub const InStream = struct { } } + pub fn readLine(is: &InStream, buf: &Buffer) -> %void { + %return buf.resize(0); + + while (true) { + var byte: u8 = %return is.readByte(); + %return buf.appendByte(byte); + + if (buf.endsWith(os.line_sep)) { + break; + } + } + } + pub fn isTty(self: &InStream) -> %bool { if (is_posix) { if (builtin.link_libc) { |
