aboutsummaryrefslogtreecommitdiff
path: root/std/io.zig
diff options
context:
space:
mode:
authorjean-dao <1405645+jean-dao@users.noreply.github.com>2017-09-10 17:10:55 +0200
committerAndrew Kelley <superjoe30@gmail.com>2017-09-10 11:10:55 -0400
commit0f7544cfca63fc5b49790974e6b01097365bb18c (patch)
tree39d9d8ac69e20b940847588f9b656dbc422ebc45 /std/io.zig
parentb00b7bd29037f25ee155f07e74fcb5de44918926 (diff)
downloadzig-0f7544cfca63fc5b49790974e6b01097365bb18c.tar.gz
zig-0f7544cfca63fc5b49790974e6b01097365bb18c.zip
std.io.InStream: add readLine function (#458)
Diffstat (limited to 'std/io.zig')
-rw-r--r--std/io.zig13
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) {