Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/std/fmt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ pub fn formatType(
},
else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }),
},
.Many => {
.Many, .C => {
if (ptr_info.child == u8) {
if (fmt.len > 0 and fmt[0] == 's') {
const len = mem.len(u8, value);
Expand All @@ -449,9 +449,6 @@ pub fn formatType(
}
return format(context, Errors, output, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) });
},
.C => {
return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
},
},
.Array => |info| {
const Slice = @Type(builtin.TypeInfo{
Expand Down Expand Up @@ -1285,8 +1282,16 @@ test "pointer" {
}

test "cstr" {
try testFmt("cstr: Test C\n", "cstr: {s}\n", .{"Test C"});
try testFmt("cstr: Test C \n", "cstr: {s:10}\n", .{"Test C"});
try testFmt(
"cstr: Test C\n",
"cstr: {s}\n",
.{@ptrCast([*c]const u8, "Test C")},
);
try testFmt(
"cstr: Test C \n",
"cstr: {s:10}\n",
.{@ptrCast([*c]const u8, "Test C")},
);
}

test "filesize" {
Expand Down