Commit | Line | Data |
---|---|---|
b0322a85 CE |
1 | /* |
2 | ** Copyright 2011 Double Precision, Inc. | |
3 | ** See COPYING for distribution information. | |
4 | ** | |
5 | */ | |
6 | ||
7 | #include "unicode_config.h" | |
8 | #include "unicode.h" | |
9 | ||
10 | #include <stdlib.h> | |
11 | ||
12 | struct i { | |
13 | size_t n_start; | |
14 | size_t n_size; | |
15 | unicode_char v; | |
16 | }; | |
17 | ||
18 | #include "unicode_htmlent.h" | |
19 | ||
20 | ||
21 | static int compar(const void *key, const void *obj) | |
22 | { | |
23 | size_t j; | |
24 | const char *p=n + ((const struct i *)obj)->n_start; | |
25 | const char *ckey=(const char *)key; | |
26 | ||
27 | for (j=0; j<((const struct i *)obj)->n_size; ++j) | |
28 | { | |
29 | if (*ckey < *p) | |
30 | return -1; | |
31 | ||
32 | if (*ckey > *p) | |
33 | return 1; | |
34 | ||
35 | ++p; | |
36 | ++ckey; | |
37 | } | |
38 | ||
39 | if (*ckey) | |
40 | return 1; | |
41 | ||
42 | return 0; | |
43 | } | |
44 | ||
45 | unicode_char unicode_html40ent_lookup(const char *n) | |
46 | { | |
47 | const struct i *ptr= | |
48 | (const struct i *)bsearch(n, ii, | |
49 | sizeof(ii)/sizeof(ii[0]), | |
50 | sizeof(ii[0]), compar); | |
51 | ||
52 | if (ptr) | |
53 | return ptr->v; | |
54 | return 0; | |
55 | } |