authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-01 13:07:31-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-01 13:07:31-05:00
log4505857e30233d87f9ece403458c0988e8c68493
tree9ec07c9f1d50a20ef4c829e6435f73d35021588a
parent0b0de22fd1b0391f0cf1c7d821afc6522041c699
signaturelock-open Commit is signed but in an unrecognized format.

revert changes outside std.fmt


3 files changed, 6 insertions(+), 19 deletions(-)

lib/std/cstr.zig+1-1
......@@ -28,7 +28,7 @@ test "cstr fns" {
2828
2929fn testCStrFnsImpl() void {
3030 testing.expect(cmp("aoeu", "aoez") == -1);
31 testing.expect(mem.len(u8, "123456789".*) == 9);
31 testing.expect(mem.len(u8, "123456789") == 9);
3232}
3333
3434/// Returns a mutable, null-terminated slice with the same length as `slice`.
lib/std/mem.zig+4-17
......@@ -470,31 +470,18 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
470470 return true;
471471}
472472
473pub fn len(comptime T: type, ptr: var) usize {
474 const sentinel: T = comptime meta.Sentinel(@TypeOf(ptr));
473pub fn len(comptime T: type, ptr: [*:0]const T) usize {
475474 var count: usize = 0;
476 while (ptr[count] != sentinel) : (count += 1) {}
475 while (ptr[count] != 0) : (count += 1) {}
477476 return count;
478477}
479478
480/// Given a sentintel-terminated pointer-to-many, find the sentintel and return a slice.
481pub fn pointerToSlice(comptime T: type, ptr: blk: {
482 var info = @typeInfo(T).Pointer;
483 info.size = .Many;
484 break :blk @Type(std.builtin.TypeInfo{ .Pointer = info });
485}) T {
486 const sentinel = comptime meta.Sentinel(T);
487 return ptr[0..len(meta.Child(T), ptr) :sentinel];
488}
489
490/// Deprecated; use pointerToSlice instead
491479pub fn toSliceConst(comptime T: type, ptr: [*:0]const T) [:0]const T {
492 return pointerToSlice([:0]const T, ptr);
480 return ptr[0..len(T, ptr) :0];
493481}
494482
495/// Deprecated; use pointerToSlice instead
496483pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T {
497 return pointerToSlice([:0]T, ptr);
484 return ptr[0..len(T, ptr) :0];
498485}
499486
500487/// Returns true if all elements in a slice are equal to the scalar value provided
test/stage1/behavior/misc.zig+1-1
......@@ -335,7 +335,7 @@ test "string concatenation" {
335335 comptime expect(@TypeOf(a) == *const [12:0]u8);
336336 comptime expect(@TypeOf(b) == *const [12:0]u8);
337337
338 const len = b.len;
338 const len = mem.len(u8, b);
339339 const len_with_null = len + 1;
340340 {
341341 var i: u32 = 0;