/src/libidn2/lib/tables.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* tables.c - IDNA table checking functions |
2 | | Copyright (C) 2011-2022 Simon Josefsson |
3 | | |
4 | | Libidn2 is free software: you can redistribute it and/or modify it |
5 | | under the terms of either: |
6 | | |
7 | | * the GNU Lesser General Public License as published by the Free |
8 | | Software Foundation; either version 3 of the License, or (at |
9 | | your option) any later version. |
10 | | |
11 | | or |
12 | | |
13 | | * the GNU General Public License as published by the Free |
14 | | Software Foundation; either version 2 of the License, or (at |
15 | | your option) any later version. |
16 | | |
17 | | or both in parallel, as here. |
18 | | |
19 | | This program is distributed in the hope that it will be useful, |
20 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | | GNU General Public License for more details. |
23 | | |
24 | | You should have received copies of the GNU General Public License and |
25 | | the GNU Lesser General Public License along with this program. If |
26 | | not, see <http://www.gnu.org/licenses/>. |
27 | | */ |
28 | | |
29 | | #include <config.h> |
30 | | |
31 | | #include "tables.h" |
32 | | |
33 | | #include <stdlib.h> /* bsearch */ |
34 | | |
35 | | #include "data.h" |
36 | | |
37 | | static int |
38 | | _compare (const struct idna_table *m1, const struct idna_table *m2) |
39 | 0 | { |
40 | 0 | if (m1->start < m2->start) |
41 | 0 | return -1; |
42 | 0 | if (m1->start > m2->end) |
43 | 0 | return 1; |
44 | 0 | return 0; |
45 | 0 | } |
46 | | |
47 | | static int |
48 | | property (uint32_t cp) |
49 | | _GL_ATTRIBUTE_CONST; |
50 | | |
51 | | static int property (uint32_t cp) |
52 | 0 | { |
53 | 0 | const struct idna_table *result; |
54 | 0 | struct idna_table key; |
55 | |
|
56 | 0 | key.start = cp; |
57 | |
|
58 | 0 | result = (struct idna_table *) |
59 | 0 | bsearch (&key, idna_table, idna_table_size, |
60 | 0 | sizeof (struct idna_table), |
61 | 0 | (int (*)(const void *, const void *)) _compare); |
62 | |
|
63 | 0 | return result ? result->state : UNASSIGNED; |
64 | 0 | } |
65 | | |
66 | | int |
67 | | _idn2_disallowed_p (uint32_t cp) |
68 | 0 | { |
69 | 0 | return property (cp) == DISALLOWED; |
70 | 0 | } |
71 | | |
72 | | int |
73 | | _idn2_contextj_p (uint32_t cp) |
74 | 0 | { |
75 | 0 | return property (cp) == CONTEXTJ; |
76 | 0 | } |
77 | | |
78 | | int |
79 | | _idn2_contexto_p (uint32_t cp) |
80 | 0 | { |
81 | 0 | return property (cp) == CONTEXTO; |
82 | 0 | } |
83 | | |
84 | | int |
85 | | _idn2_unassigned_p (uint32_t cp) |
86 | 0 | { |
87 | 0 | return property (cp) == UNASSIGNED; |
88 | 0 | } |