From 0f7544cfca63fc5b49790974e6b01097365bb18c Mon Sep 17 00:00:00 2001 From: jean-dao <1405645+jean-dao@users.noreply.github.com> Date: Sun, 10 Sep 2017 17:10:55 +0200 Subject: [PATCH] std.io.InStream: add readLine function (#458) --- std/io.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/std/io.zig b/std/io.zig index 2f0305b43fc5485dd680459c06ae75592cf681dd..1054e002f08cadb680feb77bae60c6a16064d1ec 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) { -- 2.54.0