mirror of
https://codeberg.org/andyscott/advent-of-code.git
synced 2024-12-21 17:13:10 -05:00
2024: util.zig: add inputToArrayList()
This commit is contained in:
parent
332eaae6ee
commit
4f5e5310f3
1 changed files with 10 additions and 0 deletions
|
@ -9,3 +9,13 @@ pub fn readAllInput(day: u8, allocator: std.mem.Allocator) ![]const u8 {
|
|||
const stat = try file.stat();
|
||||
return try file.reader().readAllAlloc(allocator, stat.size);
|
||||
}
|
||||
|
||||
pub fn inputToArrayList(comptime T: type, allocator: std.mem.Allocator, input: []const u8) !std.ArrayList(T) {
|
||||
var out = std.ArrayList(T).init(allocator);
|
||||
errdefer out.deinit();
|
||||
var items = std.mem.tokenizeScalar(u8, input, ' ');
|
||||
while (items.next()) |item| {
|
||||
try out.append(try std.fmt.parseInt(T, item, 10));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue