]> git.saurik.com Git - apple/icu.git/blame_incremental - icuSources/common/uprops.cpp
ICU-62108.0.1.tar.gz
[apple/icu.git] / icuSources / common / uprops.cpp
... / ...
CommitLineData
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4*******************************************************************************
5*
6* Copyright (C) 2002-2016, International Business Machines
7* Corporation and others. All Rights Reserved.
8*
9*******************************************************************************
10* file name: uprops.cpp
11* encoding: UTF-8
12* tab size: 8 (not used)
13* indentation:4
14*
15* created on: 2002feb24
16* created by: Markus W. Scherer
17*
18* Implementations for mostly non-core Unicode character properties
19* stored in uprops.icu.
20*
21* With the APIs implemented here, almost all properties files and
22* their associated implementation files are used from this file,
23* including those for normalization and case mappings.
24*/
25
26#include "unicode/utypes.h"
27#include "unicode/uchar.h"
28#include "unicode/unorm2.h"
29#include "unicode/uscript.h"
30#include "unicode/ustring.h"
31#include "cstring.h"
32#include "normalizer2impl.h"
33#include "umutex.h"
34#include "ubidi_props.h"
35#include "uprops.h"
36#include "ucase.h"
37#include "ustr_imp.h"
38
39U_NAMESPACE_USE
40
41/* general properties API functions ----------------------------------------- */
42
43struct BinaryProperty;
44
45typedef UBool BinaryPropertyContains(const BinaryProperty &prop, UChar32 c, UProperty which);
46
47struct BinaryProperty {
48 int32_t column; // SRC_PROPSVEC column, or "source" if mask==0
49 uint32_t mask;
50 BinaryPropertyContains *contains;
51};
52
53static UBool defaultContains(const BinaryProperty &prop, UChar32 c, UProperty /*which*/) {
54 /* systematic, directly stored properties */
55 return (u_getUnicodeProperties(c, prop.column)&prop.mask)!=0;
56}
57
58static UBool caseBinaryPropertyContains(const BinaryProperty &/*prop*/, UChar32 c, UProperty which) {
59 return ucase_hasBinaryProperty(c, which);
60}
61
62static UBool isBidiControl(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
63 return ubidi_isBidiControl(c);
64}
65
66static UBool isMirrored(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
67 return ubidi_isMirrored(c);
68}
69
70static UBool isJoinControl(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
71 return ubidi_isJoinControl(c);
72}
73
74#if UCONFIG_NO_NORMALIZATION
75static UBool hasFullCompositionExclusion(const BinaryProperty &, UChar32, UProperty) {
76 return FALSE;
77}
78#else
79static UBool hasFullCompositionExclusion(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
80 // By definition, Full_Composition_Exclusion is the same as NFC_QC=No.
81 UErrorCode errorCode=U_ZERO_ERROR;
82 const Normalizer2Impl *impl=Normalizer2Factory::getNFCImpl(errorCode);
83 return U_SUCCESS(errorCode) && impl->isCompNo(impl->getNorm16(c));
84}
85#endif
86
87// UCHAR_NF*_INERT properties
88#if UCONFIG_NO_NORMALIZATION
89static UBool isNormInert(const BinaryProperty &, UChar32, UProperty) {
90 return FALSE;
91}
92#else
93static UBool isNormInert(const BinaryProperty &/*prop*/, UChar32 c, UProperty which) {
94 UErrorCode errorCode=U_ZERO_ERROR;
95 const Normalizer2 *norm2=Normalizer2Factory::getInstance(
96 (UNormalizationMode)(which-UCHAR_NFD_INERT+UNORM_NFD), errorCode);
97 return U_SUCCESS(errorCode) && norm2->isInert(c);
98}
99#endif
100
101#if UCONFIG_NO_NORMALIZATION
102static UBool changesWhenCasefolded(const BinaryProperty &, UChar32, UProperty) {
103 return FALSE;
104}
105#else
106static UBool changesWhenCasefolded(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
107 UnicodeString nfd;
108 UErrorCode errorCode=U_ZERO_ERROR;
109 const Normalizer2 *nfcNorm2=Normalizer2::getNFCInstance(errorCode);
110 if(U_FAILURE(errorCode)) {
111 return FALSE;
112 }
113 if(nfcNorm2->getDecomposition(c, nfd)) {
114 /* c has a decomposition */
115 if(nfd.length()==1) {
116 c=nfd[0]; /* single BMP code point */
117 } else if(nfd.length()<=U16_MAX_LENGTH &&
118 nfd.length()==U16_LENGTH(c=nfd.char32At(0))
119 ) {
120 /* single supplementary code point */
121 } else {
122 c=U_SENTINEL;
123 }
124 } else if(c<0) {
125 return FALSE; /* protect against bad input */
126 }
127 if(c>=0) {
128 /* single code point */
129 const UChar *resultString;
130 return (UBool)(ucase_toFullFolding(c, &resultString, U_FOLD_CASE_DEFAULT)>=0);
131 } else {
132 /* guess some large but stack-friendly capacity */
133 UChar dest[2*UCASE_MAX_STRING_LENGTH];
134 int32_t destLength;
135 destLength=u_strFoldCase(dest, UPRV_LENGTHOF(dest),
136 nfd.getBuffer(), nfd.length(),
137 U_FOLD_CASE_DEFAULT, &errorCode);
138 return (UBool)(U_SUCCESS(errorCode) &&
139 0!=u_strCompare(nfd.getBuffer(), nfd.length(),
140 dest, destLength, FALSE));
141 }
142}
143#endif
144
145#if UCONFIG_NO_NORMALIZATION
146static UBool changesWhenNFKC_Casefolded(const BinaryProperty &, UChar32, UProperty) {
147 return FALSE;
148}
149#else
150static UBool changesWhenNFKC_Casefolded(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
151 UErrorCode errorCode=U_ZERO_ERROR;
152 const Normalizer2Impl *kcf=Normalizer2Factory::getNFKC_CFImpl(errorCode);
153 if(U_FAILURE(errorCode)) {
154 return FALSE;
155 }
156 UnicodeString src(c);
157 UnicodeString dest;
158 {
159 // The ReorderingBuffer must be in a block because its destructor
160 // needs to release dest's buffer before we look at its contents.
161 ReorderingBuffer buffer(*kcf, dest);
162 // Small destCapacity for NFKC_CF(c).
163 if(buffer.init(5, errorCode)) {
164 const UChar *srcArray=src.getBuffer();
165 kcf->compose(srcArray, srcArray+src.length(), FALSE,
166 TRUE, buffer, errorCode);
167 }
168 }
169 return U_SUCCESS(errorCode) && dest!=src;
170}
171#endif
172
173#if UCONFIG_NO_NORMALIZATION
174static UBool isCanonSegmentStarter(const BinaryProperty &, UChar32, UProperty) {
175 return FALSE;
176}
177#else
178static UBool isCanonSegmentStarter(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
179 UErrorCode errorCode=U_ZERO_ERROR;
180 const Normalizer2Impl *impl=Normalizer2Factory::getNFCImpl(errorCode);
181 return
182 U_SUCCESS(errorCode) && impl->ensureCanonIterData(errorCode) &&
183 impl->isCanonSegmentStarter(c);
184}
185#endif
186
187static UBool isPOSIX_alnum(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
188 return u_isalnumPOSIX(c);
189}
190
191static UBool isPOSIX_blank(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
192 return u_isblank(c);
193}
194
195static UBool isPOSIX_graph(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
196 return u_isgraphPOSIX(c);
197}
198
199static UBool isPOSIX_print(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
200 return u_isprintPOSIX(c);
201}
202
203static UBool isPOSIX_xdigit(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
204 return u_isxdigit(c);
205}
206
207static UBool isRegionalIndicator(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
208 // Property starts are a subset of lb=RI etc.
209 return 0x1F1E6<=c && c<=0x1F1FF;
210}
211
212static const BinaryProperty binProps[UCHAR_BINARY_LIMIT]={
213 /*
214 * column and mask values for binary properties from u_getUnicodeProperties().
215 * Must be in order of corresponding UProperty,
216 * and there must be exactly one entry per binary UProperty.
217 *
218 * Properties with mask==0 are handled in code.
219 * For them, column is the UPropertySource value.
220 */
221 { 1, U_MASK(UPROPS_ALPHABETIC), defaultContains },
222 { 1, U_MASK(UPROPS_ASCII_HEX_DIGIT), defaultContains },
223 { UPROPS_SRC_BIDI, 0, isBidiControl },
224 { UPROPS_SRC_BIDI, 0, isMirrored },
225 { 1, U_MASK(UPROPS_DASH), defaultContains },
226 { 1, U_MASK(UPROPS_DEFAULT_IGNORABLE_CODE_POINT), defaultContains },
227 { 1, U_MASK(UPROPS_DEPRECATED), defaultContains },
228 { 1, U_MASK(UPROPS_DIACRITIC), defaultContains },
229 { 1, U_MASK(UPROPS_EXTENDER), defaultContains },
230 { UPROPS_SRC_NFC, 0, hasFullCompositionExclusion },
231 { 1, U_MASK(UPROPS_GRAPHEME_BASE), defaultContains },
232 { 1, U_MASK(UPROPS_GRAPHEME_EXTEND), defaultContains },
233 { 1, U_MASK(UPROPS_GRAPHEME_LINK), defaultContains },
234 { 1, U_MASK(UPROPS_HEX_DIGIT), defaultContains },
235 { 1, U_MASK(UPROPS_HYPHEN), defaultContains },
236 { 1, U_MASK(UPROPS_ID_CONTINUE), defaultContains },
237 { 1, U_MASK(UPROPS_ID_START), defaultContains },
238 { 1, U_MASK(UPROPS_IDEOGRAPHIC), defaultContains },
239 { 1, U_MASK(UPROPS_IDS_BINARY_OPERATOR), defaultContains },
240 { 1, U_MASK(UPROPS_IDS_TRINARY_OPERATOR), defaultContains },
241 { UPROPS_SRC_BIDI, 0, isJoinControl },
242 { 1, U_MASK(UPROPS_LOGICAL_ORDER_EXCEPTION), defaultContains },
243 { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_LOWERCASE
244 { 1, U_MASK(UPROPS_MATH), defaultContains },
245 { 1, U_MASK(UPROPS_NONCHARACTER_CODE_POINT), defaultContains },
246 { 1, U_MASK(UPROPS_QUOTATION_MARK), defaultContains },
247 { 1, U_MASK(UPROPS_RADICAL), defaultContains },
248 { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_SOFT_DOTTED
249 { 1, U_MASK(UPROPS_TERMINAL_PUNCTUATION), defaultContains },
250 { 1, U_MASK(UPROPS_UNIFIED_IDEOGRAPH), defaultContains },
251 { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_UPPERCASE
252 { 1, U_MASK(UPROPS_WHITE_SPACE), defaultContains },
253 { 1, U_MASK(UPROPS_XID_CONTINUE), defaultContains },
254 { 1, U_MASK(UPROPS_XID_START), defaultContains },
255 { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CASE_SENSITIVE
256 { 1, U_MASK(UPROPS_S_TERM), defaultContains },
257 { 1, U_MASK(UPROPS_VARIATION_SELECTOR), defaultContains },
258 { UPROPS_SRC_NFC, 0, isNormInert }, // UCHAR_NFD_INERT
259 { UPROPS_SRC_NFKC, 0, isNormInert }, // UCHAR_NFKD_INERT
260 { UPROPS_SRC_NFC, 0, isNormInert }, // UCHAR_NFC_INERT
261 { UPROPS_SRC_NFKC, 0, isNormInert }, // UCHAR_NFKC_INERT
262 { UPROPS_SRC_NFC_CANON_ITER, 0, isCanonSegmentStarter },
263 { 1, U_MASK(UPROPS_PATTERN_SYNTAX), defaultContains },
264 { 1, U_MASK(UPROPS_PATTERN_WHITE_SPACE), defaultContains },
265 { UPROPS_SRC_CHAR_AND_PROPSVEC, 0, isPOSIX_alnum },
266 { UPROPS_SRC_CHAR, 0, isPOSIX_blank },
267 { UPROPS_SRC_CHAR, 0, isPOSIX_graph },
268 { UPROPS_SRC_CHAR, 0, isPOSIX_print },
269 { UPROPS_SRC_CHAR, 0, isPOSIX_xdigit },
270 { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CASED
271 { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CASE_IGNORABLE
272 { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CHANGES_WHEN_LOWERCASED
273 { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CHANGES_WHEN_UPPERCASED
274 { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CHANGES_WHEN_TITLECASED
275 { UPROPS_SRC_CASE_AND_NORM, 0, changesWhenCasefolded },
276 { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CHANGES_WHEN_CASEMAPPED
277 { UPROPS_SRC_NFKC_CF, 0, changesWhenNFKC_Casefolded },
278 { 2, U_MASK(UPROPS_2_EMOJI), defaultContains },
279 { 2, U_MASK(UPROPS_2_EMOJI_PRESENTATION), defaultContains },
280 { 2, U_MASK(UPROPS_2_EMOJI_MODIFIER), defaultContains },
281 { 2, U_MASK(UPROPS_2_EMOJI_MODIFIER_BASE), defaultContains },
282 { 2, U_MASK(UPROPS_2_EMOJI_COMPONENT), defaultContains },
283 { 2, 0, isRegionalIndicator },
284 { 1, U_MASK(UPROPS_PREPENDED_CONCATENATION_MARK), defaultContains },
285 { 2, U_MASK(UPROPS_2_EXTENDED_PICTOGRAPHIC), defaultContains },
286};
287
288U_CAPI UBool U_EXPORT2
289u_hasBinaryProperty(UChar32 c, UProperty which) {
290 /* c is range-checked in the functions that are called from here */
291 if(which<UCHAR_BINARY_START || UCHAR_BINARY_LIMIT<=which) {
292 /* not a known binary property */
293 return FALSE;
294 } else {
295 const BinaryProperty &prop=binProps[which];
296 return prop.contains(prop, c, which);
297 }
298}
299
300// Apple-only specific version of the above
301U_CAPI UBool U_EXPORT2
302u_isEmoji(UChar32 c) {
303 const BinaryProperty &prop=binProps[UCHAR_EMOJI];
304 return prop.contains(prop, c, UCHAR_EMOJI);
305}
306
307struct IntProperty;
308
309typedef int32_t IntPropertyGetValue(const IntProperty &prop, UChar32 c, UProperty which);
310typedef int32_t IntPropertyGetMaxValue(const IntProperty &prop, UProperty which);
311
312struct IntProperty {
313 int32_t column; // SRC_PROPSVEC column, or "source" if mask==0
314 uint32_t mask;
315 int32_t shift; // =maxValue if getMaxValueFromShift() is used
316 IntPropertyGetValue *getValue;
317 IntPropertyGetMaxValue *getMaxValue;
318};
319
320static int32_t defaultGetValue(const IntProperty &prop, UChar32 c, UProperty /*which*/) {
321 /* systematic, directly stored properties */
322 return (int32_t)(u_getUnicodeProperties(c, prop.column)&prop.mask)>>prop.shift;
323}
324
325static int32_t defaultGetMaxValue(const IntProperty &prop, UProperty /*which*/) {
326 return (uprv_getMaxValues(prop.column)&prop.mask)>>prop.shift;
327}
328
329static int32_t getMaxValueFromShift(const IntProperty &prop, UProperty /*which*/) {
330 return prop.shift;
331}
332
333static int32_t getBiDiClass(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
334 return (int32_t)u_charDirection(c);
335}
336
337static int32_t getBiDiPairedBracketType(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
338 return (int32_t)ubidi_getPairedBracketType(c);
339}
340
341static int32_t biDiGetMaxValue(const IntProperty &/*prop*/, UProperty which) {
342 return ubidi_getMaxValue(which);
343}
344
345#if UCONFIG_NO_NORMALIZATION
346static int32_t getCombiningClass(const IntProperty &, UChar32, UProperty) {
347 return 0;
348}
349#else
350static int32_t getCombiningClass(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
351 return u_getCombiningClass(c);
352}
353#endif
354
355static int32_t getGeneralCategory(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
356 return (int32_t)u_charType(c);
357}
358
359static int32_t getJoiningGroup(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
360 return ubidi_getJoiningGroup(c);
361}
362
363static int32_t getJoiningType(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
364 return ubidi_getJoiningType(c);
365}
366
367static int32_t getNumericType(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
368 int32_t ntv=(int32_t)GET_NUMERIC_TYPE_VALUE(u_getMainProperties(c));
369 return UPROPS_NTV_GET_TYPE(ntv);
370}
371
372static int32_t getScript(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
373 UErrorCode errorCode=U_ZERO_ERROR;
374 return (int32_t)uscript_getScript(c, &errorCode);
375}
376
377/*
378 * Map some of the Grapheme Cluster Break values to Hangul Syllable Types.
379 * Hangul_Syllable_Type is fully redundant with a subset of Grapheme_Cluster_Break.
380 */
381static const UHangulSyllableType gcbToHst[]={
382 U_HST_NOT_APPLICABLE, /* U_GCB_OTHER */
383 U_HST_NOT_APPLICABLE, /* U_GCB_CONTROL */
384 U_HST_NOT_APPLICABLE, /* U_GCB_CR */
385 U_HST_NOT_APPLICABLE, /* U_GCB_EXTEND */
386 U_HST_LEADING_JAMO, /* U_GCB_L */
387 U_HST_NOT_APPLICABLE, /* U_GCB_LF */
388 U_HST_LV_SYLLABLE, /* U_GCB_LV */
389 U_HST_LVT_SYLLABLE, /* U_GCB_LVT */
390 U_HST_TRAILING_JAMO, /* U_GCB_T */
391 U_HST_VOWEL_JAMO /* U_GCB_V */
392 /*
393 * Omit GCB values beyond what we need for hst.
394 * The code below checks for the array length.
395 */
396};
397
398static int32_t getHangulSyllableType(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
399 /* see comments on gcbToHst[] above */
400 int32_t gcb=(int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_GCB_MASK)>>UPROPS_GCB_SHIFT;
401 if(gcb<UPRV_LENGTHOF(gcbToHst)) {
402 return gcbToHst[gcb];
403 } else {
404 return U_HST_NOT_APPLICABLE;
405 }
406}
407
408#if UCONFIG_NO_NORMALIZATION
409static int32_t getNormQuickCheck(const IntProperty &, UChar32, UProperty) {
410 return 0;
411}
412#else
413static int32_t getNormQuickCheck(const IntProperty &/*prop*/, UChar32 c, UProperty which) {
414 return (int32_t)unorm_getQuickCheck(c, (UNormalizationMode)(which-UCHAR_NFD_QUICK_CHECK+UNORM_NFD));
415}
416#endif
417
418#if UCONFIG_NO_NORMALIZATION
419static int32_t getLeadCombiningClass(const IntProperty &, UChar32, UProperty) {
420 return 0;
421}
422#else
423static int32_t getLeadCombiningClass(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
424 return unorm_getFCD16(c)>>8;
425}
426#endif
427
428#if UCONFIG_NO_NORMALIZATION
429static int32_t getTrailCombiningClass(const IntProperty &, UChar32, UProperty) {
430 return 0;
431}
432#else
433static int32_t getTrailCombiningClass(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) {
434 return unorm_getFCD16(c)&0xff;
435}
436#endif
437
438static const IntProperty intProps[UCHAR_INT_LIMIT-UCHAR_INT_START]={
439 /*
440 * column, mask and shift values for int-value properties from u_getUnicodeProperties().
441 * Must be in order of corresponding UProperty,
442 * and there must be exactly one entry per int UProperty.
443 *
444 * Properties with mask==0 are handled in code.
445 * For them, column is the UPropertySource value.
446 */
447 { UPROPS_SRC_BIDI, 0, 0, getBiDiClass, biDiGetMaxValue },
448 { 0, UPROPS_BLOCK_MASK, UPROPS_BLOCK_SHIFT, defaultGetValue, defaultGetMaxValue },
449 { UPROPS_SRC_NFC, 0, 0xff, getCombiningClass, getMaxValueFromShift },
450 { 2, UPROPS_DT_MASK, 0, defaultGetValue, defaultGetMaxValue },
451 { 0, UPROPS_EA_MASK, UPROPS_EA_SHIFT, defaultGetValue, defaultGetMaxValue },
452 { UPROPS_SRC_CHAR, 0, (int32_t)U_CHAR_CATEGORY_COUNT-1,getGeneralCategory, getMaxValueFromShift },
453 { UPROPS_SRC_BIDI, 0, 0, getJoiningGroup, biDiGetMaxValue },
454 { UPROPS_SRC_BIDI, 0, 0, getJoiningType, biDiGetMaxValue },
455 { 2, UPROPS_LB_MASK, UPROPS_LB_SHIFT, defaultGetValue, defaultGetMaxValue },
456 { UPROPS_SRC_CHAR, 0, (int32_t)U_NT_COUNT-1, getNumericType, getMaxValueFromShift },
457 { 0, UPROPS_SCRIPT_MASK, 0, getScript, defaultGetMaxValue },
458 { UPROPS_SRC_PROPSVEC, 0, (int32_t)U_HST_COUNT-1, getHangulSyllableType, getMaxValueFromShift },
459 // UCHAR_NFD_QUICK_CHECK: max=1=YES -- never "maybe", only "no" or "yes"
460 { UPROPS_SRC_NFC, 0, (int32_t)UNORM_YES, getNormQuickCheck, getMaxValueFromShift },
461 // UCHAR_NFKD_QUICK_CHECK: max=1=YES -- never "maybe", only "no" or "yes"
462 { UPROPS_SRC_NFKC, 0, (int32_t)UNORM_YES, getNormQuickCheck, getMaxValueFromShift },
463 // UCHAR_NFC_QUICK_CHECK: max=2=MAYBE
464 { UPROPS_SRC_NFC, 0, (int32_t)UNORM_MAYBE, getNormQuickCheck, getMaxValueFromShift },
465 // UCHAR_NFKC_QUICK_CHECK: max=2=MAYBE
466 { UPROPS_SRC_NFKC, 0, (int32_t)UNORM_MAYBE, getNormQuickCheck, getMaxValueFromShift },
467 { UPROPS_SRC_NFC, 0, 0xff, getLeadCombiningClass, getMaxValueFromShift },
468 { UPROPS_SRC_NFC, 0, 0xff, getTrailCombiningClass, getMaxValueFromShift },
469 { 2, UPROPS_GCB_MASK, UPROPS_GCB_SHIFT, defaultGetValue, defaultGetMaxValue },
470 { 2, UPROPS_SB_MASK, UPROPS_SB_SHIFT, defaultGetValue, defaultGetMaxValue },
471 { 2, UPROPS_WB_MASK, UPROPS_WB_SHIFT, defaultGetValue, defaultGetMaxValue },
472 { UPROPS_SRC_BIDI, 0, 0, getBiDiPairedBracketType, biDiGetMaxValue },
473};
474
475U_CAPI int32_t U_EXPORT2
476u_getIntPropertyValue(UChar32 c, UProperty which) {
477 if(which<UCHAR_INT_START) {
478 if(UCHAR_BINARY_START<=which && which<UCHAR_BINARY_LIMIT) {
479 const BinaryProperty &prop=binProps[which];
480 return prop.contains(prop, c, which);
481 }
482 } else if(which<UCHAR_INT_LIMIT) {
483 const IntProperty &prop=intProps[which-UCHAR_INT_START];
484 return prop.getValue(prop, c, which);
485 } else if(which==UCHAR_GENERAL_CATEGORY_MASK) {
486 return U_MASK(u_charType(c));
487 }
488 return 0; // undefined
489}
490
491U_CAPI int32_t U_EXPORT2
492u_getIntPropertyMinValue(UProperty /*which*/) {
493 return 0; /* all binary/enum/int properties have a minimum value of 0 */
494}
495
496U_CAPI int32_t U_EXPORT2
497u_getIntPropertyMaxValue(UProperty which) {
498 if(which<UCHAR_INT_START) {
499 if(UCHAR_BINARY_START<=which && which<UCHAR_BINARY_LIMIT) {
500 return 1; // maximum TRUE for all binary properties
501 }
502 } else if(which<UCHAR_INT_LIMIT) {
503 const IntProperty &prop=intProps[which-UCHAR_INT_START];
504 return prop.getMaxValue(prop, which);
505 }
506 return -1; // undefined
507}
508
509U_CFUNC UPropertySource U_EXPORT2
510uprops_getSource(UProperty which) {
511 if(which<UCHAR_BINARY_START) {
512 return UPROPS_SRC_NONE; /* undefined */
513 } else if(which<UCHAR_BINARY_LIMIT) {
514 const BinaryProperty &prop=binProps[which];
515 if(prop.mask!=0) {
516 return UPROPS_SRC_PROPSVEC;
517 } else {
518 return (UPropertySource)prop.column;
519 }
520 } else if(which<UCHAR_INT_START) {
521 return UPROPS_SRC_NONE; /* undefined */
522 } else if(which<UCHAR_INT_LIMIT) {
523 const IntProperty &prop=intProps[which-UCHAR_INT_START];
524 if(prop.mask!=0) {
525 return UPROPS_SRC_PROPSVEC;
526 } else {
527 return (UPropertySource)prop.column;
528 }
529 } else if(which<UCHAR_STRING_START) {
530 switch(which) {
531 case UCHAR_GENERAL_CATEGORY_MASK:
532 case UCHAR_NUMERIC_VALUE:
533 return UPROPS_SRC_CHAR;
534
535 default:
536 return UPROPS_SRC_NONE;
537 }
538 } else if(which<UCHAR_STRING_LIMIT) {
539 switch(which) {
540 case UCHAR_AGE:
541 return UPROPS_SRC_PROPSVEC;
542
543 case UCHAR_BIDI_MIRRORING_GLYPH:
544 return UPROPS_SRC_BIDI;
545
546 case UCHAR_CASE_FOLDING:
547 case UCHAR_LOWERCASE_MAPPING:
548 case UCHAR_SIMPLE_CASE_FOLDING:
549 case UCHAR_SIMPLE_LOWERCASE_MAPPING:
550 case UCHAR_SIMPLE_TITLECASE_MAPPING:
551 case UCHAR_SIMPLE_UPPERCASE_MAPPING:
552 case UCHAR_TITLECASE_MAPPING:
553 case UCHAR_UPPERCASE_MAPPING:
554 return UPROPS_SRC_CASE;
555
556 case UCHAR_ISO_COMMENT:
557 case UCHAR_NAME:
558 case UCHAR_UNICODE_1_NAME:
559 return UPROPS_SRC_NAMES;
560
561 default:
562 return UPROPS_SRC_NONE;
563 }
564 } else {
565 switch(which) {
566 case UCHAR_SCRIPT_EXTENSIONS:
567 return UPROPS_SRC_PROPSVEC;
568 default:
569 return UPROPS_SRC_NONE; /* undefined */
570 }
571 }
572}
573
574#if !UCONFIG_NO_NORMALIZATION
575
576U_CAPI int32_t U_EXPORT2
577u_getFC_NFKC_Closure(UChar32 c, UChar *dest, int32_t destCapacity, UErrorCode *pErrorCode) {
578 if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
579 return 0;
580 }
581 if(destCapacity<0 || (dest==NULL && destCapacity>0)) {
582 *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
583 return 0;
584 }
585 // Compute the FC_NFKC_Closure on the fly:
586 // We have the API for complete coverage of Unicode properties, although
587 // this value by itself is not useful via API.
588 // (What could be useful is a custom normalization table that combines
589 // case folding and NFKC.)
590 // For the derivation, see Unicode's DerivedNormalizationProps.txt.
591 const Normalizer2 *nfkc=Normalizer2::getNFKCInstance(*pErrorCode);
592 if(U_FAILURE(*pErrorCode)) {
593 return 0;
594 }
595 // first: b = NFKC(Fold(a))
596 UnicodeString folded1String;
597 const UChar *folded1;
598 int32_t folded1Length=ucase_toFullFolding(c, &folded1, U_FOLD_CASE_DEFAULT);
599 if(folded1Length<0) {
600 const Normalizer2Impl *nfkcImpl=Normalizer2Factory::getImpl(nfkc);
601 if(nfkcImpl->getCompQuickCheck(nfkcImpl->getNorm16(c))!=UNORM_NO) {
602 return u_terminateUChars(dest, destCapacity, 0, pErrorCode); // c does not change at all under CaseFolding+NFKC
603 }
604 folded1String.setTo(c);
605 } else {
606 if(folded1Length>UCASE_MAX_STRING_LENGTH) {
607 folded1String.setTo(folded1Length);
608 } else {
609 folded1String.setTo(FALSE, folded1, folded1Length);
610 }
611 }
612 UnicodeString kc1=nfkc->normalize(folded1String, *pErrorCode);
613 // second: c = NFKC(Fold(b))
614 UnicodeString folded2String(kc1);
615 UnicodeString kc2=nfkc->normalize(folded2String.foldCase(), *pErrorCode);
616 // if (c != b) add the mapping from a to c
617 if(U_FAILURE(*pErrorCode) || kc1==kc2) {
618 return u_terminateUChars(dest, destCapacity, 0, pErrorCode);
619 } else {
620 return kc2.extract(dest, destCapacity, *pErrorCode);
621 }
622}
623
624#endif