/* ******************************************************************************* * * Copyright (C) 2002-2004, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* * file name: uprops.h * encoding: US-ASCII * tab size: 8 (not used) * indentation:4 * * created on: 2002feb24 * created by: Markus W. Scherer * * Implementations for mostly non-core Unicode character properties * stored in uprops.icu. * * With the APIs implemented here, almost all properties files and * their associated implementation files are used from this file, * including those for normalization and case mappings. */ #include "unicode/utypes.h" #include "unicode/uchar.h" #include "unicode/uscript.h" #include "cstring.h" #include "unormimp.h" #include "uprops.h" #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) /* API functions ------------------------------------------------------------ */ static const struct { int32_t column; uint32_t mask; } binProps[UCHAR_BINARY_LIMIT]={ /* * column and mask values for binary properties from u_getUnicodeProperties(). * Must be in order of corresponding UProperty, * and there must be exacly one entry per binary UProperty. * * Properties with mask 0 are handled in code. * For them, column is the UPropertySource value. */ { 1, U_MASK(UPROPS_ALPHABETIC) }, { 1, U_MASK(UPROPS_ASCII_HEX_DIGIT) }, { 1, U_MASK(UPROPS_BIDI_CONTROL) }, { -1, U_MASK(UPROPS_MIRROR_SHIFT) }, { 1, U_MASK(UPROPS_DASH) }, { 1, U_MASK(UPROPS_DEFAULT_IGNORABLE_CODE_POINT) }, { 1, U_MASK(UPROPS_DEPRECATED) }, { 1, U_MASK(UPROPS_DIACRITIC) }, { 1, U_MASK(UPROPS_EXTENDER) }, { UPROPS_SRC_NORM, 0 }, /* UCHAR_FULL_COMPOSITION_EXCLUSION */ { 1, U_MASK(UPROPS_GRAPHEME_BASE) }, { 1, U_MASK(UPROPS_GRAPHEME_EXTEND) }, { 1, U_MASK(UPROPS_GRAPHEME_LINK) }, { 1, U_MASK(UPROPS_HEX_DIGIT) }, { 1, U_MASK(UPROPS_HYPHEN) }, { 1, U_MASK(UPROPS_ID_CONTINUE) }, { 1, U_MASK(UPROPS_ID_START) }, { 1, U_MASK(UPROPS_IDEOGRAPHIC) }, { 1, U_MASK(UPROPS_IDS_BINARY_OPERATOR) }, { 1, U_MASK(UPROPS_IDS_TRINARY_OPERATOR) }, { 1, U_MASK(UPROPS_JOIN_CONTROL) }, { 1, U_MASK(UPROPS_LOGICAL_ORDER_EXCEPTION) }, { UPROPS_SRC_CASE, 0 }, /* UCHAR_LOWERCASE */ { 1, U_MASK(UPROPS_MATH) }, { 1, U_MASK(UPROPS_NONCHARACTER_CODE_POINT) }, { 1, U_MASK(UPROPS_QUOTATION_MARK) }, { 1, U_MASK(UPROPS_RADICAL) }, { UPROPS_SRC_CASE, 0 }, /* UCHAR_SOFT_DOTTED */ { 1, U_MASK(UPROPS_TERMINAL_PUNCTUATION) }, { 1, U_MASK(UPROPS_UNIFIED_IDEOGRAPH) }, { UPROPS_SRC_CASE, 0 }, /* UCHAR_UPPERCASE */ { 1, U_MASK(UPROPS_WHITE_SPACE) }, { 1, U_MASK(UPROPS_XID_CONTINUE) }, { 1, U_MASK(UPROPS_XID_START) }, { UPROPS_SRC_CASE, 0 }, /* UCHAR_CASE_SENSITIVE */ { 2, U_MASK(UPROPS_V2_S_TERM) }, { 2, U_MASK(UPROPS_V2_VARIATION_SELECTOR) }, { UPROPS_SRC_NORM, 0 }, /* UCHAR_NFD_INERT */ { UPROPS_SRC_NORM, 0 }, /* UCHAR_NFKD_INERT */ { UPROPS_SRC_NORM, 0 }, /* UCHAR_NFC_INERT */ { UPROPS_SRC_NORM, 0 }, /* UCHAR_NFKC_INERT */ { UPROPS_SRC_NORM, 0 } /* UCHAR_SEGMENT_STARTER */ }; U_CAPI UBool U_EXPORT2 u_hasBinaryProperty(UChar32 c, UProperty which) { /* c is range-checked in the functions that are called from here */ if(which>UPROPS_EA_SHIFT; case UCHAR_GENERAL_CATEGORY: return (int32_t)u_charType(c); case UCHAR_JOINING_GROUP: return (int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_JG_MASK)>>UPROPS_JG_SHIFT; case UCHAR_JOINING_TYPE: return (int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_JT_MASK)>>UPROPS_JT_SHIFT; case UCHAR_LINE_BREAK: return (int32_t)(u_getUnicodeProperties(c, 0)&UPROPS_LB_MASK)>>UPROPS_LB_SHIFT; case UCHAR_NUMERIC_TYPE: return (int32_t)GET_NUMERIC_TYPE(u_getUnicodeProperties(c, -1)); case UCHAR_SCRIPT: errorCode=U_ZERO_ERROR; return (int32_t)uscript_getScript(c, &errorCode); case UCHAR_HANGUL_SYLLABLE_TYPE: return uchar_getHST(c); #if !UCONFIG_NO_NORMALIZATION case UCHAR_NFD_QUICK_CHECK: case UCHAR_NFKD_QUICK_CHECK: case UCHAR_NFC_QUICK_CHECK: case UCHAR_NFKC_QUICK_CHECK: return (int32_t)unorm_getQuickCheck(c, (UNormalizationMode)(which-UCHAR_NFD_QUICK_CHECK)+UNORM_NFD); case UCHAR_LEAD_CANONICAL_COMBINING_CLASS: return unorm_getFCD16FromCodePoint(c)>>8; case UCHAR_TRAIL_CANONICAL_COMBINING_CLASS: return unorm_getFCD16FromCodePoint(c)&0xff; #endif default: return 0; /* undefined */ } } else if(which==UCHAR_GENERAL_CATEGORY_MASK) { return U_MASK(u_charType(c)); } else { return 0; /* undefined */ } } U_CAPI int32_t U_EXPORT2 u_getIntPropertyMinValue(UProperty which) { return 0; /* all binary/enum/int properties have a minimum value of 0 */ } U_CAPI int32_t U_EXPORT2 u_getIntPropertyMaxValue(UProperty which) { int32_t max; if(which>UPROPS_BLOCK_SHIFT; return max!=0 ? max : (int32_t)UBLOCK_COUNT-1; case UCHAR_CANONICAL_COMBINING_CLASS: case UCHAR_LEAD_CANONICAL_COMBINING_CLASS: case UCHAR_TRAIL_CANONICAL_COMBINING_CLASS: return 0xff; /* TODO do we need to be more precise, getting the actual maximum? */ case UCHAR_DECOMPOSITION_TYPE: max=uprv_getMaxValues(2)&UPROPS_DT_MASK; return max!=0 ? max : (int32_t)U_DT_COUNT-1; case UCHAR_EAST_ASIAN_WIDTH: max=(uprv_getMaxValues(0)&UPROPS_EA_MASK)>>UPROPS_EA_SHIFT; return max!=0 ? max : (int32_t)U_EA_COUNT-1; case UCHAR_GENERAL_CATEGORY: return (int32_t)U_CHAR_CATEGORY_COUNT-1; case UCHAR_JOINING_GROUP: max=(uprv_getMaxValues(2)&UPROPS_JG_MASK)>>UPROPS_JG_SHIFT; return max!=0 ? max : (int32_t)U_JG_COUNT-1; case UCHAR_JOINING_TYPE: max=(uprv_getMaxValues(2)&UPROPS_JT_MASK)>>UPROPS_JT_SHIFT; return max!=0 ? max : (int32_t)U_JT_COUNT-1; case UCHAR_LINE_BREAK: max=(uprv_getMaxValues(0)&UPROPS_LB_MASK)>>UPROPS_LB_SHIFT; return max!=0 ? max : (int32_t)U_LB_COUNT-1; case UCHAR_NUMERIC_TYPE: return (int32_t)U_NT_COUNT-1; case UCHAR_SCRIPT: max=uprv_getMaxValues(0)&UPROPS_SCRIPT_MASK; return max!=0 ? max : (int32_t)USCRIPT_CODE_LIMIT-1; case UCHAR_HANGUL_SYLLABLE_TYPE: return (int32_t)U_HST_COUNT-1; #if !UCONFIG_NO_NORMALIZATION case UCHAR_NFD_QUICK_CHECK: case UCHAR_NFKD_QUICK_CHECK: return (int32_t)UNORM_YES; /* these are never "maybe", only "no" or "yes" */ case UCHAR_NFC_QUICK_CHECK: case UCHAR_NFKC_QUICK_CHECK: return (int32_t)UNORM_MAYBE; #endif default: return -1; /* undefined */ } } else { return -1; /* undefined */ } } U_CAPI UPropertySource U_EXPORT2 uprops_getSource(UProperty which) { if(which