diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index 8999592f1a8..39a16cbccf2 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -111,6 +111,11 @@ ByteBuffer StringBuilder::to_byte_buffer() const return ByteBuffer::copy(data(), length()).release_value_but_fixme_should_propagate_errors(); } +ErrorOr StringBuilder::try_to_byte_buffer() const +{ + return TRY(ByteBuffer::copy(data(), length())); +} + #ifndef KERNEL DeprecatedString StringBuilder::to_deprecated_string() const { diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h index 0d8a8c311f3..2fe6b28ad50 100644 --- a/AK/StringBuilder.h +++ b/AK/StringBuilder.h @@ -69,6 +69,7 @@ public: ErrorOr to_fly_string() const; [[nodiscard]] ByteBuffer to_byte_buffer() const; + [[nodiscard]] ErrorOr try_to_byte_buffer() const; [[nodiscard]] StringView string_view() const; void clear();