/*
********************************************************************************
-* Copyright (C) 1996-2004, International Business Machines
+* Copyright (C) 1996-2008, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************************
*
/* dynamically loaded Unicode character properties -------------------------- */
+#define UCHAR_HARDCODE_DATA 1
+
+#if UCHAR_HARDCODE_DATA
+
+/* uchar_props_data.c is machine-generated by genprops --csource */
+#include "uchar_props_data.c"
+
+#else
+
/*
* loaded uprops.dat -
* for a description of the file format, see icu/source/tools/genprops/store.c
static UVersionInfo dataVersion={ 0, 0, 0, 0 };
static UTrie propsTrie={ 0 }, propsVectorsTrie={ 0 };
-static const uint32_t *pData32=NULL, *props32Table=NULL, *exceptionsTable=NULL, *propsVectors=NULL;
-static const UChar *ucharsTable=NULL;
+static const uint32_t *pData32=NULL, *propsVectors=NULL;
static int32_t countPropsVectors=0, propsVectorsColumns=0;
static int8_t havePropsData=0; /* == 0 -> Data has not been loaded.
/* index values loaded from uprops.dat */
static int32_t indexes[UPROPS_INDEX_COUNT];
-/* if bit 15 is set, then the folding offset is in bits 14..0 of the 16-bit trie result */
-static int32_t U_CALLCONV
-getFoldingPropsOffset(uint32_t data) {
- if(data&0x8000) {
- return (int32_t)(data&0x7fff);
- } else {
- return 0;
- }
-}
-
static UBool U_CALLCONV
isAcceptable(void *context,
const char *type, const char *name,
pInfo->dataFormat[1]==0x50 &&
pInfo->dataFormat[2]==0x72 &&
pInfo->dataFormat[3]==0x6f &&
- pInfo->formatVersion[0]==3 &&
+ pInfo->formatVersion[0]==4 &&
pInfo->formatVersion[2]==UTRIE_SHIFT &&
pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT
) {
propsData=NULL;
}
pData32=NULL;
- props32Table=NULL;
- exceptionsTable=NULL;
- ucharsTable=NULL;
propsVectors=NULL;
countPropsVectors=0;
+ uprv_memset(dataVersion, 0, U_MAX_VERSION_LENGTH);
dataErrorCode=U_ZERO_ERROR;
havePropsData=0;
if(U_FAILURE(*pErrorCode)) {
return;
}
- ucp->propsTrie.getFoldingOffset=getFoldingPropsOffset;
- /* unserialize the properties vectors trie, if any */
- if( p[UPROPS_ADDITIONAL_TRIE_INDEX]!=0 &&
- p[UPROPS_ADDITIONAL_VECTORS_INDEX]!=0
- ) {
- length=(int32_t)(p[UPROPS_ADDITIONAL_VECTORS_INDEX]-p[UPROPS_ADDITIONAL_TRIE_INDEX])*4;
+ /* unserialize the properties vectors trie */
+ length=(int32_t)(p[UPROPS_ADDITIONAL_VECTORS_INDEX]-p[UPROPS_ADDITIONAL_TRIE_INDEX])*4;
+ if(length>0) {
length=utrie_unserialize(&ucp->propsVectorsTrie, (const uint8_t *)(p+p[UPROPS_ADDITIONAL_TRIE_INDEX]), length, pErrorCode);
- if(U_FAILURE(*pErrorCode)) {
- uprv_memset(&ucp->propsVectorsTrie, 0, sizeof(ucp->propsVectorsTrie));
- } else {
- ucp->propsVectorsTrie.getFoldingOffset=getFoldingPropsOffset;
- }
+ }
+ if(length<=0 || U_FAILURE(*pErrorCode)) {
+ /*
+ * length==0:
+ * Allow the properties vectors trie to be missing -
+ * also requires propsVectorsColumns=indexes[UPROPS_ADDITIONAL_VECTORS_COLUMNS_INDEX]
+ * to be zero so that this trie is never accessed.
+ */
+ uprv_memset(&ucp->propsVectorsTrie, 0, sizeof(ucp->propsVectorsTrie));
}
}
-U_CFUNC int8_t
+#endif
+
+#if !UCHAR_HARDCODE_DATA
+static int8_t
uprv_loadPropsData(UErrorCode *pErrorCode) {
/* load Unicode character properties data from file if necessary */
*/
if(havePropsData==0) {
UCharProps ucp={ NULL };
- UCaseProps *csp;
if(U_FAILURE(*pErrorCode)) {
return havePropsData;
ucp.pData32=NULL;
uprv_memcpy(&propsTrie, &ucp.propsTrie, sizeof(propsTrie));
uprv_memcpy(&propsVectorsTrie, &ucp.propsVectorsTrie, sizeof(propsVectorsTrie));
- csp=NULL;
}
/* initialize some variables */
uprv_memcpy(indexes, pData32, sizeof(indexes));
- props32Table=pData32+indexes[UPROPS_PROPS32_INDEX];
- exceptionsTable=pData32+indexes[UPROPS_EXCEPTIONS_INDEX];
- ucharsTable=(const UChar *)(pData32+indexes[UPROPS_EXCEPTIONS_TOP_INDEX]);
/* additional properties */
if(indexes[UPROPS_ADDITIONAL_VECTORS_INDEX]!=0) {
return havePropsData;
}
-
static int8_t
loadPropsData(void) {
UErrorCode errorCode = U_ZERO_ERROR;
return retVal;
}
+#endif
-/* Unicode properties data swapping ----------------------------------------- */
-
-U_CAPI int32_t U_EXPORT2
-uprops_swap(const UDataSwapper *ds,
- const void *inData, int32_t length, void *outData,
- UErrorCode *pErrorCode) {
- const UDataInfo *pInfo;
- int32_t headerSize, i;
-
- int32_t dataIndexes[UPROPS_INDEX_COUNT];
- const int32_t *inData32;
-
- /* udata_swapDataHeader checks the arguments */
- headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode);
- if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
- return 0;
- }
-
- /* check data format and format version */
- pInfo=(const UDataInfo *)((const char *)inData+4);
- if(!(
- pInfo->dataFormat[0]==0x55 && /* dataFormat="UPro" */
- pInfo->dataFormat[1]==0x50 &&
- pInfo->dataFormat[2]==0x72 &&
- pInfo->dataFormat[3]==0x6f &&
- pInfo->formatVersion[0]==3 &&
- pInfo->formatVersion[2]==UTRIE_SHIFT &&
- pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT
- )) {
- udata_printError(ds, "uprops_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not a Unicode properties file\n",
- pInfo->dataFormat[0], pInfo->dataFormat[1],
- pInfo->dataFormat[2], pInfo->dataFormat[3],
- pInfo->formatVersion[0]);
- *pErrorCode=U_UNSUPPORTED_ERROR;
- return 0;
- }
-
- /* the properties file must contain at least the indexes array */
- if(length>=0 && (length-headerSize)<sizeof(dataIndexes)) {
- udata_printError(ds, "uprops_swap(): too few bytes (%d after header) for a Unicode properties file\n",
- length-headerSize);
- *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
- return 0;
- }
-
- /* read the indexes */
- inData32=(const int32_t *)((const char *)inData+headerSize);
- for(i=0; i<UPROPS_INDEX_COUNT; ++i) {
- dataIndexes[i]=udata_readInt32(ds, inData32[i]);
- }
-
- /*
- * comments are copied from the data format description in genprops/store.c
- * indexes[] constants are in uprops.h
- */
- if(length>=0) {
- int32_t *outData32;
-
- if((length-headerSize)<(4*dataIndexes[UPROPS_RESERVED_INDEX])) {
- udata_printError(ds, "uprops_swap(): too few bytes (%d after header) for a Unicode properties file\n",
- length-headerSize);
- *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
- return 0;
- }
-
- outData32=(int32_t *)((char *)outData+headerSize);
-
- /* copy everything for inaccessible data (padding) */
- if(inData32!=outData32) {
- uprv_memcpy(outData32, inData32, 4*dataIndexes[UPROPS_RESERVED_INDEX]);
- }
-
- /* swap the indexes[16] */
- ds->swapArray32(ds, inData32, 4*UPROPS_INDEX_COUNT, outData32, pErrorCode);
-
- /*
- * swap the main properties UTrie
- * PT serialized properties trie, see utrie.h (byte size: 4*(i0-16))
- */
- utrie_swap(ds,
- inData32+UPROPS_INDEX_COUNT,
- 4*(dataIndexes[UPROPS_PROPS32_INDEX]-UPROPS_INDEX_COUNT),
- outData32+UPROPS_INDEX_COUNT,
- pErrorCode);
-
- /*
- * swap the properties and exceptions words
- * P const uint32_t props32[i1-i0];
- * E const uint32_t exceptions[i2-i1];
- */
- ds->swapArray32(ds,
- inData32+dataIndexes[UPROPS_PROPS32_INDEX],
- 4*(dataIndexes[UPROPS_EXCEPTIONS_TOP_INDEX]-dataIndexes[UPROPS_PROPS32_INDEX]),
- outData32+dataIndexes[UPROPS_PROPS32_INDEX],
- pErrorCode);
-
- /*
- * swap the UChars
- * U const UChar uchars[2*(i3-i2)];
- */
- ds->swapArray16(ds,
- inData32+dataIndexes[UPROPS_EXCEPTIONS_TOP_INDEX],
- 4*(dataIndexes[UPROPS_ADDITIONAL_TRIE_INDEX]-dataIndexes[UPROPS_EXCEPTIONS_TOP_INDEX]),
- outData32+dataIndexes[UPROPS_EXCEPTIONS_TOP_INDEX],
- pErrorCode);
-
- /*
- * swap the additional UTrie
- * i3 additionalTrieIndex; -- 32-bit unit index to the additional trie for more properties
- */
- utrie_swap(ds,
- inData32+dataIndexes[UPROPS_ADDITIONAL_TRIE_INDEX],
- 4*(dataIndexes[UPROPS_ADDITIONAL_VECTORS_INDEX]-dataIndexes[UPROPS_ADDITIONAL_TRIE_INDEX]),
- outData32+dataIndexes[UPROPS_ADDITIONAL_TRIE_INDEX],
- pErrorCode);
+/* constants and macros for access to the data ------------------------------ */
- /*
- * swap the properties vectors
- * PV const uint32_t propsVectors[(i6-i4)/i5][i5]==uint32_t propsVectors[i6-i4];
- */
- ds->swapArray32(ds,
- inData32+dataIndexes[UPROPS_ADDITIONAL_VECTORS_INDEX],
- 4*(dataIndexes[UPROPS_RESERVED_INDEX]-dataIndexes[UPROPS_ADDITIONAL_VECTORS_INDEX]),
- outData32+dataIndexes[UPROPS_ADDITIONAL_VECTORS_INDEX],
- pErrorCode);
- }
+/* getting a uint32_t properties word from the data */
+#if UCHAR_HARDCODE_DATA
- /* i6 reservedItemIndex; -- 32-bit unit index to the top of the properties vectors table */
- return headerSize+4*dataIndexes[UPROPS_RESERVED_INDEX];
-}
+#define GET_PROPS(c, result) UTRIE_GET16(&propsTrie, c, result);
-/* constants and macros for access to the data ------------------------------ */
+#else
-/* getting a uint32_t properties word from the data */
#define HAVE_DATA (havePropsData>0 || loadPropsData()>0)
-#define VALIDATE(c) (((uint32_t)(c))<=0x10ffff && HAVE_DATA)
#define GET_PROPS_UNSAFE(c, result) \
- UTRIE_GET16(&propsTrie, c, result); \
- (result)=props32Table[(result)]
+ UTRIE_GET16(&propsTrie, c, result);
#define GET_PROPS(c, result) \
if(HAVE_DATA) { \
GET_PROPS_UNSAFE(c, result); \
(result)=0; \
}
-/* finding an exception value */
-#define HAVE_EXCEPTION_VALUE(flags, index) ((flags)&(1UL<<(index)))
-
-/* number of bits in an 8-bit integer value */
-#define EXC_GROUP 8
-static const uint8_t flagsOffset[256]={
- 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
- 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
- 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
- 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
- 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
- 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
- 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
- 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
-};
-
-#define ADD_EXCEPTION_OFFSET(flags, index, offset) { \
- if((index)>=EXC_GROUP) { \
- (offset)+=flagsOffset[(flags)&((1<<EXC_GROUP)-1)]; \
- (flags)>>=EXC_GROUP; \
- (index)-=EXC_GROUP; \
- } \
- (offset)+=flagsOffset[(flags)&((1<<(index))-1)]; \
-}
+#endif
U_CFUNC UBool
uprv_haveProperties(UErrorCode *pErrorCode) {
if(U_FAILURE(*pErrorCode)) {
return FALSE;
}
+#if !UCHAR_HARDCODE_DATA
if(havePropsData==0) {
uprv_loadPropsData(pErrorCode);
}
*pErrorCode=dataErrorCode;
return FALSE;
}
+#endif
return TRUE;
}
static uint32_t U_CALLCONV
_enumTypeValue(const void *context, uint32_t value) {
- /* access the general category from the 32-bit properties, and those from the 16-bit trie value */
- return GET_CATEGORY(props32Table[value]);
+ return GET_CATEGORY(value);
}
static UBool U_CALLCONV
u_enumCharTypes(UCharEnumTypeRange *enumRange, const void *context) {
struct _EnumTypeCallback callback;
- if(enumRange==NULL || !HAVE_DATA) {
+ if(enumRange==NULL
+#if !UCHAR_HARDCODE_DATA
+ || !HAVE_DATA
+#endif
+ ) {
return;
}
return (u_getUnicodeProperties(c, 1)&U_MASK(UPROPS_ALPHABETIC))!=0;
}
-/* Checks if ch is a letter or a decimal digit */
+/* Checks if c is a letter or a decimal digit */
U_CAPI UBool U_EXPORT2
u_isalnum(UChar32 c) {
uint32_t props;
return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_ND_MASK))!=0);
}
+/**
+ * Checks if c is alphabetic, or a decimal digit; implements UCHAR_POSIX_ALNUM.
+ * @internal
+ */
+U_CFUNC UBool
+u_isalnumPOSIX(UChar32 c) {
+ return (UBool)(u_isUAlphabetic(c) || u_isdigit(c));
+}
+
/* Checks if ch is a unicode character with assigned character type.*/
U_CAPI UBool U_EXPORT2
u_isdefined(UChar32 c) {
if((uint32_t)c<=0x9f) {
return c==9 || c==0x20; /* TAB or SPACE */
} else {
- /* White_Space but not LS (Zl) or PS (Zp) */
- return u_isUWhiteSpace(c) && ((c&0xfffffffe)!=0x2028);
+ /* Zs */
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)(GET_CATEGORY(props)==U_SPACE_SEPARATOR);
}
}
return (UBool)((CAT_MASK(props)&U_GC_C_MASK)==0);
}
+/**
+ * Checks if c is in \p{graph}\p{blank} - \p{cntrl}.
+ * Implements UCHAR_POSIX_PRINT.
+ * @internal
+ */
+U_CFUNC UBool
+u_isprintPOSIX(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ /*
+ * The only cntrl character in graph+blank is TAB (in blank).
+ * Here we implement (blank-TAB)=Zs instead of calling u_isblank().
+ */
+ return (UBool)((GET_CATEGORY(props)==U_SPACE_SEPARATOR) || u_isgraphPOSIX(c));
+}
+
U_CAPI UBool U_EXPORT2
u_isgraph(UChar32 c) {
uint32_t props;
==0);
}
+/**
+ * Checks if c is in
+ * [^\p{space}\p{gc=Control}\p{gc=Surrogate}\p{gc=Unassigned}]
+ * with space=\p{Whitespace} and Control=Cc.
+ * Implements UCHAR_POSIX_GRAPH.
+ * @internal
+ */
+U_CFUNC UBool
+u_isgraphPOSIX(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ /* \p{space}\p{gc=Control} == \p{gc=Z}\p{Control} */
+ /* comparing ==0 returns FALSE for the categories mentioned */
+ return (UBool)((CAT_MASK(props)&
+ (U_GC_CC_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK))
+ ==0);
+}
+
U_CAPI UBool U_EXPORT2
u_ispunct(UChar32 c) {
uint32_t props;
U_CAPI int32_t U_EXPORT2
u_charDigitValue(UChar32 c) {
- uint32_t props, numericType;
+ uint32_t props;
GET_PROPS(c, props);
- numericType=GET_NUMERIC_TYPE(props);
- if(numericType==1) {
- if(!PROPS_VALUE_IS_EXCEPTION(props)) {
- return GET_SIGNED_VALUE(props);
- } else {
- const uint32_t *pe=GET_EXCEPTIONS(props);
- uint32_t firstExceptionValue=*pe;
- if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_NUMERIC_VALUE)) {
- int i=EXC_NUMERIC_VALUE;
- ++pe;
- ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
- return (int32_t)*pe;
- }
- }
+ if(GET_NUMERIC_TYPE(props)==1) {
+ return GET_NUMERIC_VALUE(props);
+ } else {
+ return -1;
}
-
- return -1;
}
U_CAPI double U_EXPORT2
u_getNumericValue(UChar32 c) {
- uint32_t props, numericType;
+ uint32_t props, numericType, numericValue;
GET_PROPS(c, props);
numericType=GET_NUMERIC_TYPE(props);
- if(numericType==0 || numericType>=(int32_t)U_NT_COUNT) {
+ if(numericType==0 || numericType>=UPROPS_NT_COUNT) {
return U_NO_NUMERIC_VALUE;
- } else {
- if(!PROPS_VALUE_IS_EXCEPTION(props)) {
- return GET_SIGNED_VALUE(props);
- } else {
- const uint32_t *pe;
- uint32_t firstExceptionValue;
-
- double numValue;
- uint32_t denominator;
-
- pe=GET_EXCEPTIONS(props);
- firstExceptionValue=*pe++;
-
- if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_NUMERIC_VALUE)) {
- uint32_t flags=firstExceptionValue;
- int i=EXC_NUMERIC_VALUE;
- const uint32_t *p=pe;
- int32_t numerator;
-
- ADD_EXCEPTION_OFFSET(flags, i, p);
- numerator=(int32_t)*p;
-
- /*
- * There are special values for huge numbers that are powers of ten.
- * genprops/store.c documents:
- * if numericValue=0x7fffff00+x then numericValue=10^x
- */
- if(numerator<0x7fffff00) {
- numValue=(double)numerator;
- } else {
- numerator&=0xff;
-
- /* 10^x without math.h */
- numValue=1.;
- while(numerator>=4) {
- numValue*=10000.;
- numerator-=4;
- }
- switch(numerator) {
- case 3:
- numValue*=1000.;
- break;
- case 2:
- numValue*=100.;
- break;
- case 1:
- numValue*=10.;
- break;
- case 0:
- default:
- break;
- }
- }
- } else {
- numValue=0.;
- }
- if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_DENOMINATOR_VALUE)) {
- uint32_t flags=firstExceptionValue;
- int i=EXC_DENOMINATOR_VALUE;
- const uint32_t *p=pe;
- ADD_EXCEPTION_OFFSET(flags, i, p);
- denominator=*p;
- } else {
- denominator=0;
- }
-
- switch(firstExceptionValue&((1UL<<EXC_NUMERIC_VALUE)|(1UL<<EXC_DENOMINATOR_VALUE))) {
- case 1UL<<EXC_NUMERIC_VALUE:
- return numValue;
- case 1UL<<EXC_DENOMINATOR_VALUE:
- return (double)1./(double)denominator;
- case (1UL<<EXC_NUMERIC_VALUE)|(1UL<<EXC_DENOMINATOR_VALUE):
- return numValue/(double)denominator;
- case 0: /* none (should not occur with numericType>0) */
- default:
- return U_NO_NUMERIC_VALUE;
- }
- }
}
-}
-/* Gets the character's linguistic directionality.*/
-U_CAPI UCharDirection U_EXPORT2
-u_charDirection(UChar32 c) {
- uint32_t props;
- GET_PROPS(c, props);
- return (UCharDirection)GET_BIDI_CLASS(props);
-}
+ numericValue=GET_NUMERIC_VALUE(props);
-U_CAPI UBool U_EXPORT2
-u_isMirrored(UChar32 c) {
- uint32_t props;
- GET_PROPS(c, props);
- return (UBool)(props&(1UL<<UPROPS_MIRROR_SHIFT) ? TRUE : FALSE);
-}
+ if(numericType<U_NT_COUNT) {
+ /* normal type, the value is stored directly */
+ return numericValue;
+ } else if(numericType==UPROPS_NT_FRACTION) {
+ /* fraction value */
+ int32_t numerator;
+ uint32_t denominator;
-U_CAPI UChar32 U_EXPORT2
-u_charMirror(UChar32 c) {
- uint32_t props;
- GET_PROPS(c, props);
- if((props&(1UL<<UPROPS_MIRROR_SHIFT))==0) {
- /* not mirrored - the value is not a mirror offset */
- return c;
- } else if(!PROPS_VALUE_IS_EXCEPTION(props)) {
- return c+GET_SIGNED_VALUE(props);
- } else {
- const uint32_t *pe=GET_EXCEPTIONS(props);
- uint32_t firstExceptionValue=*pe;
- if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_MIRROR_MAPPING)) {
- int i=EXC_MIRROR_MAPPING;
- ++pe;
- ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
- return (UChar32)*pe;
+ numerator=(int32_t)numericValue>>UPROPS_FRACTION_NUM_SHIFT;
+ denominator=(numericValue&UPROPS_FRACTION_DEN_MASK)+UPROPS_FRACTION_DEN_OFFSET;
+
+ if(numerator==0) {
+ numerator=-1;
+ }
+ return (double)numerator/(double)denominator;
+ } else /* numericType==UPROPS_NT_LARGE */ {
+ /* large value with exponent */
+ double numValue;
+ int32_t mant, exp;
+
+ mant=(int32_t)numericValue>>UPROPS_LARGE_MANT_SHIFT;
+ exp=(int32_t)numericValue&UPROPS_LARGE_EXP_MASK;
+ if(mant==0) {
+ mant=1;
+ exp+=UPROPS_LARGE_EXP_OFFSET_EXTRA;
+ } else if(mant>9) {
+ return U_NO_NUMERIC_VALUE; /* reserved mantissa value */
} else {
- return c;
+ exp+=UPROPS_LARGE_EXP_OFFSET;
}
+
+ numValue=mant;
+
+ /* multiply by 10^exp without math.h */
+ while(exp>=4) {
+ numValue*=10000.;
+ exp-=4;
+ }
+ switch(exp) {
+ case 3:
+ numValue*=1000.;
+ break;
+ case 2:
+ numValue*=100.;
+ break;
+ case 1:
+ numValue*=10.;
+ break;
+ case 0:
+ default:
+ break;
+ }
+
+ return numValue;
}
}
+/* ICU 3.4: bidi/shaping properties moved to ubidi_props.c */
+
/* ICU 2.1: u_getCombiningClass() moved to unorm.cpp */
U_CAPI int32_t U_EXPORT2
U_CAPI void U_EXPORT2
u_getUnicodeVersion(UVersionInfo versionArray) {
if(versionArray!=NULL) {
- if(HAVE_DATA) {
- uprv_memcpy(versionArray, dataVersion, U_MAX_VERSION_LENGTH);
- } else {
- uprv_memset(versionArray, 0, U_MAX_VERSION_LENGTH);
- }
+ uprv_memcpy(versionArray, dataVersion, U_MAX_VERSION_LENGTH);
}
}
uint32_t props;
GET_PROPS(c, props);
return props;
- } else if( !HAVE_DATA || countPropsVectors==0 ||
- (uint32_t)c>0x10ffff ||
+ } else if(
+#if !UCHAR_HARDCODE_DATA
+ !HAVE_DATA || countPropsVectors==0 ||
+#endif
column<0 || column>=propsVectorsColumns
) {
return 0;
U_CFUNC int32_t
uprv_getMaxValues(int32_t column) {
+#if !UCHAR_HARDCODE_DATA
if(HAVE_DATA) {
+#endif
switch(column) {
case 0:
return indexes[UPROPS_MAX_VALUES_INDEX];
default:
return 0;
}
+#if !UCHAR_HARDCODE_DATA
} else {
return 0;
}
+#endif
}
/*
U_CAPI UScriptCode U_EXPORT2
uscript_getScript(UChar32 c, UErrorCode *pErrorCode) {
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
- return 0;
+ return USCRIPT_INVALID_CODE;
}
if((uint32_t)c>0x10ffff) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
- return 0;
+ return USCRIPT_INVALID_CODE;
}
return (UScriptCode)(u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_MASK);
/* property starts for UnicodeSet ------------------------------------------- */
/* for Hangul_Syllable_Type */
-U_CAPI void U_EXPORT2
-uhst_addPropertyStarts(USetAdder *sa, UErrorCode *pErrorCode) {
+U_CFUNC void U_EXPORT2
+uhst_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
UChar32 c;
int32_t value, value2;
return;
}
+#if !UCHAR_HARDCODE_DATA
if(!HAVE_DATA) {
*pErrorCode=dataErrorCode;
return;
}
+#endif
/* add code points with hardcoded properties, plus the ones following them */
static UBool U_CALLCONV
_enumPropertyStartsRange(const void *context, UChar32 start, UChar32 limit, uint32_t value) {
/* add the start code point to the USet */
- USetAdder *sa=(USetAdder *)context;
+ const USetAdder *sa=(const USetAdder *)context;
sa->add(sa->set, start);
return TRUE;
}
#define USET_ADD_CP_AND_NEXT(sa, cp) sa->add(sa->set, cp); sa->add(sa->set, cp+1)
-U_CAPI void U_EXPORT2
-uchar_addPropertyStarts(USetAdder *sa, UErrorCode *pErrorCode) {
+U_CFUNC void U_EXPORT2
+uchar_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
if(U_FAILURE(*pErrorCode)) {
return;
}
+#if !UCHAR_HARDCODE_DATA
if(!HAVE_DATA) {
*pErrorCode=dataErrorCode;
return;
}
+#endif
- /* add the start code point of each same-value range of each trie */
+ /* add the start code point of each same-value range of the main trie */
utrie_enum(&propsTrie, NULL, _enumPropertyStartsRange, sa);
- utrie_enum(&propsVectorsTrie, NULL, _enumPropertyStartsRange, sa);
/* add code points with hardcoded properties, plus the ones following them */
+ /* add for u_isblank() */
+ USET_ADD_CP_AND_NEXT(sa, TAB);
+
/* add for IS_THAT_CONTROL_SPACE() */
- sa->add(sa->set, TAB); /* range TAB..CR */
- sa->add(sa->set, CR+1);
+ sa->add(sa->set, CR+1); /* range TAB..CR */
sa->add(sa->set, 0x1c);
sa->add(sa->set, 0x1f+1);
USET_ADD_CP_AND_NEXT(sa, NL);
USET_ADD_CP_AND_NEXT(sa, FIGURESP);
USET_ADD_CP_AND_NEXT(sa, NNBSP);
- /* add for u_charDigitValue() */
- USET_ADD_CP_AND_NEXT(sa, 0x3007);
- USET_ADD_CP_AND_NEXT(sa, 0x4e00);
- USET_ADD_CP_AND_NEXT(sa, 0x4e8c);
- USET_ADD_CP_AND_NEXT(sa, 0x4e09);
- USET_ADD_CP_AND_NEXT(sa, 0x56db);
- USET_ADD_CP_AND_NEXT(sa, 0x4e94);
- USET_ADD_CP_AND_NEXT(sa, 0x516d);
- USET_ADD_CP_AND_NEXT(sa, 0x4e03);
- USET_ADD_CP_AND_NEXT(sa, 0x516b);
- USET_ADD_CP_AND_NEXT(sa, 0x4e5d);
-
/* add for u_digit() */
sa->add(sa->set, U_a);
sa->add(sa->set, U_z+1);
sa->add(sa->set, U_A);
sa->add(sa->set, U_Z+1);
+ sa->add(sa->set, U_FW_a);
+ sa->add(sa->set, U_FW_z+1);
+ sa->add(sa->set, U_FW_A);
+ sa->add(sa->set, U_FW_Z+1);
+
+ /* add for u_isxdigit() */
+ sa->add(sa->set, U_f+1);
+ sa->add(sa->set, U_F+1);
+ sa->add(sa->set, U_FW_f+1);
+ sa->add(sa->set, U_FW_F+1);
/* add for UCHAR_DEFAULT_IGNORABLE_CODE_POINT what was not added above */
sa->add(sa->set, WJ); /* range WJ..NOMDIG */
/* add for UCHAR_GRAPHEME_BASE and others */
USET_ADD_CP_AND_NEXT(sa, CGJ);
+}
- /* add for UCHAR_JOINING_TYPE */
- sa->add(sa->set, ZWNJ); /* range ZWNJ..ZWJ */
- sa->add(sa->set, ZWJ+1);
+U_CFUNC void U_EXPORT2
+upropsvec_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return;
+ }
+
+#if !UCHAR_HARDCODE_DATA
+ if(!HAVE_DATA) {
+ *pErrorCode=dataErrorCode;
+ return;
+ }
+#endif
+
+ /* add the start code point of each same-value range of the properties vectors trie */
+ if(propsVectorsColumns>0) {
+ /* if propsVectorsColumns==0 then the properties vectors trie may not be there at all */
+ utrie_enum(&propsVectorsTrie, NULL, _enumPropertyStartsRange, sa);
+ }
}