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