michael@0: /* michael@0: ******************************************************************************** michael@0: * Copyright (C) 1996-2012, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ******************************************************************************** michael@0: * michael@0: * File UCHAR.C michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 04/02/97 aliu Creation. michael@0: * 4/15/99 Madhu Updated all the function definitions for C Implementation michael@0: * 5/20/99 Madhu Added the function u_getVersion() michael@0: * 8/19/1999 srl Upgraded scripts to Unicode3.0 michael@0: * 11/11/1999 weiv added u_isalnum(), cleaned comments michael@0: * 01/11/2000 helena Renamed u_getVersion to u_getUnicodeVersion. michael@0: * 06/20/2000 helena OS/400 port changes; mostly typecast. michael@0: ****************************************************************************** michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uchar.h" michael@0: #include "unicode/uscript.h" michael@0: #include "unicode/udata.h" michael@0: #include "uassert.h" michael@0: #include "cmemory.h" michael@0: #include "ucln_cmn.h" michael@0: #include "utrie2.h" michael@0: #include "udataswp.h" michael@0: #include "uprops.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: /* uchar_props_data.h is machine-generated by genprops --csource */ michael@0: #define INCLUDED_FROM_UCHAR_C michael@0: #include "uchar_props_data.h" michael@0: michael@0: /* constants and macros for access to the data ------------------------------ */ michael@0: michael@0: /* getting a uint32_t properties word from the data */ michael@0: #define GET_PROPS(c, result) ((result)=UTRIE2_GET16(&propsTrie, c)); michael@0: michael@0: U_CFUNC UBool michael@0: uprv_haveProperties(UErrorCode *pErrorCode) { michael@0: if(U_FAILURE(*pErrorCode)) { michael@0: return FALSE; michael@0: } michael@0: return TRUE; michael@0: } michael@0: michael@0: /* API functions ------------------------------------------------------------ */ michael@0: michael@0: /* Gets the Unicode character's general category.*/ michael@0: U_CAPI int8_t U_EXPORT2 michael@0: u_charType(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (int8_t)GET_CATEGORY(props); michael@0: } michael@0: michael@0: /* Enumerate all code points with their general categories. */ michael@0: struct _EnumTypeCallback { michael@0: UCharEnumTypeRange *enumRange; michael@0: const void *context; michael@0: }; michael@0: michael@0: static uint32_t U_CALLCONV michael@0: _enumTypeValue(const void *context, uint32_t value) { michael@0: return GET_CATEGORY(value); michael@0: } michael@0: michael@0: static UBool U_CALLCONV michael@0: _enumTypeRange(const void *context, UChar32 start, UChar32 end, uint32_t value) { michael@0: /* just cast the value to UCharCategory */ michael@0: return ((struct _EnumTypeCallback *)context)-> michael@0: enumRange(((struct _EnumTypeCallback *)context)->context, michael@0: start, end+1, (UCharCategory)value); michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: u_enumCharTypes(UCharEnumTypeRange *enumRange, const void *context) { michael@0: struct _EnumTypeCallback callback; michael@0: michael@0: if(enumRange==NULL) { michael@0: return; michael@0: } michael@0: michael@0: callback.enumRange=enumRange; michael@0: callback.context=context; michael@0: utrie2_enum(&propsTrie, _enumTypeValue, _enumTypeRange, &callback); michael@0: } michael@0: michael@0: /* Checks if ch is a lower case letter.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_islower(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)(GET_CATEGORY(props)==U_LOWERCASE_LETTER); michael@0: } michael@0: michael@0: /* Checks if ch is an upper case letter.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isupper(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)(GET_CATEGORY(props)==U_UPPERCASE_LETTER); michael@0: } michael@0: michael@0: /* Checks if ch is a title case letter; usually upper case letters.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_istitle(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)(GET_CATEGORY(props)==U_TITLECASE_LETTER); michael@0: } michael@0: michael@0: /* Checks if ch is a decimal digit. */ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isdigit(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)(GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isxdigit(UChar32 c) { michael@0: uint32_t props; michael@0: michael@0: /* check ASCII and Fullwidth ASCII a-fA-F */ michael@0: if( michael@0: (c<=0x66 && c>=0x41 && (c<=0x46 || c>=0x61)) || michael@0: (c>=0xff21 && c<=0xff46 && (c<=0xff26 || c>=0xff41)) michael@0: ) { michael@0: return TRUE; michael@0: } michael@0: michael@0: GET_PROPS(c, props); michael@0: return (UBool)(GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER); michael@0: } michael@0: michael@0: /* Checks if the Unicode character is a letter.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isalpha(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)((CAT_MASK(props)&U_GC_L_MASK)!=0); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isUAlphabetic(UChar32 c) { michael@0: return (u_getUnicodeProperties(c, 1)&U_MASK(UPROPS_ALPHABETIC))!=0; michael@0: } michael@0: michael@0: /* Checks if c is a letter or a decimal digit */ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isalnum(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_ND_MASK))!=0); michael@0: } michael@0: michael@0: /** michael@0: * Checks if c is alphabetic, or a decimal digit; implements UCHAR_POSIX_ALNUM. michael@0: * @internal michael@0: */ michael@0: U_CFUNC UBool michael@0: u_isalnumPOSIX(UChar32 c) { michael@0: return (UBool)(u_isUAlphabetic(c) || u_isdigit(c)); michael@0: } michael@0: michael@0: /* Checks if ch is a unicode character with assigned character type.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isdefined(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)(GET_CATEGORY(props)!=0); michael@0: } michael@0: michael@0: /* Checks if the Unicode character is a base form character that can take a diacritic.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isbase(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_N_MASK|U_GC_MC_MASK|U_GC_ME_MASK))!=0); michael@0: } michael@0: michael@0: /* Checks if the Unicode character is a control character.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_iscntrl(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)((CAT_MASK(props)&(U_GC_CC_MASK|U_GC_CF_MASK|U_GC_ZL_MASK|U_GC_ZP_MASK))!=0); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isISOControl(UChar32 c) { michael@0: return (uint32_t)c<=0x9f && (c<=0x1f || c>=0x7f); michael@0: } michael@0: michael@0: /* Some control characters that are used as space. */ michael@0: #define IS_THAT_CONTROL_SPACE(c) \ michael@0: (c<=0x9f && ((c>=TAB && c<=CR) || (c>=0x1c && c <=0x1f) || c==NL)) michael@0: michael@0: /* Java has decided that U+0085 New Line is not whitespace any more. */ michael@0: #define IS_THAT_ASCII_CONTROL_SPACE(c) \ michael@0: (c<=0x1f && c>=TAB && (c<=CR || c>=0x1c)) michael@0: michael@0: /* Checks if the Unicode character is a space character.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isspace(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)((CAT_MASK(props)&U_GC_Z_MASK)!=0 || IS_THAT_CONTROL_SPACE(c)); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isJavaSpaceChar(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)((CAT_MASK(props)&U_GC_Z_MASK)!=0); michael@0: } michael@0: michael@0: /* Checks if the Unicode character is a whitespace character.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isWhitespace(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)( michael@0: ((CAT_MASK(props)&U_GC_Z_MASK)!=0 && michael@0: c!=NBSP && c!=FIGURESP && c!=NNBSP) || /* exclude no-break spaces */ michael@0: IS_THAT_ASCII_CONTROL_SPACE(c) michael@0: ); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isblank(UChar32 c) { michael@0: if((uint32_t)c<=0x9f) { michael@0: return c==9 || c==0x20; /* TAB or SPACE */ michael@0: } else { michael@0: /* Zs */ michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)(GET_CATEGORY(props)==U_SPACE_SEPARATOR); michael@0: } michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isUWhiteSpace(UChar32 c) { michael@0: return (u_getUnicodeProperties(c, 1)&U_MASK(UPROPS_WHITE_SPACE))!=0; michael@0: } michael@0: michael@0: /* Checks if the Unicode character is printable.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isprint(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: /* comparing ==0 returns FALSE for the categories mentioned */ michael@0: return (UBool)((CAT_MASK(props)&U_GC_C_MASK)==0); michael@0: } michael@0: michael@0: /** michael@0: * Checks if c is in \p{graph}\p{blank} - \p{cntrl}. michael@0: * Implements UCHAR_POSIX_PRINT. michael@0: * @internal michael@0: */ michael@0: U_CFUNC UBool michael@0: u_isprintPOSIX(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: /* michael@0: * The only cntrl character in graph+blank is TAB (in blank). michael@0: * Here we implement (blank-TAB)=Zs instead of calling u_isblank(). michael@0: */ michael@0: return (UBool)((GET_CATEGORY(props)==U_SPACE_SEPARATOR) || u_isgraphPOSIX(c)); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isgraph(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: /* comparing ==0 returns FALSE for the categories mentioned */ michael@0: return (UBool)((CAT_MASK(props)& michael@0: (U_GC_CC_MASK|U_GC_CF_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK)) michael@0: ==0); michael@0: } michael@0: michael@0: /** michael@0: * Checks if c is in michael@0: * [^\p{space}\p{gc=Control}\p{gc=Surrogate}\p{gc=Unassigned}] michael@0: * with space=\p{Whitespace} and Control=Cc. michael@0: * Implements UCHAR_POSIX_GRAPH. michael@0: * @internal michael@0: */ michael@0: U_CFUNC UBool michael@0: u_isgraphPOSIX(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: /* \p{space}\p{gc=Control} == \p{gc=Z}\p{Control} */ michael@0: /* comparing ==0 returns FALSE for the categories mentioned */ michael@0: return (UBool)((CAT_MASK(props)& michael@0: (U_GC_CC_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK)) michael@0: ==0); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_ispunct(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)((CAT_MASK(props)&U_GC_P_MASK)!=0); michael@0: } michael@0: michael@0: /* Checks if the Unicode character can start a Unicode identifier.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isIDStart(UChar32 c) { michael@0: /* same as u_isalpha() */ michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_NL_MASK))!=0); michael@0: } michael@0: michael@0: /* Checks if the Unicode character can be a Unicode identifier part other than starting the michael@0: identifier.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isIDPart(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)( michael@0: (CAT_MASK(props)& michael@0: (U_GC_ND_MASK|U_GC_NL_MASK| michael@0: U_GC_L_MASK| michael@0: U_GC_PC_MASK|U_GC_MC_MASK|U_GC_MN_MASK) michael@0: )!=0 || michael@0: u_isIDIgnorable(c)); michael@0: } michael@0: michael@0: /*Checks if the Unicode character can be ignorable in a Java or Unicode identifier.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isIDIgnorable(UChar32 c) { michael@0: if(c<=0x9f) { michael@0: return u_isISOControl(c) && !IS_THAT_ASCII_CONTROL_SPACE(c); michael@0: } else { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)(GET_CATEGORY(props)==U_FORMAT_CHAR); michael@0: } michael@0: } michael@0: michael@0: /*Checks if the Unicode character can start a Java identifier.*/ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isJavaIDStart(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_SC_MASK|U_GC_PC_MASK))!=0); michael@0: } michael@0: michael@0: /*Checks if the Unicode character can be a Java identifier part other than starting the michael@0: * identifier. michael@0: */ michael@0: U_CAPI UBool U_EXPORT2 michael@0: u_isJavaIDPart(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return (UBool)( michael@0: (CAT_MASK(props)& michael@0: (U_GC_ND_MASK|U_GC_NL_MASK| michael@0: U_GC_L_MASK| michael@0: U_GC_SC_MASK|U_GC_PC_MASK| michael@0: U_GC_MC_MASK|U_GC_MN_MASK) michael@0: )!=0 || michael@0: u_isIDIgnorable(c)); michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: u_charDigitValue(UChar32 c) { michael@0: uint32_t props; michael@0: int32_t value; michael@0: GET_PROPS(c, props); michael@0: value=(int32_t)GET_NUMERIC_TYPE_VALUE(props)-UPROPS_NTV_DECIMAL_START; michael@0: if(value<=9) { michael@0: return value; michael@0: } else { michael@0: return -1; michael@0: } michael@0: } michael@0: michael@0: U_CAPI double U_EXPORT2 michael@0: u_getNumericValue(UChar32 c) { michael@0: uint32_t props; michael@0: int32_t ntv; michael@0: GET_PROPS(c, props); michael@0: ntv=(int32_t)GET_NUMERIC_TYPE_VALUE(props); michael@0: michael@0: if(ntv==UPROPS_NTV_NONE) { michael@0: return U_NO_NUMERIC_VALUE; michael@0: } else if(ntv>4)-12; michael@0: int32_t denominator=(ntv&0xf)+1; michael@0: return (double)numerator/denominator; michael@0: } else if(ntv>5)-14; michael@0: int32_t exp=(ntv&0x1f)+2; michael@0: numValue=mant; michael@0: michael@0: /* multiply by 10^exp without math.h */ michael@0: while(exp>=4) { michael@0: numValue*=10000.; michael@0: exp-=4; michael@0: } michael@0: switch(exp) { michael@0: case 3: michael@0: numValue*=1000.; michael@0: break; michael@0: case 2: michael@0: numValue*=100.; michael@0: break; michael@0: case 1: michael@0: numValue*=10.; michael@0: break; michael@0: case 0: michael@0: default: michael@0: break; michael@0: } michael@0: michael@0: return numValue; michael@0: } else if(ntv>2)-0xbf; michael@0: int32_t exp=(ntv&3)+1; michael@0: michael@0: switch(exp) { michael@0: case 4: michael@0: numValue*=60*60*60*60; michael@0: break; michael@0: case 3: michael@0: numValue*=60*60*60; michael@0: break; michael@0: case 2: michael@0: numValue*=60*60; michael@0: break; michael@0: case 1: michael@0: numValue*=60; michael@0: break; michael@0: case 0: michael@0: default: michael@0: break; michael@0: } michael@0: michael@0: return numValue; michael@0: } else { michael@0: /* reserved */ michael@0: return U_NO_NUMERIC_VALUE; michael@0: } michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: u_digit(UChar32 ch, int8_t radix) { michael@0: int8_t value; michael@0: if((uint8_t)(radix-2)<=(36-2)) { michael@0: value=(int8_t)u_charDigitValue(ch); michael@0: if(value<0) { michael@0: /* ch is not a decimal digit, try latin letters */ michael@0: if(ch>=0x61 && ch<=0x7A) { michael@0: value=(int8_t)(ch-0x57); /* ch - 'a' + 10 */ michael@0: } else if(ch>=0x41 && ch<=0x5A) { michael@0: value=(int8_t)(ch-0x37); /* ch - 'A' + 10 */ michael@0: } else if(ch>=0xFF41 && ch<=0xFF5A) { michael@0: value=(int8_t)(ch-0xFF37); /* fullwidth ASCII a-z */ michael@0: } else if(ch>=0xFF21 && ch<=0xFF3A) { michael@0: value=(int8_t)(ch-0xFF17); /* fullwidth ASCII A-Z */ michael@0: } michael@0: } michael@0: } else { michael@0: value=-1; /* invalid radix */ michael@0: } michael@0: return (int8_t)((value(36-2) || (uint32_t)digit>=(uint32_t)radix) { michael@0: return 0; michael@0: } else if(digit<10) { michael@0: return (UChar32)(0x30+digit); michael@0: } else { michael@0: return (UChar32)((0x61-10)+digit); michael@0: } michael@0: } michael@0: michael@0: /* miscellaneous, and support for uprops.cpp -------------------------------- */ michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: u_getUnicodeVersion(UVersionInfo versionArray) { michael@0: if(versionArray!=NULL) { michael@0: uprv_memcpy(versionArray, dataVersion, U_MAX_VERSION_LENGTH); michael@0: } michael@0: } michael@0: michael@0: U_CFUNC uint32_t michael@0: u_getMainProperties(UChar32 c) { michael@0: uint32_t props; michael@0: GET_PROPS(c, props); michael@0: return props; michael@0: } michael@0: michael@0: U_CFUNC uint32_t michael@0: u_getUnicodeProperties(UChar32 c, int32_t column) { michael@0: U_ASSERT(column>=0); michael@0: if(column>=propsVectorsColumns) { michael@0: return 0; michael@0: } else { michael@0: uint16_t vecIndex=UTRIE2_GET16(&propsVectorsTrie, c); michael@0: return propsVectors[vecIndex+column]; michael@0: } michael@0: } michael@0: michael@0: U_CFUNC int32_t michael@0: uprv_getMaxValues(int32_t column) { michael@0: switch(column) { michael@0: case 0: michael@0: return indexes[UPROPS_MAX_VALUES_INDEX]; michael@0: case 2: michael@0: return indexes[UPROPS_MAX_VALUES_2_INDEX]; michael@0: default: michael@0: return 0; michael@0: } michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: u_charAge(UChar32 c, UVersionInfo versionArray) { michael@0: if(versionArray!=NULL) { michael@0: uint32_t version=u_getUnicodeProperties(c, 0)>>UPROPS_AGE_SHIFT; michael@0: versionArray[0]=(uint8_t)(version>>4); michael@0: versionArray[1]=(uint8_t)(version&0xf); michael@0: versionArray[2]=versionArray[3]=0; michael@0: } michael@0: } michael@0: michael@0: U_CAPI UScriptCode U_EXPORT2 michael@0: uscript_getScript(UChar32 c, UErrorCode *pErrorCode) { michael@0: uint32_t scriptX; michael@0: if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { michael@0: return USCRIPT_INVALID_CODE; michael@0: } michael@0: if((uint32_t)c>0x10ffff) { michael@0: *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; michael@0: return USCRIPT_INVALID_CODE; michael@0: } michael@0: scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK; michael@0: if(scriptX=UPROPS_SCRIPT_X_WITH_OTHER) { michael@0: scx=scriptExtensions+scx[1]; michael@0: } michael@0: if(sc>=USCRIPT_CODE_LIMIT) { michael@0: /* Guard against bogus input that would make us go past the Script_Extensions terminator. */ michael@0: return FALSE; michael@0: } michael@0: while(sc>*scx) { michael@0: ++scx; michael@0: } michael@0: return sc==(*scx&0x7fff); michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uscript_getScriptExtensions(UChar32 c, michael@0: UScriptCode *scripts, int32_t capacity, michael@0: UErrorCode *pErrorCode) { michael@0: uint32_t scriptX; michael@0: int32_t length; michael@0: const uint16_t *scx; michael@0: uint16_t sx; michael@0: if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { michael@0: return 0; michael@0: } michael@0: if(capacity<0 || (capacity>0 && scripts==NULL)) { michael@0: *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK; michael@0: if(scriptX=UPROPS_SCRIPT_X_WITH_OTHER) { michael@0: scx=scriptExtensions+scx[1]; michael@0: } michael@0: length=0; michael@0: do { michael@0: sx=*scx++; michael@0: if(lengthcapacity) { michael@0: *pErrorCode=U_BUFFER_OVERFLOW_ERROR; michael@0: } michael@0: return length; michael@0: } michael@0: michael@0: U_CAPI UBlockCode U_EXPORT2 michael@0: ublock_getCode(UChar32 c) { michael@0: return (UBlockCode)((u_getUnicodeProperties(c, 0)&UPROPS_BLOCK_MASK)>>UPROPS_BLOCK_SHIFT); michael@0: } michael@0: michael@0: /* property starts for UnicodeSet ------------------------------------------- */ michael@0: michael@0: static UBool U_CALLCONV michael@0: _enumPropertyStartsRange(const void *context, UChar32 start, UChar32 end, uint32_t value) { michael@0: /* add the start code point to the USet */ michael@0: const USetAdder *sa=(const USetAdder *)context; michael@0: sa->add(sa->set, start); michael@0: return TRUE; michael@0: } michael@0: michael@0: #define USET_ADD_CP_AND_NEXT(sa, cp) sa->add(sa->set, cp); sa->add(sa->set, cp+1) michael@0: michael@0: U_CFUNC void U_EXPORT2 michael@0: uchar_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) { michael@0: if(U_FAILURE(*pErrorCode)) { michael@0: return; michael@0: } michael@0: michael@0: /* add the start code point of each same-value range of the main trie */ michael@0: utrie2_enum(&propsTrie, NULL, _enumPropertyStartsRange, sa); michael@0: michael@0: /* add code points with hardcoded properties, plus the ones following them */ michael@0: michael@0: /* add for u_isblank() */ michael@0: USET_ADD_CP_AND_NEXT(sa, TAB); michael@0: michael@0: /* add for IS_THAT_CONTROL_SPACE() */ michael@0: sa->add(sa->set, CR+1); /* range TAB..CR */ michael@0: sa->add(sa->set, 0x1c); michael@0: sa->add(sa->set, 0x1f+1); michael@0: USET_ADD_CP_AND_NEXT(sa, NL); michael@0: michael@0: /* add for u_isIDIgnorable() what was not added above */ michael@0: sa->add(sa->set, DEL); /* range DEL..NBSP-1, NBSP added below */ michael@0: sa->add(sa->set, HAIRSP); michael@0: sa->add(sa->set, RLM+1); michael@0: sa->add(sa->set, INHSWAP); michael@0: sa->add(sa->set, NOMDIG+1); michael@0: USET_ADD_CP_AND_NEXT(sa, ZWNBSP); michael@0: michael@0: /* add no-break spaces for u_isWhitespace() what was not added above */ michael@0: USET_ADD_CP_AND_NEXT(sa, NBSP); michael@0: USET_ADD_CP_AND_NEXT(sa, FIGURESP); michael@0: USET_ADD_CP_AND_NEXT(sa, NNBSP); michael@0: michael@0: /* add for u_digit() */ michael@0: sa->add(sa->set, U_a); michael@0: sa->add(sa->set, U_z+1); michael@0: sa->add(sa->set, U_A); michael@0: sa->add(sa->set, U_Z+1); michael@0: sa->add(sa->set, U_FW_a); michael@0: sa->add(sa->set, U_FW_z+1); michael@0: sa->add(sa->set, U_FW_A); michael@0: sa->add(sa->set, U_FW_Z+1); michael@0: michael@0: /* add for u_isxdigit() */ michael@0: sa->add(sa->set, U_f+1); michael@0: sa->add(sa->set, U_F+1); michael@0: sa->add(sa->set, U_FW_f+1); michael@0: sa->add(sa->set, U_FW_F+1); michael@0: michael@0: /* add for UCHAR_DEFAULT_IGNORABLE_CODE_POINT what was not added above */ michael@0: sa->add(sa->set, WJ); /* range WJ..NOMDIG */ michael@0: sa->add(sa->set, 0xfff0); michael@0: sa->add(sa->set, 0xfffb+1); michael@0: sa->add(sa->set, 0xe0000); michael@0: sa->add(sa->set, 0xe0fff+1); michael@0: michael@0: /* add for UCHAR_GRAPHEME_BASE and others */ michael@0: USET_ADD_CP_AND_NEXT(sa, CGJ); michael@0: } michael@0: michael@0: U_CFUNC void U_EXPORT2 michael@0: upropsvec_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) { michael@0: if(U_FAILURE(*pErrorCode)) { michael@0: return; michael@0: } michael@0: michael@0: /* add the start code point of each same-value range of the properties vectors trie */ michael@0: if(propsVectorsColumns>0) { michael@0: /* if propsVectorsColumns==0 then the properties vectors trie may not be there at all */ michael@0: utrie2_enum(&propsVectorsTrie, NULL, _enumPropertyStartsRange, sa); michael@0: } michael@0: }