tuc: read invalid utf-8 characters byte by byte - neatvi - [fork] simple vi-type editor with UTF-8 support
HTML git clone git://src.adamsgaard.dk/neatvi
DIR Log
DIR Files
DIR Refs
DIR README
---
DIR commit 20cc8817475554d8448632970ff7c8d84ed2f9e2
DIR parent 5eaaf403f7dc6a08f434aea8825e692102bf258a
HTML Author: Ali Gholami Rudi <ali@rudi.ir>
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(-)
---
DIR 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)
DIR 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)