| tuc: replace comparison with bit checks in uc_len() - neatvi - [fork] simple vi… | |
| git clone git://src.adamsgaard.dk/neatvi | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit 6ec8f20a4a15db6ec888b4815d9b7eb426515dfa | |
| parent 978c4c03d19f920e0d42ca972d27f94d1dfc5327 | |
| Author: Ali Gholami Rudi <[email protected]> | |
| Date: Mon, 15 Jun 2015 18:51:47 +0430 | |
| uc: replace comparison with bit checks in uc_len() | |
| Diffstat: | |
| M uc.c | 26 +++++++++++++------------- | |
| 1 file changed, 13 insertions(+), 13 deletions(-) | |
| --- | |
| diff --git a/uc.c b/uc.c | |
| t@@ -10,19 +10,19 @@ | |
| 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 & 0x80) | |
| + return 4; | |
| + if (~c & 0x40) | |
| + return 5; | |
| + if (~c & 0x20) | |
| + return 6; | |
| + return 1; | |
| } | |
| /* the number of utf-8 characters in s */ | |
| t@@ -121,7 +121,7 @@ char *uc_chr(char *s, int off) | |
| return s && (off < 0 || i == off) ? s : ""; | |
| } | |
| -/* the number of characters between s and s + off*/ | |
| +/* the number of characters between s and s + off */ | |
| int uc_off(char *s, int off) | |
| { | |
| char *e = s + off; |