diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-27 19:47:25 -0400 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-27 19:47:25 -0400 |
commit | bf3667b8b76eefd95e33e32b4f5abbf2de0e2065 (patch) | |
tree | 241b909f0d68f3c0f355ad924375c2fa5b9a19ae /libmisc/fmt.c | |
parent | 42fb27570262b52e2ca889030c621b5f4af76fe1 (diff) | |
parent | 968f7710458f44d5e62d2624461f4e8459c04168 (diff) |
Merge branch 'lukeshu/cover'
Diffstat (limited to 'libmisc/fmt.c')
-rw-r--r-- | libmisc/fmt.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libmisc/fmt.c b/libmisc/fmt.c index 6cf1d8d..a8baa84 100644 --- a/libmisc/fmt.c +++ b/libmisc/fmt.c @@ -14,6 +14,31 @@ static const char *const hexdig = "0123456789ABCDEF"; /* small/trivial formatters ***************************************************/ +void fmt_print_mem(lo_interface fmt_dest w, const void *_str, size_t size) { + const uint8_t *str = _str; + while (size--) + fmt_print_byte(w, *(str++)); +} +void fmt_print_str(lo_interface fmt_dest w, const char *str) { + while (*str) + fmt_print_byte(w, *(str++)); +} +void fmt_print_strn(lo_interface fmt_dest w, const char *str, size_t size) { + while (size-- && *str) + fmt_print_byte(w, *(str++)); +} + +void fmt_print_hmem(lo_interface fmt_dest w, const void *_str, size_t size) { + const uint8_t *str = _str; + fmt_print_byte(w, '{'); + for (size_t i = 0; i < size; i++) { + if (i) + fmt_print_byte(w, ','); + fmt_print_hbyte(w, str[i]); + } + fmt_print_byte(w, '}'); +} + void fmt_print_byte(lo_interface fmt_dest w, uint8_t b) { LO_CALL(w, putb, b); } |