ICU-4287 use new internal APIs for bidi/shaping properties

X-SVN-Rev: 17057
This commit is contained in:
Markus Scherer 2004-12-31 13:41:56 +00:00
parent ca773f99db
commit 9ecfbdb2ee
6 changed files with 64 additions and 25 deletions

View file

@ -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;

View file

@ -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 {

View file

@ -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;

View file

@ -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(/*run<runCount-1 &&*/ u_charDirection(src[runLength-1])!=U_LEFT_TO_RIGHT) {
if(/*run<runCount-1 &&*/ ubidi_getClass(pBiDi->bdp, src[runLength-1])!=U_LEFT_TO_RIGHT) {
if(destSize>0) {
*dest++=LRM_CHAR;
}
--destSize;
}
} else {
if(/*run>0 &&*/ !(MASK_R_AL&1UL<<u_charDirection(src[runLength-1]))) {
if(/*run>0 &&*/ !(MASK_R_AL&1UL<<ubidi_getClass(pBiDi->bdp, src[runLength-1]))) {
if(destSize>0) {
*dest++=RLM_CHAR;
}
@ -488,7 +489,7 @@ ubidi_writeReordered(UBiDi *pBiDi,
dest+=runLength;
destSize-=runLength;
if(/*run<runCount-1 &&*/ !(MASK_R_AL&1UL<<u_charDirection(*src))) {
if(/*run<runCount-1 &&*/ !(MASK_R_AL&1UL<<ubidi_getClass(pBiDi->bdp, *src))) {
if(destSize>0) {
*dest++=RLM_CHAR;
}
@ -525,7 +526,7 @@ ubidi_writeReordered(UBiDi *pBiDi,
src=text+logicalStart;
if(UBIDI_LTR==dir) {
if(/*run<runCount-1 &&*/ u_charDirection(src[runLength-1])!=U_LEFT_TO_RIGHT) {
if(/*run<runCount-1 &&*/ ubidi_getClass(pBiDi->bdp, 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(/*run<runCount-1 &&*/ !(MASK_R_AL&1UL<<u_charDirection(*src))) {
if(/*run<runCount-1 &&*/ !(MASK_R_AL&1UL<<ubidi_getClass(pBiDi->bdp, *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<<u_charDirection(src[runLength-1]))) {
if(/*run>0 &&*/ !(MASK_R_AL&1UL<<ubidi_getClass(pBiDi->bdp, src[runLength-1]))) {
if(destSize>0) {
*dest++=RLM_CHAR;
}

View file

@ -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; i<length; ++i) {
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;
@ -253,7 +262,7 @@ _shapeToArabicDigitsWithContext(UChar *s, int32_t length,
} else {
for(i=length; i>0; /* 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;

View file

@ -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){