LCOV - code coverage report
Current view: top level - builds/libidn/libidn2/lib - tables.c (source / functions) Hit Total Coverage
Test: Libidn2-2.3.7.3-61ee Code Coverage Lines: 18 18 100.0 %
Date: 2024-12-01 07:08:19 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* tables.c - IDNA table checking functions
       2             :    Copyright (C) 2011-2024 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    63064277 : _compare (const struct idna_table *m1, const struct idna_table *m2)
      39             : {
      40    63064277 :   if (m1->start < m2->start)
      41    18078325 :     return -1;
      42    44985952 :   if (m1->start > m2->end)
      43    42469729 :     return 1;
      44     2516223 :   return 0;
      45             : }
      46             : 
      47             : static int
      48             : property (uint32_t cp)
      49             :   _GL_ATTRIBUTE_CONST;
      50             : 
      51     5817891 :      static int property (uint32_t cp)
      52             : {
      53             :   const struct idna_table *result;
      54             :   struct idna_table key;
      55             : 
      56     5817891 :   key.start = cp;
      57             : 
      58             :   result = (struct idna_table *)
      59     5817891 :     bsearch (&key, idna_table, idna_table_size,
      60             :              sizeof (struct idna_table),
      61             :              (int (*)(const void *, const void *)) _compare);
      62             : 
      63     5817891 :   return result ? result->state : UNASSIGNED;
      64             : }
      65             : 
      66             : int
      67     1593941 : _idn2_disallowed_p (uint32_t cp)
      68             : {
      69     1593941 :   return property (cp) == DISALLOWED;
      70             : }
      71             : 
      72             : int
      73     1409907 : _idn2_contextj_p (uint32_t cp)
      74             : {
      75     1409907 :   return property (cp) == CONTEXTJ;
      76             : }
      77             : 
      78             : int
      79     1407447 : _idn2_contexto_p (uint32_t cp)
      80             : {
      81     1407447 :   return property (cp) == CONTEXTO;
      82             : }
      83             : 
      84             : int
      85     1406596 : _idn2_unassigned_p (uint32_t cp)
      86             : {
      87     1406596 :   return property (cp) == UNASSIGNED;
      88             : }

Generated by: LCOV version 1.16