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