Blame gllib/unictype/categ_longname.c

rpm-build 858c0f
/* Categories of Unicode characters.
rpm-build 858c0f
   Copyright (C) 2002, 2006-2007, 2011-2017 Free Software Foundation, Inc.
rpm-build 858c0f
   Written by Bruno Haible <bruno@clisp.org>, 2011.
rpm-build 858c0f
rpm-build 858c0f
   This program is free software: you can redistribute it and/or modify it
rpm-build 858c0f
   under the terms of the GNU General Public License as published
rpm-build 858c0f
   by the Free Software Foundation; either version 3 of the License, or
rpm-build 858c0f
   (at your option) any later version.
rpm-build 858c0f
rpm-build 858c0f
   This program is distributed in the hope that it will be useful,
rpm-build 858c0f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 858c0f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 858c0f
   General Public License for more details.
rpm-build 858c0f
rpm-build 858c0f
   You should have received a copy of the GNU General Public License
rpm-build 858c0f
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
rpm-build 858c0f
rpm-build 858c0f
#include <config.h>
rpm-build 858c0f
rpm-build 858c0f
/* Specification.  */
rpm-build 858c0f
#include "unictype.h"
rpm-build 858c0f
rpm-build 858c0f
static const char u_category_long_name[30][22] =
rpm-build 858c0f
{
rpm-build 858c0f
  "Uppercase Letter",
rpm-build 858c0f
  "Lowercase Letter",
rpm-build 858c0f
  "Titlecase Letter",
rpm-build 858c0f
  "Modifier Letter",
rpm-build 858c0f
  "Other Letter",
rpm-build 858c0f
  "Nonspacing Mark",
rpm-build 858c0f
  "Spacing Mark",
rpm-build 858c0f
  "Enclosing Mark",
rpm-build 858c0f
  "Decimal Number",
rpm-build 858c0f
  "Letter Number",
rpm-build 858c0f
  "Other Number",
rpm-build 858c0f
  "Connector Punctuation",
rpm-build 858c0f
  "Dash Punctuation",
rpm-build 858c0f
  "Open Punctuation",
rpm-build 858c0f
  "Close Punctuation",
rpm-build 858c0f
  "Initial Punctuation",
rpm-build 858c0f
  "Final Punctuation",
rpm-build 858c0f
  "Other Punctuation",
rpm-build 858c0f
  "Math Symbol",
rpm-build 858c0f
  "Currency Symbol",
rpm-build 858c0f
  "Modifier Symbol",
rpm-build 858c0f
  "Other Symbol",
rpm-build 858c0f
  "Space Separator",
rpm-build 858c0f
  "Line Separator",
rpm-build 858c0f
  "Paragraph Separator",
rpm-build 858c0f
  "Control",
rpm-build 858c0f
  "Format",
rpm-build 858c0f
  "Surrogate",
rpm-build 858c0f
  "Private Use",
rpm-build 858c0f
  "Unassigned"
rpm-build 858c0f
};
rpm-build 858c0f
rpm-build 858c0f
const char *
rpm-build 858c0f
uc_general_category_long_name (uc_general_category_t category)
rpm-build 858c0f
{
rpm-build 858c0f
  uint32_t bitmask = category.bitmask;
rpm-build 858c0f
  /* bitmask should consist of a single bit.  */
rpm-build 858c0f
  if (bitmask != 0)
rpm-build 858c0f
    {
rpm-build 858c0f
      if ((bitmask & (bitmask - 1)) == 0)
rpm-build 858c0f
        {
rpm-build 858c0f
          int bit;
rpm-build 858c0f
          /* Take log2 using a variant of Robert Harley's method.
rpm-build 858c0f
             Found by Bruno Haible 1996.  */
rpm-build 858c0f
          uint32_t n = bitmask;
rpm-build 858c0f
          static const char ord2_tab[64] =
rpm-build 858c0f
            {
rpm-build 858c0f
              -1,  0,  1, 12,  2,  6, -1, 13,  3, -1,  7, -1, -1, -1, -1, 14,
rpm-build 858c0f
              10,  4, -1, -1,  8, -1, -1, 25, -1, -1, -1, -1, -1, 21, 27, 15,
rpm-build 858c0f
              31, 11,  5, -1, -1, -1, -1, -1,  9, -1, -1, 24, -1, -1, 20, 26,
rpm-build 858c0f
              30, -1, -1, -1, -1, 23, -1, 19, 29, -1, 22, 18, 28, 17, 16, -1
rpm-build 858c0f
            };
rpm-build 858c0f
          n += n << 4;
rpm-build 858c0f
          n += n << 6;
rpm-build 858c0f
          n = (n << 16) - n;
rpm-build 858c0f
          bit = ord2_tab[n >> 26];
rpm-build 858c0f
rpm-build 858c0f
          if (bit < sizeof (u_category_long_name) / sizeof (u_category_long_name[0]))
rpm-build 858c0f
            return u_category_long_name[bit];
rpm-build 858c0f
        }
rpm-build 858c0f
      else
rpm-build 858c0f
        {
rpm-build 858c0f
          if (bitmask == UC_CATEGORY_MASK_L)
rpm-build 858c0f
            return "Letter";
rpm-build 858c0f
          if (bitmask == UC_CATEGORY_MASK_LC)
rpm-build 858c0f
            return "Cased Letter";
rpm-build 858c0f
          if (bitmask == UC_CATEGORY_MASK_M)
rpm-build 858c0f
            return "Mark";
rpm-build 858c0f
          if (bitmask == UC_CATEGORY_MASK_N)
rpm-build 858c0f
            return "Number";
rpm-build 858c0f
          if (bitmask == UC_CATEGORY_MASK_P)
rpm-build 858c0f
            return "Punctuation";
rpm-build 858c0f
          if (bitmask == UC_CATEGORY_MASK_S)
rpm-build 858c0f
            return "Symbol";
rpm-build 858c0f
          if (bitmask == UC_CATEGORY_MASK_Z)
rpm-build 858c0f
            return "Separator";
rpm-build 858c0f
          if (bitmask == UC_CATEGORY_MASK_C)
rpm-build 858c0f
            return "Other";
rpm-build 858c0f
        }
rpm-build 858c0f
    }
rpm-build 858c0f
  return NULL;
rpm-build 858c0f
}