diff --git a/icu4c/source/common/ucase.c b/icu4c/source/common/ucase.c index 10b0bdbfa68..631f5e5d381 100644 --- a/icu4c/source/common/ucase.c +++ b/icu4c/source/common/ucase.c @@ -524,6 +524,28 @@ ucase_isCaseSensitive(const UCaseProps *csp, UChar32 c) { return (UBool)((props&UCASE_SENSITIVE)!=0); } +/* public API (see uchar.h) ------------------------------------------------- */ + +U_CAPI UBool U_EXPORT2 +u_isULowercase(UChar32 c) { + UErrorCode errorCode=U_ZERO_ERROR; + UCaseProps *csp=ucase_getSingleton(&errorCode); + if(U_FAILURE(errorCode)) { + return FALSE; + } + return (UBool)(UCASE_LOWER==ucase_getType(csp, c)); +} + +U_CAPI UBool U_EXPORT2 +u_isUUppercase(UChar32 c) { + UErrorCode errorCode=U_ZERO_ERROR; + UCaseProps *csp=ucase_getSingleton(&errorCode); + if(U_FAILURE(errorCode)) { + return FALSE; + } + return (UBool)(UCASE_UPPER==ucase_getType(csp, c)); +} + /* string casing ------------------------------------------------------------ */ /* diff --git a/icu4c/source/common/uchar.c b/icu4c/source/common/uchar.c index 7ba706ec2d3..6f7e77ae218 100644 --- a/icu4c/source/common/uchar.c +++ b/icu4c/source/common/uchar.c @@ -21,12 +21,14 @@ #include "unicode/utypes.h" #include "unicode/uchar.h" +#include "unicode/uscript.h" #include "unicode/udata.h" #include "umutex.h" #include "cmemory.h" #include "ucln_cmn.h" #include "utrie.h" #include "udataswp.h" +#include "unormimp.h" /* JAMO_L_BASE etc. */ #include "uprops.h" #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) @@ -533,6 +535,11 @@ u_isalpha(UChar32 c) { return (UBool)((CAT_MASK(props)&U_GC_L_MASK)!=0); } +U_CAPI UBool U_EXPORT2 +u_isUAlphabetic(UChar32 c) { + return (u_getUnicodeProperties(c, 1)&U_MASK(UPROPS_ALPHABETIC))!=0; +} + /* Checks if ch is a letter or a decimal digit */ U_CAPI UBool U_EXPORT2 u_isalnum(UChar32 c) { @@ -611,6 +618,11 @@ u_isblank(UChar32 c) { } } +U_CAPI UBool U_EXPORT2 +u_isUWhiteSpace(UChar32 c) { + return (u_getUnicodeProperties(c, 1)&U_MASK(UPROPS_WHITE_SPACE))!=0; +} + /* Checks if the Unicode character is printable.*/ U_CAPI UBool U_EXPORT2 u_isprint(UChar32 c) { @@ -973,6 +985,73 @@ uprv_getMaxValues(int32_t column) { } } +/* + * get Hangul Syllable Type + * implemented here so that uchar.c (uchar_addPropertyStarts()) + * does not depend on uprops.c (u_getIntPropertyValue(c, UCHAR_HANGUL_SYLLABLE_TYPE)) + */ +U_CFUNC UHangulSyllableType +uchar_getHST(UChar32 c) { + /* purely algorithmic; hardcode known characters, check for assigned new ones */ + if(c>UPROPS_AGE_SHIFT; + versionArray[0]=(uint8_t)(version>>4); + versionArray[1]=(uint8_t)(version&0xf); + versionArray[2]=versionArray[3]=0; + } +} + +U_CAPI UScriptCode U_EXPORT2 +uscript_getScript(UChar32 c, UErrorCode *pErrorCode) { + if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { + return 0; + } + if((uint32_t)c>0x10ffff) { + *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; + return 0; + } + + return (UScriptCode)(u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_MASK); +} + +U_CAPI UBlockCode U_EXPORT2 +ublock_getCode(UChar32 c) { + return (UBlockCode)((u_getUnicodeProperties(c, 0)&UPROPS_BLOCK_MASK)>>UPROPS_BLOCK_SHIFT); +} + +/* property starts for UnicodeSet ------------------------------------------- */ + static UBool U_CALLCONV _enumPropertyStartsRange(const void *context, UChar32 start, UChar32 limit, uint32_t value) { /* add the start code point to the USet */ @@ -1062,7 +1141,7 @@ uchar_addPropertyStarts(USetAdder *sa, UErrorCode *pErrorCode) { sa->add(sa->set, 0x1100); value=U_HST_LEADING_JAMO; for(c=0x115a; c<=0x115f; ++c) { - value2=u_getIntPropertyValue(c, UCHAR_HANGUL_SYLLABLE_TYPE); + value2=uchar_getHST(c); if(value!=value2) { value=value2; sa->add(sa->set, c); @@ -1072,7 +1151,7 @@ uchar_addPropertyStarts(USetAdder *sa, UErrorCode *pErrorCode) { sa->add(sa->set, 0x1160); value=U_HST_VOWEL_JAMO; for(c=0x11a3; c<=0x11a7; ++c) { - value2=u_getIntPropertyValue(c, UCHAR_HANGUL_SYLLABLE_TYPE); + value2=uchar_getHST(c); if(value!=value2) { value=value2; sa->add(sa->set, c); @@ -1082,7 +1161,7 @@ uchar_addPropertyStarts(USetAdder *sa, UErrorCode *pErrorCode) { sa->add(sa->set, 0x11a8); value=U_HST_TRAILING_JAMO; for(c=0x11fa; c<=0x11ff; ++c) { - value2=u_getIntPropertyValue(c, UCHAR_HANGUL_SYLLABLE_TYPE); + value2=uchar_getHST(c); if(value!=value2) { value=value2; sa->add(sa->set, c); diff --git a/icu4c/source/common/uprops.c b/icu4c/source/common/uprops.c index 254636efa11..880e0195da5 100644 --- a/icu4c/source/common/uprops.c +++ b/icu4c/source/common/uprops.c @@ -143,34 +143,6 @@ uprv_compareEBCDICPropertyNames(const char *name1, const char *name2) { /* API functions ------------------------------------------------------------ */ -U_CAPI void U_EXPORT2 -u_charAge(UChar32 c, UVersionInfo versionArray) { - if(versionArray!=NULL) { - uint32_t version=u_getUnicodeProperties(c, 0)>>UPROPS_AGE_SHIFT; - versionArray[0]=(uint8_t)(version>>4); - versionArray[1]=(uint8_t)(version&0xf); - versionArray[2]=versionArray[3]=0; - } -} - -U_CAPI UScriptCode U_EXPORT2 -uscript_getScript(UChar32 c, UErrorCode *pErrorCode) { - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { - return 0; - } - if((uint32_t)c>0x10ffff) { - *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; - return 0; - } - - return (UScriptCode)(u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_MASK); -} - -U_CAPI UBlockCode U_EXPORT2 -ublock_getCode(UChar32 c) { - return (UBlockCode)((u_getUnicodeProperties(c, 0)&UPROPS_BLOCK_MASK)>>UPROPS_BLOCK_SHIFT); -} - static const struct { int32_t column; uint32_t mask; @@ -278,26 +250,6 @@ u_hasBinaryProperty(UChar32 c, UProperty which) { return FALSE; } -U_CAPI UBool U_EXPORT2 -u_isUAlphabetic(UChar32 c) { - return u_hasBinaryProperty(c, UCHAR_ALPHABETIC); -} - -U_CAPI UBool U_EXPORT2 -u_isULowercase(UChar32 c) { - return u_hasBinaryProperty(c, UCHAR_LOWERCASE); -} - -U_CAPI UBool U_EXPORT2 -u_isUUppercase(UChar32 c) { - return u_hasBinaryProperty(c, UCHAR_UPPERCASE); -} - -U_CAPI UBool U_EXPORT2 -u_isUWhiteSpace(UChar32 c) { - return u_hasBinaryProperty(c, UCHAR_WHITE_SPACE); -} - U_CAPI UBool U_EXPORT2 uprv_isRuleWhiteSpace(UChar32 c) { /* "white space" in the sense of ICU rule parsers @@ -362,34 +314,7 @@ u_getIntPropertyValue(UChar32 c, UProperty which) { errorCode=U_ZERO_ERROR; return (int32_t)uscript_getScript(c, &errorCode); case UCHAR_HANGUL_SYLLABLE_TYPE: - /* purely algorithmic; hardcode known characters, check for assigned new ones */ - if(c= source){ - if(*tSourceEnd==find){ - return (uint32_t)(tSourceEnd-source); - } - tSourceEnd--; - } - return (uint32_t)(tSourceEnd-source); -} -#endif - U_CAPI void U_EXPORT2 uprv_getInclusions(USetAdder *sa, UErrorCode *pErrorCode) { if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { diff --git a/icu4c/source/common/uprops.h b/icu4c/source/common/uprops.h index a5b93f5867e..e4cfde45110 100644 --- a/icu4c/source/common/uprops.h +++ b/icu4c/source/common/uprops.h @@ -210,6 +210,13 @@ u_getUnicodeProperties(UChar32 c, int32_t column); U_CFUNC int32_t uprv_getMaxValues(int32_t column); +/** + * Get the Hangul Syllable Type for c. + * @internal + */ +U_CFUNC UHangulSyllableType +uchar_getHST(UChar32 c); + /** * Get internal UCaseProps pointer from uchar.c for uprops.c. * Other code should use ucase_getSingleton().