diff --git a/libos/include/os/File.h b/libos/include/os/File.h index d26050da..476fab1b 100644 --- a/libos/include/os/File.h +++ b/libos/include/os/File.h @@ -33,7 +33,7 @@ namespace os Result write(StringView str); Result write(const Buffer& buf); - Result read_line(); + Result read_line(bool keep_newline = true); Result read(Buffer& buf, usize size); diff --git a/libos/src/File.cpp b/libos/src/File.cpp index 9eb8b872..6387821d 100644 --- a/libos/src/File.cpp +++ b/libos/src/File.cpp @@ -108,7 +108,7 @@ namespace os return {}; } - Result File::read_line() + Result File::read_line(bool keep_newline) { Vector data; @@ -121,7 +121,11 @@ namespace os TRY(data.try_append((char)current)); - if (current == '\n') break; + if (current == '\n') + { + if (!keep_newline) data.try_pop(); + break; + } } if (!data.size()) return String {};