|
Packit |
aea12f |
/* Categories of Unicode characters.
|
|
Packit Service |
991b93 |
Copyright (C) 2002, 2006-2007, 2009-2020 Free Software Foundation, Inc.
|
|
Packit |
aea12f |
Written by Bruno Haible <bruno@clisp.org>, 2002.
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
This program is free software: you can redistribute it and/or
|
|
Packit |
aea12f |
modify it under the terms of either:
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
* the GNU Lesser General Public License as published by the Free
|
|
Packit |
aea12f |
Software Foundation; either version 3 of the License, or (at your
|
|
Packit |
aea12f |
option) any later version.
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
or
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
* the GNU General Public License as published by the Free
|
|
Packit |
aea12f |
Software Foundation; either version 2 of the License, or (at your
|
|
Packit |
aea12f |
option) any later version.
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
or both in parallel, as here.
|
|
Packit |
aea12f |
This program is distributed in the hope that it will be useful,
|
|
Packit |
aea12f |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
aea12f |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
aea12f |
Lesser General Public License for more details.
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
aea12f |
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <config.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Specification. */
|
|
Packit |
aea12f |
#include "unictype.h"
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Define u_category table. */
|
|
Packit |
aea12f |
#include "categ_of.h"
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
static inline int
|
|
Packit |
aea12f |
lookup_withtable (ucs4_t uc)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
unsigned int index1 = uc >> category_header_0;
|
|
Packit |
aea12f |
if (index1 < category_header_1)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
int lookup1 = u_category.level1[index1];
|
|
Packit |
aea12f |
if (lookup1 >= 0)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
unsigned int index2 = (uc >> category_header_2) & category_header_3;
|
|
Packit |
aea12f |
int lookup2 = u_category.level2[lookup1 + index2];
|
|
Packit |
aea12f |
if (lookup2 >= 0)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
unsigned int index3 = ((uc & category_header_4) + lookup2) * 5;
|
|
Packit |
aea12f |
/* level3 contains 5-bit values, packed into 16-bit words. */
|
|
Packit |
aea12f |
unsigned int lookup3 =
|
|
Packit |
aea12f |
(((unsigned int) u_category.level3[index3>>4]
|
|
Packit |
aea12f |
| ((unsigned int) u_category.level3[(index3>>4)+1] << 16))
|
|
Packit |
aea12f |
>> (index3 % 16))
|
|
Packit |
aea12f |
& 0x1f;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
return lookup3;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
return 29; /* = log2(UC_CATEGORY_MASK_Cn) */
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
return -1;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
bool
|
|
Packit |
aea12f |
uc_is_general_category_withtable (ucs4_t uc, uint32_t bitmask)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
int bit = lookup_withtable (uc);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (bit >= 0)
|
|
Packit |
aea12f |
return ((bitmask >> bit) & 1);
|
|
Packit |
aea12f |
else
|
|
Packit |
aea12f |
return false;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
uc_general_category_t
|
|
Packit |
aea12f |
uc_general_category (ucs4_t uc)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
int bit = lookup_withtable (uc);
|
|
Packit |
aea12f |
uc_general_category_t result;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (bit >= 0)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
result.bitmask = 1 << bit;
|
|
Packit |
aea12f |
result.generic = 1;
|
|
Packit |
aea12f |
result.lookup.lookup_fn = &uc_is_general_category_withtable;
|
|
Packit |
aea12f |
return result;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
else
|
|
Packit |
aea12f |
return _UC_CATEGORY_NONE;
|
|
Packit |
aea12f |
}
|