From a1e15ecb73695ec0615b5d3be641cd69c1ad812c Mon Sep 17 00:00:00 2001 From: moneyl <8206401+Moneyl@users.noreply.github.com> Date: Tue, 16 Mar 2021 19:39:38 -0400 Subject: [PATCH] Add ReadNullTerminatedString to System.IO.Stream Function that reads a null terminated string from the stream. --- BeefLibs/corlib/src/IO/Stream.bf | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/BeefLibs/corlib/src/IO/Stream.bf b/BeefLibs/corlib/src/IO/Stream.bf index f70f49ad..8b3c3d0f 100644 --- a/BeefLibs/corlib/src/IO/Stream.bf +++ b/BeefLibs/corlib/src/IO/Stream.bf @@ -115,6 +115,22 @@ namespace System.IO return .Ok; } + //Reads null terminated ASCII string from the stream. Null terminator is read from stream but isn't appended to output string + public Result ReadNullTerminatedString(String output) + { + Result char0; + while(true) + { + char0 = Read(); + if(char0 == .Err) + return .Err; + if(char0.Value == '\0') + return .Ok; + + output.Append(char0.Value); + } + } + public Result Read() where T : struct { T val = ?;