1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

StringBuilder: Reset the internal builder length after building.

This puts the StringBuilder back into a pristine state, allowing you
to use it to build more strings after you've built one.
This commit is contained in:
Andreas Kling 2019-07-08 15:54:42 +02:00
parent 0e75aba7c3
commit 2caec95d30

View file

@ -61,6 +61,7 @@ void StringBuilder::appendf(const char* fmt, ...)
ByteBuffer StringBuilder::to_byte_buffer()
{
m_buffer.trim(m_length);
m_length = 0;
return move(m_buffer);
}
@ -68,6 +69,7 @@ String StringBuilder::to_string()
{
auto string = String((const char*)m_buffer.pointer(), m_length);
m_buffer.clear();
m_length = 0;
return string;
}