1 /*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Wez Furlong (wez@thebrainroom.com) |
14 +----------------------------------------------------------------------+
15
16 Based on code from ucdata-2.5, which has the following Copyright:
17
18 Copyright 2001 Computing Research Labs, New Mexico State University
19
20 Permission is hereby granted, free of charge, to any person obtaining a
21 copy of this software and associated documentation files (the "Software"),
22 to deal in the Software without restriction, including without limitation
23 the rights to use, copy, modify, merge, publish, distribute, sublicense,
24 and/or sell copies of the Software, and to permit persons to whom the
25 Software is furnished to do so, subject to the following conditions:
26
27 The above copyright notice and this permission notice shall be included in
28 all copies or substantial portions of the Software.
29 */
30
31 #ifndef PHP_UNICODE_H
32 #define PHP_UNICODE_H
33
34 #define UC_MN 0 /* Mark, Non-Spacing */
35 #define UC_MC 1 /* Mark, Spacing Combining */
36 #define UC_ME 2 /* Mark, Enclosing */
37 #define UC_ND 3 /* Number, Decimal Digit */
38 #define UC_NL 4 /* Number, Letter */
39 #define UC_NO 5 /* Number, Other */
40 #define UC_ZS 6 /* Separator, Space */
41 #define UC_ZL 7 /* Separator, Line */
42 #define UC_ZP 8 /* Separator, Paragraph */
43 #define UC_OS 9 /* Other, Surrogate */
44 #define UC_CO 10 /* Other, Private Use */
45 #define UC_CN 11 /* Other, Not Assigned */
46 #define UC_LU 12 /* Letter, Uppercase */
47 #define UC_LL 13 /* Letter, Lowercase */
48 #define UC_LT 14 /* Letter, Titlecase */
49 #define UC_LM 15 /* Letter, Modifier */
50 #define UC_LO 16 /* Letter, Other */
51 #define UC_SM 17 /* Symbol, Math */
52 #define UC_SC 18 /* Symbol, Currency */
53 #define UC_SK 19 /* Symbol, Modifier */
54 #define UC_SO 20 /* Symbol, Other */
55 #define UC_L 21 /* Left-To-Right */
56 #define UC_R 22 /* Right-To-Left */
57 #define UC_EN 23 /* European Number */
58 #define UC_ES 24 /* European Number Separator */
59 #define UC_ET 25 /* European Number Terminator */
60 #define UC_AN 26 /* Arabic Number */
61 #define UC_CS 27 /* Common Number Separator */
62 #define UC_B 28 /* Block Separator */
63 #define UC_S 29 /* Segment Separator */
64 #define UC_WS 30 /* Whitespace */
65 #define UC_ON 31 /* Other Neutrals */
66 #define UC_AL 32 /* Arabic Letter */
67
68 /* Merged property categories */
69 #define UC_C 33 /* Control */
70 #define UC_P 34 /* Punctuation */
71
72 /* Derived properties from DerivedCoreProperties.txt */
73 #define UC_CASED 35
74 #define UC_CASE_IGNORABLE 36
75
76
77 MBSTRING_API bool php_unicode_is_prop(unsigned long code, ...);
78 MBSTRING_API bool php_unicode_is_prop1(unsigned long code, int prop);
79
80 MBSTRING_API char *php_unicode_convert_case(
81 int case_mode, const char *srcstr, size_t srclen, size_t *ret_len,
82 const mbfl_encoding *src_encoding, int illegal_mode, int illegal_substchar);
83
84 #define PHP_UNICODE_CASE_UPPER 0
85 #define PHP_UNICODE_CASE_LOWER 1
86 #define PHP_UNICODE_CASE_TITLE 2
87 #define PHP_UNICODE_CASE_FOLD 3
88 #define PHP_UNICODE_CASE_UPPER_SIMPLE 4
89 #define PHP_UNICODE_CASE_LOWER_SIMPLE 5
90 #define PHP_UNICODE_CASE_TITLE_SIMPLE 6
91 #define PHP_UNICODE_CASE_FOLD_SIMPLE 7
92 #define PHP_UNICODE_CASE_MODE_MAX 7
93
94 /* Optimize the common ASCII case for lower/upper */
95
php_unicode_is_lower(unsigned long code)96 static inline int php_unicode_is_lower(unsigned long code) {
97 if (code < 0x80) {
98 return code >= 0x61 && code <= 0x7A;
99 } else {
100 return php_unicode_is_prop1(code, UC_LL);
101 }
102 }
103
php_unicode_is_upper(unsigned long code)104 static inline int php_unicode_is_upper(unsigned long code) {
105 if (code < 0x80) {
106 return code >= 0x41 && code <= 0x5A;
107 } else {
108 return php_unicode_is_prop1(code, UC_LU);
109 }
110 }
111
112 #define php_unicode_is_alpha(cc) php_unicode_is_prop(cc, UC_LU, UC_LL, UC_LM, UC_LO, UC_LT, -1)
113 #define php_unicode_is_digit(cc) php_unicode_is_prop1(cc, UC_ND)
114 #define php_unicode_is_alnum(cc) php_unicode_is_prop(cc, UC_LU, UC_LL, UC_LM, UC_LO, UC_LT, UC_ND, -1)
115 #define php_unicode_is_cntrl(cc) php_unicode_is_prop1(cc, UC_C)
116 #define php_unicode_is_blank(cc) php_unicode_is_prop1(cc, UC_ZS)
117 #define php_unicode_is_punct(cc) php_unicode_is_prop1(cc, UC_P)
118 #define php_unicode_is_graph(cc) php_unicode_is_prop(cc, \
119 UC_MN, UC_MC, UC_ME, UC_ND, UC_NL, UC_NO, \
120 UC_LU, UC_LL, UC_LT, UC_LM, UC_LO, UC_P, \
121 UC_SM, UC_SM, UC_SC, UC_SK, UC_SO, -1)
122 #define php_unicode_is_print(cc) php_unicode_is_prop(cc, \
123 UC_MN, UC_MC, UC_ME, UC_ND, UC_NL, UC_NO, \
124 UC_LU, UC_LL, UC_LT, UC_LM, UC_LO, UC_P, \
125 UC_SM, UC_SM, UC_SC, UC_SK, UC_SO, UC_ZS, -1)
126 #define php_unicode_is_title(cc) php_unicode_is_prop1(cc, UC_LT)
127
128 #define php_unicode_is_symbol(cc) php_unicode_is_prop(cc, UC_SM, UC_SC, UC_SO, UC_SK, -1)
129 #define php_unicode_is_number(cc) php_unicode_is_prop(cc, UC_ND, UC_NO, UC_NL, -1)
130 #define php_unicode_is_nonspacing(cc) php_unicode_is_prop1(cc, UC_MN)
131
132 /*
133 * Directionality macros.
134 */
135 #define php_unicode_is_rtl(cc) php_unicode_is_prop1(cc, UC_R)
136 #define php_unicode_is_ltr(cc) php_unicode_is_prop1(cc, UC_L)
137 #define php_unicode_is_strong(cc) php_unicode_is_prop(cc, UC_L, UC_R, -1)
138 #define php_unicode_is_weak(cc) php_unicode_is_prop(cc, UC_EN, UC_ES, UC_ET, UC_AN, UC_CS, -1)
139 #define php_unicode_is_neutral(cc) php_unicode_is_prop(cc, UC_B, UC_S, UC_WS, UC_ON, -1)
140 #define php_unicode_is_separator(cc) php_unicode_is_prop(cc, UC_B, UC_S, -1)
141
142 /*
143 * Other macros inspired by John Cowan.
144 */
145 #define php_unicode_is_mark(cc) php_unicode_is_prop(cc, UC_MN, UC_MC, UC_ME, -1)
146 #define php_unicode_is_modif(cc) php_unicode_is_prop1(cc, UC_LM)
147 #define php_unicode_is_letnum(cc) php_unicode_is_prop1(cc, UC_NL)
148 #define php_unicode_is_math(cc) php_unicode_is_prop1(cc, UC_SM)
149 #define php_unicode_is_currency(cc) php_unicode_is_prop1(cc, UC_SC)
150 #define php_unicode_is_modifsymbol(cc) php_unicode_is_prop1(cc, UC_SK)
151 #define php_unicode_is_nsmark(cc) php_unicode_is_prop1(cc, UC_MN)
152 #define php_unicode_is_spmark(cc) php_unicode_is_prop1(cc, UC_MC)
153 #define php_unicode_is_enclosing(cc) php_unicode_is_prop1(cc, UC_ME)
154 #define php_unicode_is_private(cc) php_unicode_is_prop1(cc, UC_CO)
155 #define php_unicode_is_surrogate(cc) php_unicode_is_prop1(cc, UC_OS)
156 #define php_unicode_is_lsep(cc) php_unicode_is_prop1(cc, UC_ZL)
157 #define php_unicode_is_psep(cc) php_unicode_is_prop1(cc, UC_ZP)
158
159 /*
160 * Other miscellaneous character property macros.
161 */
162 #define php_unicode_is_han(cc) (((cc) >= 0x4e00 && (cc) <= 0x9fff) ||\
163 ((cc) >= 0xf900 && (cc) <= 0xfaff))
164 #define php_unicode_is_hangul(cc) ((cc) >= 0xac00 && (cc) <= 0xd7ff)
165
166 /*
167 * Derived core properties.
168 */
169
170 #define php_unicode_is_cased(cc) php_unicode_is_prop1(cc, UC_CASED)
171 #define php_unicode_is_case_ignorable(cc) php_unicode_is_prop1(cc, UC_CASE_IGNORABLE)
172
173 #endif /* PHP_UNICODE_H */
174