mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibCore: Make IODevice::read_line() return a String
Almost everyone using this API actually wanted String instead of a ByteBuffer anyway, and there were a bunch of slightly different ways clients would convert to String. Let's just cut out all the confusion and make it return String. :^)
This commit is contained in:
parent
4da327d650
commit
b9b7b2b28a
22 changed files with 50 additions and 66 deletions
|
@ -174,7 +174,7 @@ ByteBuffer IODevice::read_all()
|
|||
return ByteBuffer::copy(data.data(), data.size());
|
||||
}
|
||||
|
||||
ByteBuffer IODevice::read_line(size_t max_size)
|
||||
String IODevice::read_line(size_t max_size)
|
||||
{
|
||||
if (m_fd < 0)
|
||||
return {};
|
||||
|
@ -187,9 +187,9 @@ ByteBuffer IODevice::read_line(size_t max_size)
|
|||
dbgprintf("IODevice::read_line: At EOF but there's more than max_size(%zu) buffered\n", max_size);
|
||||
return {};
|
||||
}
|
||||
auto buffer = ByteBuffer::copy(m_buffered_data.data(), m_buffered_data.size());
|
||||
auto line = String((const char*)m_buffered_data.data(), m_buffered_data.size(), Chomp);
|
||||
m_buffered_data.clear();
|
||||
return buffer;
|
||||
return line;
|
||||
}
|
||||
auto line = ByteBuffer::create_uninitialized(max_size + 1);
|
||||
size_t line_index = 0;
|
||||
|
@ -201,7 +201,7 @@ ByteBuffer IODevice::read_line(size_t max_size)
|
|||
new_buffered_data.append(m_buffered_data.data() + line_index, m_buffered_data.size() - line_index);
|
||||
m_buffered_data = move(new_buffered_data);
|
||||
line.trim(line_index);
|
||||
return line;
|
||||
return String::copy(line, Chomp);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue