| ... | ... | @@ -229,6 +229,9 @@ pub fn formatType( |
| 229 | 229 | return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)); |
| 230 | 230 | }, |
| 231 | 231 | builtin.TypeInfo.Pointer.Size.Slice => { |
| 232 | if (fmt.len > 0 and ((fmt[0] == 'x') or (fmt[0] == 'X'))) { |
| 233 | return formatText(value, fmt, context, Errors, output); |
| 234 | } |
| 232 | 235 | const casted_value = ([]const u8)(value); |
| 233 | 236 | return output(context, casted_value); |
| 234 | 237 | }, |
| ... | ... | @@ -1293,6 +1296,9 @@ test "fmt.format" { |
| 1293 | 1296 | const some_bytes = "\xCA\xFE\xBA\xBE"; |
| 1294 | 1297 | try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", some_bytes); |
| 1295 | 1298 | try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", some_bytes); |
| 1299 | //Test Slices |
| 1300 | try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", some_bytes[0..2]); |
| 1301 | try testFmt("lowercase: babe\n", "lowercase: {x}\n", some_bytes[2..]); |
| 1296 | 1302 | const bytes_with_zeros = "\x00\x0E\xBA\xBE"; |
| 1297 | 1303 | try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", bytes_with_zeros); |
| 1298 | 1304 | } |