AK+LibCore: Add BufferedSocket::can_read_up_to_delimiter()

This method (unlike can_read_line) ensures that the delimiter is present
in the buffer, and doesn't return true after eof when the delimiter is
absent.
This commit is contained in:
Ali Mohammad Pur 2024-01-20 16:20:48 +03:30 committed by Andreas Kling
commit 4f6c9f410c
Notes: sideshowbarker 2024-07-17 18:06:52 +09:00
3 changed files with 23 additions and 6 deletions

View file

@ -532,6 +532,8 @@ TEST_CASE(buffered_file_without_newlines)
auto can_read_line = TRY_OR_FAIL(ro_file->can_read_line());
EXPECT(can_read_line);
auto can_read_up_to_newline = TRY_OR_FAIL(ro_file->can_read_up_to_delimiter("\n"sv.bytes()));
EXPECT(!can_read_up_to_newline);
Array<u8, new_newlines_message.length() + 1> buffer;
EXPECT(ro_file->read_line(buffer).release_value() == new_newlines_message);
}