implement command line argument parsing for windows

See #302
This commit is contained in:
Andrew Kelley
2017-10-11 10:16:13 -04:00
parent 717e791db2
commit b61a6ec8a6
8 changed files with 320 additions and 56 deletions

View File

@@ -38,6 +38,27 @@ pub const Buffer = struct {
return Buffer.init(buffer.list.allocator, buffer.toSliceConst());
}
/// Buffer takes ownership of the passed in slice. The slice must have been
/// allocated with `allocator`.
/// Must deinitialize with deinit.
pub fn fromOwnedSlice(allocator: &Allocator, slice: []u8) -> Buffer {
var self = Buffer {
.list = ArrayList(u8).fromOwnedSlice(allocator, slice),
};
self.list.append(0);
return self;
}
/// The caller owns the returned memory. The Buffer becomes null and
/// is safe to `deinit`.
pub fn toOwnedSlice(self: &Buffer) -> []u8 {
const allocator = self.list.allocator;
const result = allocator.shrink(u8, self.list.items, self.len());
*self = initNull(allocator);
return result;
}
pub fn deinit(self: &Buffer) {
self.list.deinit();
}