mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 00:57:04 +00:00
revert changes outside std.fmt
This commit is contained in:
parent
0b0de22fd1
commit
4505857e30
@ -28,7 +28,7 @@ test "cstr fns" {
|
||||
|
||||
fn testCStrFnsImpl() void {
|
||||
testing.expect(cmp("aoeu", "aoez") == -1);
|
||||
testing.expect(mem.len(u8, "123456789".*) == 9);
|
||||
testing.expect(mem.len(u8, "123456789") == 9);
|
||||
}
|
||||
|
||||
/// Returns a mutable, null-terminated slice with the same length as `slice`.
|
||||
|
@ -470,31 +470,18 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn len(comptime T: type, ptr: var) usize {
|
||||
const sentinel: T = comptime meta.Sentinel(@TypeOf(ptr));
|
||||
pub fn len(comptime T: type, ptr: [*:0]const T) usize {
|
||||
var count: usize = 0;
|
||||
while (ptr[count] != sentinel) : (count += 1) {}
|
||||
while (ptr[count] != 0) : (count += 1) {}
|
||||
return count;
|
||||
}
|
||||
|
||||
/// Given a sentintel-terminated pointer-to-many, find the sentintel and return a slice.
|
||||
pub fn pointerToSlice(comptime T: type, ptr: blk: {
|
||||
var info = @typeInfo(T).Pointer;
|
||||
info.size = .Many;
|
||||
break :blk @Type(std.builtin.TypeInfo{ .Pointer = info });
|
||||
}) T {
|
||||
const sentinel = comptime meta.Sentinel(T);
|
||||
return ptr[0..len(meta.Child(T), ptr) :sentinel];
|
||||
}
|
||||
|
||||
/// Deprecated; use pointerToSlice instead
|
||||
pub fn toSliceConst(comptime T: type, ptr: [*:0]const T) [:0]const T {
|
||||
return pointerToSlice([:0]const T, ptr);
|
||||
return ptr[0..len(T, ptr) :0];
|
||||
}
|
||||
|
||||
/// Deprecated; use pointerToSlice instead
|
||||
pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T {
|
||||
return pointerToSlice([:0]T, ptr);
|
||||
return ptr[0..len(T, ptr) :0];
|
||||
}
|
||||
|
||||
/// Returns true if all elements in a slice are equal to the scalar value provided
|
||||
|
@ -335,7 +335,7 @@ test "string concatenation" {
|
||||
comptime expect(@TypeOf(a) == *const [12:0]u8);
|
||||
comptime expect(@TypeOf(b) == *const [12:0]u8);
|
||||
|
||||
const len = b.len;
|
||||
const len = mem.len(u8, b);
|
||||
const len_with_null = len + 1;
|
||||
{
|
||||
var i: u32 = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user