Skip to content

Commit

Permalink
std.fmt.format supports ints smaller than u8
Browse files Browse the repository at this point in the history
closes #546

thanks to @dimenus for the fix
  • Loading branch information
andrewrk committed Oct 21, 2017
1 parent b3d12d2 commit 9b91c76
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion std/fmt/index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
// max_int_digits accounts for the minus sign. when printing an unsigned
// number we don't need to do that.
var buf: [max_int_digits - 1]u8 = undefined;
var a = value;
var a = if (@sizeOf(@typeOf(value)) == 1) u8(value) else value;
var index: usize = buf.len;

while (true) {
Expand Down Expand Up @@ -508,6 +508,12 @@ test "fmt.format" {
const result = bufPrint(buf1[0..], "error union: {}\n", value);
assert(mem.eql(u8, result, "error union: error.InvalidChar\n"));
}
{
var buf1: [32]u8 = undefined;
const value: u3 = 0b101;
const result = bufPrint(buf1[0..], "u3: {}\n", value);
assert(mem.eql(u8, result, "u3: 5\n"));
}
}

pub fn trim(buf: []const u8) -> []const u8 {
Expand Down

0 comments on commit 9b91c76

Please sign in to comment.