authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-24 20:30:30 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-24 20:30:30 -08:00
logfa1138e1a0a2f666b2cd26818e280b6171e417ac
tree1e218fe35225f171c0afe27a06782e96763263d1
parent3db31a0787846ce5b3133fe02f9cbcaa815ae80b

update for zig 0.9.0


1 files changed, 10 insertions(+), 10 deletions(-)

src/lib.zig+10-10
......@@ -2,11 +2,11 @@ const std = @import("std");
22const string = []const u8;
33const range = @import("range").range;
44
5pub fn fmtByteCountIEC(alloc: *std.mem.Allocator, b: u64) !string {
5pub fn fmtByteCountIEC(alloc: std.mem.Allocator, b: u64) !string {
66 return try reduceNumber(alloc, b, 1024, "B", "KMGTPEZY");
77}
88
9pub fn reduceNumber(alloc: *std.mem.Allocator, input: u64, comptime unit: u64, comptime base: string, comptime prefixes: string) !string {
9pub fn reduceNumber(alloc: std.mem.Allocator, input: u64, comptime unit: u64, comptime base: string, comptime prefixes: string) !string {
1010 if (input < unit) {
1111 return std.fmt.allocPrint(alloc, "{d} {s}", .{ input, base });
1212 }
......@@ -24,7 +24,7 @@ pub fn intToFloat(n: u64) f64 {
2424 return @intToFloat(f64, n);
2525}
2626
27pub fn addSentinel(alloc: *std.mem.Allocator, comptime T: type, input: []const T, comptime sentinel: T) ![:sentinel]const T {
27pub fn addSentinel(alloc: std.mem.Allocator, comptime T: type, input: []const T, comptime sentinel: T) ![:sentinel]const T {
2828 var list = try std.ArrayList(T).initCapacity(alloc, input.len + 1);
2929 try list.appendSlice(input);
3030 try list.append(sentinel);
......@@ -34,7 +34,7 @@ pub fn addSentinel(alloc: *std.mem.Allocator, comptime T: type, input: []const T
3434
3535const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";
3636
37pub fn randomSlice(alloc: *std.mem.Allocator, rand: *const std.rand.Random, comptime T: type, len: usize) ![]T {
37pub fn randomSlice(alloc: std.mem.Allocator, rand: *const std.rand.Random, comptime T: type, len: usize) ![]T {
3838 var buf = try alloc.alloc(T, len);
3939 var i: usize = 0;
4040 while (i < len) : (i += 1) {
......@@ -50,13 +50,13 @@ pub fn trimPrefix(in: string, prefix: string) string {
5050 return in;
5151}
5252
53pub fn base64EncodeAlloc(alloc: *std.mem.Allocator, input: string) !string {
54 const base64 = std.base64.standard_encoder;
53pub fn base64EncodeAlloc(alloc: std.mem.Allocator, input: string) !string {
54 const base64 = std.base64.standard.Encoder;
5555 var buf = try alloc.alloc(u8, base64.calcSize(input.len));
5656 return base64.encode(buf, input);
5757}
5858
59pub fn asciiUpper(alloc: *std.mem.Allocator, input: string) ![]u8 {
59pub fn asciiUpper(alloc: std.mem.Allocator, input: string) ![]u8 {
6060 var buf = try alloc.dupe(u8, input);
6161 for (range(buf.len)) |_, i| {
6262 buf[i] = std.ascii.toUpper(buf[i]);
......@@ -110,7 +110,7 @@ pub fn FieldType(comptime T: type, comptime field: std.meta.FieldEnum(T)) type {
110110 unreachable;
111111}
112112
113pub fn fileList(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]string {
113pub fn fileList(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]string {
114114 var list = std.ArrayList(string).init(alloc);
115115 defer list.deinit();
116116
......@@ -123,7 +123,7 @@ pub fn fileList(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]string {
123123 return list.toOwnedSlice();
124124}
125125
126pub fn dirSize(alloc: *std.mem.Allocator, dir: std.fs.Dir) !usize {
126pub fn dirSize(alloc: std.mem.Allocator, dir: std.fs.Dir) !usize {
127127 var res: usize = 0;
128128
129129 var walk = try dir.walk(alloc);
......@@ -157,7 +157,7 @@ pub const HashFn = enum {
157157 sha3_512,
158158};
159159
160pub fn hashFile(alloc: *std.mem.Allocator, dir: std.fs.Dir, sub_path: string, comptime algo: HashFn) !string {
160pub fn hashFile(alloc: std.mem.Allocator, dir: std.fs.Dir, sub_path: string, comptime algo: HashFn) !string {
161161 const file = try dir.openFile(sub_path, .{});
162162 defer file.close();
163163 const hash = std.crypto.hash;