diff options
| author | Nathan Michaels <nathan@nmichaels.org> | 2020-01-20 12:23:43 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-01-20 12:23:43 -0500 |
| commit | 0000de4fee601047f662dc33fe890eb8831d9787 (patch) | |
| tree | 74912dd3934522f802037fd94cfa3ca208d9e08c /lib/std | |
| parent | 7a1cde7206263c8bb3265c225ed4213d1b7bdb58 (diff) | |
| download | zig-0000de4fee601047f662dc33fe890eb8831d9787.tar.gz zig-0000de4fee601047f662dc33fe890eb8831d9787.zip | |
Handle {s} format for C strings. (#4219)
* Handle {s} format for C strings.
* Fix "cstr" test to actually use c strings.
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/fmt.zig | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 548ef8ccce..5a650c3b10 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -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); @@ -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{ @@ -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" { |
