diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-11-22 23:48:00 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-11-22 23:48:32 +0100 |
commit | 73641367db67f47c55d28d98b2d41467a8c87211 (patch) | |
tree | af02907cb8bbbc9615d1bab2c7ade01c49b3a3e3 /mscan.c | |
parent | 8b50a794b03244b5de8680bc35b40dec92e4131e (diff) | |
download | mblaze-73641367db67f47c55d28d98b2d41467a8c87211.tar.gz mblaze-73641367db67f47c55d28d98b2d41467a8c87211.tar.xz mblaze-73641367db67f47c55d28d98b2d41467a8c87211.zip |
revamp utf-8 handling code
Diffstat (limited to 'mscan.c')
-rw-r--r-- | mscan.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/mscan.c b/mscan.c index def7fd6..4260af8 100644 --- a/mscan.c +++ b/mscan.c @@ -18,6 +18,7 @@ #include <wchar.h> #include "blaze822.h" +#include "u8decode.h" static int cols; static wchar_t replacement = L'?'; @@ -41,25 +42,24 @@ u8putstr(FILE *out, char *s, ssize_t l, int pad) while (*s && l > 0) { if (*s == '\t') *s = ' '; - if (*s >= 32 && *s < 127) { - putc(*s, out); - s++; - l--; - } else if ((unsigned)*s < 32 || *s == 127) { // C0 + + if ((unsigned)*s < 32 || *s == 127) { // C0 fprintf(out, "%lc", (wint_t)(*s == 127 ? 0x2421 : 0x2400+*s)); s++; l--; } else { - wchar_t wc; - int r = mbtowc(&wc, s, 4); + uint32_t c; + int r = u8decode(s, &c); if (r < 0) { r = 1; - wc = replacement; + fprintf(out, "%lc", (wint_t)replacement); + s++; + } else { + l -= wcwidth((wchar_t)c); + if (l >= 0) + fwrite(s, 1, r, out); + s += r; } - s += r; - l -= wcwidth(wc); - if (l >= 0) - fprintf(out, "%lc", (wint_t)wc); } } if (pad) |