aboutsummaryrefslogtreecommitdiff
path: root/std/fmt/index.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-10-21 13:03:08 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-10-21 13:03:08 -0400
commit9b91c76088e784bb622008623059eca5bbcd8700 (patch)
tree4b3ebc4a8ebb45ca3bf2c714d508d71343501a4e /std/fmt/index.zig
parentb3d12d2c9e64f0cd7db02e255686ee03dbec8de9 (diff)
downloadzig-9b91c76088e784bb622008623059eca5bbcd8700.tar.gz
zig-9b91c76088e784bb622008623059eca5bbcd8700.zip
std.fmt.format supports ints smaller than u8
closes #546 thanks to @Dimenus for the fix
Diffstat (limited to 'std/fmt/index.zig')
-rw-r--r--std/fmt/index.zig8
1 files changed, 7 insertions, 1 deletions
diff --git a/std/fmt/index.zig b/std/fmt/index.zig
index 27ab3dd0dd..b378afa1b0 100644
--- a/std/fmt/index.zig
+++ b/std/fmt/index.zig
@@ -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) {
@@ -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 {