mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +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
|
@ -83,8 +83,8 @@ void ConfigFile::reparse()
|
|||
HashMap<String, String>* current_group = nullptr;
|
||||
|
||||
while (file->can_read_line()) {
|
||||
auto line = file->read_line(BUFSIZ);
|
||||
auto* cp = (const char*)line.data();
|
||||
auto line = file->read_line();
|
||||
auto* cp = line.characters();
|
||||
|
||||
while (*cp && (*cp == ' ' || *cp == '\t' || *cp == '\n'))
|
||||
++cp;
|
||||
|
|
|
@ -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 {};
|
||||
|
|
|
@ -59,8 +59,8 @@ public:
|
|||
int read(u8* buffer, int length);
|
||||
|
||||
ByteBuffer read(size_t max_size);
|
||||
ByteBuffer read_line(size_t max_size);
|
||||
ByteBuffer read_all();
|
||||
String read_line(size_t max_size = 16384);
|
||||
|
||||
bool write(const u8*, int size);
|
||||
bool write(const StringView&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue