diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-13 11:44:53 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-13 11:54:11 +0100 |
commit | b9b7b2b28aaaf8dfaa06efa15d0b92e56f6ed518 (patch) | |
tree | f48a1c56a4502f8369837aad7d8ffaca205ea51b /Libraries/LibCore | |
parent | 4da327d650af76f8541dd5a2509d6619ff4846ac (diff) | |
download | serenity-b9b7b2b28aaaf8dfaa06efa15d0b92e56f6ed518.zip |
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. :^)
Diffstat (limited to 'Libraries/LibCore')
-rw-r--r-- | Libraries/LibCore/ConfigFile.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibCore/IODevice.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibCore/IODevice.h | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/Libraries/LibCore/ConfigFile.cpp b/Libraries/LibCore/ConfigFile.cpp index f4e1536436..cb7e68576c 100644 --- a/Libraries/LibCore/ConfigFile.cpp +++ b/Libraries/LibCore/ConfigFile.cpp @@ -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; diff --git a/Libraries/LibCore/IODevice.cpp b/Libraries/LibCore/IODevice.cpp index 81d759afd0..4efda65ee4 100644 --- a/Libraries/LibCore/IODevice.cpp +++ b/Libraries/LibCore/IODevice.cpp @@ -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 {}; diff --git a/Libraries/LibCore/IODevice.h b/Libraries/LibCore/IODevice.h index 2fe1e93e65..6071a4c912 100644 --- a/Libraries/LibCore/IODevice.h +++ b/Libraries/LibCore/IODevice.h @@ -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&); |