Coverage Report

Created: 2026-05-16 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libidn2/lib/tables.c
Line
Count
Source
1
/* tables.c - IDNA table checking functions
2
   Copyright (C) 2011-2025 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
7.45M
{
40
7.45M
  if (m1->start < m2->start)
41
5.23M
    return -1;
42
2.22M
  if (m1->start > m2->end)
43
1.52M
    return 1;
44
702k
  return 0;
45
2.22M
}
46
47
static int
48
property (uint32_t cp)
49
  _GL_ATTRIBUTE_CONST;
50
51
     static int property (uint32_t cp)
52
702k
{
53
702k
  const struct idna_table *result;
54
702k
  struct idna_table key;
55
56
702k
  key.start = cp;
57
58
702k
  result = (struct idna_table *)
59
702k
    bsearch (&key, idna_table, idna_table_size,
60
702k
       sizeof (struct idna_table),
61
702k
       (int (*)(const void *, const void *)) _compare);
62
63
702k
  return result ? result->state : UNASSIGNED;
64
702k
}
65
66
int
67
_idn2_disallowed_p (uint32_t cp)
68
204k
{
69
204k
  return property (cp) == DISALLOWED;
70
204k
}
71
72
int
73
_idn2_contextj_p (uint32_t cp)
74
177k
{
75
177k
  return property (cp) == CONTEXTJ;
76
177k
}
77
78
int
79
_idn2_contexto_p (uint32_t cp)
80
159k
{
81
159k
  return property (cp) == CONTEXTO;
82
159k
}
83
84
int
85
_idn2_unassigned_p (uint32_t cp)
86
159k
{
87
159k
  return property (cp) == UNASSIGNED;
88
159k
}