1 1.1 simonb #include "lt_types.h" 2 1.1 simonb 3 1.1 simonb typedef struct wchar_range { wchar first, last; } wchar_range; 4 1.1 simonb 5 1.1 simonb static wchar_range wide_chars[] = { 6 1.1 simonb #include "../wide.uni" 7 1.1 simonb }; 8 1.1 simonb static wchar_range compose_table[] = { 9 1.1 simonb #include "../compose.uni" 10 1.1 simonb }; 11 1.1 simonb static wchar_range fmt_table[] = { 12 1.1 simonb #include "../fmt.uni" 13 1.1 simonb }; 14 1.1 simonb static wchar_range comb_table[] = { 15 1.1 simonb {0x0644,0x0622}, {0x0644,0x0623}, {0x0644,0x0625}, {0x0644,0x0627}, 16 1.1 simonb }; 17 1.1 simonb 18 1.1 simonb static int is_in_table(wchar ch, wchar_range table[], int count) { 19 1.1 simonb if (ch < table[0].first) 20 1.1 simonb return 0; 21 1.1 simonb int lo = 0; 22 1.1 simonb int hi = count - 1; 23 1.1 simonb while (lo <= hi) { 24 1.1 simonb int mid = (lo + hi) / 2; 25 1.1 simonb if (ch > table[mid].last) 26 1.1 simonb lo = mid + 1; 27 1.1 simonb else if (ch < table[mid].first) 28 1.1 simonb hi = mid - 1; 29 1.1 simonb else 30 1.1 simonb return 1; 31 1.1 simonb } 32 1.1 simonb return 0; 33 1.1 simonb } 34 1.1 simonb 35 1.1 simonb int is_wide_char(wchar ch) { 36 1.1 simonb return is_in_table(ch, wide_chars, countof(wide_chars)); 37 1.1 simonb } 38 1.1 simonb 39 1.1 simonb int is_composing_char(wchar ch) { 40 1.1 simonb return is_in_table(ch, compose_table, countof(compose_table)) || 41 1.1 simonb is_in_table(ch, fmt_table, countof(fmt_table)); 42 1.1 simonb } 43 1.1 simonb 44 1.1 simonb int is_combining_char(wchar ch1, wchar ch2) { 45 1.1 simonb int i; 46 1.1 simonb for (i = 0; i < countof(comb_table); i++) { 47 1.1 simonb if (ch1 == comb_table[i].first && 48 1.1 simonb ch2 == comb_table[i].last) 49 1.1 simonb return 1; 50 1.1 simonb } 51 1.1 simonb return 0; 52 1.1 simonb } 53