1
/*************************************************
2
* libucp - Unicode Property Table handler *
3
*************************************************/
5
/* This function provides a fast way of obtaining the basic Unicode properties
6
of a character, using a compact binary tree that occupies less than 100K bytes.
8
Copyright (c) 2004 University of Cambridge
10
-------------------------------------------------------------------------------
11
Redistribution and use in source and binary forms, with or without
12
modification, are permitted provided that the following conditions are met:
14
* Redistributions of source code must retain the above copyright notice,
15
this list of conditions and the following disclaimer.
17
* Redistributions in binary form must reproduce the above copyright
18
notice, this list of conditions and the following disclaimer in the
19
documentation and/or other materials provided with the distribution.
21
* Neither the name of the University of Cambridge nor the names of its
22
contributors may be used to endorse or promote products derived from
23
this software without specific prior written permission.
25
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
POSSIBILITY OF SUCH DAMAGE.
36
-------------------------------------------------------------------------------
40
#include "ucp.h" /* Exported interface */
41
#include "ucpinternal.h" /* Internal table details */
42
#include "ucptable.c" /* The table itself */
46
/*************************************************
47
* Search table and return data *
48
*************************************************/
50
/* Two values are returned: the category is ucp_C, ucp_L, etc. The detailed
51
character type is ucp_Lu, ucp_Nd, etc.
55
type_ptr the detailed character type is returned here
56
case_ptr for letters, the opposite case is returned here, if there
59
Returns: the character type category or -1 if not found
63
ucp_findchar(const int c, int *type_ptr, int *case_ptr)
65
cnode *node = ucp_table;
71
register int d = node->f1 | ((node->f0 & f0_chhmask) << 16);
75
if ((node->f0 & f0_leftexists) == 0) return -1;
80
register int roffset = (node->f2 & f2_rightmask) >> f2_rightshift;
81
if (roffset == 0) return -1;
82
node += 1 << (roffset - 1);
86
switch ((*type_ptr = ((node->f0 & f0_typemask) >> f0_typeshift)))
98
case_offset = node->f2 & f2_casemask;
99
if ((case_offset & 0x0100) != 0) case_offset |= 0xfffff000;
100
*case_ptr = (case_offset == 0)? 0 : cc + case_offset;
145
default: /* "Should never happen" */