diff options
Diffstat (limited to 'unicode/unicode_tablookup.c')
| -rw-r--r-- | unicode/unicode_tablookup.c | 66 |
1 files changed, 55 insertions, 11 deletions
diff --git a/unicode/unicode_tablookup.c b/unicode/unicode_tablookup.c index 1f04652..8fc177c 100644 --- a/unicode/unicode_tablookup.c +++ b/unicode/unicode_tablookup.c @@ -10,19 +10,40 @@ #define BLOCK_SIZE 256 uint8_t unicode_tab_lookup(char32_t ch, - const size_t *unicode_indextab, - size_t unicode_indextab_sizeof, + const size_t *unicode_starting_indextab, + const char32_t *unicode_starting_pagetab, + size_t unicode_tab_sizeof, const uint8_t (*unicode_rangetab)[2], + size_t unicode_rangetab_sizeof, const uint8_t *unicode_classtab, uint8_t uclass) { size_t cl=ch / BLOCK_SIZE; - if (cl < unicode_indextab_sizeof-1) + size_t b=0; + size_t e=unicode_tab_sizeof; + + while (b < e) { - const size_t start_pos=unicode_indextab[cl]; + size_t n=b + (e-b)/2; + + if (cl < unicode_starting_indextab[n]) + { + e=n; + continue; + } + else if (cl > unicode_starting_indextab[n]) + { + b=n+1; + continue; + } + + const size_t start_pos=unicode_starting_pagetab[n]; const uint8_t (*p)[2]=unicode_rangetab + start_pos; - size_t b=0, e=unicode_indextab[cl+1] - start_pos; + b=0; + e=(n+1 >= unicode_tab_sizeof + ? unicode_rangetab_sizeof + : unicode_starting_pagetab[n+1]) - start_pos; uint8_t chmodcl= ch & (BLOCK_SIZE-1); while (b < e) @@ -43,26 +64,48 @@ uint8_t unicode_tab_lookup(char32_t ch, e=n; } } + break; } return uclass; } uint32_t unicode_tab32_lookup(char32_t ch, - const size_t *unicode_indextab, - size_t unicode_indextab_sizeof, + const size_t *unicode_starting_indextab, + const char32_t *unicode_starting_pagetab, + size_t unicode_tab_sizeof, const uint8_t (*unicode_rangetab)[2], + size_t unicode_rangetab_sizeof, const uint32_t *unicode_classtab, uint32_t uclass) { size_t cl=ch / BLOCK_SIZE; - if (cl < unicode_indextab_sizeof-1) + size_t b=0; + size_t e=unicode_tab_sizeof; + + while (b < e) { - const size_t start_pos=unicode_indextab[cl]; + size_t n=b + (e-b)/2; + + if (cl < unicode_starting_indextab[n]) + { + e=n; + continue; + } + else if (cl > unicode_starting_indextab[n]) + { + b=n+1; + continue; + } + + const size_t start_pos=unicode_starting_pagetab[n]; const uint8_t (*p)[2]=unicode_rangetab + start_pos; - size_t b=0, e=unicode_indextab[cl+1] - start_pos; - uint32_t chmodcl= ch & (BLOCK_SIZE-1); + b=0; + e=(n+1 >= unicode_tab_sizeof + ? unicode_rangetab_sizeof + : unicode_starting_pagetab[n+1]) - start_pos; + uint8_t chmodcl= ch & (BLOCK_SIZE-1); while (b < e) { @@ -82,6 +125,7 @@ uint32_t unicode_tab32_lookup(char32_t ch, e=n; } } + break; } return uclass; |
