From db8024b99da7d61582417a314850d56a5aca6ff6 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Thu, 15 Mar 2001 02:01:25 +0000 Subject: [PATCH] ICU-621 hardcode behavior for ISO 8 controls (their general categories may be set by genprops to other than Cc); improve properties performance X-SVN-Rev: 4085 --- icu4c/source/common/uchar.c | 45 ++++++++++++++++++++++++---- icu4c/source/test/cintltst/cucdtst.c | 16 ++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/icu4c/source/common/uchar.c b/icu4c/source/common/uchar.c index 19bb2a54a0..a36be89aa7 100644 --- a/icu4c/source/common/uchar.c +++ b/icu4c/source/common/uchar.c @@ -29,6 +29,12 @@ #include "cstring.h" #include "ustr_imp.h" +/* + * Since genprops overrides the general category for some control codes, + * we need to hardcode ISO 8 controls for u_iscntrl(), u_isprint(), etc. + */ +#define IS_ISO_8_CONTROL(c) ((uint32_t)(c)<0x20 || (uint32_t)((c)-0x7f)<=0x20) + /* dynamically loaded Unicode character properties -------------------------- */ /* fallback properties for the ASCII range if the data cannot be loaded */ @@ -227,8 +233,17 @@ enum { INDEX_UCHARS }; -/* access values calculated from indexes */ -static uint16_t stage23Bits, stage2Mask, stage3Mask; +#ifdef UCHAR_VARIABLE_TRIE_BITS + /* access values calculated from indexes */ + static uint16_t stage23Bits, stage2Mask, stage3Mask; +# define stage3Bits indexes[INDEX_STAGE_3_BITS] +#else + /* We are now hardcoding the bit distribution for the trie table access. */ +# define stage23Bits 10 +# define stage2Mask 0x3f +# define stage3Mask 0xf +# define stage3Bits 4 +#endif static UBool isAcceptable(void *context, @@ -268,6 +283,18 @@ loadPropsData() { p=(const uint16_t *)udata_getMemory(data); +#ifndef UCHAR_VARIABLE_TRIE_BITS + /* + * We are now hardcoding the bit distribution for the trie table access. + * Check that the file is stored accordingly. + */ + if(p[INDEX_STAGE_2_BITS]!=6 || p[INDEX_STAGE_3_BITS]!=4) { + udata_close(data); + errorCode=U_INVALID_FORMAT_ERROR; + return havePropsData=-1; + } +#endif + /* in the mutex block, set the data for this process */ umtx_lock(NULL); if(propsData==NULL) { @@ -280,9 +307,11 @@ loadPropsData() { /* initialize some variables */ uprv_memcpy(indexes, propsTable, 16); +#ifdef UCHAR_VARIABLE_TRIE_BITS stage23Bits=(uint16_t)(indexes[INDEX_STAGE_2_BITS]+indexes[INDEX_STAGE_3_BITS]); stage2Mask=(uint16_t)((1<>stage23Bits)]+ \ - ((c)>>indexes[INDEX_STAGE_3_BITS]&stage2Mask)]+ \ + (((c)>>stage3Bits)&stage2Mask)]+ \ ((c)&stage3Mask) \ ] \ ] @@ -451,7 +480,9 @@ u_isbase(UChar32 c) { /* Checks if the Unicode character is a control character.*/ U_CAPI UBool U_EXPORT2 u_iscntrl(UChar32 c) { - return (UBool)(((1UL<