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

@@ -14,6 +14,7 @@ pub fn ArrayList(comptime T: type) -> type{
len: usize,
allocator: &Allocator,
/// Deinitialize with `deinit` or use `toOwnedSlice`.
pub fn init(allocator: &Allocator) -> Self {
Self {
.items = []T{},
@@ -34,6 +35,25 @@ pub fn ArrayList(comptime T: type) -> type{
return l.items[0..l.len];
}
/// ArrayList takes ownership of the passed in slice. The slice must have been
/// allocated with `allocator`.
/// Deinitialize with `deinit` or use `toOwnedSlice`.
pub fn fromOwnedSlice(allocator: &Allocator, slice: []T) -> Self {
return Self {
.items = slice,
.len = slice.len,
.allocator = allocator,
};
}
/// The caller owns the returned memory. ArrayList becomes empty.
pub fn toOwnedSlice(self: &Self) -> []T {
const allocator = self.allocator;
const result = allocator.shrink(T, self.items, self.len);
*self = init(allocator);
return result;
}
pub fn append(l: &Self, item: &const T) -> %void {
const new_item_ptr = %return l.addOne();
*new_item_ptr = *item;