/[pcre]/code/trunk/ucp_findchar.c
ViewVC logotype

Contents of /code/trunk/ucp_findchar.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 77 - (show annotations) (download)
Sat Feb 24 21:40:45 2007 UTC (7 years, 7 months ago) by nigel
File MIME type: text/plain
File size: 4389 byte(s)
Load pcre-6.0 into code/trunk.

1 /*************************************************
2 * libucp - Unicode Property Table handler *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 2004 */
6
7 /* This little library provides a fast way of obtaining the basic Unicode
8 properties of a character, using a compact binary tree that occupies less than
9 100K bytes.
10
11 -----------------------------------------------------------------------------
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14
15 * Redistributions of source code must retain the above copyright notice,
16 this list of conditions and the following disclaimer.
17
18 * Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
21
22 * Neither the name of the University of Cambridge nor the names of its
23 contributors may be used to endorse or promote products derived from
24 this software without specific prior written permission.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
37 -----------------------------------------------------------------------------
38 */
39
40
41 #include "ucp.h" /* Exported interface */
42 #include "ucpinternal.h" /* Internal table details */
43 #include "ucptable.c" /* The table itself */
44
45
46 /* In some environments, external functions have to be preceded by some magic.
47 In my world (Unix), they do not. Use a macro to deal with this. */
48
49 #ifndef EXPORT
50 #define EXPORT
51 #endif
52
53
54
55 /*************************************************
56 * Search table and return data *
57 *************************************************/
58
59 /* Two values are returned: the category is ucp_C, ucp_L, etc. The detailed
60 character type is ucp_Lu, ucp_Nd, etc.
61
62 Arguments:
63 c the character value
64 type_ptr the detailed character type is returned here
65 case_ptr for letters, the opposite case is returned here, if there
66 is one, else zero
67
68 Returns: the character type category or -1 if not found
69 */
70
71 EXPORT int
72 ucp_findchar(const int c, int *type_ptr, int *case_ptr)
73 {
74 cnode *node = ucp_table;
75 register int cc = c;
76 int case_offset;
77
78 for (;;)
79 {
80 register int d = node->f1 | ((node->f0 & f0_chhmask) << 16);
81 if (cc == d) break;
82 if (cc < d)
83 {
84 if ((node->f0 & f0_leftexists) == 0) return -1;
85 node ++;
86 }
87 else
88 {
89 register int roffset = (node->f2 & f2_rightmask) >> f2_rightshift;
90 if (roffset == 0) return -1;
91 node += 1 << (roffset - 1);
92 }
93 }
94
95 switch ((*type_ptr = ((node->f0 & f0_typemask) >> f0_typeshift)))
96 {
97 case ucp_Cc:
98 case ucp_Cf:
99 case ucp_Cn:
100 case ucp_Co:
101 case ucp_Cs:
102 return ucp_C;
103 break;
104
105 case ucp_Ll:
106 case ucp_Lu:
107 case_offset = node->f2 & f2_casemask;
108 if ((case_offset & 0x0100) != 0) case_offset |= 0xfffff000;
109 *case_ptr = (case_offset == 0)? 0 : cc + case_offset;
110 return ucp_L;
111
112 case ucp_Lm:
113 case ucp_Lo:
114 case ucp_Lt:
115 *case_ptr = 0;
116 return ucp_L;
117 break;
118
119 case ucp_Mc:
120 case ucp_Me:
121 case ucp_Mn:
122 return ucp_M;
123 break;
124
125 case ucp_Nd:
126 case ucp_Nl:
127 case ucp_No:
128 return ucp_N;
129 break;
130
131 case ucp_Pc:
132 case ucp_Pd:
133 case ucp_Pe:
134 case ucp_Pf:
135 case ucp_Pi:
136 case ucp_Ps:
137 case ucp_Po:
138 return ucp_P;
139 break;
140
141 case ucp_Sc:
142 case ucp_Sk:
143 case ucp_Sm:
144 case ucp_So:
145 return ucp_S;
146 break;
147
148 case ucp_Zl:
149 case ucp_Zp:
150 case ucp_Zs:
151 return ucp_Z;
152 break;
153
154 default: /* "Should never happen" */
155 return -1;
156 break;
157 }
158 }
159
160 /* End of ucp_findchar.c */

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12