authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-02-26 13:02:20 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-02-26 13:02:20 -08:00
log1da74fba8c47fde0af1459afa152742821590100
tree0264186b5c41e5420083b6fa13c3212a60c8d9d8
parent6ebab3dab47268e28599ac396e785f8a76acc7b6

update to zig master 0.11.0-dev.1681+0bb178bbb


2 files changed, 7 insertions(+), 19 deletions(-)

src/lib.zig+6-18
......@@ -2,18 +2,6 @@ const std = @import("std");
22const string = []const u8;
33const assert = std.debug.assert;
44
5/// Use this as a way to increment an index using a for loop. Works with both
6/// runtime and comptime integers.
7///
8/// ```zig
9/// for (range(10)) |_, i| {
10/// // 'i' will increment from 0 -> 9
11/// }
12/// ```
13pub fn range(len: usize) []const void {
14 return @as([*]void, undefined)[0..len];
15}
16
175pub fn fmtByteCountIEC(alloc: std.mem.Allocator, b: u64) !string {
186 return try reduceNumber(alloc, b, 1024, "B", "KMGTPEZYRQ");
197}
......@@ -73,7 +61,7 @@ pub fn base64EncodeAlloc(alloc: std.mem.Allocator, input: string) !string {
7361
7462pub fn asciiUpper(alloc: std.mem.Allocator, input: string) ![]u8 {
7563 var buf = try alloc.dupe(u8, input);
76 for (range(buf.len)) |_, i| {
64 for (0..buf.len) |i| {
7765 buf[i] = std.ascii.toUpper(buf[i]);
7866 }
7967 return buf;
......@@ -109,7 +97,7 @@ pub fn sliceToInt(comptime T: type, comptime E: type, slice: []const E) !T {
10997 if (a < b * slice.len) return error.Overflow;
11098
11199 var n: T = 0;
112 for (slice) |item, i| {
100 for (slice, 0..) |item, i| {
113101 const shift = @intCast(std.math.Log2Int(T), b * (slice.len - 1 - i));
114102 n = n | (@as(T, item) << shift);
115103 }
......@@ -236,7 +224,7 @@ pub fn containsString(haystack: []const string, needle: string) bool {
236224pub fn FieldsTuple(comptime T: type) type {
237225 const fields = std.meta.fields(T);
238226 var types: [fields.len]type = undefined;
239 for (fields) |item, i| {
227 for (fields, 0..) |item, i| {
240228 types[i] = item.type;
241229 }
242230 return std.meta.Tuple(&types);
......@@ -244,7 +232,7 @@ pub fn FieldsTuple(comptime T: type) type {
244232
245233pub fn positionalInit(comptime T: type, args: FieldsTuple(T)) T {
246234 var t: T = undefined;
247 inline for (std.meta.fields(T)) |field, i| {
235 inline for (std.meta.fields(T), 0..) |field, i| {
248236 @field(t, field.name) = args[i];
249237 }
250238 return t;
......@@ -288,7 +276,7 @@ pub fn readEnumBig(reader: anytype, comptime E: type) !E {
288276}
289277
290278pub fn readExpected(reader: anytype, expected: []const u8) !bool {
291 for (expected) |item, i| {
279 for (expected, 0..) |item, i| {
292280 const actual = try reader.readByte();
293281 if (actual != item) {
294282 std.log.err("expected '{d}' at index {d}, found: '{d}'", .{ item, i, actual });
......@@ -372,7 +360,7 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !
372360 },
373361 .Array => |t| {
374362 var s: T = undefined;
375 for (range(t.len)) |_, i| {
363 for (0..t.len) |i| {
376364 s[i] = try readType(reader, t.child, endian);
377365 }
378366 return s;
zig.mod+1-1
......@@ -3,4 +3,4 @@ name: extras
33main: src/lib.zig
44license: MIT
55description: An assortment of random utility functions that aren't in std and don't deserve their own pacakge.
6min_zig_version: 0.10.0-dev.3017+da94227f7
6min_zig_version: 0.11.0-dev.1681+0bb178bbb