2002-02-25 22:43:04 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
2010-01-06 23:50:03 +00:00
|
|
|
* Copyright (C) 2002-2010, International Business Machines
|
2002-02-25 22:43:04 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
2010-01-06 23:50:03 +00:00
|
|
|
* file name: uprops.cpp
|
2002-02-25 22:43:04 +00:00
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2002feb24
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*
|
|
|
|
* Implementations for mostly non-core Unicode character properties
|
2002-07-17 19:25:18 +00:00
|
|
|
* stored in uprops.icu.
|
2004-09-11 22:02:10 +00:00
|
|
|
*
|
|
|
|
* With the APIs implemented here, almost all properties files and
|
|
|
|
* their associated implementation files are used from this file,
|
|
|
|
* including those for normalization and case mappings.
|
2002-02-25 22:43:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uchar.h"
|
2002-03-01 01:59:59 +00:00
|
|
|
#include "unicode/uscript.h"
|
2009-11-13 19:25:21 +00:00
|
|
|
#include "unicode/ustring.h"
|
2002-06-01 00:33:55 +00:00
|
|
|
#include "cstring.h"
|
2010-01-06 23:50:03 +00:00
|
|
|
#include "normalizer2impl.h"
|
2005-02-23 00:54:19 +00:00
|
|
|
#include "ucln_cmn.h"
|
|
|
|
#include "umutex.h"
|
2002-03-07 19:57:23 +00:00
|
|
|
#include "unormimp.h"
|
2004-12-31 13:36:49 +00:00
|
|
|
#include "ubidi_props.h"
|
2002-02-25 22:43:04 +00:00
|
|
|
#include "uprops.h"
|
2005-07-07 07:54:43 +00:00
|
|
|
#include "ucase.h"
|
2002-02-25 22:43:04 +00:00
|
|
|
|
2003-03-07 21:49:09 +00:00
|
|
|
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
|
|
|
|
2010-01-21 23:28:30 +00:00
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
2005-02-23 00:54:19 +00:00
|
|
|
/* cleanup ------------------------------------------------------------------ */
|
|
|
|
|
2005-04-28 23:48:25 +00:00
|
|
|
static const UBiDiProps *gBdp=NULL;
|
2005-02-23 00:54:19 +00:00
|
|
|
|
|
|
|
static UBool U_CALLCONV uprops_cleanup(void) {
|
|
|
|
gBdp=NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bidi/shaping properties API ---------------------------------------------- */
|
|
|
|
|
|
|
|
/* get the UBiDiProps singleton, or else its dummy, once and for all */
|
2005-04-28 23:48:25 +00:00
|
|
|
static const UBiDiProps *
|
2005-02-23 00:54:19 +00:00
|
|
|
getBiDiProps() {
|
|
|
|
/*
|
|
|
|
* This lazy intialization with double-checked locking (without mutex protection for
|
|
|
|
* the initial check) is transiently unsafe under certain circumstances.
|
|
|
|
* Check the readme and use u_init() if necessary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* the initial check is performed by the GET_BIDI_PROPS() macro */
|
2005-04-28 23:48:25 +00:00
|
|
|
const UBiDiProps *bdp;
|
2005-02-23 00:54:19 +00:00
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
|
|
|
|
bdp=ubidi_getSingleton(&errorCode);
|
2008-02-09 00:50:08 +00:00
|
|
|
#if !UBIDI_HARDCODE_DATA
|
2005-02-23 00:54:19 +00:00
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
errorCode=U_ZERO_ERROR;
|
|
|
|
bdp=ubidi_getDummy(&errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2008-02-09 00:50:08 +00:00
|
|
|
#endif
|
2005-02-23 00:54:19 +00:00
|
|
|
|
|
|
|
umtx_lock(NULL);
|
|
|
|
if(gBdp==NULL) {
|
|
|
|
gBdp=bdp;
|
|
|
|
ucln_common_registerCleanup(UCLN_COMMON_UPROPS, uprops_cleanup);
|
|
|
|
}
|
|
|
|
umtx_unlock(NULL);
|
|
|
|
|
|
|
|
return gBdp;
|
|
|
|
}
|
|
|
|
|
2005-03-12 00:09:27 +00:00
|
|
|
/* see comment for GET_CASE_PROPS() */
|
2005-02-23 00:54:19 +00:00
|
|
|
#define GET_BIDI_PROPS() (gBdp!=NULL ? gBdp : getBiDiProps())
|
|
|
|
|
|
|
|
/* general properties API functions ----------------------------------------- */
|
2002-03-06 23:31:11 +00:00
|
|
|
|
2003-03-07 21:49:09 +00:00
|
|
|
static const struct {
|
|
|
|
int32_t column;
|
|
|
|
uint32_t mask;
|
2004-05-04 18:52:35 +00:00
|
|
|
} binProps[UCHAR_BINARY_LIMIT]={
|
2003-03-07 21:49:09 +00:00
|
|
|
/*
|
|
|
|
* column and mask values for binary properties from u_getUnicodeProperties().
|
|
|
|
* Must be in order of corresponding UProperty,
|
2009-11-13 19:25:21 +00:00
|
|
|
* and there must be exactly one entry per binary UProperty.
|
2004-09-06 15:57:11 +00:00
|
|
|
*
|
|
|
|
* Properties with mask 0 are handled in code.
|
2004-09-13 23:33:22 +00:00
|
|
|
* For them, column is the UPropertySource value.
|
2003-03-07 21:49:09 +00:00
|
|
|
*/
|
2004-09-13 23:33:22 +00:00
|
|
|
{ 1, U_MASK(UPROPS_ALPHABETIC) },
|
|
|
|
{ 1, U_MASK(UPROPS_ASCII_HEX_DIGIT) },
|
2004-12-31 13:36:49 +00:00
|
|
|
{ UPROPS_SRC_BIDI, 0 }, /* UCHAR_BIDI_CONTROL */
|
|
|
|
{ UPROPS_SRC_BIDI, 0 }, /* UCHAR_BIDI_MIRRORED */
|
2004-09-13 23:33:22 +00:00
|
|
|
{ 1, U_MASK(UPROPS_DASH) },
|
|
|
|
{ 1, U_MASK(UPROPS_DEFAULT_IGNORABLE_CODE_POINT) },
|
|
|
|
{ 1, U_MASK(UPROPS_DEPRECATED) },
|
|
|
|
{ 1, U_MASK(UPROPS_DIACRITIC) },
|
|
|
|
{ 1, U_MASK(UPROPS_EXTENDER) },
|
2010-01-06 23:50:03 +00:00
|
|
|
{ UPROPS_SRC_NFC, 0 }, /* UCHAR_FULL_COMPOSITION_EXCLUSION */
|
2004-09-13 23:33:22 +00:00
|
|
|
{ 1, U_MASK(UPROPS_GRAPHEME_BASE) },
|
|
|
|
{ 1, U_MASK(UPROPS_GRAPHEME_EXTEND) },
|
|
|
|
{ 1, U_MASK(UPROPS_GRAPHEME_LINK) },
|
|
|
|
{ 1, U_MASK(UPROPS_HEX_DIGIT) },
|
|
|
|
{ 1, U_MASK(UPROPS_HYPHEN) },
|
|
|
|
{ 1, U_MASK(UPROPS_ID_CONTINUE) },
|
|
|
|
{ 1, U_MASK(UPROPS_ID_START) },
|
|
|
|
{ 1, U_MASK(UPROPS_IDEOGRAPHIC) },
|
|
|
|
{ 1, U_MASK(UPROPS_IDS_BINARY_OPERATOR) },
|
|
|
|
{ 1, U_MASK(UPROPS_IDS_TRINARY_OPERATOR) },
|
2004-12-31 13:36:49 +00:00
|
|
|
{ UPROPS_SRC_BIDI, 0 }, /* UCHAR_JOIN_CONTROL */
|
2004-09-13 23:33:22 +00:00
|
|
|
{ 1, U_MASK(UPROPS_LOGICAL_ORDER_EXCEPTION) },
|
|
|
|
{ UPROPS_SRC_CASE, 0 }, /* UCHAR_LOWERCASE */
|
|
|
|
{ 1, U_MASK(UPROPS_MATH) },
|
|
|
|
{ 1, U_MASK(UPROPS_NONCHARACTER_CODE_POINT) },
|
|
|
|
{ 1, U_MASK(UPROPS_QUOTATION_MARK) },
|
|
|
|
{ 1, U_MASK(UPROPS_RADICAL) },
|
|
|
|
{ UPROPS_SRC_CASE, 0 }, /* UCHAR_SOFT_DOTTED */
|
|
|
|
{ 1, U_MASK(UPROPS_TERMINAL_PUNCTUATION) },
|
|
|
|
{ 1, U_MASK(UPROPS_UNIFIED_IDEOGRAPH) },
|
|
|
|
{ UPROPS_SRC_CASE, 0 }, /* UCHAR_UPPERCASE */
|
|
|
|
{ 1, U_MASK(UPROPS_WHITE_SPACE) },
|
|
|
|
{ 1, U_MASK(UPROPS_XID_CONTINUE) },
|
|
|
|
{ 1, U_MASK(UPROPS_XID_START) },
|
|
|
|
{ UPROPS_SRC_CASE, 0 }, /* UCHAR_CASE_SENSITIVE */
|
2008-04-04 22:47:43 +00:00
|
|
|
{ 1, U_MASK(UPROPS_S_TERM) },
|
|
|
|
{ 1, U_MASK(UPROPS_VARIATION_SELECTOR) },
|
2010-01-06 23:50:03 +00:00
|
|
|
{ UPROPS_SRC_NFC, 0 }, /* UCHAR_NFD_INERT */
|
|
|
|
{ UPROPS_SRC_NFKC, 0 }, /* UCHAR_NFKD_INERT */
|
|
|
|
{ UPROPS_SRC_NFC, 0 }, /* UCHAR_NFC_INERT */
|
|
|
|
{ UPROPS_SRC_NFKC, 0 }, /* UCHAR_NFKC_INERT */
|
2005-01-10 18:02:54 +00:00
|
|
|
{ UPROPS_SRC_NORM, 0 }, /* UCHAR_SEGMENT_STARTER */
|
2008-04-04 22:47:43 +00:00
|
|
|
{ 1, U_MASK(UPROPS_PATTERN_SYNTAX) },
|
|
|
|
{ 1, U_MASK(UPROPS_PATTERN_WHITE_SPACE) },
|
2005-05-28 22:54:36 +00:00
|
|
|
{ UPROPS_SRC_CHAR_AND_PROPSVEC, 0 }, /* UCHAR_POSIX_ALNUM */
|
|
|
|
{ UPROPS_SRC_CHAR, 0 }, /* UCHAR_POSIX_BLANK */
|
|
|
|
{ UPROPS_SRC_CHAR, 0 }, /* UCHAR_POSIX_GRAPH */
|
|
|
|
{ UPROPS_SRC_CHAR, 0 }, /* UCHAR_POSIX_PRINT */
|
2009-11-13 19:25:21 +00:00
|
|
|
{ UPROPS_SRC_CHAR, 0 }, /* UCHAR_POSIX_XDIGIT */
|
|
|
|
{ UPROPS_SRC_CASE, 0 }, /* UCHAR_CASED */
|
|
|
|
{ UPROPS_SRC_CASE, 0 }, /* UCHAR_CASE_IGNORABLE */
|
|
|
|
{ UPROPS_SRC_CASE, 0 }, /* UCHAR_CHANGES_WHEN_LOWERCASED */
|
|
|
|
{ UPROPS_SRC_CASE, 0 }, /* UCHAR_CHANGES_WHEN_UPPERCASED */
|
|
|
|
{ UPROPS_SRC_CASE, 0 }, /* UCHAR_CHANGES_WHEN_TITLECASED */
|
|
|
|
{ UPROPS_SRC_CASE_AND_NORM, 0 }, /* UCHAR_CHANGES_WHEN_CASEFOLDED */
|
2010-01-06 23:50:03 +00:00
|
|
|
{ UPROPS_SRC_CASE, 0 }, /* UCHAR_CHANGES_WHEN_CASEMAPPED */
|
|
|
|
{ UPROPS_SRC_NFKC_CF, 0 } /* UCHAR_CHANGES_WHEN_NFKC_CASEFOLDED */
|
2003-03-07 21:49:09 +00:00
|
|
|
};
|
|
|
|
|
2002-03-12 19:09:08 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
u_hasBinaryProperty(UChar32 c, UProperty which) {
|
2002-03-06 23:31:11 +00:00
|
|
|
/* c is range-checked in the functions that are called from here */
|
2003-03-07 21:49:09 +00:00
|
|
|
if(which<UCHAR_BINARY_START || UCHAR_BINARY_LIMIT<=which) {
|
2002-03-06 23:31:11 +00:00
|
|
|
/* not a known binary property */
|
2004-05-04 18:52:35 +00:00
|
|
|
} else {
|
|
|
|
uint32_t mask=binProps[which].mask;
|
2004-09-13 23:33:22 +00:00
|
|
|
int32_t column=binProps[which].column;
|
2004-05-04 18:52:35 +00:00
|
|
|
if(mask!=0) {
|
|
|
|
/* systematic, directly stored properties */
|
2004-09-13 23:33:22 +00:00
|
|
|
return (u_getUnicodeProperties(c, column)&mask)!=0;
|
2004-05-04 18:52:35 +00:00
|
|
|
} else {
|
2004-09-13 23:33:22 +00:00
|
|
|
if(column==UPROPS_SRC_CASE) {
|
2006-03-31 05:29:06 +00:00
|
|
|
return ucase_hasBinaryProperty(c, which);
|
2004-09-13 23:33:22 +00:00
|
|
|
} else if(column==UPROPS_SRC_NORM) {
|
2003-05-06 01:37:52 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
2004-09-13 23:33:22 +00:00
|
|
|
/* normalization properties from unorm.icu */
|
|
|
|
switch(which) {
|
|
|
|
case UCHAR_SEGMENT_STARTER:
|
|
|
|
return unorm_isCanonSafeStart(c);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-01-06 23:50:03 +00:00
|
|
|
#endif
|
2010-02-13 23:15:05 +00:00
|
|
|
} else if(column==UPROPS_SRC_NFC) {
|
2010-01-06 23:50:03 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
switch(which) {
|
|
|
|
case UCHAR_FULL_COMPOSITION_EXCLUSION: {
|
|
|
|
// By definition, Full_Composition_Exclusion is the same as NFC_QC=No.
|
|
|
|
const Normalizer2Impl *impl=Normalizer2Factory::getNFCImpl(errorCode);
|
2010-02-13 23:15:05 +00:00
|
|
|
return U_SUCCESS(errorCode) && impl->isCompNo(impl->getNorm16(c));
|
2010-01-06 23:50:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2010-02-13 23:15:05 +00:00
|
|
|
// UCHAR_NF[CD]_INERT properties
|
2010-01-06 23:50:03 +00:00
|
|
|
const Normalizer2 *norm2=Normalizer2Factory::getInstance(
|
|
|
|
(UNormalizationMode)(which-UCHAR_NFD_INERT+UNORM_NFD), errorCode);
|
2010-02-13 23:15:05 +00:00
|
|
|
return U_SUCCESS(errorCode) && norm2->isInert(c);
|
2010-01-06 23:50:03 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-13 23:15:05 +00:00
|
|
|
#endif
|
|
|
|
} else if(column==UPROPS_SRC_NFKC) {
|
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
|
|
|
// UCHAR_NFK[CD]_INERT properties
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
const Normalizer2 *norm2=Normalizer2Factory::getInstance(
|
|
|
|
(UNormalizationMode)(which-UCHAR_NFD_INERT+UNORM_NFD), errorCode);
|
|
|
|
return U_SUCCESS(errorCode) && norm2->isInert(c);
|
2010-01-06 23:50:03 +00:00
|
|
|
#endif
|
|
|
|
} else if(column==UPROPS_SRC_NFKC_CF) {
|
|
|
|
// currently only for UCHAR_CHANGES_WHEN_NFKC_CASEFOLDED
|
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
const Normalizer2Impl *kcf=Normalizer2Factory::getNFKC_CFImpl(errorCode);
|
|
|
|
if(U_SUCCESS(errorCode)) {
|
|
|
|
UnicodeString src(c);
|
|
|
|
UnicodeString dest;
|
|
|
|
{
|
|
|
|
// The ReorderingBuffer must be in a block because its destructor
|
|
|
|
// needs to release dest's buffer before we look at its contents.
|
|
|
|
ReorderingBuffer buffer(*kcf, dest);
|
|
|
|
// Small destCapacity for NFKC_CF(c).
|
2010-01-26 04:24:20 +00:00
|
|
|
if(buffer.init(5, errorCode)) {
|
2010-01-06 23:50:03 +00:00
|
|
|
const UChar *srcArray=src.getBuffer();
|
|
|
|
kcf->compose(srcArray, srcArray+src.length(), FALSE,
|
|
|
|
TRUE, buffer, errorCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return U_SUCCESS(errorCode) && dest!=src;
|
|
|
|
}
|
2003-05-06 01:37:52 +00:00
|
|
|
#endif
|
2004-12-31 13:36:49 +00:00
|
|
|
} else if(column==UPROPS_SRC_BIDI) {
|
|
|
|
/* bidi/shaping properties */
|
2005-04-28 23:48:25 +00:00
|
|
|
const UBiDiProps *bdp=GET_BIDI_PROPS();
|
2006-05-26 20:31:30 +00:00
|
|
|
if(bdp!=NULL) {
|
|
|
|
switch(which) {
|
|
|
|
case UCHAR_BIDI_MIRRORED:
|
|
|
|
return ubidi_isMirrored(bdp, c);
|
|
|
|
case UCHAR_BIDI_CONTROL:
|
|
|
|
return ubidi_isBidiControl(bdp, c);
|
|
|
|
case UCHAR_JOIN_CONTROL:
|
|
|
|
return ubidi_isJoinControl(bdp, c);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-12-31 13:36:49 +00:00
|
|
|
}
|
2006-05-26 20:31:30 +00:00
|
|
|
/* else return FALSE below */
|
2005-05-28 22:54:36 +00:00
|
|
|
} else if(column==UPROPS_SRC_CHAR) {
|
|
|
|
switch(which) {
|
|
|
|
case UCHAR_POSIX_BLANK:
|
|
|
|
return u_isblank(c);
|
|
|
|
case UCHAR_POSIX_GRAPH:
|
|
|
|
return u_isgraphPOSIX(c);
|
|
|
|
case UCHAR_POSIX_PRINT:
|
|
|
|
return u_isprintPOSIX(c);
|
|
|
|
case UCHAR_POSIX_XDIGIT:
|
|
|
|
return u_isxdigit(c);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if(column==UPROPS_SRC_CHAR_AND_PROPSVEC) {
|
|
|
|
switch(which) {
|
|
|
|
case UCHAR_POSIX_ALNUM:
|
|
|
|
return u_isalnumPOSIX(c);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-11-13 19:25:21 +00:00
|
|
|
} else if(column==UPROPS_SRC_CASE_AND_NORM) {
|
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
|
|
|
UChar nfdBuffer[4];
|
2010-01-06 23:50:03 +00:00
|
|
|
const UChar *nfd;
|
2009-11-13 19:25:21 +00:00
|
|
|
int32_t nfdLength;
|
2010-01-06 23:50:03 +00:00
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
const Normalizer2Impl *nfcImpl=Normalizer2Factory::getNFCImpl(errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-11-13 19:25:21 +00:00
|
|
|
switch(which) {
|
|
|
|
case UCHAR_CHANGES_WHEN_CASEFOLDED:
|
2010-01-06 23:50:03 +00:00
|
|
|
nfd=nfcImpl->getDecomposition(c, nfdBuffer, nfdLength);
|
2009-11-13 19:25:21 +00:00
|
|
|
if(nfd!=NULL) {
|
|
|
|
/* c has a decomposition */
|
|
|
|
if(nfdLength==1) {
|
|
|
|
c=nfd[0]; /* single BMP code point */
|
|
|
|
} else if(nfdLength<=U16_MAX_LENGTH) {
|
|
|
|
int32_t i=0;
|
|
|
|
U16_NEXT(nfd, i, nfdLength, c);
|
|
|
|
if(i==nfdLength) {
|
|
|
|
/* single supplementary code point */
|
|
|
|
} else {
|
|
|
|
c=U_SENTINEL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c=U_SENTINEL;
|
|
|
|
}
|
|
|
|
} else if(c<0) {
|
|
|
|
return FALSE; /* protect against bad input */
|
|
|
|
}
|
|
|
|
errorCode=U_ZERO_ERROR;
|
|
|
|
if(c>=0) {
|
|
|
|
/* single code point */
|
|
|
|
const UCaseProps *csp=ucase_getSingleton(&errorCode);
|
|
|
|
const UChar *resultString;
|
|
|
|
return (UBool)(ucase_toFullFolding(csp, c, &resultString, U_FOLD_CASE_DEFAULT)>=0);
|
|
|
|
} else {
|
|
|
|
/* guess some large but stack-friendly capacity */
|
|
|
|
UChar dest[2*UCASE_MAX_STRING_LENGTH];
|
|
|
|
int32_t destLength;
|
|
|
|
destLength=u_strFoldCase(dest, LENGTHOF(dest), nfd, nfdLength, U_FOLD_CASE_DEFAULT, &errorCode);
|
|
|
|
return (UBool)(U_SUCCESS(errorCode) && 0!=u_strCompare(nfd, nfdLength, dest, destLength, FALSE));
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2004-09-13 23:33:22 +00:00
|
|
|
}
|
2004-05-04 18:52:35 +00:00
|
|
|
}
|
2002-11-30 04:41:53 +00:00
|
|
|
}
|
2004-05-04 18:52:35 +00:00
|
|
|
return FALSE;
|
2002-03-06 23:31:11 +00:00
|
|
|
}
|
|
|
|
|
2010-01-06 23:50:03 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
|
|
|
|
|
|
|
U_CAPI uint8_t U_EXPORT2
|
|
|
|
u_getCombiningClass(UChar32 c) {
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
const Normalizer2Impl *impl=Normalizer2Factory::getNFCImpl(errorCode);
|
|
|
|
if(U_SUCCESS(errorCode)) {
|
|
|
|
return impl->getCC(impl->getNorm16(c));
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16_t
|
|
|
|
getFCD16(UChar32 c) {
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
const UTrie2 *trie=Normalizer2Factory::getFCDTrie(errorCode);
|
|
|
|
if(U_SUCCESS(errorCode)) {
|
|
|
|
return UTRIE2_GET16(trie, c);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-11-13 19:25:21 +00:00
|
|
|
/*
|
|
|
|
* Map some of the Grapheme Cluster Break values to Hangul Syllable Types.
|
|
|
|
* Hangul_Syllable_Type is fully redundant with a subset of Grapheme_Cluster_Break.
|
|
|
|
*/
|
|
|
|
static const UHangulSyllableType gcbToHst[]={
|
|
|
|
U_HST_NOT_APPLICABLE, /* U_GCB_OTHER */
|
|
|
|
U_HST_NOT_APPLICABLE, /* U_GCB_CONTROL */
|
|
|
|
U_HST_NOT_APPLICABLE, /* U_GCB_CR */
|
|
|
|
U_HST_NOT_APPLICABLE, /* U_GCB_EXTEND */
|
|
|
|
U_HST_LEADING_JAMO, /* U_GCB_L */
|
|
|
|
U_HST_NOT_APPLICABLE, /* U_GCB_LF */
|
|
|
|
U_HST_LV_SYLLABLE, /* U_GCB_LV */
|
|
|
|
U_HST_LVT_SYLLABLE, /* U_GCB_LVT */
|
|
|
|
U_HST_TRAILING_JAMO, /* U_GCB_T */
|
|
|
|
U_HST_VOWEL_JAMO /* U_GCB_V */
|
|
|
|
/*
|
|
|
|
* Omit GCB values beyond what we need for hst.
|
|
|
|
* The code below checks for the array length.
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
2002-07-04 00:17:12 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
u_getIntPropertyValue(UChar32 c, UProperty which) {
|
2005-01-02 00:32:39 +00:00
|
|
|
UErrorCode errorCode;
|
2002-07-04 00:17:12 +00:00
|
|
|
|
|
|
|
if(which<UCHAR_BINARY_START) {
|
|
|
|
return 0; /* undefined */
|
|
|
|
} else if(which<UCHAR_BINARY_LIMIT) {
|
|
|
|
return (int32_t)u_hasBinaryProperty(c, which);
|
|
|
|
} else if(which<UCHAR_INT_START) {
|
|
|
|
return 0; /* undefined */
|
|
|
|
} else if(which<UCHAR_INT_LIMIT) {
|
|
|
|
switch(which) {
|
|
|
|
case UCHAR_BIDI_CLASS:
|
|
|
|
return (int32_t)u_charDirection(c);
|
|
|
|
case UCHAR_BLOCK:
|
|
|
|
return (int32_t)ublock_getCode(c);
|
2003-05-06 01:37:52 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
2010-01-06 23:50:03 +00:00
|
|
|
case UCHAR_CANONICAL_COMBINING_CLASS:
|
2002-07-04 00:17:12 +00:00
|
|
|
return u_getCombiningClass(c);
|
2003-05-06 01:37:52 +00:00
|
|
|
#endif
|
2002-07-04 00:17:12 +00:00
|
|
|
case UCHAR_DECOMPOSITION_TYPE:
|
2002-07-04 16:46:36 +00:00
|
|
|
return (int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_DT_MASK);
|
2002-07-04 00:17:12 +00:00
|
|
|
case UCHAR_EAST_ASIAN_WIDTH:
|
2002-07-04 16:46:36 +00:00
|
|
|
return (int32_t)(u_getUnicodeProperties(c, 0)&UPROPS_EA_MASK)>>UPROPS_EA_SHIFT;
|
2002-07-04 00:17:12 +00:00
|
|
|
case UCHAR_GENERAL_CATEGORY:
|
|
|
|
return (int32_t)u_charType(c);
|
|
|
|
case UCHAR_JOINING_GROUP:
|
2005-02-23 00:54:19 +00:00
|
|
|
return ubidi_getJoiningGroup(GET_BIDI_PROPS(), c);
|
2002-07-04 00:17:12 +00:00
|
|
|
case UCHAR_JOINING_TYPE:
|
2005-02-23 00:54:19 +00:00
|
|
|
return ubidi_getJoiningType(GET_BIDI_PROPS(), c);
|
2002-07-04 00:17:12 +00:00
|
|
|
case UCHAR_LINE_BREAK:
|
2008-04-04 22:47:43 +00:00
|
|
|
return (int32_t)(u_getUnicodeProperties(c, UPROPS_LB_VWORD)&UPROPS_LB_MASK)>>UPROPS_LB_SHIFT;
|
2009-11-13 19:25:21 +00:00
|
|
|
case UCHAR_NUMERIC_TYPE: {
|
|
|
|
int32_t ntv=(int32_t)GET_NUMERIC_TYPE_VALUE(u_getUnicodeProperties(c, -1));
|
|
|
|
return UPROPS_NTV_GET_TYPE(ntv);
|
|
|
|
}
|
2002-07-04 00:17:12 +00:00
|
|
|
case UCHAR_SCRIPT:
|
2005-01-02 00:32:39 +00:00
|
|
|
errorCode=U_ZERO_ERROR;
|
2002-07-04 00:17:12 +00:00
|
|
|
return (int32_t)uscript_getScript(c, &errorCode);
|
2009-11-13 19:25:21 +00:00
|
|
|
case UCHAR_HANGUL_SYLLABLE_TYPE: {
|
|
|
|
/* see comments on gcbToHst[] above */
|
|
|
|
int32_t gcb=(int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_GCB_MASK)>>UPROPS_GCB_SHIFT;
|
|
|
|
if(gcb<LENGTHOF(gcbToHst)) {
|
|
|
|
return gcbToHst[gcb];
|
|
|
|
} else {
|
|
|
|
return U_HST_NOT_APPLICABLE;
|
|
|
|
}
|
|
|
|
}
|
2004-06-10 23:51:33 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
2004-04-07 00:28:39 +00:00
|
|
|
case UCHAR_NFD_QUICK_CHECK:
|
|
|
|
case UCHAR_NFKD_QUICK_CHECK:
|
|
|
|
case UCHAR_NFC_QUICK_CHECK:
|
|
|
|
case UCHAR_NFKC_QUICK_CHECK:
|
2006-08-24 17:28:52 +00:00
|
|
|
return (int32_t)unorm_getQuickCheck(c, (UNormalizationMode)(which-UCHAR_NFD_QUICK_CHECK+UNORM_NFD));
|
2004-04-07 02:57:06 +00:00
|
|
|
case UCHAR_LEAD_CANONICAL_COMBINING_CLASS:
|
2010-01-06 23:50:03 +00:00
|
|
|
return getFCD16(c)>>8;
|
2004-04-07 02:57:06 +00:00
|
|
|
case UCHAR_TRAIL_CANONICAL_COMBINING_CLASS:
|
2010-01-06 23:50:03 +00:00
|
|
|
return getFCD16(c)&0xff;
|
2004-06-10 23:51:33 +00:00
|
|
|
#endif
|
2005-01-10 18:02:54 +00:00
|
|
|
case UCHAR_GRAPHEME_CLUSTER_BREAK:
|
|
|
|
return (int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_GCB_MASK)>>UPROPS_GCB_SHIFT;
|
|
|
|
case UCHAR_SENTENCE_BREAK:
|
|
|
|
return (int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_SB_MASK)>>UPROPS_SB_SHIFT;
|
|
|
|
case UCHAR_WORD_BREAK:
|
|
|
|
return (int32_t)(u_getUnicodeProperties(c, 2)&UPROPS_WB_MASK)>>UPROPS_WB_SHIFT;
|
2002-07-04 00:17:12 +00:00
|
|
|
default:
|
|
|
|
return 0; /* undefined */
|
|
|
|
}
|
2002-12-10 00:33:45 +00:00
|
|
|
} else if(which==UCHAR_GENERAL_CATEGORY_MASK) {
|
|
|
|
return U_MASK(u_charType(c));
|
2002-07-04 00:17:12 +00:00
|
|
|
} else {
|
|
|
|
return 0; /* undefined */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
2010-05-25 22:17:12 +00:00
|
|
|
u_getIntPropertyMinValue(UProperty /*which*/) {
|
2003-03-04 00:52:07 +00:00
|
|
|
return 0; /* all binary/enum/int properties have a minimum value of 0 */
|
2002-07-04 00:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
u_getIntPropertyMaxValue(UProperty which) {
|
|
|
|
if(which<UCHAR_BINARY_START) {
|
2002-11-13 20:03:11 +00:00
|
|
|
return -1; /* undefined */
|
2002-07-04 00:17:12 +00:00
|
|
|
} else if(which<UCHAR_BINARY_LIMIT) {
|
|
|
|
return 1; /* maximum TRUE for all binary properties */
|
|
|
|
} else if(which<UCHAR_INT_START) {
|
2002-11-13 20:03:11 +00:00
|
|
|
return -1; /* undefined */
|
2002-07-04 00:17:12 +00:00
|
|
|
} else if(which<UCHAR_INT_LIMIT) {
|
|
|
|
switch(which) {
|
|
|
|
case UCHAR_BIDI_CLASS:
|
2004-12-31 13:36:49 +00:00
|
|
|
case UCHAR_JOINING_GROUP:
|
|
|
|
case UCHAR_JOINING_TYPE:
|
2005-02-23 00:54:19 +00:00
|
|
|
return ubidi_getMaxValue(GET_BIDI_PROPS(), which);
|
2002-07-04 00:17:12 +00:00
|
|
|
case UCHAR_BLOCK:
|
2005-01-10 18:02:54 +00:00
|
|
|
return (uprv_getMaxValues(0)&UPROPS_BLOCK_MASK)>>UPROPS_BLOCK_SHIFT;
|
2002-07-04 00:17:12 +00:00
|
|
|
case UCHAR_CANONICAL_COMBINING_CLASS:
|
2004-04-07 02:57:06 +00:00
|
|
|
case UCHAR_LEAD_CANONICAL_COMBINING_CLASS:
|
|
|
|
case UCHAR_TRAIL_CANONICAL_COMBINING_CLASS:
|
2002-07-04 00:17:12 +00:00
|
|
|
return 0xff; /* TODO do we need to be more precise, getting the actual maximum? */
|
|
|
|
case UCHAR_DECOMPOSITION_TYPE:
|
2005-01-10 18:02:54 +00:00
|
|
|
return uprv_getMaxValues(2)&UPROPS_DT_MASK;
|
2002-07-04 00:17:12 +00:00
|
|
|
case UCHAR_EAST_ASIAN_WIDTH:
|
2005-01-10 18:02:54 +00:00
|
|
|
return (uprv_getMaxValues(0)&UPROPS_EA_MASK)>>UPROPS_EA_SHIFT;
|
2002-07-04 00:17:12 +00:00
|
|
|
case UCHAR_GENERAL_CATEGORY:
|
|
|
|
return (int32_t)U_CHAR_CATEGORY_COUNT-1;
|
|
|
|
case UCHAR_LINE_BREAK:
|
2008-04-04 22:47:43 +00:00
|
|
|
return (uprv_getMaxValues(UPROPS_LB_VWORD)&UPROPS_LB_MASK)>>UPROPS_LB_SHIFT;
|
2002-07-04 00:17:12 +00:00
|
|
|
case UCHAR_NUMERIC_TYPE:
|
|
|
|
return (int32_t)U_NT_COUNT-1;
|
|
|
|
case UCHAR_SCRIPT:
|
2005-01-10 18:02:54 +00:00
|
|
|
return uprv_getMaxValues(0)&UPROPS_SCRIPT_MASK;
|
2003-03-08 02:00:06 +00:00
|
|
|
case UCHAR_HANGUL_SYLLABLE_TYPE:
|
|
|
|
return (int32_t)U_HST_COUNT-1;
|
2004-06-10 23:51:33 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
2004-04-07 00:28:39 +00:00
|
|
|
case UCHAR_NFD_QUICK_CHECK:
|
|
|
|
case UCHAR_NFKD_QUICK_CHECK:
|
|
|
|
return (int32_t)UNORM_YES; /* these are never "maybe", only "no" or "yes" */
|
|
|
|
case UCHAR_NFC_QUICK_CHECK:
|
|
|
|
case UCHAR_NFKC_QUICK_CHECK:
|
|
|
|
return (int32_t)UNORM_MAYBE;
|
2004-06-10 23:51:33 +00:00
|
|
|
#endif
|
2005-01-10 18:02:54 +00:00
|
|
|
case UCHAR_GRAPHEME_CLUSTER_BREAK:
|
|
|
|
return (uprv_getMaxValues(2)&UPROPS_GCB_MASK)>>UPROPS_GCB_SHIFT;
|
|
|
|
case UCHAR_SENTENCE_BREAK:
|
|
|
|
return (uprv_getMaxValues(2)&UPROPS_SB_MASK)>>UPROPS_SB_SHIFT;
|
|
|
|
case UCHAR_WORD_BREAK:
|
|
|
|
return (uprv_getMaxValues(2)&UPROPS_WB_MASK)>>UPROPS_WB_SHIFT;
|
2002-07-04 00:17:12 +00:00
|
|
|
default:
|
2002-11-13 20:03:11 +00:00
|
|
|
return -1; /* undefined */
|
2002-07-04 00:17:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-11-13 20:03:11 +00:00
|
|
|
return -1; /* undefined */
|
2002-07-04 00:17:12 +00:00
|
|
|
}
|
|
|
|
}
|
2002-10-30 18:12:49 +00:00
|
|
|
|
2009-11-13 19:25:21 +00:00
|
|
|
/*
|
|
|
|
* TODO: Simplify, similar to binProps[].
|
|
|
|
* Use an array of column/source, mask, shift values to drive returning simple
|
|
|
|
* properties and their sources.
|
|
|
|
*
|
|
|
|
* TODO: Split the single propsvec into one per column, and have
|
|
|
|
* upropsvec_addPropertyStarts() pass a trie value function that gets the
|
|
|
|
* desired column's values.
|
|
|
|
*/
|
2007-06-03 06:08:46 +00:00
|
|
|
U_CFUNC UPropertySource U_EXPORT2
|
2004-09-13 23:33:22 +00:00
|
|
|
uprops_getSource(UProperty which) {
|
|
|
|
if(which<UCHAR_BINARY_START) {
|
|
|
|
return UPROPS_SRC_NONE; /* undefined */
|
|
|
|
} else if(which<UCHAR_BINARY_LIMIT) {
|
|
|
|
if(binProps[which].mask!=0) {
|
2005-01-10 18:02:54 +00:00
|
|
|
return UPROPS_SRC_PROPSVEC;
|
2004-09-13 23:33:22 +00:00
|
|
|
} else {
|
|
|
|
return (UPropertySource)binProps[which].column;
|
|
|
|
}
|
|
|
|
} else if(which<UCHAR_INT_START) {
|
|
|
|
return UPROPS_SRC_NONE; /* undefined */
|
|
|
|
} else if(which<UCHAR_INT_LIMIT) {
|
|
|
|
switch(which) {
|
2005-01-10 18:02:54 +00:00
|
|
|
case UCHAR_GENERAL_CATEGORY:
|
|
|
|
case UCHAR_NUMERIC_TYPE:
|
|
|
|
return UPROPS_SRC_CHAR;
|
|
|
|
|
2004-09-13 23:33:22 +00:00
|
|
|
case UCHAR_CANONICAL_COMBINING_CLASS:
|
|
|
|
case UCHAR_NFD_QUICK_CHECK:
|
|
|
|
case UCHAR_NFC_QUICK_CHECK:
|
|
|
|
case UCHAR_LEAD_CANONICAL_COMBINING_CLASS:
|
|
|
|
case UCHAR_TRAIL_CANONICAL_COMBINING_CLASS:
|
2010-01-06 23:50:03 +00:00
|
|
|
return UPROPS_SRC_NFC;
|
|
|
|
case UCHAR_NFKD_QUICK_CHECK:
|
|
|
|
case UCHAR_NFKC_QUICK_CHECK:
|
|
|
|
return UPROPS_SRC_NFKC;
|
2004-12-31 13:36:49 +00:00
|
|
|
|
|
|
|
case UCHAR_BIDI_CLASS:
|
|
|
|
case UCHAR_JOINING_GROUP:
|
|
|
|
case UCHAR_JOINING_TYPE:
|
|
|
|
return UPROPS_SRC_BIDI;
|
|
|
|
|
2004-09-13 23:33:22 +00:00
|
|
|
default:
|
2005-01-10 18:02:54 +00:00
|
|
|
return UPROPS_SRC_PROPSVEC;
|
|
|
|
}
|
|
|
|
} else if(which<UCHAR_STRING_START) {
|
|
|
|
switch(which) {
|
|
|
|
case UCHAR_GENERAL_CATEGORY_MASK:
|
|
|
|
case UCHAR_NUMERIC_VALUE:
|
2004-09-13 23:33:22 +00:00
|
|
|
return UPROPS_SRC_CHAR;
|
2005-01-10 18:02:54 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return UPROPS_SRC_NONE;
|
|
|
|
}
|
|
|
|
} else if(which<UCHAR_STRING_LIMIT) {
|
|
|
|
switch(which) {
|
|
|
|
case UCHAR_AGE:
|
|
|
|
return UPROPS_SRC_PROPSVEC;
|
|
|
|
|
|
|
|
case UCHAR_BIDI_MIRRORING_GLYPH:
|
|
|
|
return UPROPS_SRC_BIDI;
|
|
|
|
|
|
|
|
case UCHAR_CASE_FOLDING:
|
|
|
|
case UCHAR_LOWERCASE_MAPPING:
|
|
|
|
case UCHAR_SIMPLE_CASE_FOLDING:
|
|
|
|
case UCHAR_SIMPLE_LOWERCASE_MAPPING:
|
|
|
|
case UCHAR_SIMPLE_TITLECASE_MAPPING:
|
|
|
|
case UCHAR_SIMPLE_UPPERCASE_MAPPING:
|
|
|
|
case UCHAR_TITLECASE_MAPPING:
|
|
|
|
case UCHAR_UPPERCASE_MAPPING:
|
|
|
|
return UPROPS_SRC_CASE;
|
|
|
|
|
|
|
|
case UCHAR_ISO_COMMENT:
|
|
|
|
case UCHAR_NAME:
|
|
|
|
case UCHAR_UNICODE_1_NAME:
|
|
|
|
return UPROPS_SRC_NAMES;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return UPROPS_SRC_NONE;
|
2004-09-13 23:33:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return UPROPS_SRC_NONE; /* undefined */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-09 23:11:48 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
|
|
|
|
2010-02-10 23:05:39 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
u_getFC_NFKC_Closure(UChar32 c, UChar *dest, int32_t destCapacity, UErrorCode *pErrorCode) {
|
|
|
|
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(destCapacity<0 || (dest==NULL && destCapacity>0)) {
|
|
|
|
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// Compute the FC_NFKC_Closure on the fly:
|
|
|
|
// We have the API for complete coverage of Unicode properties, although
|
|
|
|
// this value by itself is not useful via API.
|
|
|
|
// (What could be useful is a custom normalization table that combines
|
|
|
|
// case folding and NFKC.)
|
|
|
|
// For the derivation, see Unicode's DerivedNormalizationProps.txt.
|
|
|
|
const Normalizer2 *nfkc=Normalizer2Factory::getNFKCInstance(*pErrorCode);
|
|
|
|
const UCaseProps *csp=ucase_getSingleton(pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// first: b = NFKC(Fold(a))
|
|
|
|
UnicodeString folded1String;
|
|
|
|
const UChar *folded1;
|
|
|
|
int32_t folded1Length=ucase_toFullFolding(csp, c, &folded1, U_FOLD_CASE_DEFAULT);
|
|
|
|
if(folded1Length<0) {
|
|
|
|
const Normalizer2Impl *nfkcImpl=Normalizer2Factory::getImpl(nfkc);
|
|
|
|
if(nfkcImpl->getCompQuickCheck(nfkcImpl->getNorm16(c))!=UNORM_NO) {
|
|
|
|
return u_terminateUChars(dest, destCapacity, 0, pErrorCode); // c does not change at all under CaseFolding+NFKC
|
|
|
|
}
|
|
|
|
folded1String.setTo(c);
|
|
|
|
} else {
|
|
|
|
if(folded1Length>UCASE_MAX_STRING_LENGTH) {
|
|
|
|
folded1String.setTo(folded1Length);
|
|
|
|
} else {
|
|
|
|
folded1String.setTo(FALSE, folded1, folded1Length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UnicodeString kc1=nfkc->normalize(folded1String, *pErrorCode);
|
|
|
|
// second: c = NFKC(Fold(b))
|
|
|
|
UnicodeString folded2String(kc1);
|
|
|
|
UnicodeString kc2=nfkc->normalize(folded2String.foldCase(), *pErrorCode);
|
|
|
|
// if (c != b) add the mapping from a to c
|
|
|
|
if(U_FAILURE(*pErrorCode) || kc1==kc2) {
|
|
|
|
return u_terminateUChars(dest, destCapacity, 0, pErrorCode);
|
|
|
|
} else {
|
|
|
|
return kc2.extract(dest, destCapacity, *pErrorCode);
|
|
|
|
}
|
|
|
|
}
|
2010-03-09 23:11:48 +00:00
|
|
|
#endif
|
2010-02-10 23:05:39 +00:00
|
|
|
|
2002-10-30 18:12:49 +00:00
|
|
|
/*----------------------------------------------------------------
|
|
|
|
* Inclusions list
|
2002-11-12 00:43:02 +00:00
|
|
|
*----------------------------------------------------------------*/
|
2002-10-30 18:12:49 +00:00
|
|
|
|
2002-11-06 00:52:44 +00:00
|
|
|
/*
|
|
|
|
* Return a set of characters for property enumeration.
|
2002-11-25 22:42:55 +00:00
|
|
|
* The set implicitly contains 0x110000 as well, which is one more than the highest
|
|
|
|
* Unicode code point.
|
|
|
|
*
|
|
|
|
* This set is used as an ordered list - its code points are ordered, and
|
|
|
|
* consecutive code points (in Unicode code point order) in the set define a range.
|
2002-11-06 00:52:44 +00:00
|
|
|
* For each two consecutive characters (start, limit) in the set,
|
2002-11-25 22:42:55 +00:00
|
|
|
* all of the UCD/normalization and related properties for
|
|
|
|
* all code points start..limit-1 are all the same,
|
|
|
|
* except for character names and ISO comments.
|
|
|
|
*
|
|
|
|
* All Unicode code points U+0000..U+10ffff are covered by these ranges.
|
|
|
|
* The ranges define a partition of the Unicode code space.
|
|
|
|
* ICU uses the inclusions set to enumerate properties for generating
|
|
|
|
* UnicodeSets containing all code points that have a certain property value.
|
2002-10-30 18:12:49 +00:00
|
|
|
*
|
2002-11-06 00:52:44 +00:00
|
|
|
* The Inclusion List is generated from the UCD. It is generated
|
|
|
|
* by enumerating the data tries, and code points for hardcoded properties
|
|
|
|
* are added as well.
|
2002-10-30 18:12:49 +00:00
|
|
|
*
|
2002-11-25 22:42:55 +00:00
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*
|
2002-11-06 00:52:44 +00:00
|
|
|
* The following are ideas for getting properties-unique code point ranges,
|
|
|
|
* with possible optimizations beyond the current implementation.
|
|
|
|
* These optimizations would require more code and be more fragile.
|
|
|
|
* The current implementation generates one single list (set) for all properties.
|
2002-10-30 18:12:49 +00:00
|
|
|
*
|
|
|
|
* To enumerate properties efficiently, one needs to know ranges of
|
|
|
|
* repetitive values, so that the value of only each start code point
|
|
|
|
* can be applied to the whole range.
|
2002-11-06 00:52:44 +00:00
|
|
|
* This information is in principle available in the uprops.icu/unorm.icu data.
|
2002-10-30 18:12:49 +00:00
|
|
|
*
|
|
|
|
* There are two obstacles:
|
|
|
|
*
|
|
|
|
* 1. Some properties are computed from multiple data structures,
|
|
|
|
* making it necessary to get repetitive ranges by intersecting
|
|
|
|
* ranges from multiple tries.
|
|
|
|
*
|
|
|
|
* 2. It is not economical to write code for getting repetitive ranges
|
|
|
|
* that are precise for each of some 50 properties.
|
|
|
|
*
|
|
|
|
* Compromise ideas:
|
|
|
|
*
|
|
|
|
* - Get ranges per trie, not per individual property.
|
|
|
|
* Each range contains the same values for a whole group of properties.
|
|
|
|
* This would generate currently five range sets, two for uprops.icu tries
|
|
|
|
* and three for unorm.icu tries.
|
|
|
|
*
|
|
|
|
* - Combine sets of ranges for multiple tries to get sufficient sets
|
|
|
|
* for properties, e.g., the uprops.icu main and auxiliary tries
|
|
|
|
* for all non-normalization properties.
|
|
|
|
*
|
|
|
|
* Ideas for representing ranges and combining them:
|
|
|
|
*
|
|
|
|
* - A UnicodeSet could hold just the start code points of ranges.
|
|
|
|
* Multiple sets are easily combined by or-ing them together.
|
|
|
|
*
|
|
|
|
* - Alternatively, a UnicodeSet could hold each even-numbered range.
|
|
|
|
* All ranges could be enumerated by using each start code point
|
|
|
|
* (for the even-numbered ranges) as well as each limit (end+1) code point
|
|
|
|
* (for the odd-numbered ranges).
|
|
|
|
* It should be possible to combine two such sets by xor-ing them,
|
|
|
|
* but no more than two.
|
|
|
|
*
|
|
|
|
* The second way to represent ranges may(?!) yield smaller UnicodeSet arrays,
|
|
|
|
* but the first one is certainly simpler and applicable for combining more than
|
|
|
|
* two range sets.
|
|
|
|
*
|
|
|
|
* It is possible to combine all range sets for all uprops/unorm tries into one
|
|
|
|
* set that can be used for all properties.
|
|
|
|
* As an optimization, there could be less-combined range sets for certain
|
|
|
|
* groups of properties.
|
|
|
|
* The relationship of which less-combined range set to use for which property
|
|
|
|
* depends on the implementation of the properties and must be hardcoded
|
|
|
|
* - somewhat error-prone and higher maintenance but can be tested easily
|
|
|
|
* by building property sets "the simple way" in test code.
|
|
|
|
*
|
|
|
|
* ---
|
|
|
|
*
|
|
|
|
* Do not use a UnicodeSet pattern because that causes infinite recursion;
|
|
|
|
* UnicodeSet depends on the inclusions set.
|
2004-09-13 23:33:22 +00:00
|
|
|
*
|
|
|
|
* ---
|
|
|
|
*
|
|
|
|
* uprv_getInclusions() is commented out starting 2004-sep-13 because
|
|
|
|
* uniset_props.cpp now calls the uxyz_addPropertyStarts() directly,
|
|
|
|
* and only for the relevant property source.
|
2002-10-30 18:12:49 +00:00
|
|
|
*/
|
2004-09-13 23:33:22 +00:00
|
|
|
#if 0
|
|
|
|
|
2002-10-30 18:12:49 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2004-12-02 04:18:35 +00:00
|
|
|
uprv_getInclusions(const USetAdder *sa, UErrorCode *pErrorCode) {
|
2003-04-09 17:34:24 +00:00
|
|
|
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-05-06 01:37:52 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
2004-09-07 17:59:53 +00:00
|
|
|
unorm_addPropertyStarts(sa, pErrorCode);
|
2003-07-24 23:23:19 +00:00
|
|
|
#endif
|
2004-09-07 17:59:53 +00:00
|
|
|
uchar_addPropertyStarts(sa, pErrorCode);
|
2004-09-11 22:02:10 +00:00
|
|
|
ucase_addPropertyStarts(ucase_getSingleton(pErrorCode), sa, pErrorCode);
|
2004-12-31 13:36:49 +00:00
|
|
|
ubidi_addPropertyStarts(ubidi_getSingleton(pErrorCode), sa, pErrorCode);
|
2002-10-30 18:12:49 +00:00
|
|
|
}
|
2004-09-13 23:33:22 +00:00
|
|
|
|
|
|
|
#endif
|