Added '%h' and '%H' for printing out binary data in hexadecimal using the formatter.

This commit is contained in:
Christoffer Lerno
2025-01-16 01:06:57 +01:00
parent 15503a9054
commit 721aaa28aa
4 changed files with 62 additions and 2 deletions

View File

@@ -9,6 +9,22 @@ fault FormattingFault
BAD_FORMAT
}
fn usz! print_hex_chars(Formatter* f, char[] out, bool uppercase) @inline
{
char past_10 = (uppercase ? 'A' : 'a') - 10;
usz len = 0;
foreach (c : out)
{
char digit = c >> 4;
f.out(digit + (digit < 10 ? '0' : past_10))!;
len++;
digit = c & 0xf;
f.out(digit + (digit < 10 ? '0' : past_10))!;
len++;
}
return len;
}
macro Formatter.first_err(&self, anyfault f)
{
if (self.first_fault) return self.first_fault;