root/maint/gnulib/lib/unictype/blocks.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. uc_block
  2. uc_all_blocks

   1 /* Blocks of Unicode characters.
   2    Copyright (C) 2007, 2009-2021 Free Software Foundation, Inc.
   3    Written by Bruno Haible <bruno@clisp.org>, 2007.
   4 
   5    This file is free software.
   6    It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+".
   7    You can redistribute it and/or modify it under either
   8      - the terms of the GNU Lesser General Public License as published
   9        by the Free Software Foundation; either version 3, or (at your
  10        option) any later version, or
  11      - the terms of the GNU General Public License as published by the
  12        Free Software Foundation; either version 2, or (at your option)
  13        any later version, or
  14      - the same dual license "the GNU LGPLv3+ or the GNU GPLv2+".
  15 
  16    This file is distributed in the hope that it will be useful,
  17    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19    Lesser General Public License and the GNU General Public License
  20    for more details.
  21 
  22    You should have received a copy of the GNU Lesser General Public
  23    License and of the GNU General Public License along with this
  24    program.  If not, see <https://www.gnu.org/licenses/>.  */
  25 
  26 #include <config.h>
  27 
  28 /* Specification.  */
  29 #include "unictype.h"
  30 
  31 #include "blocks.h"
  32 
  33 const uc_block_t *
  34 uc_block (ucs4_t uc)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36   unsigned int first_index;
  37   unsigned int last_index;
  38 
  39   if (uc < blocks_level1_threshold)
  40     {
  41       unsigned int index1 = uc >> blocks_level1_shift;
  42       first_index = blocks_level1[2 * index1];
  43       last_index = blocks_level1[2 * index1 + 1];
  44     }
  45   else
  46     {
  47       first_index = blocks_upper_first_index;
  48       last_index = blocks_upper_last_index;
  49     }
  50   /* We know that the relevant blocks are blocks[i] with
  51      first_index <= i < last_index.  Now perform a binary search.  */
  52   while (first_index < last_index)
  53     {
  54       unsigned int mid_index = (first_index + last_index) / 2;
  55       if (blocks[mid_index].end < uc)
  56         first_index = mid_index + 1;
  57       else if (uc < blocks[mid_index].start)
  58         last_index = mid_index;
  59       else
  60         return &blocks[mid_index];
  61     }
  62   return NULL;
  63 }
  64 
  65 void
  66 uc_all_blocks (const uc_block_t **blocksp, size_t *countp)
     /* [previous][next][first][last][top][bottom][index][help] */
  67 {
  68   *blocksp = blocks;
  69   *countp = sizeof (blocks) / sizeof (blocks[0]);
  70 }

/* [previous][next][first][last][top][bottom][index][help] */