From bcfe32ad1e5178b43c92236f1dbb67a2b53f0b40 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 22 Dec 2019 19:33:38 +1300 Subject: Make some dense code a little less opaque --- wtf8.c | 9 +++++++-- wtf8.h | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/wtf8.c b/wtf8.c index 714a7cc..7078ec1 100644 --- a/wtf8.c +++ b/wtf8.c @@ -18,8 +18,13 @@ void print_octets(char *s) { /* * Iterate through the string, printing each octet, ending with a newline */ - while ((c = *s++)) - printf("%c%02x", (is_utf8_cont(c) ? '-' : ' '), c); + while ((c = *s++)) { + char sep; + sep = is_utf8_cont(c) + ? BYTE_SEP + : CHAR_SEP; + printf("%c%02x", sep, c); + } putchar('\n'); return; diff --git a/wtf8.h b/wtf8.h index a635e1e..f6f3de6 100644 --- a/wtf8.h +++ b/wtf8.h @@ -2,6 +2,9 @@ #include #include +#define BYTE_SEP '-' +#define CHAR_SEP ' ' + int is_utf8_cont(unsigned char); void print_octets(char *); void print_characters(char *); -- cgit v1.2.3