ucdata.h 14 KB

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