aboutsummaryrefslogtreecommitdiff
path: root/core/bytes/buffer.odin
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-12-17 00:36:25 +0000
committergingerBill <bill@gingerbill.org>2020-12-17 00:36:25 +0000
commit1470cab842ef41b3ec61255b0366feb51a21f67f (patch)
tree6b9d4883f46056906cdfb4a22ed46025eb568b30 /core/bytes/buffer.odin
parenta31b992d2bf2f252ebede90c1849ef4a99ada666 (diff)
Make bytes.odin consistent with strings.odin in functionality
Diffstat (limited to 'core/bytes/buffer.odin')
-rw-r--r--core/bytes/buffer.odin10
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{