michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 2002-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * file name: uprops.cpp michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2002feb24 michael@0: * created by: Markus W. Scherer michael@0: * michael@0: * Implementations for mostly non-core Unicode character properties michael@0: * stored in uprops.icu. michael@0: * michael@0: * With the APIs implemented here, almost all properties files and michael@0: * their associated implementation files are used from this file, michael@0: * including those for normalization and case mappings. michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uchar.h" michael@0: #include "unicode/unorm2.h" michael@0: #include "unicode/uscript.h" michael@0: #include "unicode/ustring.h" michael@0: #include "cstring.h" michael@0: #include "normalizer2impl.h" michael@0: #include "ucln_cmn.h" michael@0: #include "umutex.h" michael@0: #include "ubidi_props.h" michael@0: #include "uprops.h" michael@0: #include "ucase.h" michael@0: #include "ustr_imp.h" michael@0: michael@0: #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) michael@0: michael@0: U_NAMESPACE_USE michael@0: michael@0: #define GET_BIDI_PROPS() ubidi_getSingleton() michael@0: michael@0: /* general properties API functions ----------------------------------------- */ michael@0: michael@0: struct BinaryProperty; michael@0: michael@0: typedef UBool BinaryPropertyContains(const BinaryProperty &prop, UChar32 c, UProperty which); michael@0: michael@0: struct BinaryProperty { michael@0: int32_t column; // SRC_PROPSVEC column, or "source" if mask==0 michael@0: uint32_t mask; michael@0: BinaryPropertyContains *contains; michael@0: }; michael@0: michael@0: static UBool defaultContains(const BinaryProperty &prop, UChar32 c, UProperty /*which*/) { michael@0: /* systematic, directly stored properties */ michael@0: return (u_getUnicodeProperties(c, prop.column)&prop.mask)!=0; michael@0: } michael@0: michael@0: static UBool caseBinaryPropertyContains(const BinaryProperty &/*prop*/, UChar32 c, UProperty which) { michael@0: return ucase_hasBinaryProperty(c, which); michael@0: } michael@0: michael@0: static UBool isBidiControl(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return ubidi_isBidiControl(GET_BIDI_PROPS(), c); michael@0: } michael@0: michael@0: static UBool isMirrored(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return ubidi_isMirrored(GET_BIDI_PROPS(), c); michael@0: } michael@0: michael@0: static UBool isJoinControl(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return ubidi_isJoinControl(GET_BIDI_PROPS(), c); michael@0: } michael@0: michael@0: #if UCONFIG_NO_NORMALIZATION michael@0: static UBool hasFullCompositionExclusion(const BinaryProperty &, UChar32, UProperty) { michael@0: return FALSE; michael@0: } michael@0: #else michael@0: static UBool hasFullCompositionExclusion(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: // By definition, Full_Composition_Exclusion is the same as NFC_QC=No. michael@0: UErrorCode errorCode=U_ZERO_ERROR; michael@0: const Normalizer2Impl *impl=Normalizer2Factory::getNFCImpl(errorCode); michael@0: return U_SUCCESS(errorCode) && impl->isCompNo(impl->getNorm16(c)); michael@0: } michael@0: #endif michael@0: michael@0: // UCHAR_NF*_INERT properties michael@0: #if UCONFIG_NO_NORMALIZATION michael@0: static UBool isNormInert(const BinaryProperty &, UChar32, UProperty) { michael@0: return FALSE; michael@0: } michael@0: #else michael@0: static UBool isNormInert(const BinaryProperty &/*prop*/, UChar32 c, UProperty which) { michael@0: UErrorCode errorCode=U_ZERO_ERROR; michael@0: const Normalizer2 *norm2=Normalizer2Factory::getInstance( michael@0: (UNormalizationMode)(which-UCHAR_NFD_INERT+UNORM_NFD), errorCode); michael@0: return U_SUCCESS(errorCode) && norm2->isInert(c); michael@0: } michael@0: #endif michael@0: michael@0: #if UCONFIG_NO_NORMALIZATION michael@0: static UBool changesWhenCasefolded(const BinaryProperty &, UChar32, UProperty) { michael@0: return FALSE; michael@0: } michael@0: #else michael@0: static UBool changesWhenCasefolded(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: UnicodeString nfd; michael@0: UErrorCode errorCode=U_ZERO_ERROR; michael@0: const Normalizer2 *nfcNorm2=Normalizer2Factory::getNFCInstance(errorCode); michael@0: if(U_FAILURE(errorCode)) { michael@0: return FALSE; michael@0: } michael@0: if(nfcNorm2->getDecomposition(c, nfd)) { michael@0: /* c has a decomposition */ michael@0: if(nfd.length()==1) { michael@0: c=nfd[0]; /* single BMP code point */ michael@0: } else if(nfd.length()<=U16_MAX_LENGTH && michael@0: nfd.length()==U16_LENGTH(c=nfd.char32At(0)) michael@0: ) { michael@0: /* single supplementary code point */ michael@0: } else { michael@0: c=U_SENTINEL; michael@0: } michael@0: } else if(c<0) { michael@0: return FALSE; /* protect against bad input */ michael@0: } michael@0: if(c>=0) { michael@0: /* single code point */ michael@0: const UCaseProps *csp=ucase_getSingleton(); michael@0: const UChar *resultString; michael@0: return (UBool)(ucase_toFullFolding(csp, c, &resultString, U_FOLD_CASE_DEFAULT)>=0); michael@0: } else { michael@0: /* guess some large but stack-friendly capacity */ michael@0: UChar dest[2*UCASE_MAX_STRING_LENGTH]; michael@0: int32_t destLength; michael@0: destLength=u_strFoldCase(dest, LENGTHOF(dest), michael@0: nfd.getBuffer(), nfd.length(), michael@0: U_FOLD_CASE_DEFAULT, &errorCode); michael@0: return (UBool)(U_SUCCESS(errorCode) && michael@0: 0!=u_strCompare(nfd.getBuffer(), nfd.length(), michael@0: dest, destLength, FALSE)); michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: #if UCONFIG_NO_NORMALIZATION michael@0: static UBool changesWhenNFKC_Casefolded(const BinaryProperty &, UChar32, UProperty) { michael@0: return FALSE; michael@0: } michael@0: #else michael@0: static UBool changesWhenNFKC_Casefolded(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: UErrorCode errorCode=U_ZERO_ERROR; michael@0: const Normalizer2Impl *kcf=Normalizer2Factory::getNFKC_CFImpl(errorCode); michael@0: if(U_FAILURE(errorCode)) { michael@0: return FALSE; michael@0: } michael@0: UnicodeString src(c); michael@0: UnicodeString dest; michael@0: { michael@0: // The ReorderingBuffer must be in a block because its destructor michael@0: // needs to release dest's buffer before we look at its contents. michael@0: ReorderingBuffer buffer(*kcf, dest); michael@0: // Small destCapacity for NFKC_CF(c). michael@0: if(buffer.init(5, errorCode)) { michael@0: const UChar *srcArray=src.getBuffer(); michael@0: kcf->compose(srcArray, srcArray+src.length(), FALSE, michael@0: TRUE, buffer, errorCode); michael@0: } michael@0: } michael@0: return U_SUCCESS(errorCode) && dest!=src; michael@0: } michael@0: #endif michael@0: michael@0: #if UCONFIG_NO_NORMALIZATION michael@0: static UBool isCanonSegmentStarter(const BinaryProperty &, UChar32, UProperty) { michael@0: return FALSE; michael@0: } michael@0: #else michael@0: static UBool isCanonSegmentStarter(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: UErrorCode errorCode=U_ZERO_ERROR; michael@0: const Normalizer2Impl *impl=Normalizer2Factory::getNFCImpl(errorCode); michael@0: return michael@0: U_SUCCESS(errorCode) && impl->ensureCanonIterData(errorCode) && michael@0: impl->isCanonSegmentStarter(c); michael@0: } michael@0: #endif michael@0: michael@0: static UBool isPOSIX_alnum(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return u_isalnumPOSIX(c); michael@0: } michael@0: michael@0: static UBool isPOSIX_blank(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return u_isblank(c); michael@0: } michael@0: michael@0: static UBool isPOSIX_graph(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return u_isgraphPOSIX(c); michael@0: } michael@0: michael@0: static UBool isPOSIX_print(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return u_isprintPOSIX(c); michael@0: } michael@0: michael@0: static UBool isPOSIX_xdigit(const BinaryProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return u_isxdigit(c); michael@0: } michael@0: michael@0: static const BinaryProperty binProps[UCHAR_BINARY_LIMIT]={ michael@0: /* michael@0: * column and mask values for binary properties from u_getUnicodeProperties(). michael@0: * Must be in order of corresponding UProperty, michael@0: * and there must be exactly one entry per binary UProperty. michael@0: * michael@0: * Properties with mask==0 are handled in code. michael@0: * For them, column is the UPropertySource value. michael@0: */ michael@0: { 1, U_MASK(UPROPS_ALPHABETIC), defaultContains }, michael@0: { 1, U_MASK(UPROPS_ASCII_HEX_DIGIT), defaultContains }, michael@0: { UPROPS_SRC_BIDI, 0, isBidiControl }, michael@0: { UPROPS_SRC_BIDI, 0, isMirrored }, michael@0: { 1, U_MASK(UPROPS_DASH), defaultContains }, michael@0: { 1, U_MASK(UPROPS_DEFAULT_IGNORABLE_CODE_POINT), defaultContains }, michael@0: { 1, U_MASK(UPROPS_DEPRECATED), defaultContains }, michael@0: { 1, U_MASK(UPROPS_DIACRITIC), defaultContains }, michael@0: { 1, U_MASK(UPROPS_EXTENDER), defaultContains }, michael@0: { UPROPS_SRC_NFC, 0, hasFullCompositionExclusion }, michael@0: { 1, U_MASK(UPROPS_GRAPHEME_BASE), defaultContains }, michael@0: { 1, U_MASK(UPROPS_GRAPHEME_EXTEND), defaultContains }, michael@0: { 1, U_MASK(UPROPS_GRAPHEME_LINK), defaultContains }, michael@0: { 1, U_MASK(UPROPS_HEX_DIGIT), defaultContains }, michael@0: { 1, U_MASK(UPROPS_HYPHEN), defaultContains }, michael@0: { 1, U_MASK(UPROPS_ID_CONTINUE), defaultContains }, michael@0: { 1, U_MASK(UPROPS_ID_START), defaultContains }, michael@0: { 1, U_MASK(UPROPS_IDEOGRAPHIC), defaultContains }, michael@0: { 1, U_MASK(UPROPS_IDS_BINARY_OPERATOR), defaultContains }, michael@0: { 1, U_MASK(UPROPS_IDS_TRINARY_OPERATOR), defaultContains }, michael@0: { UPROPS_SRC_BIDI, 0, isJoinControl }, michael@0: { 1, U_MASK(UPROPS_LOGICAL_ORDER_EXCEPTION), defaultContains }, michael@0: { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_LOWERCASE michael@0: { 1, U_MASK(UPROPS_MATH), defaultContains }, michael@0: { 1, U_MASK(UPROPS_NONCHARACTER_CODE_POINT), defaultContains }, michael@0: { 1, U_MASK(UPROPS_QUOTATION_MARK), defaultContains }, michael@0: { 1, U_MASK(UPROPS_RADICAL), defaultContains }, michael@0: { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_SOFT_DOTTED michael@0: { 1, U_MASK(UPROPS_TERMINAL_PUNCTUATION), defaultContains }, michael@0: { 1, U_MASK(UPROPS_UNIFIED_IDEOGRAPH), defaultContains }, michael@0: { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_UPPERCASE michael@0: { 1, U_MASK(UPROPS_WHITE_SPACE), defaultContains }, michael@0: { 1, U_MASK(UPROPS_XID_CONTINUE), defaultContains }, michael@0: { 1, U_MASK(UPROPS_XID_START), defaultContains }, michael@0: { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CASE_SENSITIVE michael@0: { 1, U_MASK(UPROPS_S_TERM), defaultContains }, michael@0: { 1, U_MASK(UPROPS_VARIATION_SELECTOR), defaultContains }, michael@0: { UPROPS_SRC_NFC, 0, isNormInert }, // UCHAR_NFD_INERT michael@0: { UPROPS_SRC_NFKC, 0, isNormInert }, // UCHAR_NFKD_INERT michael@0: { UPROPS_SRC_NFC, 0, isNormInert }, // UCHAR_NFC_INERT michael@0: { UPROPS_SRC_NFKC, 0, isNormInert }, // UCHAR_NFKC_INERT michael@0: { UPROPS_SRC_NFC_CANON_ITER, 0, isCanonSegmentStarter }, michael@0: { 1, U_MASK(UPROPS_PATTERN_SYNTAX), defaultContains }, michael@0: { 1, U_MASK(UPROPS_PATTERN_WHITE_SPACE), defaultContains }, michael@0: { UPROPS_SRC_CHAR_AND_PROPSVEC, 0, isPOSIX_alnum }, michael@0: { UPROPS_SRC_CHAR, 0, isPOSIX_blank }, michael@0: { UPROPS_SRC_CHAR, 0, isPOSIX_graph }, michael@0: { UPROPS_SRC_CHAR, 0, isPOSIX_print }, michael@0: { UPROPS_SRC_CHAR, 0, isPOSIX_xdigit }, michael@0: { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CASED michael@0: { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CASE_IGNORABLE michael@0: { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CHANGES_WHEN_LOWERCASED michael@0: { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CHANGES_WHEN_UPPERCASED michael@0: { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CHANGES_WHEN_TITLECASED michael@0: { UPROPS_SRC_CASE_AND_NORM, 0, changesWhenCasefolded }, michael@0: { UPROPS_SRC_CASE, 0, caseBinaryPropertyContains }, // UCHAR_CHANGES_WHEN_CASEMAPPED michael@0: { UPROPS_SRC_NFKC_CF, 0, changesWhenNFKC_Casefolded } michael@0: }; michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_hasBinaryProperty(UChar32 c, UProperty which) { michael@0: /* c is range-checked in the functions that are called from here */ michael@0: if(which>prop.shift; michael@0: } michael@0: michael@0: static int32_t defaultGetMaxValue(const IntProperty &prop, UProperty /*which*/) { michael@0: return (uprv_getMaxValues(prop.column)&prop.mask)>>prop.shift; michael@0: } michael@0: michael@0: static int32_t getMaxValueFromShift(const IntProperty &prop, UProperty /*which*/) { michael@0: return prop.shift; michael@0: } michael@0: michael@0: static int32_t getBiDiClass(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return (int32_t)u_charDirection(c); michael@0: } michael@0: michael@0: static int32_t getBiDiPairedBracketType(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return (int32_t)ubidi_getPairedBracketType(GET_BIDI_PROPS(), c); michael@0: } michael@0: michael@0: static int32_t biDiGetMaxValue(const IntProperty &/*prop*/, UProperty which) { michael@0: return ubidi_getMaxValue(GET_BIDI_PROPS(), which); michael@0: } michael@0: michael@0: #if UCONFIG_NO_NORMALIZATION michael@0: static int32_t getCombiningClass(const IntProperty &, UChar32, UProperty) { michael@0: return 0; michael@0: } michael@0: #else michael@0: static int32_t getCombiningClass(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return u_getCombiningClass(c); michael@0: } michael@0: #endif michael@0: michael@0: static int32_t getGeneralCategory(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return (int32_t)u_charType(c); michael@0: } michael@0: michael@0: static int32_t getJoiningGroup(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return ubidi_getJoiningGroup(GET_BIDI_PROPS(), c); michael@0: } michael@0: michael@0: static int32_t getJoiningType(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return ubidi_getJoiningType(GET_BIDI_PROPS(), c); michael@0: } michael@0: michael@0: static int32_t getNumericType(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: int32_t ntv=(int32_t)GET_NUMERIC_TYPE_VALUE(u_getMainProperties(c)); michael@0: return UPROPS_NTV_GET_TYPE(ntv); michael@0: } michael@0: michael@0: static int32_t getScript(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: UErrorCode errorCode=U_ZERO_ERROR; michael@0: return (int32_t)uscript_getScript(c, &errorCode); michael@0: } michael@0: michael@0: /* michael@0: * Map some of the Grapheme Cluster Break values to Hangul Syllable Types. michael@0: * Hangul_Syllable_Type is fully redundant with a subset of Grapheme_Cluster_Break. michael@0: */ michael@0: static const UHangulSyllableType gcbToHst[]={ michael@0: U_HST_NOT_APPLICABLE, /* U_GCB_OTHER */ michael@0: U_HST_NOT_APPLICABLE, /* U_GCB_CONTROL */ michael@0: U_HST_NOT_APPLICABLE, /* U_GCB_CR */ michael@0: U_HST_NOT_APPLICABLE, /* U_GCB_EXTEND */ michael@0: U_HST_LEADING_JAMO, /* U_GCB_L */ michael@0: U_HST_NOT_APPLICABLE, /* U_GCB_LF */ michael@0: U_HST_LV_SYLLABLE, /* U_GCB_LV */ michael@0: U_HST_LVT_SYLLABLE, /* U_GCB_LVT */ michael@0: U_HST_TRAILING_JAMO, /* U_GCB_T */ michael@0: U_HST_VOWEL_JAMO /* U_GCB_V */ michael@0: /* michael@0: * Omit GCB values beyond what we need for hst. michael@0: * The code below checks for the array length. michael@0: */ michael@0: }; michael@0: michael@0: static int32_t getHangulSyllableType(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: /* see comments on gcbToHst[] above */ michael@0: int32_t gcb=(int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_GCB_MASK)>>UPROPS_GCB_SHIFT; michael@0: if(gcb>8; michael@0: } michael@0: #endif michael@0: michael@0: #if UCONFIG_NO_NORMALIZATION michael@0: static int32_t getTrailCombiningClass(const IntProperty &, UChar32, UProperty) { michael@0: return 0; michael@0: } michael@0: #else michael@0: static int32_t getTrailCombiningClass(const IntProperty &/*prop*/, UChar32 c, UProperty /*which*/) { michael@0: return unorm_getFCD16(c)&0xff; michael@0: } michael@0: #endif michael@0: michael@0: static const IntProperty intProps[UCHAR_INT_LIMIT-UCHAR_INT_START]={ michael@0: /* michael@0: * column, mask and shift values for int-value properties from u_getUnicodeProperties(). michael@0: * Must be in order of corresponding UProperty, michael@0: * and there must be exactly one entry per int UProperty. michael@0: * michael@0: * Properties with mask==0 are handled in code. michael@0: * For them, column is the UPropertySource value. michael@0: */ michael@0: { UPROPS_SRC_BIDI, 0, 0, getBiDiClass, biDiGetMaxValue }, michael@0: { 0, UPROPS_BLOCK_MASK, UPROPS_BLOCK_SHIFT, defaultGetValue, defaultGetMaxValue }, michael@0: { UPROPS_SRC_NFC, 0, 0xff, getCombiningClass, getMaxValueFromShift }, michael@0: { 2, UPROPS_DT_MASK, 0, defaultGetValue, defaultGetMaxValue }, michael@0: { 0, UPROPS_EA_MASK, UPROPS_EA_SHIFT, defaultGetValue, defaultGetMaxValue }, michael@0: { UPROPS_SRC_CHAR, 0, (int32_t)U_CHAR_CATEGORY_COUNT-1,getGeneralCategory, getMaxValueFromShift }, michael@0: { UPROPS_SRC_BIDI, 0, 0, getJoiningGroup, biDiGetMaxValue }, michael@0: { UPROPS_SRC_BIDI, 0, 0, getJoiningType, biDiGetMaxValue }, michael@0: { 2, UPROPS_LB_MASK, UPROPS_LB_SHIFT, defaultGetValue, defaultGetMaxValue }, michael@0: { UPROPS_SRC_CHAR, 0, (int32_t)U_NT_COUNT-1, getNumericType, getMaxValueFromShift }, michael@0: { 0, UPROPS_SCRIPT_MASK, 0, getScript, defaultGetMaxValue }, michael@0: { UPROPS_SRC_PROPSVEC, 0, (int32_t)U_HST_COUNT-1, getHangulSyllableType, getMaxValueFromShift }, michael@0: // UCHAR_NFD_QUICK_CHECK: max=1=YES -- never "maybe", only "no" or "yes" michael@0: { UPROPS_SRC_NFC, 0, (int32_t)UNORM_YES, getNormQuickCheck, getMaxValueFromShift }, michael@0: // UCHAR_NFKD_QUICK_CHECK: max=1=YES -- never "maybe", only "no" or "yes" michael@0: { UPROPS_SRC_NFKC, 0, (int32_t)UNORM_YES, getNormQuickCheck, getMaxValueFromShift }, michael@0: // UCHAR_NFC_QUICK_CHECK: max=2=MAYBE michael@0: { UPROPS_SRC_NFC, 0, (int32_t)UNORM_MAYBE, getNormQuickCheck, getMaxValueFromShift }, michael@0: // UCHAR_NFKC_QUICK_CHECK: max=2=MAYBE michael@0: { UPROPS_SRC_NFKC, 0, (int32_t)UNORM_MAYBE, getNormQuickCheck, getMaxValueFromShift }, michael@0: { UPROPS_SRC_NFC, 0, 0xff, getLeadCombiningClass, getMaxValueFromShift }, michael@0: { UPROPS_SRC_NFC, 0, 0xff, getTrailCombiningClass, getMaxValueFromShift }, michael@0: { 2, UPROPS_GCB_MASK, UPROPS_GCB_SHIFT, defaultGetValue, defaultGetMaxValue }, michael@0: { 2, UPROPS_SB_MASK, UPROPS_SB_SHIFT, defaultGetValue, defaultGetMaxValue }, michael@0: { 2, UPROPS_WB_MASK, UPROPS_WB_SHIFT, defaultGetValue, defaultGetMaxValue }, michael@0: { UPROPS_SRC_BIDI, 0, 0, getBiDiPairedBracketType, biDiGetMaxValue }, michael@0: }; michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: u_getIntPropertyValue(UChar32 c, UProperty which) { michael@0: if(which0)) { michael@0: *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: // Compute the FC_NFKC_Closure on the fly: michael@0: // We have the API for complete coverage of Unicode properties, although michael@0: // this value by itself is not useful via API. michael@0: // (What could be useful is a custom normalization table that combines michael@0: // case folding and NFKC.) michael@0: // For the derivation, see Unicode's DerivedNormalizationProps.txt. michael@0: const Normalizer2 *nfkc=Normalizer2Factory::getNFKCInstance(*pErrorCode); michael@0: const UCaseProps *csp=ucase_getSingleton(); michael@0: if(U_FAILURE(*pErrorCode)) { michael@0: return 0; michael@0: } michael@0: // first: b = NFKC(Fold(a)) michael@0: UnicodeString folded1String; michael@0: const UChar *folded1; michael@0: int32_t folded1Length=ucase_toFullFolding(csp, c, &folded1, U_FOLD_CASE_DEFAULT); michael@0: if(folded1Length<0) { michael@0: const Normalizer2Impl *nfkcImpl=Normalizer2Factory::getImpl(nfkc); michael@0: if(nfkcImpl->getCompQuickCheck(nfkcImpl->getNorm16(c))!=UNORM_NO) { michael@0: return u_terminateUChars(dest, destCapacity, 0, pErrorCode); // c does not change at all under CaseFolding+NFKC michael@0: } michael@0: folded1String.setTo(c); michael@0: } else { michael@0: if(folded1Length>UCASE_MAX_STRING_LENGTH) { michael@0: folded1String.setTo(folded1Length); michael@0: } else { michael@0: folded1String.setTo(FALSE, folded1, folded1Length); michael@0: } michael@0: } michael@0: UnicodeString kc1=nfkc->normalize(folded1String, *pErrorCode); michael@0: // second: c = NFKC(Fold(b)) michael@0: UnicodeString folded2String(kc1); michael@0: UnicodeString kc2=nfkc->normalize(folded2String.foldCase(), *pErrorCode); michael@0: // if (c != b) add the mapping from a to c michael@0: if(U_FAILURE(*pErrorCode) || kc1==kc2) { michael@0: return u_terminateUChars(dest, destCapacity, 0, pErrorCode); michael@0: } else { michael@0: return kc2.extract(dest, destCapacity, *pErrorCode); michael@0: } michael@0: } michael@0: michael@0: #endif