Coverage Report

Created: 2026-09-28 06:47

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.61M
{
40
7.61M
  if (m1->start < m2->start)
41
5.31M
    return -1;
42
2.29M
  if (m1->start > m2->end)
43
1.58M
    return 1;
44
716k
  return 0;
45
2.29M
}
46
47
static int
48
property (uint32_t cp)
49
  _GL_ATTRIBUTE_CONST;
50
51
     static int property (uint32_t cp)
52
716k
{
53
716k
  const struct idna_table *result;
54
716k
  struct idna_table key;
55
56
716k
  key.start = cp;
57
58
716k
  result = (struct idna_table *)
59
716k
    bsearch (&key, idna_table, idna_table_size,
60
716k
       sizeof (struct idna_table),
61
716k
       (int (*)(const void *, const void *)) _compare);
62
63
716k
  return result ? result->state : UNASSIGNED;
64
716k
}
65
66
int
67
_idn2_disallowed_p (uint32_t cp)
68
205k
{
69
205k
  return property (cp) == DISALLOWED;
70
205k
}
71
72
int
73
_idn2_contextj_p (uint32_t cp)
74
181k
{
75
181k
  return property (cp) == CONTEXTJ;
76
181k
}
77
78
int
79
_idn2_contexto_p (uint32_t cp)
80
164k
{
81
164k
  return property (cp) == CONTEXTO;
82
164k
}
83
84
int
85
_idn2_unassigned_p (uint32_t cp)
86
164k
{
87
164k
  return property (cp) == UNASSIGNED;
88
164k
}