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

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

DEFINITIONS

This source file includes following definitions.
  1. uc_general_category_long_name

   1 /* Categories of Unicode characters.
   2    Copyright (C) 2002, 2006-2007, 2011-2021 Free Software Foundation, Inc.
   3    Written by Bruno Haible <bruno@clisp.org>, 2011.
   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 static const char u_category_long_name[30][22] =
  32 {
  33   "Uppercase Letter",
  34   "Lowercase Letter",
  35   "Titlecase Letter",
  36   "Modifier Letter",
  37   "Other Letter",
  38   "Nonspacing Mark",
  39   "Spacing Mark",
  40   "Enclosing Mark",
  41   "Decimal Number",
  42   "Letter Number",
  43   "Other Number",
  44   "Connector Punctuation",
  45   "Dash Punctuation",
  46   "Open Punctuation",
  47   "Close Punctuation",
  48   "Initial Punctuation",
  49   "Final Punctuation",
  50   "Other Punctuation",
  51   "Math Symbol",
  52   "Currency Symbol",
  53   "Modifier Symbol",
  54   "Other Symbol",
  55   "Space Separator",
  56   "Line Separator",
  57   "Paragraph Separator",
  58   "Control",
  59   "Format",
  60   "Surrogate",
  61   "Private Use",
  62   "Unassigned"
  63 };
  64 
  65 const char *
  66 uc_general_category_long_name (uc_general_category_t category)
     /* [previous][next][first][last][top][bottom][index][help] */
  67 {
  68   uint32_t bitmask = category.bitmask;
  69   /* bitmask should consist of a single bit.  */
  70   if (bitmask != 0)
  71     {
  72       if ((bitmask & (bitmask - 1)) == 0)
  73         {
  74           int bit;
  75           /* Take log2 using a variant of Robert Harley's method.
  76              Found by Bruno Haible 1996.  */
  77           uint32_t n = bitmask;
  78           static const char ord2_tab[64] =
  79             {
  80               -1,  0,  1, 12,  2,  6, -1, 13,  3, -1,  7, -1, -1, -1, -1, 14,
  81               10,  4, -1, -1,  8, -1, -1, 25, -1, -1, -1, -1, -1, 21, 27, 15,
  82               31, 11,  5, -1, -1, -1, -1, -1,  9, -1, -1, 24, -1, -1, 20, 26,
  83               30, -1, -1, -1, -1, 23, -1, 19, 29, -1, 22, 18, 28, 17, 16, -1
  84             };
  85           n += n << 4;
  86           n += n << 6;
  87           n = (n << 16) - n;
  88           bit = ord2_tab[n >> 26];
  89 
  90           if (bit < sizeof (u_category_long_name) / sizeof (u_category_long_name[0]))
  91             return u_category_long_name[bit];
  92         }
  93       else
  94         {
  95           if (bitmask == UC_CATEGORY_MASK_L)
  96             return "Letter";
  97           if (bitmask == UC_CATEGORY_MASK_LC)
  98             return "Cased Letter";
  99           if (bitmask == UC_CATEGORY_MASK_M)
 100             return "Mark";
 101           if (bitmask == UC_CATEGORY_MASK_N)
 102             return "Number";
 103           if (bitmask == UC_CATEGORY_MASK_P)
 104             return "Punctuation";
 105           if (bitmask == UC_CATEGORY_MASK_S)
 106             return "Symbol";
 107           if (bitmask == UC_CATEGORY_MASK_Z)
 108             return "Separator";
 109           if (bitmask == UC_CATEGORY_MASK_C)
 110             return "Other";
 111         }
 112     }
 113   return NULL;
 114 }

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