Makes sure builder has at least minimum_bytes of free space in one piece and returns all of it as a slice. Write into
the slice, then call advance_through_ensured_space with the number of bytes you used. Use it to format straight into the
builder instead of building a temporary string first. An empty slice means the builder failed.
ensure_contiguous_space_and_return_available_range :: (
builder: *String_Builder,
minimum_bytes := 1
) -> [] u8
Parameters
- builder: *String_Builder
- minimum_bytes := 1
Returns
- [] u8
builder: String_Builder;
defer free_buffers(*builder);
space := ensure_contiguous_space_and_return_available_range(*builder, 8);
space[0] = #char "h";
space[1] = #char "i";
advance_through_ensured_space(*builder, 2);
text := builder_to_string(*builder);
defer free(text);
assert(text == "hi");