make utf check a macro: ISUTF8 - sob - simple output bar
 (HTM) git clone git://git.codemadness.org/sob
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 7afed68f4206f4ec42a64635120162970a38a11a
 (DIR) parent b46f6c23707a2270319dbe3ba9b20129b8f8d823
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Sun, 12 Oct 2014 21:59:51 +0000
       
       make utf check a macro: ISUTF8
       
       Diffstat:
         M sob.c                               |      11 ++++++-----
       
       1 file changed, 6 insertions(+), 5 deletions(-)
       ---
 (DIR) diff --git a/sob.c b/sob.c
       @@ -19,6 +19,7 @@ char *argv0;
        #include "util.h"
        
        #define LEN(x)    (sizeof (x) / sizeof *(x))
       +#define ISUTF8(c) (((c) & 0xc0) != 0x80)
        
        struct line {
                char line[BUFSIZ]; /* static line buffer */
       @@ -104,7 +105,7 @@ colw(const char *s, size_t max)
                int r;
        
                for(i = 0; *s && i < max; s++, i++) {
       -                if((*s & 0xc0) != 0x80) {
       +                if(ISUTF8(*s)) {
                                if((r = mbtowc(&w, s, i + 4 > max ? max - i : 4)) == -1)
                                        break;
                                if((r = wcwidth(w)) == -1)
       @@ -121,7 +122,7 @@ utf8len(const char *s)
                size_t i;
        
                for(i = 0; *s; s++) {
       -                if((*s & 0xc0) != 0x80)
       +                if(ISUTF8(*s))
                                i++;
                }
                return i;
       @@ -136,7 +137,7 @@ utfprevn(const char *s, size_t p, size_t n)
        
                for(i = 0; p > 0; p--) {
                        i++;
       -                if((s[p - 1] & 0xc0) != 0x80 && !--n)
       +                if(ISUTF8(s[p - 1]) && !--n)
                                return i;
                }
                return 0;
       @@ -151,7 +152,7 @@ utfnextn(const char *s, size_t p, size_t n)
        
                for(i = 0; s[p]; p++) {
                        i++;
       -                if((s[p + 1] & 0xc0) != 0x80 && !--n)
       +                if(ISUTF8(s[p + 1]) && !--n)
                                return i;
                }
                return 0;
       @@ -224,7 +225,7 @@ line_promptlen(void)
                for(i = 0; prompt[i]; i++) {
                        if(prompt[i] == 1)
                                t = !t;
       -                else if(!t && (prompt[i] & 0xc0) != 0x80)
       +                else if(!t && ISUTF8(prompt[i]))
                                n++;
                }
                return n;