mirror of
https://github.com/ziglang/zig.git
synced 2025-01-09 19:50:29 +00:00
std.fmt.format supports ints smaller than u8
closes #546 thanks to @Dimenus for the fix
This commit is contained in:
parent
b3d12d2c9e
commit
9b91c76088
@ -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
|
// max_int_digits accounts for the minus sign. when printing an unsigned
|
||||||
// number we don't need to do that.
|
// number we don't need to do that.
|
||||||
var buf: [max_int_digits - 1]u8 = undefined;
|
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;
|
var index: usize = buf.len;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -508,6 +508,12 @@ test "fmt.format" {
|
|||||||
const result = bufPrint(buf1[0..], "error union: {}\n", value);
|
const result = bufPrint(buf1[0..], "error union: {}\n", value);
|
||||||
assert(mem.eql(u8, result, "error union: error.InvalidChar\n"));
|
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 {
|
pub fn trim(buf: []const u8) -> []const u8 {
|
||||||
|
Loading…
Reference in New Issue
Block a user