Make bytes.odin consistent with strings.odin in functionality

This commit is contained in:
gingerBill
2020-12-17 00:36:25 +00:00
parent a31b992d2b
commit 1470cab842
2 changed files with 49 additions and 54 deletions
+10
View File
@@ -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{