mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibCore: Let IODevice::can_read_line() buffer until \n or EOF
If a line was larger than 1024 bytes or the file ended without a newline character, can_read_line would return false. IODevice::can_read_line() now reads until a newline is found or EOF is reached. fixes #5907
This commit is contained in:
parent
edcfbdf4bd
commit
943f4eb287
Notes:
sideshowbarker
2024-07-18 17:40:14 +09:00
Author: https://github.com/r-paiva Commit: https://github.com/SerenityOS/serenity/commit/943f4eb2879 Pull-request: https://github.com/SerenityOS/serenity/pull/6738 Issue: https://github.com/SerenityOS/serenity/issues/5907 Reviewed-by: https://github.com/alimpfard ✅ Reviewed-by: https://github.com/linusg
2 changed files with 21 additions and 6 deletions
|
@ -161,8 +161,6 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
// NOTE: Vector::is_null() exists for the benefit of String::copy().
|
||||
bool is_null() const { return false; }
|
||||
bool is_empty() const { return size() == 0; }
|
||||
ALWAYS_INLINE size_t size() const { return m_size; }
|
||||
size_t capacity() const { return m_capacity; }
|
||||
|
|
|
@ -105,14 +105,31 @@ bool IODevice::can_read_line() const
|
|||
{
|
||||
if (m_eof && !m_buffered_data.is_empty())
|
||||
return true;
|
||||
|
||||
if (m_buffered_data.contains_slow('\n'))
|
||||
return true;
|
||||
|
||||
if (!can_read_from_fd())
|
||||
return false;
|
||||
populate_read_buffer();
|
||||
if (m_eof && !m_buffered_data.is_empty())
|
||||
return true;
|
||||
return m_buffered_data.contains_slow('\n');
|
||||
|
||||
while (true) {
|
||||
// Populate buffer until a newline is found or we reach EOF.
|
||||
|
||||
auto previous_buffer_size = m_buffered_data.size();
|
||||
populate_read_buffer();
|
||||
auto new_buffer_size = m_buffered_data.size();
|
||||
|
||||
if (m_error)
|
||||
return false;
|
||||
|
||||
if (m_eof)
|
||||
return !m_buffered_data.is_empty();
|
||||
|
||||
if (m_buffered_data.contains_in_range('\n', previous_buffer_size, new_buffer_size - 1))
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IODevice::can_read() const
|
||||
|
|
Loading…
Reference in a new issue