diff options
Diffstat (limited to 'sys/cmd/rc/lex.c')
-rw-r--r-- | sys/cmd/rc/lex.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/sys/cmd/rc/lex.c b/sys/cmd/rc/lex.c index 9a58f21..9ca2453 100644 --- a/sys/cmd/rc/lex.c +++ b/sys/cmd/rc/lex.c @@ -142,28 +142,23 @@ putbyte(char *buf, int c) return buf; } -#define onebyte(c) ((c&0x80)==0x00) -#define twobyte(c) ((c&0xe0)==0xc0) -#define threebyte(c) ((c&0xf0)==0xe0) -#define fourbyte(c) ((c&0xf8)==0xf0) - static char * putrune(char *buf, int c) { buf = putbyte(buf, c); - if(onebyte(c)) + if(utf8·onebyte(c)) return buf; - if(twobyte(c)) - return putbyte(buf,c); - if(threebyte(c)){ - buf = putbyte(buf,c); - return putbyte(buf,c); + if(utf8·twobyte(c)) + return putbyte(buf,advance()); + if(utf8·threebyte(c)){ + buf = putbyte(buf,advance()); + return putbyte(buf,advance()); } - if(fourbyte(c)){ - buf = putbyte(buf,c); - buf = putbyte(buf,c); - return putbyte(buf,c); + if(utf8·fourbyte(c)){ + buf = putbyte(buf,advance()); + buf = putbyte(buf,advance()); + return putbyte(buf,advance()); } fatal("malformed utf8 stream"); |