aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-12-15 19:40:54 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-12-15 19:40:54 +1300
commit1f6f97aec816c1ecfb816ba3df64054e8bd84458 (patch)
treecd53dfbab1f570ffe717630b51d31dd741e9c72a
parentMove includes into header file (diff)
downloadwtf8-1f6f97aec816c1ecfb816ba3df64054e8bd84458.tar.gz
wtf8-1f6f97aec816c1ecfb816ba3df64054e8bd84458.zip
Move magic constant test into separate function
-rw-r--r--wtf8.c6
-rw-r--r--wtf8.h2
2 files changed, 7 insertions, 1 deletions
diff --git a/wtf8.c b/wtf8.c
index fd8bc78..c80875d 100644
--- a/wtf8.c
+++ b/wtf8.c
@@ -1,5 +1,9 @@
#include "wtf8.h"
+int is_utf8_cont(char c) {
+ return (c & 0xC0) == 0x80;
+}
+
int main(int argc, char **argv) {
char *p;
int c;
@@ -12,7 +16,7 @@ int main(int argc, char **argv) {
putchar('\n');
for (p = argv[1]; *p; ) {
- for (c = 1; p[c] && (p[c] & 0xC0) == 0x80; c++)
+ for (c = 1; p[c] && is_utf8_cont(p[c]); c++)
printf(" ");
putchar(' ');
for (; c > 0; c--)
diff --git a/wtf8.h b/wtf8.h
index fbfff34..64ac8a1 100644
--- a/wtf8.h
+++ b/wtf8.h
@@ -1,2 +1,4 @@
#include <stdio.h>
#include <stdlib.h>
+
+int is_utf8_cont(char);