Blame gllib/unictype/scripts.c

rpm-build 858c0f
/* Scripts of Unicode characters.
rpm-build 858c0f
   Copyright (C) 2007, 2009-2017 Free Software Foundation, Inc.
rpm-build 858c0f
   Written by Bruno Haible <bruno@clisp.org>, 2007.
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
#include <string.h>
rpm-build 858c0f
rpm-build 858c0f
#include "scripts.h"
rpm-build 858c0f
#include "unictype/scripts_byname.h"
rpm-build 858c0f
rpm-build 858c0f
const uc_script_t *
rpm-build 858c0f
uc_script (ucs4_t uc)
rpm-build 858c0f
{
rpm-build 858c0f
  unsigned int index1 = uc >> script_header_0;
rpm-build 858c0f
  if (index1 < script_header_1)
rpm-build 858c0f
    {
rpm-build 858c0f
      int lookup1 = u_script.level1[index1];
rpm-build 858c0f
      if (lookup1 >= 0)
rpm-build 858c0f
        {
rpm-build 858c0f
          unsigned int index2 = (uc >> script_header_2) & script_header_3;
rpm-build 858c0f
          int lookup2 = u_script.level2[lookup1 + index2];
rpm-build 858c0f
          if (lookup2 >= 0)
rpm-build 858c0f
            {
rpm-build 858c0f
              unsigned int index3 = (uc & script_header_4);
rpm-build 858c0f
              unsigned char lookup3 = u_script.level3[lookup2 + index3];
rpm-build 858c0f
rpm-build 858c0f
              if (lookup3 != 0xff)
rpm-build 858c0f
                return &scripts[lookup3];
rpm-build 858c0f
            }
rpm-build 858c0f
        }
rpm-build 858c0f
    }
rpm-build 858c0f
  return NULL;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
const uc_script_t *
rpm-build 858c0f
uc_script_byname (const char *script_name)
rpm-build 858c0f
{
rpm-build 858c0f
  const struct named_script *found;
rpm-build 858c0f
rpm-build 858c0f
  found = uc_script_lookup (script_name, strlen (script_name));
rpm-build 858c0f
  if (found != NULL)
rpm-build 858c0f
    return &scripts[found->index];
rpm-build 858c0f
  else
rpm-build 858c0f
    return NULL;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
bool
rpm-build 858c0f
uc_is_script (ucs4_t uc, const uc_script_t *script)
rpm-build 858c0f
{
rpm-build 858c0f
  return uc_script (uc) == script;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
void
rpm-build 858c0f
uc_all_scripts (const uc_script_t **scriptsp, size_t *countp)
rpm-build 858c0f
{
rpm-build 858c0f
  *scriptsp = scripts;
rpm-build 858c0f
  *countp = sizeof (scripts) / sizeof (scripts[0]);
rpm-build 858c0f
}