1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 2002-2016, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: uprops.cpp
12 * tab size: 8 (not used)
15 * created on: 2002feb24
16 * created by: Markus W. Scherer
18 * Implementations for mostly non-core Unicode character properties
19 * stored in uprops.icu.
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.
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"
32 #include "normalizer2impl.h"
34 #include "ubidi_props.h"
41 #define GET_BIDI_PROPS() ubidi_getSingleton()
43 /* general properties API functions ----------------------------------------- */
45 struct BinaryProperty
;
47 typedef UBool
BinaryPropertyContains(const BinaryProperty
&prop
, UChar32 c
, UProperty which
);
49 struct BinaryProperty
{
50 int32_t column
; // SRC_PROPSVEC column, or "source" if mask==0
52 BinaryPropertyContains
*contains
;
55 static UBool
defaultContains(const BinaryProperty
&prop
, UChar32 c
, UProperty
/*which*/) {
56 /* systematic, directly stored properties */
57 return (u_getUnicodeProperties(c
, prop
.column
)&prop
.mask
)!=0;
60 static UBool
caseBinaryPropertyContains(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty which
) {
61 return ucase_hasBinaryProperty(c
, which
);
64 static UBool
isBidiControl(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
65 return ubidi_isBidiControl(GET_BIDI_PROPS(), c
);
68 static UBool
isMirrored(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
69 return ubidi_isMirrored(GET_BIDI_PROPS(), c
);
72 static UBool
isJoinControl(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
73 return ubidi_isJoinControl(GET_BIDI_PROPS(), c
);
76 #if UCONFIG_NO_NORMALIZATION
77 static UBool
hasFullCompositionExclusion(const BinaryProperty
&, UChar32
, UProperty
) {
81 static UBool
hasFullCompositionExclusion(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
82 // By definition, Full_Composition_Exclusion is the same as NFC_QC=No.
83 UErrorCode errorCode
=U_ZERO_ERROR
;
84 const Normalizer2Impl
*impl
=Normalizer2Factory::getNFCImpl(errorCode
);
85 return U_SUCCESS(errorCode
) && impl
->isCompNo(impl
->getNorm16(c
));
89 // UCHAR_NF*_INERT properties
90 #if UCONFIG_NO_NORMALIZATION
91 static UBool
isNormInert(const BinaryProperty
&, UChar32
, UProperty
) {
95 static UBool
isNormInert(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty which
) {
96 UErrorCode errorCode
=U_ZERO_ERROR
;
97 const Normalizer2
*norm2
=Normalizer2Factory::getInstance(
98 (UNormalizationMode
)(which
-UCHAR_NFD_INERT
+UNORM_NFD
), errorCode
);
99 return U_SUCCESS(errorCode
) && norm2
->isInert(c
);
103 #if UCONFIG_NO_NORMALIZATION
104 static UBool
changesWhenCasefolded(const BinaryProperty
&, UChar32
, UProperty
) {
108 static UBool
changesWhenCasefolded(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
110 UErrorCode errorCode
=U_ZERO_ERROR
;
111 const Normalizer2
*nfcNorm2
=Normalizer2::getNFCInstance(errorCode
);
112 if(U_FAILURE(errorCode
)) {
115 if(nfcNorm2
->getDecomposition(c
, nfd
)) {
116 /* c has a decomposition */
117 if(nfd
.length()==1) {
118 c
=nfd
[0]; /* single BMP code point */
119 } else if(nfd
.length()<=U16_MAX_LENGTH
&&
120 nfd
.length()==U16_LENGTH(c
=nfd
.char32At(0))
122 /* single supplementary code point */
127 return FALSE
; /* protect against bad input */
130 /* single code point */
131 const UChar
*resultString
;
132 return (UBool
)(ucase_toFullFolding(c
, &resultString
, U_FOLD_CASE_DEFAULT
)>=0);
134 /* guess some large but stack-friendly capacity */
135 UChar dest
[2*UCASE_MAX_STRING_LENGTH
];
137 destLength
=u_strFoldCase(dest
, UPRV_LENGTHOF(dest
),
138 nfd
.getBuffer(), nfd
.length(),
139 U_FOLD_CASE_DEFAULT
, &errorCode
);
140 return (UBool
)(U_SUCCESS(errorCode
) &&
141 0!=u_strCompare(nfd
.getBuffer(), nfd
.length(),
142 dest
, destLength
, FALSE
));
147 #if UCONFIG_NO_NORMALIZATION
148 static UBool
changesWhenNFKC_Casefolded(const BinaryProperty
&, UChar32
, UProperty
) {
152 static UBool
changesWhenNFKC_Casefolded(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
153 UErrorCode errorCode
=U_ZERO_ERROR
;
154 const Normalizer2Impl
*kcf
=Normalizer2Factory::getNFKC_CFImpl(errorCode
);
155 if(U_FAILURE(errorCode
)) {
158 UnicodeString
src(c
);
161 // The ReorderingBuffer must be in a block because its destructor
162 // needs to release dest's buffer before we look at its contents.
163 ReorderingBuffer
buffer(*kcf
, dest
);
164 // Small destCapacity for NFKC_CF(c).
165 if(buffer
.init(5, errorCode
)) {
166 const UChar
*srcArray
=src
.getBuffer();
167 kcf
->compose(srcArray
, srcArray
+src
.length(), FALSE
,
168 TRUE
, buffer
, errorCode
);
171 return U_SUCCESS(errorCode
) && dest
!=src
;
175 #if UCONFIG_NO_NORMALIZATION
176 static UBool
isCanonSegmentStarter(const BinaryProperty
&, UChar32
, UProperty
) {
180 static UBool
isCanonSegmentStarter(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
181 UErrorCode errorCode
=U_ZERO_ERROR
;
182 const Normalizer2Impl
*impl
=Normalizer2Factory::getNFCImpl(errorCode
);
184 U_SUCCESS(errorCode
) && impl
->ensureCanonIterData(errorCode
) &&
185 impl
->isCanonSegmentStarter(c
);
189 static UBool
isPOSIX_alnum(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
190 return u_isalnumPOSIX(c
);
193 static UBool
isPOSIX_blank(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
197 static UBool
isPOSIX_graph(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
198 return u_isgraphPOSIX(c
);
201 static UBool
isPOSIX_print(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
202 return u_isprintPOSIX(c
);
205 static UBool
isPOSIX_xdigit(const BinaryProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
206 return u_isxdigit(c
);
209 static const BinaryProperty binProps
[UCHAR_BINARY_LIMIT
]={
211 * column and mask values for binary properties from u_getUnicodeProperties().
212 * Must be in order of corresponding UProperty,
213 * and there must be exactly one entry per binary UProperty.
215 * Properties with mask==0 are handled in code.
216 * For them, column is the UPropertySource value.
218 { 1, U_MASK(UPROPS_ALPHABETIC
), defaultContains
},
219 { 1, U_MASK(UPROPS_ASCII_HEX_DIGIT
), defaultContains
},
220 { UPROPS_SRC_BIDI
, 0, isBidiControl
},
221 { UPROPS_SRC_BIDI
, 0, isMirrored
},
222 { 1, U_MASK(UPROPS_DASH
), defaultContains
},
223 { 1, U_MASK(UPROPS_DEFAULT_IGNORABLE_CODE_POINT
), defaultContains
},
224 { 1, U_MASK(UPROPS_DEPRECATED
), defaultContains
},
225 { 1, U_MASK(UPROPS_DIACRITIC
), defaultContains
},
226 { 1, U_MASK(UPROPS_EXTENDER
), defaultContains
},
227 { UPROPS_SRC_NFC
, 0, hasFullCompositionExclusion
},
228 { 1, U_MASK(UPROPS_GRAPHEME_BASE
), defaultContains
},
229 { 1, U_MASK(UPROPS_GRAPHEME_EXTEND
), defaultContains
},
230 { 1, U_MASK(UPROPS_GRAPHEME_LINK
), defaultContains
},
231 { 1, U_MASK(UPROPS_HEX_DIGIT
), defaultContains
},
232 { 1, U_MASK(UPROPS_HYPHEN
), defaultContains
},
233 { 1, U_MASK(UPROPS_ID_CONTINUE
), defaultContains
},
234 { 1, U_MASK(UPROPS_ID_START
), defaultContains
},
235 { 1, U_MASK(UPROPS_IDEOGRAPHIC
), defaultContains
},
236 { 1, U_MASK(UPROPS_IDS_BINARY_OPERATOR
), defaultContains
},
237 { 1, U_MASK(UPROPS_IDS_TRINARY_OPERATOR
), defaultContains
},
238 { UPROPS_SRC_BIDI
, 0, isJoinControl
},
239 { 1, U_MASK(UPROPS_LOGICAL_ORDER_EXCEPTION
), defaultContains
},
240 { UPROPS_SRC_CASE
, 0, caseBinaryPropertyContains
}, // UCHAR_LOWERCASE
241 { 1, U_MASK(UPROPS_MATH
), defaultContains
},
242 { 1, U_MASK(UPROPS_NONCHARACTER_CODE_POINT
), defaultContains
},
243 { 1, U_MASK(UPROPS_QUOTATION_MARK
), defaultContains
},
244 { 1, U_MASK(UPROPS_RADICAL
), defaultContains
},
245 { UPROPS_SRC_CASE
, 0, caseBinaryPropertyContains
}, // UCHAR_SOFT_DOTTED
246 { 1, U_MASK(UPROPS_TERMINAL_PUNCTUATION
), defaultContains
},
247 { 1, U_MASK(UPROPS_UNIFIED_IDEOGRAPH
), defaultContains
},
248 { UPROPS_SRC_CASE
, 0, caseBinaryPropertyContains
}, // UCHAR_UPPERCASE
249 { 1, U_MASK(UPROPS_WHITE_SPACE
), defaultContains
},
250 { 1, U_MASK(UPROPS_XID_CONTINUE
), defaultContains
},
251 { 1, U_MASK(UPROPS_XID_START
), defaultContains
},
252 { UPROPS_SRC_CASE
, 0, caseBinaryPropertyContains
}, // UCHAR_CASE_SENSITIVE
253 { 1, U_MASK(UPROPS_S_TERM
), defaultContains
},
254 { 1, U_MASK(UPROPS_VARIATION_SELECTOR
), defaultContains
},
255 { UPROPS_SRC_NFC
, 0, isNormInert
}, // UCHAR_NFD_INERT
256 { UPROPS_SRC_NFKC
, 0, isNormInert
}, // UCHAR_NFKD_INERT
257 { UPROPS_SRC_NFC
, 0, isNormInert
}, // UCHAR_NFC_INERT
258 { UPROPS_SRC_NFKC
, 0, isNormInert
}, // UCHAR_NFKC_INERT
259 { UPROPS_SRC_NFC_CANON_ITER
, 0, isCanonSegmentStarter
},
260 { 1, U_MASK(UPROPS_PATTERN_SYNTAX
), defaultContains
},
261 { 1, U_MASK(UPROPS_PATTERN_WHITE_SPACE
), defaultContains
},
262 { UPROPS_SRC_CHAR_AND_PROPSVEC
, 0, isPOSIX_alnum
},
263 { UPROPS_SRC_CHAR
, 0, isPOSIX_blank
},
264 { UPROPS_SRC_CHAR
, 0, isPOSIX_graph
},
265 { UPROPS_SRC_CHAR
, 0, isPOSIX_print
},
266 { UPROPS_SRC_CHAR
, 0, isPOSIX_xdigit
},
267 { UPROPS_SRC_CASE
, 0, caseBinaryPropertyContains
}, // UCHAR_CASED
268 { UPROPS_SRC_CASE
, 0, caseBinaryPropertyContains
}, // UCHAR_CASE_IGNORABLE
269 { UPROPS_SRC_CASE
, 0, caseBinaryPropertyContains
}, // UCHAR_CHANGES_WHEN_LOWERCASED
270 { UPROPS_SRC_CASE
, 0, caseBinaryPropertyContains
}, // UCHAR_CHANGES_WHEN_UPPERCASED
271 { UPROPS_SRC_CASE
, 0, caseBinaryPropertyContains
}, // UCHAR_CHANGES_WHEN_TITLECASED
272 { UPROPS_SRC_CASE_AND_NORM
, 0, changesWhenCasefolded
},
273 { UPROPS_SRC_CASE
, 0, caseBinaryPropertyContains
}, // UCHAR_CHANGES_WHEN_CASEMAPPED
274 { UPROPS_SRC_NFKC_CF
, 0, changesWhenNFKC_Casefolded
},
275 { 2, U_MASK(UPROPS_2_EMOJI
), defaultContains
},
276 { 2, U_MASK(UPROPS_2_EMOJI_PRESENTATION
), defaultContains
},
277 { 2, U_MASK(UPROPS_2_EMOJI_MODIFIER
), defaultContains
},
278 { 2, U_MASK(UPROPS_2_EMOJI_MODIFIER_BASE
), defaultContains
},
281 U_CAPI UBool U_EXPORT2
282 u_hasBinaryProperty(UChar32 c
, UProperty which
) {
283 /* c is range-checked in the functions that are called from here */
284 if(which
<UCHAR_BINARY_START
|| UCHAR_BINARY_LIMIT
<=which
) {
285 /* not a known binary property */
288 const BinaryProperty
&prop
=binProps
[which
];
289 return prop
.contains(prop
, c
, which
);
295 typedef int32_t IntPropertyGetValue(const IntProperty
&prop
, UChar32 c
, UProperty which
);
296 typedef int32_t IntPropertyGetMaxValue(const IntProperty
&prop
, UProperty which
);
299 int32_t column
; // SRC_PROPSVEC column, or "source" if mask==0
301 int32_t shift
; // =maxValue if getMaxValueFromShift() is used
302 IntPropertyGetValue
*getValue
;
303 IntPropertyGetMaxValue
*getMaxValue
;
306 static int32_t defaultGetValue(const IntProperty
&prop
, UChar32 c
, UProperty
/*which*/) {
307 /* systematic, directly stored properties */
308 return (int32_t)(u_getUnicodeProperties(c
, prop
.column
)&prop
.mask
)>>prop
.shift
;
311 static int32_t defaultGetMaxValue(const IntProperty
&prop
, UProperty
/*which*/) {
312 return (uprv_getMaxValues(prop
.column
)&prop
.mask
)>>prop
.shift
;
315 static int32_t getMaxValueFromShift(const IntProperty
&prop
, UProperty
/*which*/) {
319 static int32_t getBiDiClass(const IntProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
320 return (int32_t)u_charDirection(c
);
323 static int32_t getBiDiPairedBracketType(const IntProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
324 return (int32_t)ubidi_getPairedBracketType(GET_BIDI_PROPS(), c
);
327 static int32_t biDiGetMaxValue(const IntProperty
&/*prop*/, UProperty which
) {
328 return ubidi_getMaxValue(GET_BIDI_PROPS(), which
);
331 #if UCONFIG_NO_NORMALIZATION
332 static int32_t getCombiningClass(const IntProperty
&, UChar32
, UProperty
) {
336 static int32_t getCombiningClass(const IntProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
337 return u_getCombiningClass(c
);
341 static int32_t getGeneralCategory(const IntProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
342 return (int32_t)u_charType(c
);
345 static int32_t getJoiningGroup(const IntProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
346 return ubidi_getJoiningGroup(GET_BIDI_PROPS(), c
);
349 static int32_t getJoiningType(const IntProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
350 return ubidi_getJoiningType(GET_BIDI_PROPS(), c
);
353 static int32_t getNumericType(const IntProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
354 int32_t ntv
=(int32_t)GET_NUMERIC_TYPE_VALUE(u_getMainProperties(c
));
355 return UPROPS_NTV_GET_TYPE(ntv
);
358 static int32_t getScript(const IntProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
359 UErrorCode errorCode
=U_ZERO_ERROR
;
360 return (int32_t)uscript_getScript(c
, &errorCode
);
364 * Map some of the Grapheme Cluster Break values to Hangul Syllable Types.
365 * Hangul_Syllable_Type is fully redundant with a subset of Grapheme_Cluster_Break.
367 static const UHangulSyllableType gcbToHst
[]={
368 U_HST_NOT_APPLICABLE
, /* U_GCB_OTHER */
369 U_HST_NOT_APPLICABLE
, /* U_GCB_CONTROL */
370 U_HST_NOT_APPLICABLE
, /* U_GCB_CR */
371 U_HST_NOT_APPLICABLE
, /* U_GCB_EXTEND */
372 U_HST_LEADING_JAMO
, /* U_GCB_L */
373 U_HST_NOT_APPLICABLE
, /* U_GCB_LF */
374 U_HST_LV_SYLLABLE
, /* U_GCB_LV */
375 U_HST_LVT_SYLLABLE
, /* U_GCB_LVT */
376 U_HST_TRAILING_JAMO
, /* U_GCB_T */
377 U_HST_VOWEL_JAMO
/* U_GCB_V */
379 * Omit GCB values beyond what we need for hst.
380 * The code below checks for the array length.
384 static int32_t getHangulSyllableType(const IntProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
385 /* see comments on gcbToHst[] above */
386 int32_t gcb
=(int32_t)(u_getUnicodeProperties(c
, 2)&UPROPS_GCB_MASK
)>>UPROPS_GCB_SHIFT
;
387 if(gcb
<UPRV_LENGTHOF(gcbToHst
)) {
388 return gcbToHst
[gcb
];
390 return U_HST_NOT_APPLICABLE
;
394 #if UCONFIG_NO_NORMALIZATION
395 static int32_t getNormQuickCheck(const IntProperty
&, UChar32
, UProperty
) {
399 static int32_t getNormQuickCheck(const IntProperty
&/*prop*/, UChar32 c
, UProperty which
) {
400 return (int32_t)unorm_getQuickCheck(c
, (UNormalizationMode
)(which
-UCHAR_NFD_QUICK_CHECK
+UNORM_NFD
));
404 #if UCONFIG_NO_NORMALIZATION
405 static int32_t getLeadCombiningClass(const IntProperty
&, UChar32
, UProperty
) {
409 static int32_t getLeadCombiningClass(const IntProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
410 return unorm_getFCD16(c
)>>8;
414 #if UCONFIG_NO_NORMALIZATION
415 static int32_t getTrailCombiningClass(const IntProperty
&, UChar32
, UProperty
) {
419 static int32_t getTrailCombiningClass(const IntProperty
&/*prop*/, UChar32 c
, UProperty
/*which*/) {
420 return unorm_getFCD16(c
)&0xff;
424 static const IntProperty intProps
[UCHAR_INT_LIMIT
-UCHAR_INT_START
]={
426 * column, mask and shift values for int-value properties from u_getUnicodeProperties().
427 * Must be in order of corresponding UProperty,
428 * and there must be exactly one entry per int UProperty.
430 * Properties with mask==0 are handled in code.
431 * For them, column is the UPropertySource value.
433 { UPROPS_SRC_BIDI
, 0, 0, getBiDiClass
, biDiGetMaxValue
},
434 { 0, UPROPS_BLOCK_MASK
, UPROPS_BLOCK_SHIFT
, defaultGetValue
, defaultGetMaxValue
},
435 { UPROPS_SRC_NFC
, 0, 0xff, getCombiningClass
, getMaxValueFromShift
},
436 { 2, UPROPS_DT_MASK
, 0, defaultGetValue
, defaultGetMaxValue
},
437 { 0, UPROPS_EA_MASK
, UPROPS_EA_SHIFT
, defaultGetValue
, defaultGetMaxValue
},
438 { UPROPS_SRC_CHAR
, 0, (int32_t)U_CHAR_CATEGORY_COUNT
-1,getGeneralCategory
, getMaxValueFromShift
},
439 { UPROPS_SRC_BIDI
, 0, 0, getJoiningGroup
, biDiGetMaxValue
},
440 { UPROPS_SRC_BIDI
, 0, 0, getJoiningType
, biDiGetMaxValue
},
441 { 2, UPROPS_LB_MASK
, UPROPS_LB_SHIFT
, defaultGetValue
, defaultGetMaxValue
},
442 { UPROPS_SRC_CHAR
, 0, (int32_t)U_NT_COUNT
-1, getNumericType
, getMaxValueFromShift
},
443 { 0, UPROPS_SCRIPT_MASK
, 0, getScript
, defaultGetMaxValue
},
444 { UPROPS_SRC_PROPSVEC
, 0, (int32_t)U_HST_COUNT
-1, getHangulSyllableType
, getMaxValueFromShift
},
445 // UCHAR_NFD_QUICK_CHECK: max=1=YES -- never "maybe", only "no" or "yes"
446 { UPROPS_SRC_NFC
, 0, (int32_t)UNORM_YES
, getNormQuickCheck
, getMaxValueFromShift
},
447 // UCHAR_NFKD_QUICK_CHECK: max=1=YES -- never "maybe", only "no" or "yes"
448 { UPROPS_SRC_NFKC
, 0, (int32_t)UNORM_YES
, getNormQuickCheck
, getMaxValueFromShift
},
449 // UCHAR_NFC_QUICK_CHECK: max=2=MAYBE
450 { UPROPS_SRC_NFC
, 0, (int32_t)UNORM_MAYBE
, getNormQuickCheck
, getMaxValueFromShift
},
451 // UCHAR_NFKC_QUICK_CHECK: max=2=MAYBE
452 { UPROPS_SRC_NFKC
, 0, (int32_t)UNORM_MAYBE
, getNormQuickCheck
, getMaxValueFromShift
},
453 { UPROPS_SRC_NFC
, 0, 0xff, getLeadCombiningClass
, getMaxValueFromShift
},
454 { UPROPS_SRC_NFC
, 0, 0xff, getTrailCombiningClass
, getMaxValueFromShift
},
455 { 2, UPROPS_GCB_MASK
, UPROPS_GCB_SHIFT
, defaultGetValue
, defaultGetMaxValue
},
456 { 2, UPROPS_SB_MASK
, UPROPS_SB_SHIFT
, defaultGetValue
, defaultGetMaxValue
},
457 { 2, UPROPS_WB_MASK
, UPROPS_WB_SHIFT
, defaultGetValue
, defaultGetMaxValue
},
458 { UPROPS_SRC_BIDI
, 0, 0, getBiDiPairedBracketType
, biDiGetMaxValue
},
461 U_CAPI
int32_t U_EXPORT2
462 u_getIntPropertyValue(UChar32 c
, UProperty which
) {
463 if(which
<UCHAR_INT_START
) {
464 if(UCHAR_BINARY_START
<=which
&& which
<UCHAR_BINARY_LIMIT
) {
465 const BinaryProperty
&prop
=binProps
[which
];
466 return prop
.contains(prop
, c
, which
);
468 } else if(which
<UCHAR_INT_LIMIT
) {
469 const IntProperty
&prop
=intProps
[which
-UCHAR_INT_START
];
470 return prop
.getValue(prop
, c
, which
);
471 } else if(which
==UCHAR_GENERAL_CATEGORY_MASK
) {
472 return U_MASK(u_charType(c
));
474 return 0; // undefined
477 U_CAPI
int32_t U_EXPORT2
478 u_getIntPropertyMinValue(UProperty
/*which*/) {
479 return 0; /* all binary/enum/int properties have a minimum value of 0 */
482 U_CAPI
int32_t U_EXPORT2
483 u_getIntPropertyMaxValue(UProperty which
) {
484 if(which
<UCHAR_INT_START
) {
485 if(UCHAR_BINARY_START
<=which
&& which
<UCHAR_BINARY_LIMIT
) {
486 return 1; // maximum TRUE for all binary properties
488 } else if(which
<UCHAR_INT_LIMIT
) {
489 const IntProperty
&prop
=intProps
[which
-UCHAR_INT_START
];
490 return prop
.getMaxValue(prop
, which
);
492 return -1; // undefined
495 U_CFUNC UPropertySource U_EXPORT2
496 uprops_getSource(UProperty which
) {
497 if(which
<UCHAR_BINARY_START
) {
498 return UPROPS_SRC_NONE
; /* undefined */
499 } else if(which
<UCHAR_BINARY_LIMIT
) {
500 const BinaryProperty
&prop
=binProps
[which
];
502 return UPROPS_SRC_PROPSVEC
;
504 return (UPropertySource
)prop
.column
;
506 } else if(which
<UCHAR_INT_START
) {
507 return UPROPS_SRC_NONE
; /* undefined */
508 } else if(which
<UCHAR_INT_LIMIT
) {
509 const IntProperty
&prop
=intProps
[which
-UCHAR_INT_START
];
511 return UPROPS_SRC_PROPSVEC
;
513 return (UPropertySource
)prop
.column
;
515 } else if(which
<UCHAR_STRING_START
) {
517 case UCHAR_GENERAL_CATEGORY_MASK
:
518 case UCHAR_NUMERIC_VALUE
:
519 return UPROPS_SRC_CHAR
;
522 return UPROPS_SRC_NONE
;
524 } else if(which
<UCHAR_STRING_LIMIT
) {
527 return UPROPS_SRC_PROPSVEC
;
529 case UCHAR_BIDI_MIRRORING_GLYPH
:
530 return UPROPS_SRC_BIDI
;
532 case UCHAR_CASE_FOLDING
:
533 case UCHAR_LOWERCASE_MAPPING
:
534 case UCHAR_SIMPLE_CASE_FOLDING
:
535 case UCHAR_SIMPLE_LOWERCASE_MAPPING
:
536 case UCHAR_SIMPLE_TITLECASE_MAPPING
:
537 case UCHAR_SIMPLE_UPPERCASE_MAPPING
:
538 case UCHAR_TITLECASE_MAPPING
:
539 case UCHAR_UPPERCASE_MAPPING
:
540 return UPROPS_SRC_CASE
;
542 case UCHAR_ISO_COMMENT
:
544 case UCHAR_UNICODE_1_NAME
:
545 return UPROPS_SRC_NAMES
;
548 return UPROPS_SRC_NONE
;
552 case UCHAR_SCRIPT_EXTENSIONS
:
553 return UPROPS_SRC_PROPSVEC
;
555 return UPROPS_SRC_NONE
; /* undefined */
560 #if !UCONFIG_NO_NORMALIZATION
562 U_CAPI
int32_t U_EXPORT2
563 u_getFC_NFKC_Closure(UChar32 c
, UChar
*dest
, int32_t destCapacity
, UErrorCode
*pErrorCode
) {
564 if(pErrorCode
==NULL
|| U_FAILURE(*pErrorCode
)) {
567 if(destCapacity
<0 || (dest
==NULL
&& destCapacity
>0)) {
568 *pErrorCode
=U_ILLEGAL_ARGUMENT_ERROR
;
571 // Compute the FC_NFKC_Closure on the fly:
572 // We have the API for complete coverage of Unicode properties, although
573 // this value by itself is not useful via API.
574 // (What could be useful is a custom normalization table that combines
575 // case folding and NFKC.)
576 // For the derivation, see Unicode's DerivedNormalizationProps.txt.
577 const Normalizer2
*nfkc
=Normalizer2::getNFKCInstance(*pErrorCode
);
578 if(U_FAILURE(*pErrorCode
)) {
581 // first: b = NFKC(Fold(a))
582 UnicodeString folded1String
;
583 const UChar
*folded1
;
584 int32_t folded1Length
=ucase_toFullFolding(c
, &folded1
, U_FOLD_CASE_DEFAULT
);
585 if(folded1Length
<0) {
586 const Normalizer2Impl
*nfkcImpl
=Normalizer2Factory::getImpl(nfkc
);
587 if(nfkcImpl
->getCompQuickCheck(nfkcImpl
->getNorm16(c
))!=UNORM_NO
) {
588 return u_terminateUChars(dest
, destCapacity
, 0, pErrorCode
); // c does not change at all under CaseFolding+NFKC
590 folded1String
.setTo(c
);
592 if(folded1Length
>UCASE_MAX_STRING_LENGTH
) {
593 folded1String
.setTo(folded1Length
);
595 folded1String
.setTo(FALSE
, folded1
, folded1Length
);
598 UnicodeString kc1
=nfkc
->normalize(folded1String
, *pErrorCode
);
599 // second: c = NFKC(Fold(b))
600 UnicodeString
folded2String(kc1
);
601 UnicodeString kc2
=nfkc
->normalize(folded2String
.foldCase(), *pErrorCode
);
602 // if (c != b) add the mapping from a to c
603 if(U_FAILURE(*pErrorCode
) || kc1
==kc2
) {
604 return u_terminateUChars(dest
, destCapacity
, 0, pErrorCode
);
606 return kc2
.extract(dest
, destCapacity
, *pErrorCode
);