]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ******************************************************************************* | |
3 | * | |
73c04bcf | 4 | * Copyright (C) 2002-2006, International Business Machines |
b75a7d8f A |
5 | * Corporation and others. All Rights Reserved. |
6 | * | |
7 | ******************************************************************************* | |
8 | * file name: uprops.h | |
9 | * encoding: US-ASCII | |
10 | * tab size: 8 (not used) | |
11 | * indentation:4 | |
12 | * | |
13 | * created on: 2002feb24 | |
14 | * created by: Markus W. Scherer | |
15 | * | |
16 | * Implementations for mostly non-core Unicode character properties | |
17 | * stored in uprops.icu. | |
374ca955 A |
18 | * |
19 | * With the APIs implemented here, almost all properties files and | |
20 | * their associated implementation files are used from this file, | |
21 | * including those for normalization and case mappings. | |
b75a7d8f A |
22 | */ |
23 | ||
24 | #include "unicode/utypes.h" | |
25 | #include "unicode/uchar.h" | |
26 | #include "unicode/uscript.h" | |
27 | #include "cstring.h" | |
73c04bcf A |
28 | #include "ucln_cmn.h" |
29 | #include "umutex.h" | |
b75a7d8f | 30 | #include "unormimp.h" |
73c04bcf | 31 | #include "ubidi_props.h" |
b75a7d8f | 32 | #include "uprops.h" |
73c04bcf | 33 | #include "ucase.h" |
b75a7d8f A |
34 | |
35 | #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) | |
36 | ||
73c04bcf A |
37 | /* cleanup ------------------------------------------------------------------ */ |
38 | ||
39 | static const UBiDiProps *gBdp=NULL; | |
40 | ||
41 | static UBool U_CALLCONV uprops_cleanup(void) { | |
42 | gBdp=NULL; | |
43 | return TRUE; | |
44 | } | |
45 | ||
46 | /* bidi/shaping properties API ---------------------------------------------- */ | |
47 | ||
48 | /* get the UBiDiProps singleton, or else its dummy, once and for all */ | |
49 | static const UBiDiProps * | |
50 | getBiDiProps() { | |
51 | /* | |
52 | * This lazy intialization with double-checked locking (without mutex protection for | |
53 | * the initial check) is transiently unsafe under certain circumstances. | |
54 | * Check the readme and use u_init() if necessary. | |
55 | */ | |
56 | ||
57 | /* the initial check is performed by the GET_BIDI_PROPS() macro */ | |
58 | const UBiDiProps *bdp; | |
59 | UErrorCode errorCode=U_ZERO_ERROR; | |
60 | ||
61 | bdp=ubidi_getSingleton(&errorCode); | |
62 | if(U_FAILURE(errorCode)) { | |
63 | errorCode=U_ZERO_ERROR; | |
64 | bdp=ubidi_getDummy(&errorCode); | |
65 | if(U_FAILURE(errorCode)) { | |
66 | return NULL; | |
67 | } | |
68 | } | |
69 | ||
70 | umtx_lock(NULL); | |
71 | if(gBdp==NULL) { | |
72 | gBdp=bdp; | |
73 | bdp=NULL; | |
74 | ucln_common_registerCleanup(UCLN_COMMON_UPROPS, uprops_cleanup); | |
75 | } | |
76 | umtx_unlock(NULL); | |
77 | ||
78 | return gBdp; | |
79 | } | |
80 | ||
81 | /* see comment for GET_CASE_PROPS() */ | |
82 | #define GET_BIDI_PROPS() (gBdp!=NULL ? gBdp : getBiDiProps()) | |
83 | ||
84 | /* general properties API functions ----------------------------------------- */ | |
b75a7d8f | 85 | |
b75a7d8f A |
86 | static const struct { |
87 | int32_t column; | |
88 | uint32_t mask; | |
374ca955 | 89 | } binProps[UCHAR_BINARY_LIMIT]={ |
b75a7d8f A |
90 | /* |
91 | * column and mask values for binary properties from u_getUnicodeProperties(). | |
92 | * Must be in order of corresponding UProperty, | |
93 | * and there must be exacly one entry per binary UProperty. | |
374ca955 A |
94 | * |
95 | * Properties with mask 0 are handled in code. | |
96 | * For them, column is the UPropertySource value. | |
b75a7d8f | 97 | */ |
374ca955 A |
98 | { 1, U_MASK(UPROPS_ALPHABETIC) }, |
99 | { 1, U_MASK(UPROPS_ASCII_HEX_DIGIT) }, | |
73c04bcf A |
100 | { UPROPS_SRC_BIDI, 0 }, /* UCHAR_BIDI_CONTROL */ |
101 | { UPROPS_SRC_BIDI, 0 }, /* UCHAR_BIDI_MIRRORED */ | |
374ca955 A |
102 | { 1, U_MASK(UPROPS_DASH) }, |
103 | { 1, U_MASK(UPROPS_DEFAULT_IGNORABLE_CODE_POINT) }, | |
104 | { 1, U_MASK(UPROPS_DEPRECATED) }, | |
105 | { 1, U_MASK(UPROPS_DIACRITIC) }, | |
106 | { 1, U_MASK(UPROPS_EXTENDER) }, | |
107 | { UPROPS_SRC_NORM, 0 }, /* UCHAR_FULL_COMPOSITION_EXCLUSION */ | |
108 | { 1, U_MASK(UPROPS_GRAPHEME_BASE) }, | |
109 | { 1, U_MASK(UPROPS_GRAPHEME_EXTEND) }, | |
110 | { 1, U_MASK(UPROPS_GRAPHEME_LINK) }, | |
111 | { 1, U_MASK(UPROPS_HEX_DIGIT) }, | |
112 | { 1, U_MASK(UPROPS_HYPHEN) }, | |
113 | { 1, U_MASK(UPROPS_ID_CONTINUE) }, | |
114 | { 1, U_MASK(UPROPS_ID_START) }, | |
115 | { 1, U_MASK(UPROPS_IDEOGRAPHIC) }, | |
116 | { 1, U_MASK(UPROPS_IDS_BINARY_OPERATOR) }, | |
117 | { 1, U_MASK(UPROPS_IDS_TRINARY_OPERATOR) }, | |
73c04bcf | 118 | { UPROPS_SRC_BIDI, 0 }, /* UCHAR_JOIN_CONTROL */ |
374ca955 A |
119 | { 1, U_MASK(UPROPS_LOGICAL_ORDER_EXCEPTION) }, |
120 | { UPROPS_SRC_CASE, 0 }, /* UCHAR_LOWERCASE */ | |
121 | { 1, U_MASK(UPROPS_MATH) }, | |
122 | { 1, U_MASK(UPROPS_NONCHARACTER_CODE_POINT) }, | |
123 | { 1, U_MASK(UPROPS_QUOTATION_MARK) }, | |
124 | { 1, U_MASK(UPROPS_RADICAL) }, | |
125 | { UPROPS_SRC_CASE, 0 }, /* UCHAR_SOFT_DOTTED */ | |
126 | { 1, U_MASK(UPROPS_TERMINAL_PUNCTUATION) }, | |
127 | { 1, U_MASK(UPROPS_UNIFIED_IDEOGRAPH) }, | |
128 | { UPROPS_SRC_CASE, 0 }, /* UCHAR_UPPERCASE */ | |
129 | { 1, U_MASK(UPROPS_WHITE_SPACE) }, | |
130 | { 1, U_MASK(UPROPS_XID_CONTINUE) }, | |
131 | { 1, U_MASK(UPROPS_XID_START) }, | |
132 | { UPROPS_SRC_CASE, 0 }, /* UCHAR_CASE_SENSITIVE */ | |
133 | { 2, U_MASK(UPROPS_V2_S_TERM) }, | |
134 | { 2, U_MASK(UPROPS_V2_VARIATION_SELECTOR) }, | |
135 | { UPROPS_SRC_NORM, 0 }, /* UCHAR_NFD_INERT */ | |
136 | { UPROPS_SRC_NORM, 0 }, /* UCHAR_NFKD_INERT */ | |
137 | { UPROPS_SRC_NORM, 0 }, /* UCHAR_NFC_INERT */ | |
138 | { UPROPS_SRC_NORM, 0 }, /* UCHAR_NFKC_INERT */ | |
73c04bcf A |
139 | { UPROPS_SRC_NORM, 0 }, /* UCHAR_SEGMENT_STARTER */ |
140 | { 2, U_MASK(UPROPS_V2_PATTERN_SYNTAX) }, | |
141 | { 2, U_MASK(UPROPS_V2_PATTERN_WHITE_SPACE) }, | |
142 | { UPROPS_SRC_CHAR_AND_PROPSVEC, 0 }, /* UCHAR_POSIX_ALNUM */ | |
143 | { UPROPS_SRC_CHAR, 0 }, /* UCHAR_POSIX_BLANK */ | |
144 | { UPROPS_SRC_CHAR, 0 }, /* UCHAR_POSIX_GRAPH */ | |
145 | { UPROPS_SRC_CHAR, 0 }, /* UCHAR_POSIX_PRINT */ | |
146 | { UPROPS_SRC_CHAR, 0 } /* UCHAR_POSIX_XDIGIT */ | |
b75a7d8f A |
147 | }; |
148 | ||
149 | U_CAPI UBool U_EXPORT2 | |
150 | u_hasBinaryProperty(UChar32 c, UProperty which) { | |
151 | /* c is range-checked in the functions that are called from here */ | |
152 | if(which<UCHAR_BINARY_START || UCHAR_BINARY_LIMIT<=which) { | |
153 | /* not a known binary property */ | |
374ca955 A |
154 | } else { |
155 | uint32_t mask=binProps[which].mask; | |
156 | int32_t column=binProps[which].column; | |
157 | if(mask!=0) { | |
158 | /* systematic, directly stored properties */ | |
159 | return (u_getUnicodeProperties(c, column)&mask)!=0; | |
160 | } else { | |
161 | if(column==UPROPS_SRC_CASE) { | |
73c04bcf | 162 | return ucase_hasBinaryProperty(c, which); |
374ca955 | 163 | } else if(column==UPROPS_SRC_NORM) { |
b75a7d8f | 164 | #if !UCONFIG_NO_NORMALIZATION |
374ca955 A |
165 | /* normalization properties from unorm.icu */ |
166 | switch(which) { | |
167 | case UCHAR_FULL_COMPOSITION_EXCLUSION: | |
168 | return unorm_internalIsFullCompositionExclusion(c); | |
169 | case UCHAR_NFD_INERT: | |
170 | case UCHAR_NFKD_INERT: | |
171 | case UCHAR_NFC_INERT: | |
172 | case UCHAR_NFKC_INERT: | |
73c04bcf | 173 | return unorm_isNFSkippable(c, (UNormalizationMode)(which-UCHAR_NFD_INERT+UNORM_NFD)); |
374ca955 A |
174 | case UCHAR_SEGMENT_STARTER: |
175 | return unorm_isCanonSafeStart(c); | |
176 | default: | |
177 | break; | |
178 | } | |
b75a7d8f | 179 | #endif |
73c04bcf A |
180 | } else if(column==UPROPS_SRC_BIDI) { |
181 | /* bidi/shaping properties */ | |
182 | const UBiDiProps *bdp=GET_BIDI_PROPS(); | |
183 | if(bdp!=NULL) { | |
184 | switch(which) { | |
185 | case UCHAR_BIDI_MIRRORED: | |
186 | return ubidi_isMirrored(bdp, c); | |
187 | case UCHAR_BIDI_CONTROL: | |
188 | return ubidi_isBidiControl(bdp, c); | |
189 | case UCHAR_JOIN_CONTROL: | |
190 | return ubidi_isJoinControl(bdp, c); | |
191 | default: | |
192 | break; | |
193 | } | |
194 | } | |
195 | /* else return FALSE below */ | |
196 | } else if(column==UPROPS_SRC_CHAR) { | |
197 | switch(which) { | |
198 | case UCHAR_POSIX_BLANK: | |
199 | return u_isblank(c); | |
200 | case UCHAR_POSIX_GRAPH: | |
201 | return u_isgraphPOSIX(c); | |
202 | case UCHAR_POSIX_PRINT: | |
203 | return u_isprintPOSIX(c); | |
204 | case UCHAR_POSIX_XDIGIT: | |
205 | return u_isxdigit(c); | |
206 | default: | |
207 | break; | |
208 | } | |
209 | } else if(column==UPROPS_SRC_CHAR_AND_PROPSVEC) { | |
210 | switch(which) { | |
211 | case UCHAR_POSIX_ALNUM: | |
212 | return u_isalnumPOSIX(c); | |
213 | default: | |
214 | break; | |
215 | } | |
374ca955 A |
216 | } |
217 | } | |
b75a7d8f | 218 | } |
374ca955 | 219 | return FALSE; |
b75a7d8f A |
220 | } |
221 | ||
222 | U_CAPI int32_t U_EXPORT2 | |
223 | u_getIntPropertyValue(UChar32 c, UProperty which) { | |
224 | UErrorCode errorCode; | |
73c04bcf | 225 | int32_t type; |
b75a7d8f A |
226 | |
227 | if(which<UCHAR_BINARY_START) { | |
228 | return 0; /* undefined */ | |
229 | } else if(which<UCHAR_BINARY_LIMIT) { | |
230 | return (int32_t)u_hasBinaryProperty(c, which); | |
231 | } else if(which<UCHAR_INT_START) { | |
232 | return 0; /* undefined */ | |
233 | } else if(which<UCHAR_INT_LIMIT) { | |
234 | switch(which) { | |
235 | case UCHAR_BIDI_CLASS: | |
236 | return (int32_t)u_charDirection(c); | |
237 | case UCHAR_BLOCK: | |
238 | return (int32_t)ublock_getCode(c); | |
239 | case UCHAR_CANONICAL_COMBINING_CLASS: | |
240 | #if !UCONFIG_NO_NORMALIZATION | |
241 | return u_getCombiningClass(c); | |
242 | #else | |
243 | return 0; | |
244 | #endif | |
245 | case UCHAR_DECOMPOSITION_TYPE: | |
246 | return (int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_DT_MASK); | |
247 | case UCHAR_EAST_ASIAN_WIDTH: | |
248 | return (int32_t)(u_getUnicodeProperties(c, 0)&UPROPS_EA_MASK)>>UPROPS_EA_SHIFT; | |
249 | case UCHAR_GENERAL_CATEGORY: | |
250 | return (int32_t)u_charType(c); | |
251 | case UCHAR_JOINING_GROUP: | |
73c04bcf | 252 | return ubidi_getJoiningGroup(GET_BIDI_PROPS(), c); |
b75a7d8f | 253 | case UCHAR_JOINING_TYPE: |
73c04bcf | 254 | return ubidi_getJoiningType(GET_BIDI_PROPS(), c); |
b75a7d8f A |
255 | case UCHAR_LINE_BREAK: |
256 | return (int32_t)(u_getUnicodeProperties(c, 0)&UPROPS_LB_MASK)>>UPROPS_LB_SHIFT; | |
257 | case UCHAR_NUMERIC_TYPE: | |
73c04bcf A |
258 | type=(int32_t)GET_NUMERIC_TYPE(u_getUnicodeProperties(c, -1)); |
259 | if(type>U_NT_NUMERIC) { | |
260 | /* keep internal variants of U_NT_NUMERIC from becoming visible */ | |
261 | type=U_NT_NUMERIC; | |
262 | } | |
263 | return type; | |
b75a7d8f A |
264 | case UCHAR_SCRIPT: |
265 | errorCode=U_ZERO_ERROR; | |
266 | return (int32_t)uscript_getScript(c, &errorCode); | |
267 | case UCHAR_HANGUL_SYLLABLE_TYPE: | |
374ca955 A |
268 | return uchar_getHST(c); |
269 | #if !UCONFIG_NO_NORMALIZATION | |
270 | case UCHAR_NFD_QUICK_CHECK: | |
271 | case UCHAR_NFKD_QUICK_CHECK: | |
272 | case UCHAR_NFC_QUICK_CHECK: | |
273 | case UCHAR_NFKC_QUICK_CHECK: | |
73c04bcf | 274 | return (int32_t)unorm_getQuickCheck(c, (UNormalizationMode)(which-UCHAR_NFD_QUICK_CHECK+UNORM_NFD)); |
374ca955 A |
275 | case UCHAR_LEAD_CANONICAL_COMBINING_CLASS: |
276 | return unorm_getFCD16FromCodePoint(c)>>8; | |
277 | case UCHAR_TRAIL_CANONICAL_COMBINING_CLASS: | |
278 | return unorm_getFCD16FromCodePoint(c)&0xff; | |
279 | #endif | |
73c04bcf A |
280 | case UCHAR_GRAPHEME_CLUSTER_BREAK: |
281 | return (int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_GCB_MASK)>>UPROPS_GCB_SHIFT; | |
282 | case UCHAR_SENTENCE_BREAK: | |
283 | return (int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_SB_MASK)>>UPROPS_SB_SHIFT; | |
284 | case UCHAR_WORD_BREAK: | |
285 | return (int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_WB_MASK)>>UPROPS_WB_SHIFT; | |
b75a7d8f A |
286 | default: |
287 | return 0; /* undefined */ | |
288 | } | |
289 | } else if(which==UCHAR_GENERAL_CATEGORY_MASK) { | |
290 | return U_MASK(u_charType(c)); | |
291 | } else { | |
292 | return 0; /* undefined */ | |
293 | } | |
294 | } | |
295 | ||
296 | U_CAPI int32_t U_EXPORT2 | |
297 | u_getIntPropertyMinValue(UProperty which) { | |
298 | return 0; /* all binary/enum/int properties have a minimum value of 0 */ | |
299 | } | |
300 | ||
301 | U_CAPI int32_t U_EXPORT2 | |
302 | u_getIntPropertyMaxValue(UProperty which) { | |
b75a7d8f A |
303 | if(which<UCHAR_BINARY_START) { |
304 | return -1; /* undefined */ | |
305 | } else if(which<UCHAR_BINARY_LIMIT) { | |
306 | return 1; /* maximum TRUE for all binary properties */ | |
307 | } else if(which<UCHAR_INT_START) { | |
308 | return -1; /* undefined */ | |
309 | } else if(which<UCHAR_INT_LIMIT) { | |
310 | switch(which) { | |
311 | case UCHAR_BIDI_CLASS: | |
73c04bcf A |
312 | case UCHAR_JOINING_GROUP: |
313 | case UCHAR_JOINING_TYPE: | |
314 | return ubidi_getMaxValue(GET_BIDI_PROPS(), which); | |
b75a7d8f | 315 | case UCHAR_BLOCK: |
73c04bcf | 316 | return (uprv_getMaxValues(0)&UPROPS_BLOCK_MASK)>>UPROPS_BLOCK_SHIFT; |
b75a7d8f | 317 | case UCHAR_CANONICAL_COMBINING_CLASS: |
374ca955 A |
318 | case UCHAR_LEAD_CANONICAL_COMBINING_CLASS: |
319 | case UCHAR_TRAIL_CANONICAL_COMBINING_CLASS: | |
b75a7d8f A |
320 | return 0xff; /* TODO do we need to be more precise, getting the actual maximum? */ |
321 | case UCHAR_DECOMPOSITION_TYPE: | |
73c04bcf | 322 | return uprv_getMaxValues(2)&UPROPS_DT_MASK; |
b75a7d8f | 323 | case UCHAR_EAST_ASIAN_WIDTH: |
73c04bcf | 324 | return (uprv_getMaxValues(0)&UPROPS_EA_MASK)>>UPROPS_EA_SHIFT; |
b75a7d8f A |
325 | case UCHAR_GENERAL_CATEGORY: |
326 | return (int32_t)U_CHAR_CATEGORY_COUNT-1; | |
b75a7d8f | 327 | case UCHAR_LINE_BREAK: |
73c04bcf | 328 | return (uprv_getMaxValues(0)&UPROPS_LB_MASK)>>UPROPS_LB_SHIFT; |
b75a7d8f A |
329 | case UCHAR_NUMERIC_TYPE: |
330 | return (int32_t)U_NT_COUNT-1; | |
331 | case UCHAR_SCRIPT: | |
73c04bcf | 332 | return uprv_getMaxValues(0)&UPROPS_SCRIPT_MASK; |
b75a7d8f A |
333 | case UCHAR_HANGUL_SYLLABLE_TYPE: |
334 | return (int32_t)U_HST_COUNT-1; | |
374ca955 A |
335 | #if !UCONFIG_NO_NORMALIZATION |
336 | case UCHAR_NFD_QUICK_CHECK: | |
337 | case UCHAR_NFKD_QUICK_CHECK: | |
338 | return (int32_t)UNORM_YES; /* these are never "maybe", only "no" or "yes" */ | |
339 | case UCHAR_NFC_QUICK_CHECK: | |
340 | case UCHAR_NFKC_QUICK_CHECK: | |
341 | return (int32_t)UNORM_MAYBE; | |
342 | #endif | |
73c04bcf A |
343 | case UCHAR_GRAPHEME_CLUSTER_BREAK: |
344 | return (uprv_getMaxValues(2)&UPROPS_GCB_MASK)>>UPROPS_GCB_SHIFT; | |
345 | case UCHAR_SENTENCE_BREAK: | |
346 | return (uprv_getMaxValues(2)&UPROPS_SB_MASK)>>UPROPS_SB_SHIFT; | |
347 | case UCHAR_WORD_BREAK: | |
348 | return (uprv_getMaxValues(2)&UPROPS_WB_MASK)>>UPROPS_WB_SHIFT; | |
b75a7d8f A |
349 | default: |
350 | return -1; /* undefined */ | |
351 | } | |
352 | } else { | |
353 | return -1; /* undefined */ | |
354 | } | |
355 | } | |
356 | ||
374ca955 A |
357 | U_CAPI UPropertySource U_EXPORT2 |
358 | uprops_getSource(UProperty which) { | |
359 | if(which<UCHAR_BINARY_START) { | |
360 | return UPROPS_SRC_NONE; /* undefined */ | |
361 | } else if(which<UCHAR_BINARY_LIMIT) { | |
362 | if(binProps[which].mask!=0) { | |
73c04bcf | 363 | return UPROPS_SRC_PROPSVEC; |
374ca955 A |
364 | } else { |
365 | return (UPropertySource)binProps[which].column; | |
366 | } | |
367 | } else if(which<UCHAR_INT_START) { | |
368 | return UPROPS_SRC_NONE; /* undefined */ | |
369 | } else if(which<UCHAR_INT_LIMIT) { | |
370 | switch(which) { | |
73c04bcf A |
371 | case UCHAR_GENERAL_CATEGORY: |
372 | case UCHAR_NUMERIC_TYPE: | |
373 | return UPROPS_SRC_CHAR; | |
374 | ||
374ca955 A |
375 | case UCHAR_HANGUL_SYLLABLE_TYPE: |
376 | return UPROPS_SRC_HST; | |
73c04bcf | 377 | |
374ca955 A |
378 | case UCHAR_CANONICAL_COMBINING_CLASS: |
379 | case UCHAR_NFD_QUICK_CHECK: | |
380 | case UCHAR_NFKD_QUICK_CHECK: | |
381 | case UCHAR_NFC_QUICK_CHECK: | |
382 | case UCHAR_NFKC_QUICK_CHECK: | |
383 | case UCHAR_LEAD_CANONICAL_COMBINING_CLASS: | |
384 | case UCHAR_TRAIL_CANONICAL_COMBINING_CLASS: | |
385 | return UPROPS_SRC_NORM; | |
73c04bcf A |
386 | |
387 | case UCHAR_BIDI_CLASS: | |
388 | case UCHAR_JOINING_GROUP: | |
389 | case UCHAR_JOINING_TYPE: | |
390 | return UPROPS_SRC_BIDI; | |
391 | ||
374ca955 | 392 | default: |
73c04bcf A |
393 | return UPROPS_SRC_PROPSVEC; |
394 | } | |
395 | } else if(which<UCHAR_STRING_START) { | |
396 | switch(which) { | |
397 | case UCHAR_GENERAL_CATEGORY_MASK: | |
398 | case UCHAR_NUMERIC_VALUE: | |
374ca955 | 399 | return UPROPS_SRC_CHAR; |
73c04bcf A |
400 | |
401 | default: | |
402 | return UPROPS_SRC_NONE; | |
403 | } | |
404 | } else if(which<UCHAR_STRING_LIMIT) { | |
405 | switch(which) { | |
406 | case UCHAR_AGE: | |
407 | return UPROPS_SRC_PROPSVEC; | |
408 | ||
409 | case UCHAR_BIDI_MIRRORING_GLYPH: | |
410 | return UPROPS_SRC_BIDI; | |
411 | ||
412 | case UCHAR_CASE_FOLDING: | |
413 | case UCHAR_LOWERCASE_MAPPING: | |
414 | case UCHAR_SIMPLE_CASE_FOLDING: | |
415 | case UCHAR_SIMPLE_LOWERCASE_MAPPING: | |
416 | case UCHAR_SIMPLE_TITLECASE_MAPPING: | |
417 | case UCHAR_SIMPLE_UPPERCASE_MAPPING: | |
418 | case UCHAR_TITLECASE_MAPPING: | |
419 | case UCHAR_UPPERCASE_MAPPING: | |
420 | return UPROPS_SRC_CASE; | |
421 | ||
422 | case UCHAR_ISO_COMMENT: | |
423 | case UCHAR_NAME: | |
424 | case UCHAR_UNICODE_1_NAME: | |
425 | return UPROPS_SRC_NAMES; | |
426 | ||
427 | default: | |
428 | return UPROPS_SRC_NONE; | |
374ca955 | 429 | } |
374ca955 A |
430 | } else { |
431 | return UPROPS_SRC_NONE; /* undefined */ | |
432 | } | |
433 | } | |
434 | ||
b75a7d8f A |
435 | /*---------------------------------------------------------------- |
436 | * Inclusions list | |
437 | *----------------------------------------------------------------*/ | |
438 | ||
439 | /* | |
440 | * Return a set of characters for property enumeration. | |
441 | * The set implicitly contains 0x110000 as well, which is one more than the highest | |
442 | * Unicode code point. | |
443 | * | |
444 | * This set is used as an ordered list - its code points are ordered, and | |
445 | * consecutive code points (in Unicode code point order) in the set define a range. | |
446 | * For each two consecutive characters (start, limit) in the set, | |
447 | * all of the UCD/normalization and related properties for | |
448 | * all code points start..limit-1 are all the same, | |
449 | * except for character names and ISO comments. | |
450 | * | |
451 | * All Unicode code points U+0000..U+10ffff are covered by these ranges. | |
452 | * The ranges define a partition of the Unicode code space. | |
453 | * ICU uses the inclusions set to enumerate properties for generating | |
454 | * UnicodeSets containing all code points that have a certain property value. | |
455 | * | |
456 | * The Inclusion List is generated from the UCD. It is generated | |
457 | * by enumerating the data tries, and code points for hardcoded properties | |
458 | * are added as well. | |
459 | * | |
460 | * -------------------------------------------------------------------------- | |
461 | * | |
462 | * The following are ideas for getting properties-unique code point ranges, | |
463 | * with possible optimizations beyond the current implementation. | |
464 | * These optimizations would require more code and be more fragile. | |
465 | * The current implementation generates one single list (set) for all properties. | |
466 | * | |
467 | * To enumerate properties efficiently, one needs to know ranges of | |
468 | * repetitive values, so that the value of only each start code point | |
469 | * can be applied to the whole range. | |
470 | * This information is in principle available in the uprops.icu/unorm.icu data. | |
471 | * | |
472 | * There are two obstacles: | |
473 | * | |
474 | * 1. Some properties are computed from multiple data structures, | |
475 | * making it necessary to get repetitive ranges by intersecting | |
476 | * ranges from multiple tries. | |
477 | * | |
478 | * 2. It is not economical to write code for getting repetitive ranges | |
479 | * that are precise for each of some 50 properties. | |
480 | * | |
481 | * Compromise ideas: | |
482 | * | |
483 | * - Get ranges per trie, not per individual property. | |
484 | * Each range contains the same values for a whole group of properties. | |
485 | * This would generate currently five range sets, two for uprops.icu tries | |
486 | * and three for unorm.icu tries. | |
487 | * | |
488 | * - Combine sets of ranges for multiple tries to get sufficient sets | |
489 | * for properties, e.g., the uprops.icu main and auxiliary tries | |
490 | * for all non-normalization properties. | |
491 | * | |
492 | * Ideas for representing ranges and combining them: | |
493 | * | |
494 | * - A UnicodeSet could hold just the start code points of ranges. | |
495 | * Multiple sets are easily combined by or-ing them together. | |
496 | * | |
497 | * - Alternatively, a UnicodeSet could hold each even-numbered range. | |
498 | * All ranges could be enumerated by using each start code point | |
499 | * (for the even-numbered ranges) as well as each limit (end+1) code point | |
500 | * (for the odd-numbered ranges). | |
501 | * It should be possible to combine two such sets by xor-ing them, | |
502 | * but no more than two. | |
503 | * | |
504 | * The second way to represent ranges may(?!) yield smaller UnicodeSet arrays, | |
505 | * but the first one is certainly simpler and applicable for combining more than | |
506 | * two range sets. | |
507 | * | |
508 | * It is possible to combine all range sets for all uprops/unorm tries into one | |
509 | * set that can be used for all properties. | |
510 | * As an optimization, there could be less-combined range sets for certain | |
511 | * groups of properties. | |
512 | * The relationship of which less-combined range set to use for which property | |
513 | * depends on the implementation of the properties and must be hardcoded | |
514 | * - somewhat error-prone and higher maintenance but can be tested easily | |
515 | * by building property sets "the simple way" in test code. | |
516 | * | |
517 | * --- | |
518 | * | |
519 | * Do not use a UnicodeSet pattern because that causes infinite recursion; | |
520 | * UnicodeSet depends on the inclusions set. | |
374ca955 A |
521 | * |
522 | * --- | |
523 | * | |
524 | * uprv_getInclusions() is commented out starting 2004-sep-13 because | |
525 | * uniset_props.cpp now calls the uxyz_addPropertyStarts() directly, | |
526 | * and only for the relevant property source. | |
b75a7d8f | 527 | */ |
374ca955 A |
528 | #if 0 |
529 | ||
b75a7d8f | 530 | U_CAPI void U_EXPORT2 |
73c04bcf | 531 | uprv_getInclusions(const USetAdder *sa, UErrorCode *pErrorCode) { |
b75a7d8f A |
532 | if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { |
533 | return; | |
534 | } | |
535 | ||
b75a7d8f | 536 | #if !UCONFIG_NO_NORMALIZATION |
374ca955 | 537 | unorm_addPropertyStarts(sa, pErrorCode); |
b75a7d8f | 538 | #endif |
374ca955 | 539 | uchar_addPropertyStarts(sa, pErrorCode); |
73c04bcf | 540 | uhst_addPropertyStarts(sa, pErrorCode); |
374ca955 | 541 | ucase_addPropertyStarts(ucase_getSingleton(pErrorCode), sa, pErrorCode); |
73c04bcf | 542 | ubidi_addPropertyStarts(ubidi_getSingleton(pErrorCode), sa, pErrorCode); |
b75a7d8f | 543 | } |
374ca955 A |
544 | |
545 | #endif |