mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-4078 move functions to make uchar.c (core properties APIs) independent of uprops.c (universal properties APIs)
X-SVN-Rev: 16301
This commit is contained in:
parent
b92c4979a1
commit
b5eebb331e
4 changed files with 112 additions and 93 deletions
|
@ -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 ------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
|
|
|
@ -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<JAMO_L_BASE) {
|
||||
/* U_HST_NOT_APPLICABLE */
|
||||
} else if(c<=0x11ff) {
|
||||
/* Jamo range */
|
||||
if(c<=0x115f) {
|
||||
/* Jamo L range, HANGUL CHOSEONG ... */
|
||||
if(c==0x115f || c<=0x1159 || u_charType(c)==U_OTHER_LETTER) {
|
||||
return U_HST_LEADING_JAMO;
|
||||
}
|
||||
} else if(c<=0x11a7) {
|
||||
/* Jamo V range, HANGUL JUNGSEONG ... */
|
||||
if(c<=0x11a2 || u_charType(c)==U_OTHER_LETTER) {
|
||||
return U_HST_VOWEL_JAMO;
|
||||
}
|
||||
} else {
|
||||
/* Jamo T range */
|
||||
if(c<=0x11f9 || u_charType(c)==U_OTHER_LETTER) {
|
||||
return U_HST_TRAILING_JAMO;
|
||||
}
|
||||
}
|
||||
} else if((c-=HANGUL_BASE)<0) {
|
||||
/* U_HST_NOT_APPLICABLE */
|
||||
} else if(c<HANGUL_COUNT) {
|
||||
/* Hangul syllable */
|
||||
return c%JAMO_T_COUNT==0 ? U_HST_LV_SYLLABLE : U_HST_LVT_SYLLABLE;
|
||||
}
|
||||
return U_HST_NOT_APPLICABLE;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
|
|
@ -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<JAMO_L_BASE) {
|
||||
/* U_HST_NOT_APPLICABLE */
|
||||
} else if(c<=0x11ff) {
|
||||
/* Jamo range */
|
||||
if(c<=0x115f) {
|
||||
/* Jamo L range, HANGUL CHOSEONG ... */
|
||||
if(c==0x115f || c<=0x1159 || u_charType(c)==U_OTHER_LETTER) {
|
||||
return U_HST_LEADING_JAMO;
|
||||
}
|
||||
} else if(c<=0x11a7) {
|
||||
/* Jamo V range, HANGUL JUNGSEONG ... */
|
||||
if(c<=0x11a2 || u_charType(c)==U_OTHER_LETTER) {
|
||||
return U_HST_VOWEL_JAMO;
|
||||
}
|
||||
} else {
|
||||
/* Jamo T range */
|
||||
if(c<=0x11f9 || u_charType(c)==U_OTHER_LETTER) {
|
||||
return U_HST_TRAILING_JAMO;
|
||||
}
|
||||
}
|
||||
} else if((c-=HANGUL_BASE)<0) {
|
||||
/* U_HST_NOT_APPLICABLE */
|
||||
} else if(c<HANGUL_COUNT) {
|
||||
/* Hangul syllable */
|
||||
return c%JAMO_T_COUNT==0 ? U_HST_LV_SYLLABLE : U_HST_LVT_SYLLABLE;
|
||||
}
|
||||
return U_HST_NOT_APPLICABLE;
|
||||
return uchar_getHST(c);
|
||||
#if !UCONFIG_NO_NORMALIZATION
|
||||
case UCHAR_NFD_QUICK_CHECK:
|
||||
case UCHAR_NFKD_QUICK_CHECK:
|
||||
|
@ -564,20 +489,6 @@ u_getIntPropertyMaxValue(UProperty which) {
|
|||
* Do not use a UnicodeSet pattern because that causes infinite recursion;
|
||||
* UnicodeSet depends on the inclusions set.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
static uint32_t
|
||||
strrch(const char* source,uint32_t sourceLen,char find){
|
||||
const char* tSourceEnd =source + (sourceLen-1);
|
||||
while(tSourceEnd>= 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)) {
|
||||
|
|
|
@ -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().
|
||||
|
|
Loading…
Add table
Reference in a new issue