diff --git a/icu4c/source/common/sprpimpl.h b/icu4c/source/common/sprpimpl.h index 50d7c350e43..e9b711cf0b3 100644 --- a/icu4c/source/common/sprpimpl.h +++ b/icu4c/source/common/sprpimpl.h @@ -27,6 +27,7 @@ #include "unicode/udata.h" #include "utrie.h" #include "udataswp.h" +#include "ubidi_props.h" #define _SPREP_DATA_TYPE "spp" @@ -87,6 +88,7 @@ struct UStringPrepProfile{ UTrie sprepTrie; const uint16_t* mappingData; UDataMemory* sprepData; + UBiDiProps *bdp; // used only if checkBiDi is set UBool isDataLoaded; int32_t refCount; UBool doNFKC; diff --git a/icu4c/source/common/ubidi.c b/icu4c/source/common/ubidi.c index 2e7713f0a4d..8e1cf8335d4 100644 --- a/icu4c/source/common/ubidi.c +++ b/icu4c/source/common/ubidi.c @@ -24,6 +24,7 @@ #include "unicode/ustring.h" #include "unicode/uchar.h" #include "unicode/ubidi.h" +#include "ubidi_props.h" #include "ubidiimp.h" /* @@ -147,6 +148,13 @@ ubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode) /* reset the object, all pointers NULL, all flags FALSE, all sizes 0 */ uprv_memset(pBiDi, 0, sizeof(UBiDi)); + /* get BiDi properties */ + pBiDi->bdp=ubidi_getSingleton(pErrorCode); + if(U_FAILURE(*pErrorCode)) { + uprv_free(pBiDi); + return NULL; + } + /* allocate memory for arrays as requested */ if(maxLength>0) { if( !getInitialDirPropsMemory(pBiDi, maxLength) || @@ -281,7 +289,7 @@ getDirProps(UBiDi *pBiDi, const UChar *text) { i0=i; /* index of first code unit */ UTF_NEXT_CHAR(text, i, length, uchar); i1=i-1; /* index of last code unit, gets the directional property */ - flags|=DIRPROP_FLAG(dirProps[i1]=dirProp=u_charDirection(uchar)); + flags|=DIRPROP_FLAG(dirProps[i1]=dirProp=ubidi_getClass(pBiDi->bdp, uchar)); if(i1>i0) { /* set previous code units' properties to BN */ flags|=DIRPROP_FLAG(BN); do { @@ -314,7 +322,7 @@ getDirProps(UBiDi *pBiDi, const UChar *text) { i0=i; /* index of first code unit */ UTF_NEXT_CHAR(text, i, length, uchar); i1=i-1; /* index of last code unit, gets the directional property */ - flags|=DIRPROP_FLAG(dirProps[i1]=dirProp=u_charDirection(uchar)); + flags|=DIRPROP_FLAG(dirProps[i1]=dirProp=ubidi_getClass(pBiDi->bdp, uchar)); if(i1>i0) { /* set previous code units' properties to BN */ flags|=DIRPROP_FLAG(BN); do { diff --git a/icu4c/source/common/ubidiimp.h b/icu4c/source/common/ubidiimp.h index 310e2a72ce0..d8fad84e908 100644 --- a/icu4c/source/common/ubidiimp.h +++ b/icu4c/source/common/ubidiimp.h @@ -1,7 +1,7 @@ /* ****************************************************************************** * -* Copyright (C) 1999-2001, International Business Machines +* Copyright (C) 1999-2004, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** @@ -22,6 +22,7 @@ #include "unicode/utypes.h" #include "unicode/uchar.h" +#include "ubidi_props.h" /* miscellaneous definitions ---------------------------------------------- */ @@ -128,6 +129,8 @@ ubidi_getRuns(UBiDi *pBiDi); /* UBiDi structure ----------------------------------------------------------- */ struct UBiDi { + UBiDiProps *bdp; + /* alias pointer to the current text */ const UChar *text; diff --git a/icu4c/source/common/ubidiwrt.c b/icu4c/source/common/ubidiwrt.c index 2d16465d4c2..149196bbe45 100644 --- a/icu4c/source/common/ubidiwrt.c +++ b/icu4c/source/common/ubidiwrt.c @@ -1,7 +1,7 @@ /* ****************************************************************************** * -* Copyright (C) 2000-2001, International Business Machines +* Copyright (C) 2000-2004, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** @@ -28,6 +28,7 @@ #include "unicode/ubidi.h" #include "cmemory.h" #include "ustr_imp.h" +#include "ubidi_props.h" #include "ubidiimp.h" /* @@ -455,7 +456,7 @@ ubidi_writeReordered(UBiDi *pBiDi, src=text+logicalStart; if(UBIDI_LTR==dir) { - if(/*run>0 &&*/ u_charDirection(*src)!=U_LEFT_TO_RIGHT) { + if(/*run>0 &&*/ ubidi_getClass(pBiDi->bdp, *src)!=U_LEFT_TO_RIGHT) { if(destSize>0) { *dest++=LRM_CHAR; } @@ -468,14 +469,14 @@ ubidi_writeReordered(UBiDi *pBiDi, dest+=runLength; destSize-=runLength; - if(/*runbdp, src[runLength-1])!=U_LEFT_TO_RIGHT) { if(destSize>0) { *dest++=LRM_CHAR; } --destSize; } } else { - if(/*run>0 &&*/ !(MASK_R_AL&1UL<0 &&*/ !(MASK_R_AL&1UL<bdp, src[runLength-1]))) { if(destSize>0) { *dest++=RLM_CHAR; } @@ -488,7 +489,7 @@ ubidi_writeReordered(UBiDi *pBiDi, dest+=runLength; destSize-=runLength; - if(/*runbdp, *src))) { if(destSize>0) { *dest++=RLM_CHAR; } @@ -525,7 +526,7 @@ ubidi_writeReordered(UBiDi *pBiDi, src=text+logicalStart; if(UBIDI_LTR==dir) { - if(/*runbdp, src[runLength-1])!=U_LEFT_TO_RIGHT) { if(destSize>0) { *dest++=LRM_CHAR; } @@ -538,14 +539,14 @@ ubidi_writeReordered(UBiDi *pBiDi, dest+=runLength; destSize-=runLength; - if(/*run>0 &&*/ u_charDirection(*src)!=U_LEFT_TO_RIGHT) { + if(/*run>0 &&*/ ubidi_getClass(pBiDi->bdp, *src)!=U_LEFT_TO_RIGHT) { if(destSize>0) { *dest++=LRM_CHAR; } --destSize; } } else { - if(/*runbdp, *src))) { if(destSize>0) { *dest++=RLM_CHAR; } @@ -558,7 +559,7 @@ ubidi_writeReordered(UBiDi *pBiDi, dest+=runLength; destSize-=runLength; - if(/*run>0 &&*/ !(MASK_R_AL&1UL<0 &&*/ !(MASK_R_AL&1UL<bdp, src[runLength-1]))) { if(destSize>0) { *dest++=RLM_CHAR; } diff --git a/icu4c/source/common/ushape.c b/icu4c/source/common/ushape.c index a4f62977a12..308c5cd3881 100644 --- a/icu4c/source/common/ushape.c +++ b/icu4c/source/common/ushape.c @@ -23,6 +23,7 @@ #include "cmemory.h" #include "putilimp.h" #include "ustr_imp.h" +#include "ubidi_props.h" #if UTF_SIZE<16 /* @@ -224,16 +225,24 @@ static void _shapeToArabicDigitsWithContext(UChar *s, int32_t length, UChar digitBase, UBool isLogical, UBool lastStrongWasAL) { + UBiDiProps *bdp; + UErrorCode errorCode; + int32_t i; UChar c; + bdp=ubidi_getSingleton(&errorCode); + if(U_FAILURE(errorCode)) { + return; + } + digitBase-=0x30; /* the iteration direction depends on the type of input */ if(isLogical) { for(i=0; i0; /* pre-decrement in the body */) { c=s[--i]; - switch(u_charDirection(c)) { + switch(ubidi_getClass(bdp, c)) { case U_LEFT_TO_RIGHT: /* L */ case U_RIGHT_TO_LEFT: /* R */ lastStrongWasAL=FALSE; diff --git a/icu4c/source/common/usprep.cpp b/icu4c/source/common/usprep.cpp index 975a598d2fd..a558d336fa5 100644 --- a/icu4c/source/common/usprep.cpp +++ b/icu4c/source/common/usprep.cpp @@ -33,6 +33,7 @@ #include "udataswp.h" #include "ucln_cmn.h" #include "unormimp.h" +#include "ubidi_props.h" U_CDECL_BEGIN @@ -371,6 +372,19 @@ usprep_getProfile(const char* path, /* get the options */ profile->doNFKC = (UBool)((profile->indexes[_SPREP_OPTIONS] & _SPREP_NORMALIZATION_ON) > 0); profile->checkBiDi = (UBool)((profile->indexes[_SPREP_OPTIONS] & _SPREP_CHECK_BIDI_ON) > 0); + + if(profile->checkBiDi) { + profile->bdp = ubidi_getSingleton(status); + if(U_FAILURE(*status)) { + usprep_unload(profile); + uprv_free(key->path); + uprv_free(key); + uprv_free(profile); + return NULL; + } + } else { + profile->bdp = NULL; + } umtx_lock(&usprepMutex); /* add the data object to the cache */ @@ -752,17 +766,19 @@ usprep_prepare( const UStringPrepProfile* profile, goto CLEANUP; } - direction = u_charDirection(ch); - if(firstCharDir == U_CHAR_DIRECTION_COUNT){ - firstCharDir = direction; - } - if(direction == U_LEFT_TO_RIGHT){ - leftToRight = TRUE; - ltrPos = b2Index-1; - } - if(direction == U_RIGHT_TO_LEFT || direction == U_RIGHT_TO_LEFT_ARABIC){ - rightToLeft = TRUE; - rtlPos = b2Index-1; + if(profile->checkBiDi) { + direction = ubidi_getClass(profile->bdp, ch); + if(firstCharDir == U_CHAR_DIRECTION_COUNT){ + firstCharDir = direction; + } + if(direction == U_LEFT_TO_RIGHT){ + leftToRight = TRUE; + ltrPos = b2Index-1; + } + if(direction == U_RIGHT_TO_LEFT || direction == U_RIGHT_TO_LEFT_ARABIC){ + rightToLeft = TRUE; + rtlPos = b2Index-1; + } } } if(profile->checkBiDi == TRUE){