1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:38:10 +00:00

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
parent 4d1d88aa16
commit 4f6c9f410c
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);
}