libos: Make File::read_line optionally strip the ending newline
This commit is contained in:
parent
e654ed6415
commit
63a2df112d
@ -33,7 +33,7 @@ namespace os
|
||||
Result<void> write(StringView str);
|
||||
Result<void> write(const Buffer& buf);
|
||||
|
||||
Result<String> read_line();
|
||||
Result<String> read_line(bool keep_newline = true);
|
||||
|
||||
Result<void> read(Buffer& buf, usize size);
|
||||
|
||||
|
@ -108,7 +108,7 @@ namespace os
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<String> File::read_line()
|
||||
Result<String> File::read_line(bool keep_newline)
|
||||
{
|
||||
Vector<char> 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 {};
|
||||
|
Loading…
Reference in New Issue
Block a user