aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-12-22 19:33:38 +1300
committerTom Ryder <tom@sanctum.geek.nz>2021-09-20 16:05:31 +1200
commitbcfe32ad1e5178b43c92236f1dbb67a2b53f0b40 (patch)
treee3ae7810faed1c8352c74664e3f89aecfd92c679
parentBump VERSION (diff)
downloadwtf8-bcfe32ad1e5178b43c92236f1dbb67a2b53f0b40.tar.gz
wtf8-bcfe32ad1e5178b43c92236f1dbb67a2b53f0b40.zip
Make some dense code a little less opaque
-rw-r--r--wtf8.c9
-rw-r--r--wtf8.h3
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 <stdio.h>
#include <stdlib.h>
+#define BYTE_SEP '-'
+#define CHAR_SEP ' '
+
int is_utf8_cont(unsigned char);
void print_octets(char *);
void print_characters(char *);