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");...@@ -2,11 +2,11 @@ const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const range = @import("range").range;3const 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 {
6 return try reduceNumber(alloc, b, 1024, "B", "KMGTPEZY");6 return try reduceNumber(alloc, b, 1024, "B", "KMGTPEZY");
7}7}
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 {
10 if (input < unit) {10 if (input < unit) {
11 return std.fmt.allocPrint(alloc, "{d} {s}", .{ input, base });11 return std.fmt.allocPrint(alloc, "{d} {s}", .{ input, base });
12 }12 }
...@@ -24,7 +24,7 @@ pub fn intToFloat(n: u64) f64 {...@@ -24,7 +24,7 @@ pub fn intToFloat(n: u64) f64 {
24 return @intToFloat(f64, n);24 return @intToFloat(f64, n);
25}25}
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 {
28 var list = try std.ArrayList(T).initCapacity(alloc, input.len + 1);28 var list = try std.ArrayList(T).initCapacity(alloc, input.len + 1);
29 try list.appendSlice(input);29 try list.appendSlice(input);
30 try list.append(sentinel);30 try list.append(sentinel);
...@@ -34,7 +34,7 @@ pub fn addSentinel(alloc: *std.mem.Allocator, comptime T: type, input: []const T...@@ -34,7 +34,7 @@ pub fn addSentinel(alloc: *std.mem.Allocator, comptime T: type, input: []const T
3434
35const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";35const 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 {
38 var buf = try alloc.alloc(T, len);38 var buf = try alloc.alloc(T, len);
39 var i: usize = 0;39 var i: usize = 0;
40 while (i < len) : (i += 1) {40 while (i < len) : (i += 1) {
...@@ -50,13 +50,13 @@ pub fn trimPrefix(in: string, prefix: string) string {...@@ -50,13 +50,13 @@ pub fn trimPrefix(in: string, prefix: string) string {
50 return in;50 return in;
51}51}
5252
53pub fn base64EncodeAlloc(alloc: *std.mem.Allocator, input: string) !string {53pub fn base64EncodeAlloc(alloc: std.mem.Allocator, input: string) !string {
54 const base64 = std.base64.standard_encoder;54 const base64 = std.base64.standard.Encoder;
55 var buf = try alloc.alloc(u8, base64.calcSize(input.len));55 var buf = try alloc.alloc(u8, base64.calcSize(input.len));
56 return base64.encode(buf, input);56 return base64.encode(buf, input);
57}57}
5858
59pub fn asciiUpper(alloc: *std.mem.Allocator, input: string) ![]u8 {59pub fn asciiUpper(alloc: std.mem.Allocator, input: string) ![]u8 {
60 var buf = try alloc.dupe(u8, input);60 var buf = try alloc.dupe(u8, input);
61 for (range(buf.len)) |_, i| {61 for (range(buf.len)) |_, i| {
62 buf[i] = std.ascii.toUpper(buf[i]);62 buf[i] = std.ascii.toUpper(buf[i]);
...@@ -110,7 +110,7 @@ pub fn FieldType(comptime T: type, comptime field: std.meta.FieldEnum(T)) type {...@@ -110,7 +110,7 @@ pub fn FieldType(comptime T: type, comptime field: std.meta.FieldEnum(T)) type {
110 unreachable;110 unreachable;
111}111}
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 {
114 var list = std.ArrayList(string).init(alloc);114 var list = std.ArrayList(string).init(alloc);
115 defer list.deinit();115 defer list.deinit();
116116
...@@ -123,7 +123,7 @@ pub fn fileList(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]string {...@@ -123,7 +123,7 @@ pub fn fileList(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]string {
123 return list.toOwnedSlice();123 return list.toOwnedSlice();
124}124}
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 {
127 var res: usize = 0;127 var res: usize = 0;
128128
129 var walk = try dir.walk(alloc);129 var walk = try dir.walk(alloc);
...@@ -157,7 +157,7 @@ pub const HashFn = enum {...@@ -157,7 +157,7 @@ pub const HashFn = enum {
157 sha3_512,157 sha3_512,
158};158};
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 {
161 const file = try dir.openFile(sub_path, .{});161 const file = try dir.openFile(sub_path, .{});
162 defer file.close();162 defer file.close();
163 const hash = std.crypto.hash;163 const hash = std.crypto.hash;