diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index a047ea70fc..7831cfb652 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -85,19 +85,19 @@ void StringBuilder::appendf(const char* fmt, ...) va_end(ap); } -ByteBuffer StringBuilder::to_byte_buffer() +ByteBuffer StringBuilder::to_byte_buffer() const { - m_buffer.trim(m_length); - m_length = 0; - return move(m_buffer); + ByteBuffer buffer_copy = m_buffer.isolated_copy(); + buffer_copy.trim(m_length); + return buffer_copy; } -String StringBuilder::to_string() +String StringBuilder::to_string() const { return String((const char*)m_buffer.data(), m_length); } -String StringBuilder::build() +String StringBuilder::build() const { return to_string(); } diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h index 7bbf8f7049..139fe3017a 100644 --- a/AK/StringBuilder.h +++ b/AK/StringBuilder.h @@ -45,9 +45,9 @@ public: void appendf(const char*, ...); void appendvf(const char*, va_list); - String build(); - String to_string(); - ByteBuffer to_byte_buffer(); + String build() const; + String to_string() const; + ByteBuffer to_byte_buffer() const; StringView string_view() const; void clear();