mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
string.c (mrb_utf8len): reduce UTF-8 table size.
This commit is contained in:
+5
-15
@@ -238,27 +238,17 @@ mrb_gc_free_str(mrb_state *mrb, struct RString *str)
|
||||
}
|
||||
|
||||
#ifdef MRB_UTF8_STRING
|
||||
static const char utf8len_codepage[256] =
|
||||
{
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
|
||||
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,1,1,1,1,1,1,1,1,1,1,1,
|
||||
};
|
||||
|
||||
#define utf8_islead(c) ((unsigned char)((c)&0xc0) != 0x80)
|
||||
|
||||
mrb_int
|
||||
mrb_utf8len(const char* p, const char* e)
|
||||
{
|
||||
mrb_int len;
|
||||
|
||||
if ((unsigned char)*p < 0x80) return 1;
|
||||
len = utf8len_codepage[(unsigned char)*p];
|
||||
static const char lengths[] = {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 4, 0
|
||||
};
|
||||
mrb_int len = lengths[(unsigned char)p[0] >> 3];
|
||||
if (len > e - p) return 1;
|
||||
switch (len) {
|
||||
case 1:
|
||||
|
||||
Reference in New Issue
Block a user