]> git.sur5r.net Git - openldap/blob - libraries/liblunicode/ucdata/ucdata.h
Cyrus SASL uses screwy terms.
[openldap] / libraries / liblunicode / ucdata / ucdata.h
1 /*
2  * Copyright 1999 Computing Research Labs, New Mexico State University
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
20  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 #ifndef _h_ucdata
23 #define _h_ucdata
24
25 /*
26  * $Id: ucdata.h,v 1.5 1999/11/19 15:24:29 mleisher Exp $
27  */
28
29 LDAP_BEGIN_DECL
30
31 #undef __
32 #define __(x) x
33
34 #define UCDATA_VERSION "2.3"
35
36 /**************************************************************************
37  *
38  * Masks and macros for character properties.
39  *
40  **************************************************************************/
41
42 /*
43  * Values that can appear in the `mask1' parameter of the ucisprop()
44  * function.
45  */
46 #define UC_MN 0x00000001 /* Mark, Non-Spacing          */
47 #define UC_MC 0x00000002 /* Mark, Spacing Combining    */
48 #define UC_ME 0x00000004 /* Mark, Enclosing            */
49 #define UC_ND 0x00000008 /* Number, Decimal Digit      */
50 #define UC_NL 0x00000010 /* Number, Letter             */
51 #define UC_NO 0x00000020 /* Number, Other              */
52 #define UC_ZS 0x00000040 /* Separator, Space           */
53 #define UC_ZL 0x00000080 /* Separator, Line            */
54 #define UC_ZP 0x00000100 /* Separator, Paragraph       */
55 #define UC_CC 0x00000200 /* Other, Control             */
56 #define UC_CF 0x00000400 /* Other, Format              */
57 #define UC_OS 0x00000800 /* Other, Surrogate           */
58 #define UC_CO 0x00001000 /* Other, Private Use         */
59 #define UC_CN 0x00002000 /* Other, Not Assigned        */
60 #define UC_LU 0x00004000 /* Letter, Uppercase          */
61 #define UC_LL 0x00008000 /* Letter, Lowercase          */
62 #define UC_LT 0x00010000 /* Letter, Titlecase          */
63 #define UC_LM 0x00020000 /* Letter, Modifier           */
64 #define UC_LO 0x00040000 /* Letter, Other              */
65 #define UC_PC 0x00080000 /* Punctuation, Connector     */
66 #define UC_PD 0x00100000 /* Punctuation, Dash          */
67 #define UC_PS 0x00200000 /* Punctuation, Open          */
68 #define UC_PE 0x00400000 /* Punctuation, Close         */
69 #define UC_PO 0x00800000 /* Punctuation, Other         */
70 #define UC_SM 0x01000000 /* Symbol, Math               */
71 #define UC_SC 0x02000000 /* Symbol, Currency           */
72 #define UC_SK 0x04000000 /* Symbol, Modifier           */
73 #define UC_SO 0x08000000 /* Symbol, Other              */
74 #define UC_L  0x10000000 /* Left-To-Right              */
75 #define UC_R  0x20000000 /* Right-To-Left              */
76 #define UC_EN 0x40000000 /* European Number            */
77 #define UC_ES 0x80000000 /* European Number Separator  */
78
79 /*
80  * Values that can appear in the `mask2' parameter of the ucisprop()
81  * function.
82  */
83 #define UC_ET 0x00000001 /* European Number Terminator */
84 #define UC_AN 0x00000002 /* Arabic Number              */
85 #define UC_CS 0x00000004 /* Common Number Separator    */
86 #define UC_B  0x00000008 /* Block Separator            */
87 #define UC_S  0x00000010 /* Segment Separator          */
88 #define UC_WS 0x00000020 /* Whitespace                 */
89 #define UC_ON 0x00000040 /* Other Neutrals             */
90 /*
91  * Implementation specific character properties.
92  */
93 #define UC_CM 0x00000080 /* Composite                  */
94 #define UC_NB 0x00000100 /* Non-Breaking               */
95 #define UC_SY 0x00000200 /* Symmetric                  */
96 #define UC_HD 0x00000400 /* Hex Digit                  */
97 #define UC_QM 0x00000800 /* Quote Mark                 */
98 #define UC_MR 0x00001000 /* Mirroring                  */
99 #define UC_SS 0x00002000 /* Space, other               */
100
101 #define UC_CP 0x00004000 /* Defined                    */
102
103 /*
104  * Added for UnicodeData-2.1.3.
105  */
106 #define UC_PI 0x00008000 /* Punctuation, Initial       */
107 #define UC_PF 0x00010000 /* Punctuation, Final         */
108
109 /*
110  * This is the primary function for testing to see if a character has some set
111  * of properties.  The macros that test for various character properties all
112  * call this function with some set of masks.
113  */
114 extern int ucisprop __((unsigned long code, unsigned long mask1,
115                         unsigned long mask2));
116
117 #define ucisalpha(cc) ucisprop(cc, UC_LU|UC_LL|UC_LM|UC_LO|UC_LT, 0)
118 #define ucisdigit(cc) ucisprop(cc, UC_ND, 0)
119 #define ucisalnum(cc) ucisprop(cc, UC_LU|UC_LL|UC_LM|UC_LO|UC_LT|UC_ND, 0)
120 #define uciscntrl(cc) ucisprop(cc, UC_CC|UC_CF, 0)
121 #define ucisspace(cc) ucisprop(cc, UC_ZS|UC_SS, 0)
122 #define ucisblank(cc) ucisprop(cc, UC_ZS, 0)
123 #define ucispunct(cc) ucisprop(cc, UC_PD|UC_PS|UC_PE|UC_PO, UC_PI|UC_PF)
124 #define ucisgraph(cc) ucisprop(cc, UC_MN|UC_MC|UC_ME|UC_ND|UC_NL|UC_NO|\
125                                UC_LU|UC_LL|UC_LT|UC_LM|UC_LO|UC_PC|UC_PD|\
126                                UC_PS|UC_PE|UC_PO|UC_SM|UC_SM|UC_SC|UC_SK|\
127                                UC_SO, UC_PI|UC_PF)
128 #define ucisprint(cc) ucisprop(cc, UC_MN|UC_MC|UC_ME|UC_ND|UC_NL|UC_NO|\
129                                UC_LU|UC_LL|UC_LT|UC_LM|UC_LO|UC_PC|UC_PD|\
130                                UC_PS|UC_PE|UC_PO|UC_SM|UC_SM|UC_SC|UC_SK|\
131                                UC_SO|UC_ZS, UC_PI|UC_PF)
132 #define ucisupper(cc) ucisprop(cc, UC_LU, 0)
133 #define ucislower(cc) ucisprop(cc, UC_LL, 0)
134 #define ucistitle(cc) ucisprop(cc, UC_LT, 0)
135 #define ucisxdigit(cc) ucisprop(cc, 0, UC_HD)
136
137 #define ucisisocntrl(cc) ucisprop(cc, UC_CC, 0)
138 #define ucisfmtcntrl(cc) ucisprop(cc, UC_CF, 0)
139
140 #define ucissymbol(cc) ucisprop(cc, UC_SM|UC_SC|UC_SO|UC_SK, 0)
141 #define ucisnumber(cc) ucisprop(cc, UC_ND|UC_NO|UC_NL, 0)
142 #define ucisnonspacing(cc) ucisprop(cc, UC_MN, 0)
143 #define ucisopenpunct(cc) ucisprop(cc, UC_PS, 0)
144 #define ucisclosepunct(cc) ucisprop(cc, UC_PE, 0)
145 #define ucisinitialpunct(cc) ucisprop(cc, 0, UC_PI)
146 #define ucisfinalpunct(cc) ucisprop(cc, 0, UC_PF)
147
148 #define uciscomposite(cc) ucisprop(cc, 0, UC_CM)
149 #define ucishex(cc) ucisprop(cc, 0, UC_HD)
150 #define ucisquote(cc) ucisprop(cc, 0, UC_QM)
151 #define ucissymmetric(cc) ucisprop(cc, 0, UC_SY)
152 #define ucismirroring(cc) ucisprop(cc, 0, UC_MR)
153 #define ucisnonbreaking(cc) ucisprop(cc, 0, UC_NB)
154
155 /*
156  * Directionality macros.
157  */
158 #define ucisrtl(cc) ucisprop(cc, UC_R, 0)
159 #define ucisltr(cc) ucisprop(cc, UC_L, 0)
160 #define ucisstrong(cc) ucisprop(cc, UC_L|UC_R, 0)
161 #define ucisweak(cc) ucisprop(cc, UC_EN|UC_ES, UC_ET|UC_AN|UC_CS)
162 #define ucisneutral(cc) ucisprop(cc, 0, UC_B|UC_S|UC_WS|UC_ON)
163 #define ucisseparator(cc) ucisprop(cc, 0, UC_B|UC_S)
164
165 /*
166  * Other macros inspired by John Cowan.
167  */
168 #define ucismark(cc) ucisprop(cc, UC_MN|UC_MC|UC_ME, 0)
169 #define ucismodif(cc) ucisprop(cc, UC_LM, 0)
170 #define ucisletnum(cc) ucisprop(cc, UC_NL, 0)
171 #define ucisconnect(cc) ucisprop(cc, UC_PC, 0)
172 #define ucisdash(cc) ucisprop(cc, UC_PD, 0)
173 #define ucismath(cc) ucisprop(cc, UC_SM, 0)
174 #define uciscurrency(cc) ucisprop(cc, UC_SC, 0)
175 #define ucismodifsymbol(cc) ucisprop(cc, UC_SK, 0)
176 #define ucisnsmark(cc) ucisprop(cc, UC_MN, 0)
177 #define ucisspmark(cc) ucisprop(cc, UC_MC, 0)
178 #define ucisenclosing(cc) ucisprop(cc, UC_ME, 0)
179 #define ucisprivate(cc) ucisprop(cc, UC_CO, 0)
180 #define ucissurrogate(cc) ucisprop(cc, UC_OS, 0)
181 #define ucislsep(cc) ucisprop(cc, UC_ZL, 0)
182 #define ucispsep(cc) ucisprop(cc, UC_ZP, 0)
183
184 #define ucisidentstart(cc) ucisprop(cc, UC_LU|UC_LL|UC_LT|UC_LO|UC_NL, 0)
185 #define ucisidentpart(cc) ucisprop(cc, UC_LU|UC_LL|UC_LT|UC_LO|UC_NL|\
186                                    UC_MN|UC_MC|UC_ND|UC_PC|UC_CF, 0)
187
188 #define ucisdefined(cc) ucisprop(cc, 0, UC_CP)
189 #define ucisundefined(cc) !ucisprop(cc, 0, UC_CP)
190
191 /*
192  * Other miscellaneous character property macros.
193  */
194 #define ucishan(cc) (((cc) >= 0x4e00 && (cc) <= 0x9fff) ||\
195                      ((cc) >= 0xf900 && (cc) <= 0xfaff))
196 #define ucishangul(cc) ((cc) >= 0xac00 && (cc) <= 0xd7ff)
197
198 /**************************************************************************
199  *
200  * Functions for case conversion.
201  *
202  **************************************************************************/
203
204 extern unsigned long uctoupper __((unsigned long code));
205 extern unsigned long uctolower __((unsigned long code));
206 extern unsigned long uctotitle __((unsigned long code));
207
208 /**************************************************************************
209  *
210  * Functions for getting decompositions.
211  *
212  **************************************************************************/
213
214 /*
215  * This routine determines if the code has a decomposition.  If it returns 0,
216  * there is no decomposition.  Any other value indicates a decomposition was
217  * returned.
218  */
219 extern int ucdecomp __((unsigned long code, unsigned long *num,
220
221                         unsigned long **decomp));
222
223 /*
224  * If the code is a Hangul syllable, this routine decomposes it into the array
225  * passed.  The array size should be at least 3.
226  */
227 extern int ucdecomp_hangul __((unsigned long code, unsigned long *num,
228                                unsigned long decomp[]));
229
230 /**************************************************************************
231  *
232  * Functions for getting combining classes.
233  *
234  **************************************************************************/
235
236 /*
237  * This will return the combining class for a character to be used with the
238  * Canonical Ordering algorithm.
239  */
240 extern unsigned long uccombining_class __((unsigned long code));
241
242 /**************************************************************************
243  *
244  * Functions for getting numbers and digits.
245  *
246  **************************************************************************/
247
248 struct ucnumber {
249     int numerator;
250     int denominator;
251 };
252
253 extern int ucnumber_lookup __((unsigned long code, struct ucnumber *num));
254 extern int ucdigit_lookup __((unsigned long code, int *digit));
255
256 /*
257  * For compatibility with John Cowan's "uctype" package.
258  */
259 extern struct ucnumber ucgetnumber __((unsigned long code));
260 extern int ucgetdigit __((unsigned long code));
261
262 /**************************************************************************
263  *
264  * Functions library initialization and cleanup.
265  *
266  **************************************************************************/
267
268 /*
269  * Macros for specifying the data tables to be loaded, unloaded, or reloaded
270  * by the ucdata_load(), ucdata_unload(), and ucdata_reload() routines.
271  */
272 #define UCDATA_CASE   0x01
273 #define UCDATA_CTYPE  0x02
274 #define UCDATA_DECOMP 0x04
275 #define UCDATA_CMBCL  0x08
276 #define UCDATA_NUM    0x10
277
278 #define UCDATA_ALL (UCDATA_CASE|UCDATA_CTYPE|UCDATA_DECOMP|\
279                     UCDATA_CMBCL|UCDATA_NUM)
280
281 /*
282  * Functions to load, unload, and reload specific data files.
283  */
284 extern void ucdata_load __((char *paths, int mask));
285 extern void ucdata_unload __((int mask));
286 extern void ucdata_reload __((char *paths, int mask));
287
288 #ifdef UCDATA_DEPRECATED
289 /*
290  * Deprecated functions, now just compatibility macros.
291  */
292 #define ucdata_setup(p) ucdata_load(p, UCDATA_ALL)
293 #define ucdata_cleanup() ucdata_unload(UCDATA_ALL)
294 #endif
295
296 #undef __
297
298 LDAP_END_DECL
299
300 #endif /* _h_ucdata */