#include #include #include Result StringBuilder::add(StringView value) { return m_data.append_data((const u8*)value.chars(), value.length()); } Result StringBuilder::add(const String& value) { return add(value.view()); } Result StringBuilder::add(void* value) { return format("%p"_sv, value); } Result StringBuilder::add(long value) { return format("%li"_sv, value); } Result StringBuilder::add(unsigned long value) { return format("%lu"_sv, value); } Result StringBuilder::add(char value) { return m_data.append_data((const u8*)&value, 1); } Result StringBuilder::format(StringView fmt, ...) { va_list ap; va_start(ap, fmt); auto rc = vformat(fmt, ap); va_end(ap); return rc; } Result StringBuilder::vformat(StringView fmt, va_list ap) { Vector temp; TRY(cstyle_format( fmt.chars(), [](char c, void* buf) -> Result { return ((Vector*)buf)->try_append(c); }, &temp, ap)); TRY(m_data.append_data((u8*)temp.data(), temp.size())); return {}; } Result StringBuilder::string() { char nul = '\0'; TRY(m_data.append_data((u8*)&nul, 1)); return String { (char*)m_data.release_data() }; }