tregex: use bit masks in uc_len() - neatvi - [fork] simple vi-type editor with UTF-8 support
(HTM) git clone git://src.adamsgaard.dk/neatvi
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit 09ae245a5a3197522cab51d55914d331f8512de5
(DIR) parent a2fe7e9ef29a43cf747296180156b2970b309a53
(HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
Date: Sun, 22 May 2016 12:37:13 +0430
regex: use bit masks in uc_len()
Diffstat:
M regex.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
---
(DIR) diff --git a/regex.c b/regex.c
t@@ -96,19 +96,19 @@ static void rnode_free(struct rnode *rnode)
static int uc_len(char *s)
{
int c = (unsigned char) s[0];
- if (c > 0 && c <= 0x7f)
- return 1;
- if (c >= 0xfc)
- return 6;
- if (c >= 0xf8)
- return 5;
- if (c >= 0xf0)
- return 4;
- if (c >= 0xe0)
- return 3;
- if (c >= 0xc0)
+ if (~c & 0x80)
+ return c > 0;
+ if (~c & 0x20)
return 2;
- return c != 0;
+ if (~c & 0x10)
+ return 3;
+ if (~c & 0x08)
+ return 4;
+ if (~c & 0x04)
+ return 5;
+ if (~c & 0x02)
+ return 6;
+ return 1;
}
static int uc_dec(char *s)