diff options
| author | gingerBill <bill@gingerbill.org> | 2020-12-17 00:36:25 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-12-17 00:36:25 +0000 |
| commit | 1470cab842ef41b3ec61255b0366feb51a21f67f (patch) | |
| tree | 6b9d4883f46056906cdfb4a22ed46025eb568b30 /core/bytes/buffer.odin | |
| parent | a31b992d2bf2f252ebede90c1849ef4a99ada666 (diff) | |
Make bytes.odin consistent with strings.odin in functionality
Diffstat (limited to 'core/bytes/buffer.odin')
| -rw-r--r-- | core/bytes/buffer.odin | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/core/bytes/buffer.odin b/core/bytes/buffer.odin index 61fde9605..af9c1e57f 100644 --- a/core/bytes/buffer.odin +++ b/core/bytes/buffer.odin @@ -35,6 +35,11 @@ buffer_init_string :: proc(b: ^Buffer, s: string) { copy(b.buf[:], s); } +buffer_init_allocator :: proc(b: ^Buffer, len, cap: int, allocator := context.allocator) { + b.buf.allocator = allocator; + reserve(&b.buf, cap); + resize(&b.buf, len); +} buffer_destroy :: proc(b: ^Buffer) { delete(b.buf); @@ -283,6 +288,11 @@ buffer_to_stream :: proc(b: ^Buffer) -> (s: io.Stream) { s.stream_vtable = _buffer_vtable; return; } +buffer_to_writer :: proc(b: ^Buffer) -> (s: io.Writer) { + s.stream_data = b; + s.stream_vtable = _buffer_vtable; + return; +} @(private) _buffer_vtable := &io.Stream_VTable{ |