Coverage Report

Created: 2025-07-23 06:43

/src/libidn2/lib/tables.c
Line
Count
Source (jump to first uncovered line)
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
1.09M
{
40
1.09M
  if (m1->start < m2->start)
41
747k
    return -1;
42
351k
  if (m1->start > m2->end)
43
248k
    return 1;
44
103k
  return 0;
45
351k
}
46
47
static int
48
property (uint32_t cp)
49
  _GL_ATTRIBUTE_CONST;
50
51
     static int property (uint32_t cp)
52
103k
{
53
103k
  const struct idna_table *result;
54
103k
  struct idna_table key;
55
56
103k
  key.start = cp;
57
58
103k
  result = (struct idna_table *)
59
103k
    bsearch (&key, idna_table, idna_table_size,
60
103k
       sizeof (struct idna_table),
61
103k
       (int (*)(const void *, const void *)) _compare);
62
63
103k
  return result ? result->state : UNASSIGNED;
64
103k
}
65
66
int
67
_idn2_disallowed_p (uint32_t cp)
68
32.2k
{
69
32.2k
  return property (cp) == DISALLOWED;
70
32.2k
}
71
72
int
73
_idn2_contextj_p (uint32_t cp)
74
25.5k
{
75
25.5k
  return property (cp) == CONTEXTJ;
76
25.5k
}
77
78
int
79
_idn2_contexto_p (uint32_t cp)
80
22.9k
{
81
22.9k
  return property (cp) == CONTEXTO;
82
22.9k
}
83
84
int
85
_idn2_unassigned_p (uint32_t cp)
86
22.9k
{
87
22.9k
  return property (cp) == UNASSIGNED;
88
22.9k
}