1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
********************************************************************************
|
2003-03-08 18:00:51 +00:00
|
|
|
* Copyright (C) 1996-2003, International Business Machines
|
2000-01-11 23:20:26 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
1999-08-16 21:50:52 +00:00
|
|
|
********************************************************************************
|
|
|
|
*
|
2000-06-20 23:42:20 +00:00
|
|
|
* File UCHAR.C
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 04/02/97 aliu Creation.
|
2000-01-11 23:20:26 +00:00
|
|
|
* 4/15/99 Madhu Updated all the function definitions for C Implementation
|
2001-03-21 20:44:20 +00:00
|
|
|
* 5/20/99 Madhu Added the function u_getVersion()
|
2000-01-11 23:20:26 +00:00
|
|
|
* 8/19/1999 srl Upgraded scripts to Unicode3.0
|
1999-11-19 18:48:16 +00:00
|
|
|
* 11/11/1999 weiv added u_isalnum(), cleaned comments
|
2000-01-11 23:20:26 +00:00
|
|
|
* 01/11/2000 helena Renamed u_getVersion to u_getUnicodeVersion.
|
2000-06-20 23:42:20 +00:00
|
|
|
* 06/20/2000 helena OS/400 port changes; mostly typecast.
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
2001-01-31 18:20:26 +00:00
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uchar.h"
|
2000-04-24 22:44:06 +00:00
|
|
|
#include "unicode/udata.h"
|
2001-01-31 18:20:26 +00:00
|
|
|
#include "unicode/uloc.h"
|
2002-02-20 02:07:29 +00:00
|
|
|
#include "unicode/uiter.h"
|
2003-02-15 00:22:31 +00:00
|
|
|
#include "unicode/uset.h"
|
2001-01-31 18:20:26 +00:00
|
|
|
#include "umutex.h"
|
1999-10-12 00:07:24 +00:00
|
|
|
#include "cmemory.h"
|
2001-08-31 02:14:47 +00:00
|
|
|
#include "ucln_cmn.h"
|
2001-12-06 01:23:47 +00:00
|
|
|
#include "utrie.h"
|
|
|
|
#include "ustr_imp.h"
|
2003-08-12 12:23:56 +00:00
|
|
|
#include "udataswp.h"
|
2002-02-25 22:40:32 +00:00
|
|
|
#include "uprops.h"
|
2003-08-22 23:26:53 +00:00
|
|
|
#include "uassert.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-03-01 00:13:40 +00:00
|
|
|
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
|
|
|
|
2000-04-24 22:44:06 +00:00
|
|
|
/* dynamically loaded Unicode character properties -------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* loaded uprops.dat -
|
|
|
|
* for a description of the file format, see icu/source/tools/genprops/store.c
|
|
|
|
*/
|
2002-01-21 21:48:25 +00:00
|
|
|
static const char DATA_NAME[] = "uprops";
|
2002-07-17 21:02:09 +00:00
|
|
|
static const char DATA_TYPE[] = "icu";
|
2000-04-24 22:44:06 +00:00
|
|
|
|
|
|
|
static UDataMemory *propsData=NULL;
|
2002-11-08 02:22:15 +00:00
|
|
|
static UErrorCode dataErrorCode=U_ZERO_ERROR;
|
2000-04-24 22:44:06 +00:00
|
|
|
|
|
|
|
static uint8_t formatVersion[4]={ 0, 0, 0, 0 };
|
2003-05-28 00:33:04 +00:00
|
|
|
static UVersionInfo dataVersion={ 0, 0, 0, 0 };
|
2000-04-24 22:44:06 +00:00
|
|
|
|
2002-02-25 22:40:32 +00:00
|
|
|
static UTrie propsTrie={ 0 }, propsVectorsTrie={ 0 };
|
|
|
|
static const uint32_t *pData32=NULL, *props32Table=NULL, *exceptionsTable=NULL, *propsVectors=NULL;
|
2001-02-14 00:47:36 +00:00
|
|
|
static const UChar *ucharsTable=NULL;
|
2002-02-25 22:40:32 +00:00
|
|
|
static int32_t countPropsVectors=0, propsVectorsColumns=0;
|
2001-02-14 00:47:36 +00:00
|
|
|
|
2003-08-22 23:26:53 +00:00
|
|
|
static int8_t havePropsData=0; /* == 0 -> Data has not been loaded.
|
|
|
|
* < 0 -> Error occured attempting to load data.
|
|
|
|
* > 0 -> Data has been successfully loaded.
|
|
|
|
*/
|
2000-04-24 22:44:06 +00:00
|
|
|
|
|
|
|
/* index values loaded from uprops.dat */
|
2002-02-25 22:40:32 +00:00
|
|
|
static int32_t indexes[UPROPS_INDEX_COUNT];
|
2000-04-24 22:44:06 +00:00
|
|
|
|
2001-12-06 01:23:47 +00:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
2000-04-24 22:44:06 +00:00
|
|
|
|
2002-07-23 23:01:08 +00:00
|
|
|
static UBool U_CALLCONV
|
2000-04-24 22:44:06 +00:00
|
|
|
isAcceptable(void *context,
|
|
|
|
const char *type, const char *name,
|
2000-05-03 23:15:02 +00:00
|
|
|
const UDataInfo *pInfo) {
|
2000-04-24 22:44:06 +00:00
|
|
|
if(
|
|
|
|
pInfo->size>=20 &&
|
|
|
|
pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
|
|
|
|
pInfo->charsetFamily==U_CHARSET_FAMILY &&
|
|
|
|
pInfo->dataFormat[0]==0x55 && /* dataFormat="UPro" */
|
|
|
|
pInfo->dataFormat[1]==0x50 &&
|
|
|
|
pInfo->dataFormat[2]==0x72 &&
|
|
|
|
pInfo->dataFormat[3]==0x6f &&
|
2002-03-04 01:25:51 +00:00
|
|
|
pInfo->formatVersion[0]==3 &&
|
2001-12-06 01:23:47 +00:00
|
|
|
pInfo->formatVersion[2]==UTRIE_SHIFT &&
|
|
|
|
pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT
|
2000-04-24 22:44:06 +00:00
|
|
|
) {
|
|
|
|
uprv_memcpy(formatVersion, pInfo->formatVersion, 4);
|
|
|
|
uprv_memcpy(dataVersion, pInfo->dataVersion, 4);
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-31 02:14:47 +00:00
|
|
|
UBool
|
|
|
|
uchar_cleanup()
|
|
|
|
{
|
|
|
|
if (propsData) {
|
|
|
|
udata_close(propsData);
|
2001-12-06 01:23:47 +00:00
|
|
|
propsData=NULL;
|
2001-08-31 02:14:47 +00:00
|
|
|
}
|
2001-12-06 01:23:47 +00:00
|
|
|
pData32=NULL;
|
|
|
|
props32Table=NULL;
|
|
|
|
exceptionsTable=NULL;
|
|
|
|
ucharsTable=NULL;
|
2002-02-25 22:40:32 +00:00
|
|
|
propsVectors=NULL;
|
|
|
|
countPropsVectors=0;
|
2002-11-08 02:22:15 +00:00
|
|
|
dataErrorCode=U_ZERO_ERROR;
|
2003-08-22 23:26:53 +00:00
|
|
|
havePropsData=0;
|
2003-02-15 00:22:31 +00:00
|
|
|
|
2001-08-31 02:14:47 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-08-22 23:26:53 +00:00
|
|
|
|
|
|
|
U_CFUNC int8_t
|
|
|
|
uprv_loadPropsData(UErrorCode *errorCode) {
|
2000-04-24 22:44:06 +00:00
|
|
|
/* load Unicode character properties data from file if necessary */
|
2003-05-06 23:56:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This lazy intialization with double-checked locking (without mutex protection for
|
|
|
|
* haveNormData==0) is transiently unsafe under certain circumstances.
|
|
|
|
* Check the readme and use u_init() if necessary.
|
|
|
|
*/
|
2000-04-24 22:44:06 +00:00
|
|
|
if(havePropsData==0) {
|
2002-02-25 22:40:32 +00:00
|
|
|
UTrie trie={ 0 }, trie2={ 0 };
|
2000-04-24 22:44:06 +00:00
|
|
|
UDataMemory *data;
|
2001-12-06 01:23:47 +00:00
|
|
|
const uint32_t *p=NULL;
|
|
|
|
int32_t length;
|
2000-04-24 22:44:06 +00:00
|
|
|
|
|
|
|
/* open the data outside the mutex block */
|
2003-08-22 23:26:53 +00:00
|
|
|
data=udata_openChoice(NULL, DATA_TYPE, DATA_NAME, isAcceptable, NULL, errorCode);
|
|
|
|
dataErrorCode=*errorCode;
|
|
|
|
if(U_FAILURE(*errorCode)) {
|
2000-04-24 22:44:06 +00:00
|
|
|
return havePropsData=-1;
|
|
|
|
}
|
|
|
|
|
2001-12-06 01:23:47 +00:00
|
|
|
p=(const uint32_t *)udata_getMemory(data);
|
2000-04-24 22:44:06 +00:00
|
|
|
|
2002-02-25 22:40:32 +00:00
|
|
|
/* unserialize the trie; it is directly after the int32_t indexes[UPROPS_INDEX_COUNT] */
|
|
|
|
length=(int32_t)p[UPROPS_PROPS32_INDEX]*4;
|
2003-08-22 23:26:53 +00:00
|
|
|
length=utrie_unserialize(&trie, (const uint8_t *)(p+UPROPS_INDEX_COUNT), length-64, errorCode);
|
|
|
|
if(U_FAILURE(*errorCode)) {
|
|
|
|
dataErrorCode=*errorCode;
|
2001-03-15 02:01:25 +00:00
|
|
|
udata_close(data);
|
|
|
|
return havePropsData=-1;
|
|
|
|
}
|
2001-12-06 01:23:47 +00:00
|
|
|
trie.getFoldingOffset=getFoldingPropsOffset;
|
2001-03-15 02:01:25 +00:00
|
|
|
|
2002-02-25 22:40:32 +00:00
|
|
|
/* unserialize the properties vectors trie, if any */
|
2002-03-04 01:25:51 +00:00
|
|
|
if( p[UPROPS_ADDITIONAL_TRIE_INDEX]!=0 &&
|
2002-02-25 22:40:32 +00:00
|
|
|
p[UPROPS_ADDITIONAL_VECTORS_INDEX]!=0
|
|
|
|
) {
|
|
|
|
length=(int32_t)(p[UPROPS_ADDITIONAL_VECTORS_INDEX]-p[UPROPS_ADDITIONAL_TRIE_INDEX])*4;
|
2003-08-22 23:26:53 +00:00
|
|
|
length=utrie_unserialize(&trie2, (const uint8_t *)(p+p[UPROPS_ADDITIONAL_TRIE_INDEX]), length, errorCode);
|
|
|
|
if(U_FAILURE(*errorCode)) {
|
2002-02-25 22:40:32 +00:00
|
|
|
uprv_memset(&trie2, 0, sizeof(trie2));
|
|
|
|
} else {
|
|
|
|
trie2.getFoldingOffset=getFoldingPropsOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-24 22:44:06 +00:00
|
|
|
/* in the mutex block, set the data for this process */
|
|
|
|
umtx_lock(NULL);
|
|
|
|
if(propsData==NULL) {
|
|
|
|
propsData=data;
|
|
|
|
data=NULL;
|
2001-12-06 01:23:47 +00:00
|
|
|
pData32=p;
|
2000-04-24 22:44:06 +00:00
|
|
|
p=NULL;
|
2001-12-06 01:23:47 +00:00
|
|
|
uprv_memcpy(&propsTrie, &trie, sizeof(trie));
|
2002-02-25 22:40:32 +00:00
|
|
|
uprv_memcpy(&propsVectorsTrie, &trie2, sizeof(trie2));
|
2000-04-24 22:44:06 +00:00
|
|
|
}
|
|
|
|
umtx_unlock(NULL);
|
|
|
|
|
|
|
|
/* initialize some variables */
|
2001-12-06 01:23:47 +00:00
|
|
|
uprv_memcpy(indexes, pData32, sizeof(indexes));
|
2002-02-25 22:40:32 +00:00
|
|
|
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) {
|
|
|
|
propsVectors=pData32+indexes[UPROPS_ADDITIONAL_VECTORS_INDEX];
|
2002-03-13 19:18:36 +00:00
|
|
|
countPropsVectors=indexes[UPROPS_RESERVED_INDEX]-indexes[UPROPS_ADDITIONAL_VECTORS_INDEX];
|
2002-02-25 22:40:32 +00:00
|
|
|
propsVectorsColumns=indexes[UPROPS_ADDITIONAL_VECTORS_COLUMNS_INDEX];
|
|
|
|
}
|
|
|
|
|
2000-04-24 22:44:06 +00:00
|
|
|
havePropsData=1;
|
|
|
|
|
|
|
|
/* if a different thread set it first, then close the extra data */
|
|
|
|
if(data!=NULL) {
|
|
|
|
udata_close(data); /* NULL if it was set correctly */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return havePropsData;
|
|
|
|
}
|
|
|
|
|
2003-08-22 23:26:53 +00:00
|
|
|
|
|
|
|
static int8_t
|
|
|
|
loadPropsData(void) {
|
|
|
|
UErrorCode errorCode = U_ZERO_ERROR;
|
|
|
|
int8_t retVal = uprv_loadPropsData(&errorCode);
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-12 12:23:56 +00:00
|
|
|
/* 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 indexes[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(indexes)) {
|
|
|
|
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) {
|
|
|
|
indexes[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*indexes[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*indexes[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*(indexes[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+indexes[UPROPS_PROPS32_INDEX],
|
|
|
|
4*(indexes[UPROPS_EXCEPTIONS_TOP_INDEX]-indexes[UPROPS_PROPS32_INDEX]),
|
|
|
|
outData32+indexes[UPROPS_PROPS32_INDEX],
|
|
|
|
pErrorCode);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* swap the UChars
|
|
|
|
* U const UChar uchars[2*(i3-i2)];
|
|
|
|
*/
|
|
|
|
ds->swapArray16(ds,
|
|
|
|
inData32+indexes[UPROPS_EXCEPTIONS_TOP_INDEX],
|
|
|
|
4*(indexes[UPROPS_ADDITIONAL_TRIE_INDEX]-indexes[UPROPS_EXCEPTIONS_TOP_INDEX]),
|
|
|
|
outData32+indexes[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+indexes[UPROPS_ADDITIONAL_TRIE_INDEX],
|
|
|
|
4*(indexes[UPROPS_ADDITIONAL_VECTORS_INDEX]-indexes[UPROPS_ADDITIONAL_TRIE_INDEX]),
|
|
|
|
outData32+indexes[UPROPS_ADDITIONAL_TRIE_INDEX],
|
|
|
|
pErrorCode);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* swap the properties vectors
|
|
|
|
* PV const uint32_t propsVectors[(i6-i4)/i5][i5]==uint32_t propsVectors[i6-i4];
|
|
|
|
*/
|
|
|
|
ds->swapArray32(ds,
|
|
|
|
inData32+indexes[UPROPS_ADDITIONAL_VECTORS_INDEX],
|
|
|
|
4*(indexes[UPROPS_RESERVED_INDEX]-indexes[UPROPS_ADDITIONAL_VECTORS_INDEX]),
|
|
|
|
outData32+indexes[UPROPS_ADDITIONAL_VECTORS_INDEX],
|
|
|
|
pErrorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* i6 reservedItemIndex; -- 32-bit unit index to the top of the properties vectors table */
|
|
|
|
return headerSize+4*indexes[UPROPS_RESERVED_INDEX];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* constants and macros for access to the data ------------------------------ */
|
2000-04-24 22:44:06 +00:00
|
|
|
|
|
|
|
/* getting a uint32_t properties word from the data */
|
2003-08-22 23:26:53 +00:00
|
|
|
#define HAVE_DATA (havePropsData>0 || loadPropsData()>0)
|
2000-04-24 22:44:06 +00:00
|
|
|
#define VALIDATE(c) (((uint32_t)(c))<=0x10ffff && HAVE_DATA)
|
2001-12-06 01:23:47 +00:00
|
|
|
#define GET_PROPS_UNSAFE(c, result) \
|
|
|
|
UTRIE_GET16(&propsTrie, c, result); \
|
|
|
|
(result)=props32Table[(result)]
|
|
|
|
#define GET_PROPS(c, result) \
|
|
|
|
if(HAVE_DATA) { \
|
|
|
|
GET_PROPS_UNSAFE(c, result); \
|
|
|
|
} else { \
|
|
|
|
(result)=0; \
|
|
|
|
}
|
2000-04-24 22:44:06 +00:00
|
|
|
|
|
|
|
/* finding an exception value */
|
|
|
|
#define HAVE_EXCEPTION_VALUE(flags, index) ((flags)&(1UL<<(index)))
|
|
|
|
|
2000-05-18 17:47:11 +00:00
|
|
|
/* number of bits in an 8-bit integer value */
|
|
|
|
#define EXC_GROUP 8
|
2001-08-29 18:13:00 +00:00
|
|
|
static const uint8_t flagsOffset[256]={
|
2000-05-18 17:47:11 +00:00
|
|
|
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
|
2000-04-24 22:44:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define ADD_EXCEPTION_OFFSET(flags, index, offset) { \
|
2000-05-18 17:47:11 +00:00
|
|
|
if((index)>=EXC_GROUP) { \
|
|
|
|
(offset)+=flagsOffset[(flags)&((1<<EXC_GROUP)-1)]; \
|
|
|
|
(flags)>>=EXC_GROUP; \
|
|
|
|
(index)-=EXC_GROUP; \
|
2000-04-24 22:44:06 +00:00
|
|
|
} \
|
|
|
|
(offset)+=flagsOffset[(flags)&((1<<(index))-1)]; \
|
|
|
|
}
|
|
|
|
|
2001-02-14 00:47:36 +00:00
|
|
|
U_CFUNC UBool
|
2002-11-08 02:22:15 +00:00
|
|
|
uprv_haveProperties(UErrorCode *pErrorCode) {
|
2003-08-22 23:26:53 +00:00
|
|
|
U_ASSERT(havePropsData>0);
|
|
|
|
if (havePropsData == 0) {
|
|
|
|
uprv_loadPropsData(pErrorCode);
|
2002-11-08 02:22:15 +00:00
|
|
|
}
|
2003-08-22 23:26:53 +00:00
|
|
|
return (havePropsData>0);
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
|
|
|
|
2003-08-22 23:26:53 +00:00
|
|
|
|
2000-05-18 17:47:11 +00:00
|
|
|
/* API functions ------------------------------------------------------------ */
|
|
|
|
|
|
|
|
/* Gets the Unicode character's general category.*/
|
|
|
|
U_CAPI int8_t U_EXPORT2
|
|
|
|
u_charType(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
|
|
|
return (int8_t)GET_CATEGORY(props);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
2002-01-12 00:11:09 +00:00
|
|
|
/* Enumerate all code points with their general categories. */
|
|
|
|
struct _EnumTypeCallback {
|
|
|
|
UCharEnumTypeRange *enumRange;
|
|
|
|
const void *context;
|
|
|
|
};
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static UBool U_CALLCONV
|
|
|
|
_enumTypeRange(const void *context, UChar32 start, UChar32 limit, uint32_t value) {
|
|
|
|
/* just cast the value to UCharCategory */
|
|
|
|
return ((struct _EnumTypeCallback *)context)->
|
|
|
|
enumRange(((struct _EnumTypeCallback *)context)->context,
|
|
|
|
start, limit, (UCharCategory)value);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
u_enumCharTypes(UCharEnumTypeRange *enumRange, const void *context) {
|
|
|
|
struct _EnumTypeCallback callback;
|
|
|
|
|
|
|
|
if(enumRange==NULL || !HAVE_DATA) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback.enumRange=enumRange;
|
|
|
|
callback.context=context;
|
|
|
|
utrie_enum(&propsTrie, _enumTypeValue, _enumTypeRange, &callback);
|
|
|
|
}
|
|
|
|
|
2000-05-18 17:47:11 +00:00
|
|
|
/* Checks if ch is a lower case letter.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_islower(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
|
|
|
return (UBool)(GET_CATEGORY(props)==U_LOWERCASE_LETTER);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if ch is an upper case letter.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isupper(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
|
|
|
return (UBool)(GET_CATEGORY(props)==U_UPPERCASE_LETTER);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if ch is a title case letter; usually upper case letters.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_istitle(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
|
|
|
return (UBool)(GET_CATEGORY(props)==U_TITLECASE_LETTER);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if ch is a decimal digit. */
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isdigit(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2003-02-09 21:02:26 +00:00
|
|
|
return (UBool)(GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
2003-04-24 23:09:26 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
u_isxdigit(UChar32 c) {
|
|
|
|
uint32_t props;
|
|
|
|
|
|
|
|
/* check ASCII and Fullwidth ASCII a-fA-F */
|
|
|
|
if(
|
|
|
|
(c<=0x66 && c>=0x41 && (c<=0x46 || c>=0x61)) ||
|
|
|
|
(c>=0xff21 && c<=0xff46 && (c<=0xff26 || c>=0xff41))
|
|
|
|
) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GET_PROPS(c, props);
|
|
|
|
return (UBool)(GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER);
|
|
|
|
}
|
|
|
|
|
2000-05-18 17:47:11 +00:00
|
|
|
/* Checks if the Unicode character is a letter.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isalpha(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2003-02-11 23:30:09 +00:00
|
|
|
return (UBool)((CAT_MASK(props)&U_GC_L_MASK)!=0);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if ch is a letter or a decimal digit */
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isalnum(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2003-02-11 23:30:09 +00:00
|
|
|
return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_ND_MASK))!=0);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if ch is a unicode character with assigned character type.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isdefined(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
|
|
|
return (UBool)(GET_CATEGORY(props)!=0);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if the Unicode character is a base form character that can take a diacritic.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isbase(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2003-02-11 23:30:09 +00:00
|
|
|
return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_N_MASK|U_GC_MC_MASK|U_GC_ME_MASK))!=0);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if the Unicode character is a control character.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_iscntrl(UChar32 c) {
|
2002-02-24 21:00:19 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2003-02-11 23:30:09 +00:00
|
|
|
return (UBool)((CAT_MASK(props)&(U_GC_CC_MASK|U_GC_CF_MASK|U_GC_ZL_MASK|U_GC_ZP_MASK))!=0);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
2003-02-09 21:02:26 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
u_isISOControl(UChar32 c) {
|
|
|
|
return (uint32_t)c<=0x9f && (c<=0x1f || c>=0x7f);
|
|
|
|
}
|
|
|
|
|
2002-02-24 21:00:19 +00:00
|
|
|
/* Some control characters that are used as space. */
|
|
|
|
#define IS_THAT_CONTROL_SPACE(c) \
|
2003-02-11 23:30:09 +00:00
|
|
|
(c<=0x9f && ((c>=TAB && c<=CR) || (c>=0x1c && c <=0x1f) || c==NL))
|
2002-02-24 21:00:19 +00:00
|
|
|
|
2000-05-18 17:47:11 +00:00
|
|
|
/* Checks if the Unicode character is a space character.*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isspace(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2003-02-11 23:30:09 +00:00
|
|
|
return (UBool)((CAT_MASK(props)&U_GC_Z_MASK)!=0 || IS_THAT_CONTROL_SPACE(c));
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
2003-02-09 21:02:26 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
u_isJavaSpaceChar(UChar32 c) {
|
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2003-02-11 23:30:09 +00:00
|
|
|
return (UBool)((CAT_MASK(props)&U_GC_Z_MASK)!=0);
|
2003-02-09 21:02:26 +00:00
|
|
|
}
|
|
|
|
|
2000-05-18 17:47:11 +00:00
|
|
|
/* Checks if the Unicode character is a whitespace character.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isWhitespace(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2003-02-09 21:02:26 +00:00
|
|
|
return (UBool)(
|
2003-02-11 23:30:09 +00:00
|
|
|
((CAT_MASK(props)&U_GC_Z_MASK)!=0 &&
|
2003-02-09 21:02:26 +00:00
|
|
|
c!=NBSP && c!=FIGURESP && c!=NNBSP) || /* exclude no-break spaces */
|
|
|
|
IS_THAT_CONTROL_SPACE(c)
|
|
|
|
);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
2003-04-24 23:09:26 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
u_isblank(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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-18 17:47:11 +00:00
|
|
|
/* Checks if the Unicode character is printable.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2001-03-15 02:01:25 +00:00
|
|
|
u_isprint(UChar32 c) {
|
2002-02-24 21:00:19 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2003-02-11 23:30:09 +00:00
|
|
|
/* comparing ==0 returns FALSE for the categories mentioned */
|
|
|
|
return (UBool)((CAT_MASK(props)&U_GC_C_MASK)==0);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
2003-04-24 23:09:26 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
u_isgraph(UChar32 c) {
|
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
|
|
|
/* comparing ==0 returns FALSE for the categories mentioned */
|
|
|
|
return (UBool)((CAT_MASK(props)&
|
|
|
|
(U_GC_CC_MASK|U_GC_CF_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;
|
|
|
|
GET_PROPS(c, props);
|
|
|
|
return (UBool)((CAT_MASK(props)&U_GC_P_MASK)!=0);
|
|
|
|
}
|
|
|
|
|
2000-05-18 17:47:11 +00:00
|
|
|
/* Checks if the Unicode character can start a Unicode identifier.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isIDStart(UChar32 c) {
|
|
|
|
/* same as u_isalpha() */
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2003-02-11 23:30:09 +00:00
|
|
|
return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_NL_MASK))!=0);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if the Unicode character can be a Unicode identifier part other than starting the
|
|
|
|
identifier.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isIDPart(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2000-08-08 23:26:10 +00:00
|
|
|
return (UBool)(
|
2003-02-11 23:30:09 +00:00
|
|
|
(CAT_MASK(props)&
|
|
|
|
(U_GC_ND_MASK|U_GC_NL_MASK|
|
|
|
|
U_GC_L_MASK|
|
|
|
|
U_GC_PC_MASK|U_GC_MC_MASK|U_GC_MN_MASK)
|
2000-05-18 17:47:11 +00:00
|
|
|
)!=0 ||
|
2000-08-08 23:26:10 +00:00
|
|
|
u_isIDIgnorable(c));
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Checks if the Unicode character can be ignorable in a Java or Unicode identifier.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isIDIgnorable(UChar32 c) {
|
2003-02-09 21:02:26 +00:00
|
|
|
if(c<=0x9f) {
|
|
|
|
return u_isISOControl(c) && !IS_THAT_CONTROL_SPACE(c);
|
|
|
|
} else {
|
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
|
|
|
return (UBool)(GET_CATEGORY(props)==U_FORMAT_CHAR);
|
|
|
|
}
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Checks if the Unicode character can start a Java identifier.*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isJavaIDStart(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2003-02-11 23:30:09 +00:00
|
|
|
return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_SC_MASK|U_GC_PC_MASK))!=0);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Checks if the Unicode character can be a Java identifier part other than starting the
|
|
|
|
* identifier.
|
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-05-18 17:47:11 +00:00
|
|
|
u_isJavaIDPart(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2000-08-08 23:26:10 +00:00
|
|
|
return (UBool)(
|
2003-02-11 23:30:09 +00:00
|
|
|
(CAT_MASK(props)&
|
|
|
|
(U_GC_ND_MASK|U_GC_NL_MASK|
|
|
|
|
U_GC_L_MASK|
|
|
|
|
U_GC_SC_MASK|U_GC_PC_MASK|
|
|
|
|
U_GC_MC_MASK|U_GC_MN_MASK)
|
2000-05-18 17:47:11 +00:00
|
|
|
)!=0 ||
|
2000-08-08 23:26:10 +00:00
|
|
|
u_isIDIgnorable(c));
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Transforms the Unicode character to its lower case equivalent.*/
|
|
|
|
U_CAPI UChar32 U_EXPORT2
|
|
|
|
u_tolower(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2000-05-18 17:47:11 +00:00
|
|
|
if(!PROPS_VALUE_IS_EXCEPTION(props)) {
|
2003-02-11 23:30:09 +00:00
|
|
|
if(CAT_MASK(props)&(U_GC_LU_MASK|U_GC_LT_MASK)) {
|
2000-05-18 17:47:11 +00:00
|
|
|
return c+GET_SIGNED_VALUE(props);
|
|
|
|
}
|
|
|
|
} else {
|
2001-12-06 01:23:47 +00:00
|
|
|
const uint32_t *pe=GET_EXCEPTIONS(props);
|
2000-05-18 17:47:11 +00:00
|
|
|
uint32_t firstExceptionValue=*pe;
|
|
|
|
if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_LOWERCASE)) {
|
|
|
|
int i=EXC_LOWERCASE;
|
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
|
|
|
return (UChar32)*pe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c; /* no mapping - return c itself */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Transforms the Unicode character to its upper case equivalent.*/
|
|
|
|
U_CAPI UChar32 U_EXPORT2
|
|
|
|
u_toupper(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2000-05-18 17:47:11 +00:00
|
|
|
if(!PROPS_VALUE_IS_EXCEPTION(props)) {
|
|
|
|
if(GET_CATEGORY(props)==U_LOWERCASE_LETTER) {
|
|
|
|
return c-GET_SIGNED_VALUE(props);
|
|
|
|
}
|
|
|
|
} else {
|
2001-12-06 01:23:47 +00:00
|
|
|
const uint32_t *pe=GET_EXCEPTIONS(props);
|
2000-05-18 17:47:11 +00:00
|
|
|
uint32_t firstExceptionValue=*pe;
|
|
|
|
if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_UPPERCASE)) {
|
|
|
|
int i=EXC_UPPERCASE;
|
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
|
|
|
return (UChar32)*pe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c; /* no mapping - return c itself */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Transforms the Unicode character to its title case equivalent.*/
|
|
|
|
U_CAPI UChar32 U_EXPORT2
|
|
|
|
u_totitle(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2000-05-18 17:47:11 +00:00
|
|
|
if(!PROPS_VALUE_IS_EXCEPTION(props)) {
|
|
|
|
if(GET_CATEGORY(props)==U_LOWERCASE_LETTER) {
|
|
|
|
/* here, titlecase is same as uppercase */
|
|
|
|
return c-GET_SIGNED_VALUE(props);
|
|
|
|
}
|
|
|
|
} else {
|
2001-12-06 01:23:47 +00:00
|
|
|
const uint32_t *pe=GET_EXCEPTIONS(props);
|
2000-05-18 17:47:11 +00:00
|
|
|
uint32_t firstExceptionValue=*pe;
|
|
|
|
if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_TITLECASE)) {
|
|
|
|
int i=EXC_TITLECASE;
|
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
|
|
|
return (UChar32)*pe;
|
|
|
|
} else if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_UPPERCASE)) {
|
|
|
|
/* here, titlecase is same as uppercase */
|
|
|
|
int i=EXC_UPPERCASE;
|
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
|
|
|
return (UChar32)*pe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c; /* no mapping - return c itself */
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
u_charDigitValue(UChar32 c) {
|
2002-03-04 01:25:51 +00:00
|
|
|
uint32_t props, numericType;
|
2001-12-06 01:23:47 +00:00
|
|
|
GET_PROPS(c, props);
|
2002-03-04 01:25:51 +00:00
|
|
|
numericType=GET_NUMERIC_TYPE(props);
|
|
|
|
|
|
|
|
if(numericType==1) {
|
|
|
|
if(!PROPS_VALUE_IS_EXCEPTION(props)) {
|
2000-05-18 17:47:11 +00:00
|
|
|
return GET_SIGNED_VALUE(props);
|
2002-03-04 01:25:51 +00:00
|
|
|
} 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;
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-09 19:04:01 +00:00
|
|
|
return -1;
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
2002-07-04 00:17:12 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
|
|
|
u_getNumericValue(UChar32 c) {
|
|
|
|
uint32_t props, numericType;
|
|
|
|
GET_PROPS(c, props);
|
|
|
|
numericType=GET_NUMERIC_TYPE(props);
|
|
|
|
|
|
|
|
if(numericType==0 || numericType>=(int32_t)U_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;
|
|
|
|
|
2002-07-13 01:04:28 +00:00
|
|
|
double numValue;
|
2002-07-04 00:17:12 +00:00
|
|
|
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;
|
2002-07-13 01:04:28 +00:00
|
|
|
int32_t numerator;
|
|
|
|
|
2002-07-04 00:17:12 +00:00
|
|
|
ADD_EXCEPTION_OFFSET(flags, i, p);
|
|
|
|
numerator=(int32_t)*p;
|
2002-07-13 01:04:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
2002-07-04 00:17:12 +00:00
|
|
|
} else {
|
2002-07-13 01:04:28 +00:00
|
|
|
numValue=0.;
|
2002-07-04 00:17:12 +00:00
|
|
|
}
|
|
|
|
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:
|
2002-07-13 01:04:28 +00:00
|
|
|
return numValue;
|
2002-07-04 00:17:12 +00:00
|
|
|
case 1UL<<EXC_DENOMINATOR_VALUE:
|
|
|
|
return (double)1./(double)denominator;
|
|
|
|
case (1UL<<EXC_NUMERIC_VALUE)|(1UL<<EXC_DENOMINATOR_VALUE):
|
2002-07-13 01:04:28 +00:00
|
|
|
return numValue/(double)denominator;
|
2002-07-04 00:17:12 +00:00
|
|
|
case 0: /* none (should not occur with numericType>0) */
|
|
|
|
default:
|
|
|
|
return U_NO_NUMERIC_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-18 17:47:11 +00:00
|
|
|
/* Gets the character's linguistic directionality.*/
|
|
|
|
U_CAPI UCharDirection U_EXPORT2
|
|
|
|
u_charDirection(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2003-04-03 19:41:00 +00:00
|
|
|
return (UCharDirection)GET_BIDI_CLASS(props);
|
2000-05-18 17:47:11 +00:00
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2000-04-24 22:44:06 +00:00
|
|
|
u_isMirrored(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2002-03-04 01:25:51 +00:00
|
|
|
return (UBool)(props&(1UL<<UPROPS_MIRROR_SHIFT) ? TRUE : FALSE);
|
2000-04-24 22:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UChar32 U_EXPORT2
|
|
|
|
u_charMirror(UChar32 c) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2002-03-04 01:25:51 +00:00
|
|
|
if((props&(1UL<<UPROPS_MIRROR_SHIFT))==0) {
|
2000-04-24 22:44:06 +00:00
|
|
|
/* 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 {
|
2001-12-06 01:23:47 +00:00
|
|
|
const uint32_t *pe=GET_EXCEPTIONS(props);
|
2000-04-24 22:44:06 +00:00
|
|
|
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;
|
|
|
|
} else {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-04 01:25:51 +00:00
|
|
|
/* ICU 2.1: u_getCombiningClass() moved to unorm.cpp */
|
2001-01-23 23:45:21 +00:00
|
|
|
|
2001-11-12 23:01:17 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-09-21 00:27:17 +00:00
|
|
|
u_digit(UChar32 ch, int8_t radix) {
|
|
|
|
int8_t value;
|
|
|
|
if((uint8_t)(radix-2)<=(36-2)) {
|
|
|
|
value=(int8_t)u_charDigitValue(ch);
|
|
|
|
if(value<0) {
|
|
|
|
/* ch is not a decimal digit, try latin letters */
|
|
|
|
if(ch>=0x61 && ch<=0x7A) {
|
|
|
|
value=(int8_t)(ch-0x57); /* ch - 'a' + 10 */
|
|
|
|
} else if(ch>=0x41 && ch<=0x5A) {
|
|
|
|
value=(int8_t)(ch-0x37); /* ch - 'A' + 10 */
|
2003-04-24 23:09:26 +00:00
|
|
|
} else if(ch>=0xFF41 && ch<=0xFF5A) {
|
|
|
|
value=(int8_t)(ch-0xFF37); /* fullwidth ASCII a-z */
|
|
|
|
} else if(ch>=0xFF21 && ch<=0xFF3A) {
|
|
|
|
value=(int8_t)(ch-0xFF17); /* fullwidth ASCII A-Z */
|
2001-09-21 00:27:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
value=-1; /* invalid radix */
|
|
|
|
}
|
|
|
|
return (int8_t)((value<radix) ? value : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UChar32 U_EXPORT2
|
|
|
|
u_forDigit(int32_t digit, int8_t radix) {
|
|
|
|
if((uint8_t)(radix-2)>(36-2) || (uint32_t)digit>=(uint32_t)radix) {
|
|
|
|
return 0;
|
|
|
|
} else if(digit<10) {
|
|
|
|
return (UChar32)(0x30+digit);
|
|
|
|
} else {
|
|
|
|
return (UChar32)((0x61-10)+digit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-06 00:52:44 +00:00
|
|
|
/* miscellaneous, and support for uprops.c ---------------------------------- */
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
u_getUnicodeVersion(UVersionInfo versionArray) {
|
2000-04-24 22:44:06 +00:00
|
|
|
if(versionArray!=NULL) {
|
2001-11-15 00:05:07 +00:00
|
|
|
if(HAVE_DATA) {
|
|
|
|
uprv_memcpy(versionArray, dataVersion, U_MAX_VERSION_LENGTH);
|
|
|
|
} else {
|
|
|
|
uprv_memset(versionArray, 0, U_MAX_VERSION_LENGTH);
|
|
|
|
}
|
2000-04-24 22:44:06 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-11-16 21:43:12 +00:00
|
|
|
|
2002-02-25 22:40:32 +00:00
|
|
|
U_CFUNC uint32_t
|
|
|
|
u_getUnicodeProperties(UChar32 c, int32_t column) {
|
|
|
|
uint16_t vecIndex;
|
|
|
|
|
2002-07-04 00:17:12 +00:00
|
|
|
if(column==-1) {
|
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
|
|
|
return props;
|
|
|
|
} else if( !HAVE_DATA || countPropsVectors==0 ||
|
|
|
|
(uint32_t)c>0x10ffff ||
|
|
|
|
column<0 || column>=propsVectorsColumns
|
2002-02-25 22:40:32 +00:00
|
|
|
) {
|
|
|
|
return 0;
|
2002-07-04 00:17:12 +00:00
|
|
|
} else {
|
|
|
|
UTRIE_GET16(&propsVectorsTrie, c, vecIndex);
|
|
|
|
return propsVectors[vecIndex+column];
|
2002-02-25 22:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-04 16:41:49 +00:00
|
|
|
U_CFUNC int32_t
|
2003-03-07 21:49:09 +00:00
|
|
|
uprv_getMaxValues(int32_t column) {
|
2002-07-04 16:41:49 +00:00
|
|
|
if(HAVE_DATA) {
|
2003-03-07 21:49:09 +00:00
|
|
|
switch(column) {
|
|
|
|
case 0:
|
|
|
|
return indexes[UPROPS_MAX_VALUES_INDEX];
|
|
|
|
case 2:
|
|
|
|
return indexes[UPROPS_MAX_VALUES_2_INDEX];
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2002-07-04 16:41:49 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-06 00:52:44 +00:00
|
|
|
static UBool U_CALLCONV
|
|
|
|
_enumPropertyStartsRange(const void *context, UChar32 start, UChar32 limit, uint32_t value) {
|
|
|
|
/* add the start code point to the USet */
|
|
|
|
uset_add((USet *)context, start);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define USET_ADD_CP_AND_NEXT(set, cp) uset_add(set, cp); uset_add(set, cp+1)
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
2003-04-09 17:34:24 +00:00
|
|
|
uchar_addPropertyStarts(USet *set, UErrorCode *pErrorCode) {
|
2003-03-08 02:00:06 +00:00
|
|
|
UChar32 c;
|
|
|
|
int32_t value, value2;
|
|
|
|
|
2002-11-06 00:52:44 +00:00
|
|
|
if(!HAVE_DATA) {
|
2003-04-09 17:34:24 +00:00
|
|
|
*pErrorCode=dataErrorCode;
|
2002-11-06 00:52:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add the start code point of each same-value range of each trie */
|
|
|
|
utrie_enum(&propsTrie, NULL, _enumPropertyStartsRange, set);
|
|
|
|
utrie_enum(&propsVectorsTrie, NULL, _enumPropertyStartsRange, set);
|
|
|
|
|
|
|
|
/* add code points with hardcoded properties, plus the ones following them */
|
|
|
|
|
|
|
|
/* add for IS_THAT_CONTROL_SPACE() */
|
|
|
|
uset_add(set, TAB); /* range TAB..CR */
|
|
|
|
uset_add(set, CR+1);
|
|
|
|
uset_add(set, 0x1c);
|
|
|
|
uset_add(set, 0x1f+1);
|
|
|
|
USET_ADD_CP_AND_NEXT(set, NL);
|
|
|
|
|
|
|
|
/* add for u_isIDIgnorable() what was not added above */
|
|
|
|
uset_add(set, DEL); /* range DEL..NBSP-1, NBSP added below */
|
|
|
|
uset_add(set, HAIRSP);
|
|
|
|
uset_add(set, RLM+1);
|
|
|
|
uset_add(set, INHSWAP);
|
|
|
|
uset_add(set, NOMDIG+1);
|
|
|
|
USET_ADD_CP_AND_NEXT(set, ZWNBSP);
|
|
|
|
|
|
|
|
/* add no-break spaces for u_isWhitespace() what was not added above */
|
|
|
|
USET_ADD_CP_AND_NEXT(set, NBSP);
|
2003-02-09 21:02:26 +00:00
|
|
|
USET_ADD_CP_AND_NEXT(set, FIGURESP);
|
2002-11-06 00:52:44 +00:00
|
|
|
USET_ADD_CP_AND_NEXT(set, NNBSP);
|
|
|
|
|
|
|
|
/* add for u_charDigitValue() */
|
|
|
|
USET_ADD_CP_AND_NEXT(set, 0x3007);
|
|
|
|
USET_ADD_CP_AND_NEXT(set, 0x4e00);
|
|
|
|
USET_ADD_CP_AND_NEXT(set, 0x4e8c);
|
|
|
|
USET_ADD_CP_AND_NEXT(set, 0x4e09);
|
|
|
|
USET_ADD_CP_AND_NEXT(set, 0x56db);
|
|
|
|
USET_ADD_CP_AND_NEXT(set, 0x4e94);
|
|
|
|
USET_ADD_CP_AND_NEXT(set, 0x516d);
|
|
|
|
USET_ADD_CP_AND_NEXT(set, 0x4e03);
|
|
|
|
USET_ADD_CP_AND_NEXT(set, 0x516b);
|
|
|
|
USET_ADD_CP_AND_NEXT(set, 0x4e5d);
|
|
|
|
|
|
|
|
/* add for u_digit() */
|
2002-11-06 20:50:03 +00:00
|
|
|
uset_add(set, U_a);
|
|
|
|
uset_add(set, U_z+1);
|
|
|
|
uset_add(set, U_A);
|
|
|
|
uset_add(set, U_Z+1);
|
2002-11-06 00:52:44 +00:00
|
|
|
|
|
|
|
/* add for UCHAR_DEFAULT_IGNORABLE_CODE_POINT what was not added above */
|
|
|
|
uset_add(set, WJ); /* range WJ..NOMDIG */
|
|
|
|
uset_add(set, 0xfff0);
|
|
|
|
uset_add(set, 0xfffb+1);
|
|
|
|
uset_add(set, 0xe0000);
|
|
|
|
uset_add(set, 0xe0fff+1);
|
|
|
|
|
|
|
|
/* add for UCHAR_GRAPHEME_BASE and others */
|
|
|
|
USET_ADD_CP_AND_NEXT(set, CGJ);
|
|
|
|
|
|
|
|
/* add for UCHAR_JOINING_TYPE */
|
|
|
|
uset_add(set, ZWNJ); /* range ZWNJ..ZWJ */
|
|
|
|
uset_add(set, ZWJ+1);
|
|
|
|
|
2003-06-06 19:03:44 +00:00
|
|
|
/*
|
|
|
|
* Add Jamo type boundaries for UCHAR_HANGUL_SYLLABLE_TYPE.
|
|
|
|
* First, we add fixed boundaries for the blocks of Jamos.
|
|
|
|
* Then we check in loops to see where the current Unicode version
|
|
|
|
* actually stops assigning such Jamos. We start each loop
|
|
|
|
* at the end of the per-Jamo-block assignments in Unicode 4 or earlier.
|
|
|
|
* (These have not changed since Unicode 2.)
|
|
|
|
*/
|
2003-03-08 02:00:06 +00:00
|
|
|
uset_add(set, 0x1100);
|
|
|
|
value=U_HST_LEADING_JAMO;
|
|
|
|
for(c=0x115a; c<=0x115f; ++c) {
|
|
|
|
value2=u_getIntPropertyValue(c, UCHAR_HANGUL_SYLLABLE_TYPE);
|
|
|
|
if(value!=value2) {
|
|
|
|
value=value2;
|
|
|
|
uset_add(set, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uset_add(set, 0x1160);
|
|
|
|
value=U_HST_VOWEL_JAMO;
|
|
|
|
for(c=0x11a3; c<=0x11a7; ++c) {
|
|
|
|
value2=u_getIntPropertyValue(c, UCHAR_HANGUL_SYLLABLE_TYPE);
|
|
|
|
if(value!=value2) {
|
|
|
|
value=value2;
|
|
|
|
uset_add(set, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uset_add(set, 0x11a8);
|
|
|
|
value=U_HST_TRAILING_JAMO;
|
|
|
|
for(c=0x11fa; c<=0x11ff; ++c) {
|
|
|
|
value2=u_getIntPropertyValue(c, UCHAR_HANGUL_SYLLABLE_TYPE);
|
|
|
|
if(value!=value2) {
|
|
|
|
value=value2;
|
|
|
|
uset_add(set, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-06 00:52:44 +00:00
|
|
|
/*
|
|
|
|
* Omit code points with hardcoded specialcasing properties
|
|
|
|
* because we do not build property UnicodeSets for them right now.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2000-11-16 21:43:12 +00:00
|
|
|
/* string casing ------------------------------------------------------------ */
|
|
|
|
|
2001-01-31 18:20:26 +00:00
|
|
|
/*
|
|
|
|
* These internal string case mapping functions are here instead of ustring.c
|
|
|
|
* because we need efficient access to the character properties.
|
2002-02-20 02:07:29 +00:00
|
|
|
*
|
|
|
|
* This section contains helper functions that check for conditions
|
|
|
|
* in the input text surrounding the current code point
|
|
|
|
* according to SpecialCasing.txt.
|
|
|
|
*
|
|
|
|
* Starting with ICU 2.1, the "surrounding text" is passed in as an instance of
|
|
|
|
* UCharIterator to allow the core case mapping functions to be used
|
|
|
|
* inside transliterators (using Replaceable instead of UnicodeString/UChar *)
|
|
|
|
* etc.
|
|
|
|
*
|
|
|
|
* Each helper function gets the index
|
|
|
|
* - after the current code point if it looks at following text
|
|
|
|
* - before the current code point if it looks at preceding text
|
2002-06-07 18:53:49 +00:00
|
|
|
*
|
|
|
|
* Unicode 3.2 UAX 21 "Case Mappings" defines the conditions as follows:
|
|
|
|
*
|
|
|
|
* Final_Sigma
|
|
|
|
* C is preceded by a sequence consisting of
|
|
|
|
* a cased letter and a case-ignorable sequence,
|
|
|
|
* and C is not followed by a sequence consisting of
|
|
|
|
* an ignorable sequence and then a cased letter.
|
|
|
|
*
|
|
|
|
* More_Above
|
|
|
|
* C is followed by one or more characters of combining class 230 (ABOVE)
|
|
|
|
* in the combining character sequence.
|
|
|
|
*
|
|
|
|
* After_Soft_Dotted
|
|
|
|
* The last preceding character with combining class of zero before C
|
|
|
|
* was Soft_Dotted,
|
|
|
|
* and there is no intervening combining character class 230 (ABOVE).
|
|
|
|
*
|
|
|
|
* Before_Dot
|
|
|
|
* C is followed by combining dot above (U+0307).
|
|
|
|
* Any sequence of characters with a combining class that is neither 0 nor 230
|
|
|
|
* may intervene between the current character and the combining dot above.
|
|
|
|
*
|
2003-02-16 19:20:04 +00:00
|
|
|
* The erratum from 2002-10-31 adds the condition
|
|
|
|
*
|
|
|
|
* After_I
|
|
|
|
* The last preceding base character was an uppercase I, and there is no
|
|
|
|
* intervening combining character class 230 (ABOVE).
|
|
|
|
*
|
|
|
|
* (See Jitterbug 2344 and the comments on After_I below.)
|
|
|
|
*
|
2002-06-07 18:53:49 +00:00
|
|
|
* Helper definitions in Unicode 3.2 UAX 21:
|
|
|
|
*
|
|
|
|
* D1. A character C is defined to be cased
|
|
|
|
* if it meets any of the following criteria:
|
|
|
|
*
|
|
|
|
* - The general category of C is Titlecase Letter (Lt)
|
|
|
|
* - In [CoreProps], C has one of the properties Uppercase, or Lowercase
|
|
|
|
* - Given D = NFD(C), then it is not the case that:
|
|
|
|
* D = UCD_lower(D) = UCD_upper(D) = UCD_title(D)
|
|
|
|
* (This third criterium does not add any characters to the list
|
|
|
|
* for Unicode 3.2. Ignored.)
|
|
|
|
*
|
|
|
|
* D2. A character C is defined to be case-ignorable
|
|
|
|
* if it meets either of the following criteria:
|
|
|
|
*
|
|
|
|
* - The general category of C is
|
|
|
|
* Nonspacing Mark (Mn), or Enclosing Mark (Me), or Format Control (Cf), or
|
|
|
|
* Letter Modifier (Lm), or Symbol Modifier (Sk)
|
|
|
|
* - C is one of the following characters
|
|
|
|
* U+0027 APOSTROPHE
|
|
|
|
* U+00AD SOFT HYPHEN (SHY)
|
|
|
|
* U+2019 RIGHT SINGLE QUOTATION MARK
|
|
|
|
* (the preferred character for apostrophe)
|
|
|
|
*
|
|
|
|
* D3. A case-ignorable sequence is a sequence of
|
|
|
|
* zero or more case-ignorable characters.
|
2001-01-31 18:20:26 +00:00
|
|
|
*/
|
|
|
|
|
2003-05-06 01:37:52 +00:00
|
|
|
#if UCONFIG_NO_NORMALIZATION
|
|
|
|
/* no normalization - no combining classes */
|
|
|
|
static U_INLINE uint8_t
|
|
|
|
u_getCombiningClass(UChar32 c) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-01-31 18:20:26 +00:00
|
|
|
enum {
|
|
|
|
LOC_ROOT,
|
2001-02-02 23:24:40 +00:00
|
|
|
LOC_TURKISH,
|
|
|
|
LOC_LITHUANIAN
|
2001-01-31 18:20:26 +00:00
|
|
|
};
|
|
|
|
|
2001-02-02 23:24:40 +00:00
|
|
|
static int32_t
|
|
|
|
getCaseLocale(const char *locale) {
|
2001-10-17 00:17:15 +00:00
|
|
|
char lang[32];
|
|
|
|
UErrorCode errorCode;
|
|
|
|
int32_t length;
|
|
|
|
|
|
|
|
errorCode=U_ZERO_ERROR;
|
|
|
|
length=uloc_getLanguage(locale, lang, sizeof(lang), &errorCode);
|
|
|
|
if(U_FAILURE(errorCode) || length!=2) {
|
|
|
|
return LOC_ROOT;
|
2001-02-02 23:24:40 +00:00
|
|
|
}
|
2001-10-17 00:17:15 +00:00
|
|
|
|
2001-11-30 23:53:55 +00:00
|
|
|
if( (lang[0]=='t' && lang[1]=='r') ||
|
|
|
|
(lang[0]=='a' && lang[1]=='z')
|
2001-02-02 23:24:40 +00:00
|
|
|
) {
|
|
|
|
return LOC_TURKISH;
|
2001-11-30 23:53:55 +00:00
|
|
|
} else if(lang[0]=='l' && lang[1]=='t') {
|
2001-02-02 23:24:40 +00:00
|
|
|
return LOC_LITHUANIAN;
|
|
|
|
} else {
|
|
|
|
return LOC_ROOT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-07 18:53:49 +00:00
|
|
|
/* Is case-ignorable? */
|
2001-10-23 00:38:03 +00:00
|
|
|
static U_INLINE UBool
|
2001-10-17 00:17:15 +00:00
|
|
|
isCaseIgnorable(UChar32 c, uint32_t category) {
|
2002-06-07 18:53:49 +00:00
|
|
|
return (FLAG(category)&(_Mn|_Me|_Cf|_Lm|_Sk))!=0 ||
|
|
|
|
c==0x27 || c==0xad || c==0x2019;
|
2001-10-17 00:17:15 +00:00
|
|
|
}
|
|
|
|
|
2002-06-07 18:53:49 +00:00
|
|
|
/* Is this a "cased" character? */
|
|
|
|
static U_INLINE UBool
|
|
|
|
isCased(UChar32 c, uint32_t category) {
|
|
|
|
/* Lt+Uppercase+Lowercase = Lt+Lu+Ll+Other_Uppercase+Other_Lowercase */
|
|
|
|
return (FLAG(category)&(_Lt|_Lu|_Ll))!=0 ||
|
2003-03-07 21:49:09 +00:00
|
|
|
(u_getUnicodeProperties(c, 1)&(FLAG(UPROPS_UPPERCASE)|FLAG(UPROPS_LOWERCASE)))!=0;
|
2002-06-07 18:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Is Soft_Dotted? */
|
|
|
|
static U_INLINE UBool
|
|
|
|
isSoftDotted(UChar32 c) {
|
|
|
|
return (u_getUnicodeProperties(c, 1)&FLAG(UPROPS_SOFT_DOTTED))!=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is followed by {case-ignorable}* cased ? */
|
2001-10-17 00:17:15 +00:00
|
|
|
static UBool
|
2002-02-20 02:07:29 +00:00
|
|
|
isFollowedByCasedLetter(UCharIterator *iter, int32_t index) {
|
2002-03-25 17:43:35 +00:00
|
|
|
/* This is volatile because AIX 5.1 Visual Age 5.0 in 32-bit mode can't
|
|
|
|
optimize this correctly. It couldn't optimize (1UL<<category)&0xE
|
|
|
|
*/
|
|
|
|
volatile uint32_t category;
|
|
|
|
uint32_t props;
|
2002-02-20 02:07:29 +00:00
|
|
|
int32_t c;
|
2001-10-17 00:17:15 +00:00
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
if(iter==NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-20 17:04:56 +00:00
|
|
|
iter->move(iter, index, UITER_ZERO);
|
2002-02-20 02:07:29 +00:00
|
|
|
for(;;) {
|
|
|
|
c=uiter_next32(iter);
|
|
|
|
if(c<0) {
|
|
|
|
break;
|
|
|
|
}
|
2001-12-06 01:23:47 +00:00
|
|
|
GET_PROPS_UNSAFE(c, props);
|
2001-10-17 00:17:15 +00:00
|
|
|
category=GET_CATEGORY(props);
|
2002-06-07 18:53:49 +00:00
|
|
|
if(isCased(c, category)) {
|
2001-10-17 00:17:15 +00:00
|
|
|
return TRUE; /* followed by cased letter */
|
|
|
|
}
|
|
|
|
if(!isCaseIgnorable(c, category)) {
|
|
|
|
return FALSE; /* not ignorable */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE; /* not followed by cased letter */
|
|
|
|
}
|
|
|
|
|
2002-06-07 18:53:49 +00:00
|
|
|
/* Is preceded by cased {case-ignorable}* ? */
|
2001-10-17 00:17:15 +00:00
|
|
|
static UBool
|
2002-02-20 02:07:29 +00:00
|
|
|
isPrecededByCasedLetter(UCharIterator *iter, int32_t index) {
|
2002-03-25 17:43:35 +00:00
|
|
|
/* This is volatile because AIX 5.1 Visual Age 5.0 in 32-bit mode can't
|
|
|
|
optimize this correctly. It couldn't optimize (1UL<<category)&0xE
|
|
|
|
*/
|
|
|
|
volatile uint32_t category;
|
|
|
|
uint32_t props;
|
2002-02-20 02:07:29 +00:00
|
|
|
int32_t c;
|
2001-10-17 00:17:15 +00:00
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
if(iter==NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-20 17:04:56 +00:00
|
|
|
iter->move(iter, index, UITER_ZERO);
|
2002-02-20 02:07:29 +00:00
|
|
|
for(;;) {
|
|
|
|
c=uiter_previous32(iter);
|
|
|
|
if(c<0) {
|
|
|
|
break;
|
|
|
|
}
|
2001-12-06 01:23:47 +00:00
|
|
|
GET_PROPS_UNSAFE(c, props);
|
2001-10-17 00:17:15 +00:00
|
|
|
category=GET_CATEGORY(props);
|
2002-06-07 18:53:49 +00:00
|
|
|
if(isCased(c, category)) {
|
2001-10-17 00:17:15 +00:00
|
|
|
return TRUE; /* preceded by cased letter */
|
|
|
|
}
|
|
|
|
if(!isCaseIgnorable(c, category)) {
|
|
|
|
return FALSE; /* not ignorable */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE; /* not followed by cased letter */
|
|
|
|
}
|
|
|
|
|
2002-06-07 18:53:49 +00:00
|
|
|
/* Is preceded by Soft_Dotted character with no intervening cc=230 ? */
|
2001-10-17 00:17:15 +00:00
|
|
|
static UBool
|
2002-06-07 18:53:49 +00:00
|
|
|
isPrecededBySoftDotted(UCharIterator *iter, int32_t index) {
|
2002-02-20 02:07:29 +00:00
|
|
|
int32_t c;
|
2001-10-17 00:17:15 +00:00
|
|
|
uint8_t cc;
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
if(iter==NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-20 17:04:56 +00:00
|
|
|
iter->move(iter, index, UITER_ZERO);
|
2002-02-20 02:07:29 +00:00
|
|
|
for(;;) {
|
|
|
|
c=uiter_previous32(iter);
|
|
|
|
if(c<0) {
|
|
|
|
break;
|
|
|
|
}
|
2002-06-07 18:53:49 +00:00
|
|
|
if(isSoftDotted(c)) {
|
2001-10-17 00:17:15 +00:00
|
|
|
return TRUE; /* preceded by TYPE_i */
|
|
|
|
}
|
|
|
|
|
2002-03-04 01:25:51 +00:00
|
|
|
cc=u_getCombiningClass(c);
|
2001-10-17 00:17:15 +00:00
|
|
|
if(cc==0 || cc==230) {
|
|
|
|
return FALSE; /* preceded by different base character (not TYPE_i), or intervening cc==230 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE; /* not preceded by TYPE_i */
|
|
|
|
}
|
|
|
|
|
2002-06-07 18:53:49 +00:00
|
|
|
/*
|
2003-02-16 19:20:04 +00:00
|
|
|
* See Jitterbug 2344:
|
|
|
|
* The condition After_I for Turkic-lowercasing of U+0307 combining dot above
|
|
|
|
* is checked in ICU 2.0, 2.1, 2.6 but was not in 2.2 & 2.4 because
|
|
|
|
* we made those releases compatible with Unicode 3.2 which had not fixed
|
|
|
|
* a related but in SpecialCasing.txt.
|
2002-06-07 18:53:49 +00:00
|
|
|
*
|
2003-02-16 19:20:04 +00:00
|
|
|
* From the Jitterbug 2344 text:
|
|
|
|
* ... this bug is listed as a Unicode erratum
|
|
|
|
* from 2002-10-31 at http://www.unicode.org/uni2errata/UnicodeErrata.html
|
|
|
|
* <quote>
|
|
|
|
* There are two errors in SpecialCasing.txt.
|
|
|
|
* 1. Missing semicolons on two lines. ... [irrelevant for ICU]
|
|
|
|
* 2. An incorrect context definition. Correct as follows:
|
|
|
|
* < 0307; ; 0307; 0307; tr After_Soft_Dotted; # COMBINING DOT ABOVE
|
|
|
|
* < 0307; ; 0307; 0307; az After_Soft_Dotted; # COMBINING DOT ABOVE
|
|
|
|
* ---
|
|
|
|
* > 0307; ; 0307; 0307; tr After_I; # COMBINING DOT ABOVE
|
|
|
|
* > 0307; ; 0307; 0307; az After_I; # COMBINING DOT ABOVE
|
|
|
|
* where the context After_I is defined as:
|
|
|
|
* The last preceding base character was an uppercase I, and there is no
|
|
|
|
* intervening combining character class 230 (ABOVE).
|
|
|
|
* </quote>
|
2002-06-07 18:53:49 +00:00
|
|
|
*
|
2003-02-16 19:20:04 +00:00
|
|
|
* Note that SpecialCasing.txt even in Unicode 3.2 described the condition as:
|
|
|
|
*
|
|
|
|
* # When lowercasing, remove dot_above in the sequence I + dot_above, which will turn into i.
|
|
|
|
* # This matches the behavior of the canonically equivalent I-dot_above
|
2002-06-07 18:53:49 +00:00
|
|
|
*
|
2003-02-16 19:20:04 +00:00
|
|
|
* See also the description in this place in older versions of uchar.c (revision 1.100).
|
|
|
|
*
|
|
|
|
* Markus W. Scherer 2003-feb-15
|
2002-06-07 18:53:49 +00:00
|
|
|
*/
|
|
|
|
|
2001-10-17 00:17:15 +00:00
|
|
|
/* Is preceded by base character 'I' with no intervening cc=230 ? */
|
|
|
|
static UBool
|
2003-02-16 19:20:04 +00:00
|
|
|
isPrecededBy_I(UCharIterator *iter, int32_t index) {
|
2002-02-20 02:07:29 +00:00
|
|
|
int32_t c;
|
2001-10-17 00:17:15 +00:00
|
|
|
uint8_t cc;
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
if(iter==NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-20 17:04:56 +00:00
|
|
|
iter->move(iter, index, UITER_ZERO);
|
2002-02-20 02:07:29 +00:00
|
|
|
for(;;) {
|
|
|
|
c=uiter_previous32(iter);
|
|
|
|
if(c<0) {
|
|
|
|
break;
|
|
|
|
}
|
2001-10-17 00:17:15 +00:00
|
|
|
if(c==0x49) {
|
|
|
|
return TRUE; /* preceded by I */
|
|
|
|
}
|
|
|
|
|
2002-03-04 01:25:51 +00:00
|
|
|
cc=u_getCombiningClass(c);
|
2001-10-17 00:17:15 +00:00
|
|
|
if(cc==0 || cc==230) {
|
|
|
|
return FALSE; /* preceded by different base character (not I), or intervening cc==230 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE; /* not preceded by I */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is followed by one or more cc==230 ? */
|
|
|
|
static UBool
|
2002-02-20 02:07:29 +00:00
|
|
|
isFollowedByMoreAbove(UCharIterator *iter, int32_t index) {
|
|
|
|
int32_t c;
|
2001-10-17 00:17:15 +00:00
|
|
|
uint8_t cc;
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
if(iter==NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-20 17:04:56 +00:00
|
|
|
iter->move(iter, index, UITER_ZERO);
|
2002-02-20 02:07:29 +00:00
|
|
|
for(;;) {
|
|
|
|
c=uiter_next32(iter);
|
|
|
|
if(c<0) {
|
|
|
|
break;
|
|
|
|
}
|
2002-03-04 01:25:51 +00:00
|
|
|
cc=u_getCombiningClass(c);
|
2001-10-17 00:17:15 +00:00
|
|
|
if(cc==230) {
|
|
|
|
return TRUE; /* at least one cc==230 following */
|
|
|
|
}
|
|
|
|
if(cc==0) {
|
|
|
|
return FALSE; /* next base character, no more cc==230 following */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE; /* no more cc==230 following */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is followed by a dot above (without cc==230 in between) ? */
|
|
|
|
static UBool
|
2002-02-20 02:07:29 +00:00
|
|
|
isFollowedByDotAbove(UCharIterator *iter, int32_t index) {
|
|
|
|
int32_t c;
|
2001-10-17 00:17:15 +00:00
|
|
|
uint8_t cc;
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
if(iter==NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-20 17:04:56 +00:00
|
|
|
iter->move(iter, index, UITER_ZERO);
|
2002-02-20 02:07:29 +00:00
|
|
|
for(;;) {
|
|
|
|
c=uiter_next32(iter);
|
|
|
|
if(c<0) {
|
|
|
|
break;
|
|
|
|
}
|
2001-10-17 00:17:15 +00:00
|
|
|
if(c==0x307) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-03-04 01:25:51 +00:00
|
|
|
cc=u_getCombiningClass(c);
|
2001-10-17 00:17:15 +00:00
|
|
|
if(cc==0 || cc==230) {
|
|
|
|
return FALSE; /* next base character or cc==230 in between */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE; /* no dot above following */
|
|
|
|
}
|
|
|
|
|
2001-11-29 20:44:54 +00:00
|
|
|
/* lowercasing -------------------------------------------------------------- */
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
/* internal, see ustr_imp.h */
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
u_internalToLower(UChar32 c, UCharIterator *iter,
|
|
|
|
UChar *dest, int32_t destCapacity,
|
|
|
|
const char *locale) {
|
2001-10-17 00:17:15 +00:00
|
|
|
UChar buffer[8];
|
2002-02-20 02:07:29 +00:00
|
|
|
uint32_t props;
|
|
|
|
UChar32 result;
|
|
|
|
int32_t i, length;
|
2001-01-31 18:20:26 +00:00
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
result=c;
|
|
|
|
GET_PROPS(c, props);
|
|
|
|
if(!PROPS_VALUE_IS_EXCEPTION(props)) {
|
2003-02-11 23:30:09 +00:00
|
|
|
if(CAT_MASK(props)&(U_GC_LU_MASK|U_GC_LT_MASK)) {
|
2002-02-20 02:07:29 +00:00
|
|
|
result=c+GET_SIGNED_VALUE(props);
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
2002-03-03 04:39:22 +00:00
|
|
|
} else {
|
2002-02-20 02:07:29 +00:00
|
|
|
const UChar *u;
|
|
|
|
const uint32_t *pe=GET_EXCEPTIONS(props);
|
|
|
|
uint32_t firstExceptionValue=*pe, specialCasing;
|
2002-03-12 16:57:57 +00:00
|
|
|
int32_t minLength;
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_SPECIAL_CASING)) {
|
|
|
|
i=EXC_SPECIAL_CASING;
|
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
|
|
|
specialCasing=*pe;
|
|
|
|
/* fill u and length with the case mapping result string */
|
|
|
|
if(specialCasing&0x80000000) {
|
|
|
|
/* use hardcoded conditions and mappings */
|
|
|
|
int32_t loc=getCaseLocale(locale),
|
|
|
|
srcIndex= iter!=NULL ? iter->getIndex(iter, UITER_CURRENT) : 0;
|
|
|
|
|
2002-06-07 18:53:49 +00:00
|
|
|
/*
|
|
|
|
* Test for conditional mappings first
|
|
|
|
* (otherwise the unconditional default mappings are always taken),
|
|
|
|
* then test for characters that have unconditional mappings in SpecialCasing.txt,
|
|
|
|
* then get the UnicodeData.txt mappings.
|
|
|
|
*/
|
2002-02-20 02:07:29 +00:00
|
|
|
if( loc==LOC_LITHUANIAN &&
|
|
|
|
/* base characters, find accents above */
|
|
|
|
(((c==0x49 || c==0x4a || c==0x12e) &&
|
|
|
|
isFollowedByMoreAbove(iter, srcIndex)) ||
|
|
|
|
/* precomposed with accent above, no need to find one */
|
|
|
|
(c==0xcc || c==0xcd || c==0x128))
|
2001-01-31 18:20:26 +00:00
|
|
|
) {
|
2002-06-07 18:53:49 +00:00
|
|
|
/*
|
|
|
|
# Lithuanian
|
|
|
|
|
|
|
|
# Lithuanian retains the dot in a lowercase i when followed by accents.
|
|
|
|
|
|
|
|
# Introduce an explicit dot above when lowercasing capital I's and J's
|
|
|
|
# whenever there are more accents above.
|
|
|
|
# (of the accents used in Lithuanian: grave, acute, tilde above, and ogonek)
|
|
|
|
|
|
|
|
0049; 0069 0307; 0049; 0049; lt More_Above; # LATIN CAPITAL LETTER I
|
|
|
|
004A; 006A 0307; 004A; 004A; lt More_Above; # LATIN CAPITAL LETTER J
|
|
|
|
012E; 012F 0307; 012E; 012E; lt More_Above; # LATIN CAPITAL LETTER I WITH OGONEK
|
|
|
|
00CC; 0069 0307 0300; 00CC; 00CC; lt; # LATIN CAPITAL LETTER I WITH GRAVE
|
|
|
|
00CD; 0069 0307 0301; 00CD; 00CD; lt; # LATIN CAPITAL LETTER I WITH ACUTE
|
|
|
|
0128; 0069 0307 0303; 0128; 0128; lt; # LATIN CAPITAL LETTER I WITH TILDE
|
|
|
|
*/
|
2002-02-20 21:35:54 +00:00
|
|
|
u=buffer;
|
2002-02-20 02:07:29 +00:00
|
|
|
buffer[1]=0x307;
|
|
|
|
switch(c) {
|
|
|
|
case 0x49: /* LATIN CAPITAL LETTER I */
|
|
|
|
buffer[0]=0x69;
|
2002-02-20 21:35:54 +00:00
|
|
|
length=2;
|
2002-02-20 02:07:29 +00:00
|
|
|
break;
|
|
|
|
case 0x4a: /* LATIN CAPITAL LETTER J */
|
|
|
|
buffer[0]=0x6a;
|
2002-02-20 21:35:54 +00:00
|
|
|
length=2;
|
2002-02-20 02:07:29 +00:00
|
|
|
break;
|
|
|
|
case 0x12e: /* LATIN CAPITAL LETTER I WITH OGONEK */
|
|
|
|
buffer[0]=0x12f;
|
2002-02-20 21:35:54 +00:00
|
|
|
length=2;
|
2002-02-20 02:07:29 +00:00
|
|
|
break;
|
|
|
|
case 0xcc: /* LATIN CAPITAL LETTER I WITH GRAVE */
|
|
|
|
buffer[0]=0x69;
|
|
|
|
buffer[2]=0x300;
|
2002-02-20 21:35:54 +00:00
|
|
|
length=3;
|
2002-02-20 02:07:29 +00:00
|
|
|
break;
|
|
|
|
case 0xcd: /* LATIN CAPITAL LETTER I WITH ACUTE */
|
|
|
|
buffer[0]=0x69;
|
|
|
|
buffer[2]=0x301;
|
2002-02-20 21:35:54 +00:00
|
|
|
length=3;
|
2002-02-20 02:07:29 +00:00
|
|
|
break;
|
|
|
|
case 0x128: /* LATIN CAPITAL LETTER I WITH TILDE */
|
|
|
|
buffer[0]=0x69;
|
|
|
|
buffer[2]=0x303;
|
2002-02-20 21:35:54 +00:00
|
|
|
length=3;
|
2002-02-20 02:07:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0; /* will not occur */
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
2002-06-07 18:53:49 +00:00
|
|
|
/* # Turkish and Azeri */
|
|
|
|
} else if(loc==LOC_TURKISH && c==0x130) {
|
|
|
|
/*
|
|
|
|
# I and i-dotless; I-dot and i are case pairs in Turkish and Azeri
|
|
|
|
# The following rules handle those cases.
|
|
|
|
|
|
|
|
0130; 0069; 0130; 0130; tr # LATIN CAPITAL LETTER I WITH DOT ABOVE
|
|
|
|
0130; 0069; 0130; 0130; az # LATIN CAPITAL LETTER I WITH DOT ABOVE
|
|
|
|
*/
|
|
|
|
result=0x69;
|
|
|
|
goto single;
|
2003-02-16 19:20:04 +00:00
|
|
|
} else if(loc==LOC_TURKISH && c==0x307 && isPrecededBy_I(iter, srcIndex-1)) {
|
2002-06-07 18:53:49 +00:00
|
|
|
/*
|
|
|
|
# When lowercasing, remove dot_above in the sequence I + dot_above, which will turn into i.
|
|
|
|
# This matches the behavior of the canonically equivalent I-dot_above
|
|
|
|
|
2003-02-16 19:20:04 +00:00
|
|
|
0307; ; 0307; 0307; tr After_I; # COMBINING DOT ABOVE
|
|
|
|
0307; ; 0307; 0307; az After_I; # COMBINING DOT ABOVE
|
2002-06-07 18:53:49 +00:00
|
|
|
*/
|
|
|
|
return 0; /* remove the dot (continue without output) */
|
2002-02-20 02:07:29 +00:00
|
|
|
} else if(loc==LOC_TURKISH && c==0x49 && !isFollowedByDotAbove(iter, srcIndex)) {
|
2002-06-07 18:53:49 +00:00
|
|
|
/*
|
|
|
|
# When lowercasing, unless an I is before a dot_above, it turns into a dotless i.
|
|
|
|
|
|
|
|
0049; 0131; 0049; 0049; tr Not_Before_Dot; # LATIN CAPITAL LETTER I
|
|
|
|
0049; 0131; 0049; 0049; az Not_Before_Dot; # LATIN CAPITAL LETTER I
|
|
|
|
*/
|
2002-02-20 02:07:29 +00:00
|
|
|
result=0x131;
|
|
|
|
goto single;
|
2002-06-07 18:53:49 +00:00
|
|
|
} else if(c==0x130) {
|
|
|
|
/*
|
|
|
|
# Preserve canonical equivalence for I with dot. Turkic is handled below.
|
|
|
|
|
|
|
|
0130; 0069 0307; 0130; 0130; # LATIN CAPITAL LETTER I WITH DOT ABOVE
|
|
|
|
*/
|
|
|
|
static const UChar iWithDot[2]={ 0x69, 0x307 };
|
|
|
|
u=iWithDot;
|
|
|
|
length=2;
|
2002-02-20 02:07:29 +00:00
|
|
|
} else if( c==0x3a3 &&
|
|
|
|
!isFollowedByCasedLetter(iter, srcIndex) &&
|
|
|
|
isPrecededByCasedLetter(iter, srcIndex-1)
|
|
|
|
) {
|
2002-06-07 18:53:49 +00:00
|
|
|
/* greek capital sigma maps depending on surrounding cased letters (see SpecialCasing.txt) */
|
|
|
|
/*
|
|
|
|
# Special case for final form of sigma
|
|
|
|
|
|
|
|
03A3; 03C2; 03A3; 03A3; Final_Sigma; # GREEK CAPITAL LETTER SIGMA
|
|
|
|
*/
|
2002-02-20 02:07:29 +00:00
|
|
|
result=0x3c2; /* greek small final sigma */
|
|
|
|
goto single;
|
2001-01-31 18:20:26 +00:00
|
|
|
} else {
|
2002-02-20 02:07:29 +00:00
|
|
|
/* no known conditional special case mapping, use a normal mapping */
|
|
|
|
pe=GET_EXCEPTIONS(props); /* restore the initial exception pointer */
|
|
|
|
firstExceptionValue=*pe;
|
|
|
|
goto notSpecial;
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
} else {
|
|
|
|
/* get the special case mapping string from the data file */
|
|
|
|
u=ucharsTable+(specialCasing&0xffff);
|
2002-03-12 16:57:57 +00:00
|
|
|
length=(int32_t)((*u++)&0x1f);
|
2001-10-17 00:17:15 +00:00
|
|
|
}
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
/* copy the result string */
|
2002-03-12 16:57:57 +00:00
|
|
|
minLength = (length < destCapacity) ? length : destCapacity;
|
2002-02-20 02:07:29 +00:00
|
|
|
i=0;
|
2002-03-12 16:57:57 +00:00
|
|
|
while(i<minLength) {
|
2002-02-20 02:07:29 +00:00
|
|
|
dest[i++]=*u++;
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
return length;
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
notSpecial:
|
|
|
|
if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_LOWERCASE)) {
|
|
|
|
i=EXC_LOWERCASE;
|
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
|
|
|
result=(UChar32)*pe;
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
single:
|
|
|
|
length=UTF_CHAR_LENGTH(result);
|
|
|
|
if(length<=destCapacity) {
|
|
|
|
/* write result to dest */
|
|
|
|
i=0;
|
|
|
|
UTF_APPEND_CHAR_UNSAFE(dest, i, result);
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
return (result==c) ? -length : length;
|
2000-11-16 21:43:12 +00:00
|
|
|
}
|
|
|
|
|
2002-02-21 17:58:51 +00:00
|
|
|
/*
|
|
|
|
* Lowercases [srcStart..srcLimit[ but takes
|
|
|
|
* context [0..srcLength[ into account.
|
|
|
|
*/
|
2001-01-31 18:20:26 +00:00
|
|
|
U_CFUNC int32_t
|
2002-02-20 02:07:29 +00:00
|
|
|
u_internalStrToLower(UChar *dest, int32_t destCapacity,
|
2001-01-31 18:20:26 +00:00
|
|
|
const UChar *src, int32_t srcLength,
|
2002-02-21 17:58:51 +00:00
|
|
|
int32_t srcStart, int32_t srcLimit,
|
2001-01-31 18:20:26 +00:00
|
|
|
const char *locale,
|
|
|
|
UErrorCode *pErrorCode) {
|
2002-02-20 02:07:29 +00:00
|
|
|
UCharIterator iter;
|
|
|
|
uint32_t props;
|
|
|
|
int32_t srcIndex, destIndex;
|
2001-01-31 18:20:26 +00:00
|
|
|
UChar32 c;
|
|
|
|
|
|
|
|
/* test early, once, if there is a data file */
|
|
|
|
if(!HAVE_DATA) {
|
2002-03-03 04:39:22 +00:00
|
|
|
*pErrorCode=U_FILE_ACCESS_ERROR;
|
|
|
|
return 0;
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set up local variables */
|
2002-02-20 02:07:29 +00:00
|
|
|
uiter_setString(&iter, src, srcLength);
|
2001-01-31 18:20:26 +00:00
|
|
|
|
|
|
|
/* case mapping loop */
|
2002-02-21 17:58:51 +00:00
|
|
|
srcIndex=srcStart;
|
|
|
|
destIndex=0;
|
|
|
|
while(srcIndex<srcLimit) {
|
|
|
|
UTF_NEXT_CHAR(src, srcIndex, srcLimit, c);
|
2001-12-06 01:23:47 +00:00
|
|
|
GET_PROPS_UNSAFE(c, props);
|
2001-01-31 18:20:26 +00:00
|
|
|
if(!PROPS_VALUE_IS_EXCEPTION(props)) {
|
2003-02-11 23:30:09 +00:00
|
|
|
if(CAT_MASK(props)&(U_GC_LU_MASK|U_GC_LT_MASK)) {
|
2002-02-20 02:07:29 +00:00
|
|
|
c+=GET_SIGNED_VALUE(props);
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
/* handle 1:1 code point mappings from UnicodeData.txt */
|
|
|
|
if(c<=0xffff) {
|
|
|
|
if(destIndex<destCapacity) {
|
|
|
|
dest[destIndex++]=(UChar)c;
|
|
|
|
} else {
|
|
|
|
/* buffer overflow */
|
|
|
|
/* keep incrementing the destIndex for preflighting */
|
|
|
|
++destIndex;
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
} else {
|
|
|
|
if((destIndex+2)<=destCapacity) {
|
|
|
|
dest[destIndex++]=UTF16_LEAD(c);
|
|
|
|
dest[destIndex++]=UTF16_TRAIL(c);
|
2001-01-31 18:20:26 +00:00
|
|
|
} else {
|
|
|
|
/* buffer overflow */
|
2002-02-20 02:07:29 +00:00
|
|
|
/* write the first surrogate if possible */
|
|
|
|
if(destIndex<destCapacity) {
|
|
|
|
dest[destIndex]=UTF16_LEAD(c);
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
|
|
|
/* keep incrementing the destIndex for preflighting */
|
2002-02-20 02:07:29 +00:00
|
|
|
destIndex+=2;
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
} else {
|
|
|
|
/* handle all exceptions in u_internalToLower() */
|
|
|
|
int32_t length;
|
2001-01-31 18:20:26 +00:00
|
|
|
|
2002-03-20 17:04:56 +00:00
|
|
|
iter.move(&iter, srcIndex, UITER_ZERO);
|
2002-02-20 02:07:29 +00:00
|
|
|
if(destIndex<destCapacity) {
|
|
|
|
length=u_internalToLower(c, &iter, dest+destIndex, destCapacity-destIndex, locale);
|
2001-01-31 18:20:26 +00:00
|
|
|
} else {
|
2002-02-20 02:07:29 +00:00
|
|
|
length=u_internalToLower(c, &iter, NULL, 0, locale);
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
if(length<0) {
|
|
|
|
length=-length;
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
destIndex+=length;
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(destIndex>destCapacity) {
|
|
|
|
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
|
|
|
return destIndex;
|
|
|
|
}
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
/* uppercasing -------------------------------------------------------------- */
|
2001-11-29 20:44:54 +00:00
|
|
|
|
|
|
|
/* internal */
|
2002-02-20 02:07:29 +00:00
|
|
|
static int32_t
|
|
|
|
u_internalToUpperOrTitle(UChar32 c, UCharIterator *iter,
|
|
|
|
UChar *dest, int32_t destCapacity,
|
|
|
|
const char *locale,
|
|
|
|
UBool upperNotTitle) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
2002-02-20 02:07:29 +00:00
|
|
|
UChar32 result;
|
2001-11-29 20:44:54 +00:00
|
|
|
int32_t i, length;
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
result=c;
|
2001-12-06 01:23:47 +00:00
|
|
|
GET_PROPS(c, props);
|
2001-11-29 20:44:54 +00:00
|
|
|
if(!PROPS_VALUE_IS_EXCEPTION(props)) {
|
|
|
|
if(GET_CATEGORY(props)==U_LOWERCASE_LETTER) {
|
2002-02-20 02:07:29 +00:00
|
|
|
result=c-GET_SIGNED_VALUE(props);
|
2001-11-29 20:44:54 +00:00
|
|
|
}
|
2002-03-03 04:39:22 +00:00
|
|
|
} else {
|
2001-11-29 20:44:54 +00:00
|
|
|
const UChar *u;
|
2001-12-06 01:23:47 +00:00
|
|
|
const uint32_t *pe=GET_EXCEPTIONS(props);
|
2001-11-29 20:44:54 +00:00
|
|
|
uint32_t firstExceptionValue=*pe, specialCasing;
|
|
|
|
if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_SPECIAL_CASING)) {
|
|
|
|
i=EXC_SPECIAL_CASING;
|
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
|
|
|
specialCasing=*pe;
|
|
|
|
/* fill u and length with the case mapping result string */
|
|
|
|
if(specialCasing&0x80000000) {
|
|
|
|
/* use hardcoded conditions and mappings */
|
2002-02-20 02:07:29 +00:00
|
|
|
int32_t loc=getCaseLocale(locale),
|
|
|
|
srcIndex= iter!=NULL ? iter->getIndex(iter, UITER_CURRENT) : 0;
|
2001-11-29 20:44:54 +00:00
|
|
|
|
|
|
|
if(loc==LOC_TURKISH && c==0x69) {
|
2002-06-07 18:53:49 +00:00
|
|
|
/*
|
|
|
|
# Turkish and Azeri
|
|
|
|
|
|
|
|
# I and i-dotless; I-dot and i are case pairs in Turkish and Azeri
|
|
|
|
# The following rules handle those cases.
|
|
|
|
|
|
|
|
# When uppercasing, i turns into a dotted capital I
|
|
|
|
|
|
|
|
0069; 0069; 0130; 0130; tr; # LATIN SMALL LETTER I
|
|
|
|
0069; 0069; 0130; 0130; az; # LATIN SMALL LETTER I
|
|
|
|
*/
|
2002-02-20 02:07:29 +00:00
|
|
|
result=0x130;
|
2001-11-29 20:44:54 +00:00
|
|
|
goto single;
|
2002-06-07 18:53:49 +00:00
|
|
|
} else if(loc==LOC_LITHUANIAN && c==0x307 && isPrecededBySoftDotted(iter, srcIndex-1)) {
|
|
|
|
/*
|
|
|
|
# Lithuanian
|
|
|
|
|
|
|
|
# Lithuanian retains the dot in a lowercase i when followed by accents.
|
|
|
|
|
|
|
|
# Remove DOT ABOVE after "i" with upper or titlecase
|
|
|
|
|
|
|
|
0307; 0307; ; ; lt After_Soft_Dotted; # COMBINING DOT ABOVE
|
|
|
|
*/
|
2001-11-29 20:44:54 +00:00
|
|
|
return 0; /* remove the dot (continue without output) */
|
|
|
|
} else {
|
|
|
|
/* no known conditional special case mapping, use a normal mapping */
|
|
|
|
pe=GET_EXCEPTIONS(props); /* restore the initial exception pointer */
|
|
|
|
firstExceptionValue=*pe;
|
|
|
|
goto notSpecial;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* get the special case mapping string from the data file */
|
|
|
|
u=ucharsTable+(specialCasing&0xffff);
|
|
|
|
length=(int32_t)*u++;
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
/* skip the lowercase result string */
|
|
|
|
u+=length&0x1f;
|
|
|
|
if(upperNotTitle) {
|
|
|
|
length=(length>>5)&0x1f;
|
|
|
|
} else {
|
|
|
|
/* skip the uppercase result strings too */
|
|
|
|
u+=(length>>5)&0x1f;
|
|
|
|
length=(length>>10)&0x1f;
|
|
|
|
}
|
2001-11-29 20:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy the result string */
|
|
|
|
i=0;
|
|
|
|
while(i<length && i<destCapacity) {
|
|
|
|
dest[i++]=*u++;
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
notSpecial:
|
2002-02-20 02:07:29 +00:00
|
|
|
if(!upperNotTitle && HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_TITLECASE)) {
|
2001-11-29 20:44:54 +00:00
|
|
|
i=EXC_TITLECASE;
|
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
2002-02-20 02:07:29 +00:00
|
|
|
result=(UChar32)*pe;
|
2001-11-29 20:44:54 +00:00
|
|
|
} else if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_UPPERCASE)) {
|
|
|
|
/* here, titlecase is same as uppercase */
|
|
|
|
i=EXC_UPPERCASE;
|
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
2002-02-20 02:07:29 +00:00
|
|
|
result=(UChar32)*pe;
|
2001-11-29 20:44:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
single:
|
2002-02-20 02:07:29 +00:00
|
|
|
length=UTF_CHAR_LENGTH(result);
|
2001-11-29 20:44:54 +00:00
|
|
|
if(length<=destCapacity) {
|
2002-02-20 02:07:29 +00:00
|
|
|
/* write result to dest */
|
2001-11-29 20:44:54 +00:00
|
|
|
i=0;
|
2002-02-20 02:07:29 +00:00
|
|
|
UTF_APPEND_CHAR_UNSAFE(dest, i, result);
|
2001-11-29 20:44:54 +00:00
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
return (result==c) ? -length : length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* internal, see ustr_imp.h */
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
u_internalToUpper(UChar32 c, UCharIterator *iter,
|
|
|
|
UChar *dest, int32_t destCapacity,
|
|
|
|
const char *locale) {
|
|
|
|
return u_internalToUpperOrTitle(c, iter, dest, destCapacity, locale, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CFUNC int32_t
|
|
|
|
u_internalStrToUpper(UChar *dest, int32_t destCapacity,
|
|
|
|
const UChar *src, int32_t srcLength,
|
|
|
|
const char *locale,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
UCharIterator iter;
|
|
|
|
uint32_t props;
|
|
|
|
int32_t srcIndex, destIndex;
|
|
|
|
UChar32 c;
|
|
|
|
|
|
|
|
/* test early, once, if there is a data file */
|
|
|
|
if(!HAVE_DATA) {
|
2002-03-03 04:39:22 +00:00
|
|
|
*pErrorCode=U_FILE_ACCESS_ERROR;
|
|
|
|
return 0;
|
2002-02-20 02:07:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set up local variables */
|
|
|
|
uiter_setString(&iter, src, srcLength);
|
|
|
|
|
|
|
|
/* case mapping loop */
|
|
|
|
srcIndex=destIndex=0;
|
|
|
|
while(srcIndex<srcLength) {
|
|
|
|
UTF_NEXT_CHAR(src, srcIndex, srcLength, c);
|
|
|
|
GET_PROPS_UNSAFE(c, props);
|
|
|
|
if(!PROPS_VALUE_IS_EXCEPTION(props)) {
|
|
|
|
if(GET_CATEGORY(props)==U_LOWERCASE_LETTER) {
|
|
|
|
c-=GET_SIGNED_VALUE(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle 1:1 code point mappings from UnicodeData.txt */
|
|
|
|
if(c<=0xffff) {
|
|
|
|
if(destIndex<destCapacity) {
|
|
|
|
dest[destIndex++]=(UChar)c;
|
|
|
|
} else {
|
|
|
|
/* buffer overflow */
|
|
|
|
/* keep incrementing the destIndex for preflighting */
|
|
|
|
++destIndex;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if((destIndex+2)<=destCapacity) {
|
|
|
|
dest[destIndex++]=UTF16_LEAD(c);
|
|
|
|
dest[destIndex++]=UTF16_TRAIL(c);
|
|
|
|
} else {
|
|
|
|
/* buffer overflow */
|
|
|
|
/* write the first surrogate if possible */
|
|
|
|
if(destIndex<destCapacity) {
|
|
|
|
dest[destIndex]=UTF16_LEAD(c);
|
|
|
|
}
|
|
|
|
/* keep incrementing the destIndex for preflighting */
|
|
|
|
destIndex+=2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* handle all exceptions in u_internalToUpper() */
|
|
|
|
int32_t length;
|
|
|
|
|
2002-03-20 17:04:56 +00:00
|
|
|
iter.move(&iter, srcIndex, UITER_ZERO);
|
2002-02-20 02:07:29 +00:00
|
|
|
if(destIndex<destCapacity) {
|
|
|
|
length=u_internalToUpperOrTitle(c, &iter, dest+destIndex, destCapacity-destIndex, locale, TRUE);
|
|
|
|
} else {
|
|
|
|
length=u_internalToUpperOrTitle(c, &iter, NULL, 0, locale, TRUE);
|
|
|
|
}
|
|
|
|
if(length<0) {
|
|
|
|
length=-length;
|
|
|
|
}
|
|
|
|
destIndex+=length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(destIndex>destCapacity) {
|
|
|
|
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
|
|
|
return destIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* titlecasing -------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* internal, see ustr_imp.h */
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
u_internalToTitle(UChar32 c, UCharIterator *iter,
|
|
|
|
UChar *dest, int32_t destCapacity,
|
|
|
|
const char *locale) {
|
|
|
|
return u_internalToUpperOrTitle(c, iter, dest, destCapacity, locale, FALSE);
|
2001-11-29 20:44:54 +00:00
|
|
|
}
|
|
|
|
|
2001-02-14 00:47:36 +00:00
|
|
|
/* case folding ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Case folding is similar to lowercasing.
|
|
|
|
* The result may be a simple mapping, i.e., a single code point, or
|
|
|
|
* a full mapping, i.e., a string.
|
|
|
|
* If the case folding for a code point is the same as its simple (1:1) lowercase mapping,
|
|
|
|
* then only the lowercase mapping is stored.
|
2002-06-03 03:33:44 +00:00
|
|
|
*
|
|
|
|
* Some special cases are hardcoded because their conditions cannot be
|
|
|
|
* parsed and processed from CaseFolding.txt.
|
|
|
|
*
|
|
|
|
* Unicode 3.2 CaseFolding.txt specifies for its status field:
|
|
|
|
|
|
|
|
# C: common case folding, common mappings shared by both simple and full mappings.
|
|
|
|
# F: full case folding, mappings that cause strings to grow in length. Multiple characters are separated by spaces.
|
|
|
|
# S: simple case folding, mappings to single characters where different from F.
|
|
|
|
# T: special case for uppercase I and dotted uppercase I
|
|
|
|
# - For non-Turkic languages, this mapping is normally not used.
|
|
|
|
# - For Turkic languages (tr, az), this mapping can be used instead of the normal mapping for these characters.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# A. To do a simple case folding, use the mappings with status C + S.
|
|
|
|
# B. To do a full case folding, use the mappings with status C + F.
|
|
|
|
#
|
|
|
|
# The mappings with status T can be used or omitted depending on the desired case-folding
|
|
|
|
# behavior. (The default option is to exclude them.)
|
|
|
|
|
|
|
|
* Unicode 3.2 has 'T' mappings as follows:
|
|
|
|
|
|
|
|
0049; T; 0131; # LATIN CAPITAL LETTER I
|
|
|
|
0130; T; 0069; # LATIN CAPITAL LETTER I WITH DOT ABOVE
|
|
|
|
|
|
|
|
* while the default mappings for these code points are:
|
|
|
|
|
|
|
|
0049; C; 0069; # LATIN CAPITAL LETTER I
|
|
|
|
0130; F; 0069 0307; # LATIN CAPITAL LETTER I WITH DOT ABOVE
|
|
|
|
|
|
|
|
* U+0130 is otherwise lowercased to U+0069 (UnicodeData.txt).
|
|
|
|
*
|
|
|
|
* In case this code is used with CaseFolding.txt from an older version of Unicode
|
|
|
|
* where CaseFolding.txt contains mappings with a status of 'I' that
|
|
|
|
* have the opposite polarity ('I' mappings are included by default but excluded for Turkic),
|
|
|
|
* we must also hardcode the Unicode 3.2 mappings for the code points
|
|
|
|
* with 'I' mappings.
|
|
|
|
* Unicode 3.1.1 has 'I' mappings for U+0130 and U+0131.
|
|
|
|
* Unicode 3.2 has a 'T' mapping for U+0130, and lowercases U+0131 to itself (see UnicodeData.txt).
|
2001-02-14 00:47:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* return the simple case folding mapping for c */
|
|
|
|
U_CAPI UChar32 U_EXPORT2
|
|
|
|
u_foldCase(UChar32 c, uint32_t options) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
|
|
|
GET_PROPS(c, props);
|
2001-02-14 00:47:36 +00:00
|
|
|
if(!PROPS_VALUE_IS_EXCEPTION(props)) {
|
2003-02-11 23:30:09 +00:00
|
|
|
if(CAT_MASK(props)&(U_GC_LU_MASK|U_GC_LT_MASK)) {
|
2001-02-14 00:47:36 +00:00
|
|
|
return c+GET_SIGNED_VALUE(props);
|
|
|
|
}
|
2002-03-03 04:39:22 +00:00
|
|
|
} else {
|
2001-12-06 01:23:47 +00:00
|
|
|
const uint32_t *pe=GET_EXCEPTIONS(props);
|
2001-02-14 00:47:36 +00:00
|
|
|
uint32_t firstExceptionValue=*pe;
|
|
|
|
if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_CASE_FOLDING)) {
|
2001-12-06 01:23:47 +00:00
|
|
|
const uint32_t *oldPE=pe;
|
2001-02-14 00:47:36 +00:00
|
|
|
int i=EXC_CASE_FOLDING;
|
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
|
|
|
props=*pe;
|
|
|
|
if(props!=0) {
|
|
|
|
/* return the simple mapping, if there is one */
|
|
|
|
const UChar *uchars=ucharsTable+(props&0xffff);
|
|
|
|
UChar32 simple;
|
|
|
|
i=0;
|
|
|
|
UTF_NEXT_CHAR_UNSAFE(uchars, i, simple);
|
|
|
|
if(simple!=0) {
|
|
|
|
return simple;
|
|
|
|
}
|
|
|
|
/* fall through to use the lowercase exception value if there is no simple mapping */
|
|
|
|
pe=oldPE;
|
|
|
|
} else {
|
|
|
|
/* special case folding mappings, hardcoded */
|
2002-06-03 03:33:44 +00:00
|
|
|
if((options&_FOLD_CASE_OPTIONS_MASK)==U_FOLD_CASE_DEFAULT) {
|
|
|
|
/* default mappings */
|
|
|
|
if(c==0x49) {
|
|
|
|
/* 0049; C; 0069; # LATIN CAPITAL LETTER I */
|
|
|
|
return 0x69;
|
|
|
|
} else if(c==0x130) {
|
|
|
|
/* no simple default mapping for U+0130, use UnicodeData.txt */
|
|
|
|
return 0x69;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Turkic mappings */
|
|
|
|
if(c==0x49) {
|
|
|
|
/* 0049; T; 0131; # LATIN CAPITAL LETTER I */
|
|
|
|
return 0x131;
|
|
|
|
} else if(c==0x130) {
|
|
|
|
/* 0130; T; 0069; # LATIN CAPITAL LETTER I WITH DOT ABOVE */
|
|
|
|
return 0x69;
|
|
|
|
}
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
2002-06-03 03:33:44 +00:00
|
|
|
/* return c itself because there is no special mapping for it */
|
2001-02-14 00:47:36 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* not else! - allow to fall through from above */
|
|
|
|
if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_LOWERCASE)) {
|
|
|
|
int i=EXC_LOWERCASE;
|
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
|
|
|
return (UChar32)*pe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c; /* no mapping - return c itself */
|
|
|
|
}
|
|
|
|
|
2003-03-01 00:13:40 +00:00
|
|
|
/*
|
2003-03-10 00:59:10 +00:00
|
|
|
* Issue for canonical caseless match (UAX #21):
|
|
|
|
* Turkic casefolding (using "T" mappings in CaseFolding.txt) does not preserve
|
|
|
|
* canonical equivalence, unlike default-option casefolding.
|
|
|
|
* For example, I-grave and I + grave fold to strings that are not canonically
|
|
|
|
* equivalent.
|
|
|
|
* For more details, see the comment in unorm_compare() in unorm.cpp
|
|
|
|
* and the intermediate prototype changes for Jitterbug 2021.
|
|
|
|
* (For example, revision 1.104 of uchar.c and 1.4 of CaseFolding.txt.)
|
|
|
|
*
|
|
|
|
* This did not get fixed because it appears that it is not possible to fix
|
|
|
|
* it for uppercase and lowercase characters (I-grave vs. i-grave)
|
|
|
|
* together in a way that they still fold to common result strings.
|
2003-03-01 00:13:40 +00:00
|
|
|
*/
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
/* internal, see ustr_imp.h */
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
u_internalFoldCase(UChar32 c,
|
|
|
|
UChar *dest, int32_t destCapacity,
|
|
|
|
uint32_t options) {
|
2001-12-06 01:23:47 +00:00
|
|
|
uint32_t props;
|
2002-02-20 02:07:29 +00:00
|
|
|
UChar32 result;
|
|
|
|
int32_t i, length;
|
2001-02-14 00:47:36 +00:00
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
result=c;
|
2001-12-06 01:23:47 +00:00
|
|
|
GET_PROPS_UNSAFE(c, props);
|
2001-02-14 00:47:36 +00:00
|
|
|
if(!PROPS_VALUE_IS_EXCEPTION(props)) {
|
2003-02-11 23:30:09 +00:00
|
|
|
if(CAT_MASK(props)&(U_GC_LU_MASK|U_GC_LT_MASK)) {
|
2002-02-20 02:07:29 +00:00
|
|
|
/* same as lowercase */
|
|
|
|
result=c+GET_SIGNED_VALUE(props);
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2001-12-06 01:23:47 +00:00
|
|
|
const uint32_t *pe=GET_EXCEPTIONS(props);
|
2001-02-14 00:47:36 +00:00
|
|
|
uint32_t firstExceptionValue=*pe;
|
|
|
|
if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_CASE_FOLDING)) {
|
2001-02-27 23:45:16 +00:00
|
|
|
i=EXC_CASE_FOLDING;
|
2001-02-14 00:47:36 +00:00
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
|
|
|
props=*pe;
|
|
|
|
if(props!=0) {
|
|
|
|
/* return the full mapping */
|
|
|
|
const UChar *uchars=ucharsTable+(props&0xffff)+2;
|
2002-03-12 16:57:57 +00:00
|
|
|
int32_t minLength;
|
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
length=props>>24;
|
2002-03-12 16:57:57 +00:00
|
|
|
minLength = (length < destCapacity) ? length : destCapacity;
|
2001-02-14 00:47:36 +00:00
|
|
|
|
|
|
|
/* copy the result string */
|
|
|
|
i=0;
|
2002-03-12 16:57:57 +00:00
|
|
|
while(i<minLength) {
|
|
|
|
dest[i++]=*(uchars++);
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
return length;
|
2001-02-14 00:47:36 +00:00
|
|
|
} else {
|
|
|
|
/* special case folding mappings, hardcoded */
|
2002-06-03 03:33:44 +00:00
|
|
|
if((options&_FOLD_CASE_OPTIONS_MASK)==U_FOLD_CASE_DEFAULT) {
|
|
|
|
/* default mappings */
|
|
|
|
if(c==0x49) {
|
|
|
|
/* 0049; C; 0069; # LATIN CAPITAL LETTER I */
|
|
|
|
result=0x69;
|
|
|
|
} else if(c==0x130) {
|
|
|
|
/* 0130; F; 0069 0307; # LATIN CAPITAL LETTER I WITH DOT ABOVE */
|
|
|
|
if(0<destCapacity) {
|
|
|
|
dest[0]=0x69;
|
|
|
|
}
|
|
|
|
if(1<destCapacity) {
|
|
|
|
dest[1]=0x307;
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Turkic mappings */
|
|
|
|
if(c==0x49) {
|
|
|
|
/* 0049; T; 0131; # LATIN CAPITAL LETTER I */
|
|
|
|
result=0x131;
|
|
|
|
} else if(c==0x130) {
|
|
|
|
/* 0130; T; 0069; # LATIN CAPITAL LETTER I WITH DOT ABOVE */
|
|
|
|
result=0x69;
|
|
|
|
}
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
2002-06-03 03:33:44 +00:00
|
|
|
/* return c itself because there is no special mapping for it */
|
|
|
|
/* goto single; */
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
|
|
|
} else if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_LOWERCASE)) {
|
2001-02-27 23:45:16 +00:00
|
|
|
i=EXC_LOWERCASE;
|
2001-02-14 00:47:36 +00:00
|
|
|
++pe;
|
|
|
|
ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe);
|
2002-02-20 02:07:29 +00:00
|
|
|
result=(UChar32)*pe;
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-12 16:57:57 +00:00
|
|
|
/* single: */
|
2002-02-20 02:07:29 +00:00
|
|
|
length=UTF_CHAR_LENGTH(result);
|
|
|
|
if(length<=destCapacity) {
|
|
|
|
/* write result to dest */
|
|
|
|
i=0;
|
|
|
|
UTF_APPEND_CHAR_UNSAFE(dest, i, result);
|
|
|
|
}
|
|
|
|
return (result==c) ? -length : length;
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* case-fold the source string using the full mappings */
|
|
|
|
U_CFUNC int32_t
|
|
|
|
u_internalStrFoldCase(UChar *dest, int32_t destCapacity,
|
|
|
|
const UChar *src, int32_t srcLength,
|
|
|
|
uint32_t options,
|
|
|
|
UErrorCode *pErrorCode) {
|
2002-02-20 02:07:29 +00:00
|
|
|
uint32_t props;
|
|
|
|
int32_t srcIndex, destIndex;
|
2001-02-14 00:47:36 +00:00
|
|
|
UChar32 c;
|
|
|
|
|
|
|
|
/* test early, once, if there is a data file */
|
|
|
|
if(!HAVE_DATA) {
|
2002-03-03 04:39:22 +00:00
|
|
|
*pErrorCode=U_FILE_ACCESS_ERROR;
|
|
|
|
return 0;
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* case mapping loop */
|
|
|
|
srcIndex=destIndex=0;
|
|
|
|
while(srcIndex<srcLength) {
|
|
|
|
UTF_NEXT_CHAR(src, srcIndex, srcLength, c);
|
2001-12-06 01:23:47 +00:00
|
|
|
GET_PROPS_UNSAFE(c, props);
|
2001-02-14 00:47:36 +00:00
|
|
|
if(!PROPS_VALUE_IS_EXCEPTION(props)) {
|
2003-02-11 23:30:09 +00:00
|
|
|
if(CAT_MASK(props)&(U_GC_LU_MASK|U_GC_LT_MASK)) {
|
2001-02-14 00:47:36 +00:00
|
|
|
c+=GET_SIGNED_VALUE(props);
|
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
|
|
|
|
/* handle 1:1 code point mappings from UnicodeData.txt */
|
|
|
|
if(c<=0xffff) {
|
|
|
|
if(destIndex<destCapacity) {
|
|
|
|
dest[destIndex++]=(UChar)c;
|
2001-02-14 00:47:36 +00:00
|
|
|
} else {
|
2002-02-20 02:07:29 +00:00
|
|
|
/* buffer overflow */
|
|
|
|
/* keep incrementing the destIndex for preflighting */
|
|
|
|
++destIndex;
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
} else {
|
|
|
|
if((destIndex+2)<=destCapacity) {
|
|
|
|
dest[destIndex++]=UTF16_LEAD(c);
|
|
|
|
dest[destIndex++]=UTF16_TRAIL(c);
|
2001-02-14 00:47:36 +00:00
|
|
|
} else {
|
|
|
|
/* buffer overflow */
|
2002-02-20 02:07:29 +00:00
|
|
|
/* write the first surrogate if possible */
|
|
|
|
if(destIndex<destCapacity) {
|
|
|
|
dest[destIndex]=UTF16_LEAD(c);
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
|
|
|
/* keep incrementing the destIndex for preflighting */
|
2002-02-20 02:07:29 +00:00
|
|
|
destIndex+=2;
|
2001-02-14 00:47:36 +00:00
|
|
|
}
|
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
} else {
|
|
|
|
/* handle all exceptions in u_internalFoldCase() */
|
|
|
|
int32_t length;
|
2001-02-14 00:47:36 +00:00
|
|
|
|
2002-02-20 02:07:29 +00:00
|
|
|
if(destIndex<destCapacity) {
|
|
|
|
length=u_internalFoldCase(c, dest+destIndex, destCapacity-destIndex, options);
|
2001-02-14 00:47:36 +00:00
|
|
|
} else {
|
2002-02-20 02:07:29 +00:00
|
|
|
length=u_internalFoldCase(c, NULL, 0, options);
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
if(length<0) {
|
|
|
|
length=-length;
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
2002-02-20 02:07:29 +00:00
|
|
|
destIndex+=length;
|
2001-01-31 18:20:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(destIndex>destCapacity) {
|
|
|
|
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
|
|
|
return destIndex;
|
2000-11-16 21:43:12 +00:00
|
|
|
}
|