tuc: read invalid utf-8 characters byte by byte - neatvi - [fork] simple vi-typ… | |
git clone git://src.adamsgaard.dk/neatvi | |
Log | |
Files | |
Refs | |
README | |
--- | |
commit 20cc8817475554d8448632970ff7c8d84ed2f9e2 | |
parent 5eaaf403f7dc6a08f434aea8825e692102bf258a | |
Author: Ali Gholami Rudi <[email protected]> | |
Date: Mon, 23 May 2016 21:22:12 +0430 | |
uc: read invalid utf-8 characters byte by byte | |
Diffstat: | |
M regex.c | 4 +++- | |
M uc.c | 4 +++- | |
2 files changed, 6 insertions(+), 2 deletions(-) | |
--- | |
diff --git a/regex.c b/regex.c | |
t@@ -96,8 +96,10 @@ static void rnode_free(struct rnode *rnode) | |
static int uc_len(char *s) | |
{ | |
int c = (unsigned char) s[0]; | |
- if (~c & 0x80) | |
+ if (~c & 0x80) /* ASCII */ | |
return c > 0; | |
+ if (~c & 0x40) /* invalid UTF-8 */ | |
+ return 1; | |
if (~c & 0x20) | |
return 2; | |
if (~c & 0x10) | |
diff --git a/uc.c b/uc.c | |
t@@ -10,8 +10,10 @@ | |
int uc_len(char *s) | |
{ | |
int c = (unsigned char) s[0]; | |
- if (~c & 0x80) | |
+ if (~c & 0x80) /* ASCII */ | |
return c > 0; | |
+ if (~c & 0x40) /* invalid UTF-8 */ | |
+ return 1; | |
if (~c & 0x20) | |
return 2; | |
if (~c & 0x10) |