]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/ucase.c
ICU-461.12.tar.gz
[apple/icu.git] / icuSources / common / ucase.c
index 491b02a353bf181db3e0df6413855c9c88dea1df..0f9c526e66253307f034dc26801f0a245bde67f8 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2004-2008, International Business Machines
+*   Copyright (C) 2004-2010, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
@@ -25,7 +25,7 @@
 #include "umutex.h"
 #include "uassert.h"
 #include "cmemory.h"
-#include "utrie.h"
+#include "utrie2.h"
 #include "ucase.h"
 #include "ucln_cmn.h"
 
@@ -35,299 +35,24 @@ struct UCaseProps {
     const uint16_t *exceptions;
     const UChar *unfold;
 
-    UTrie trie;
+    UTrie2 trie;
     uint8_t formatVersion[4];
 };
 
-/* data loading etc. -------------------------------------------------------- */
-
-#if UCASE_HARDCODE_DATA
-
 /* ucase_props_data.c is machine-generated by gencase --csource */
 #include "ucase_props_data.c"
 
-#else
-
-static UBool U_CALLCONV
-isAcceptable(void *context,
-             const char *type, const char *name,
-             const UDataInfo *pInfo) {
-    if(
-        pInfo->size>=20 &&
-        pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
-        pInfo->charsetFamily==U_CHARSET_FAMILY &&
-        pInfo->dataFormat[0]==UCASE_FMT_0 &&    /* dataFormat="cAsE" */
-        pInfo->dataFormat[1]==UCASE_FMT_1 &&
-        pInfo->dataFormat[2]==UCASE_FMT_2 &&
-        pInfo->dataFormat[3]==UCASE_FMT_3 &&
-        pInfo->formatVersion[0]==1 &&
-        pInfo->formatVersion[2]==UTRIE_SHIFT &&
-        pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT
-    ) {
-        UCaseProps *csp=(UCaseProps *)context;
-        uprv_memcpy(csp->formatVersion, pInfo->formatVersion, 4);
-        return TRUE;
-    } else {
-        return FALSE;
-    }
-}
-
-static UCaseProps *
-ucase_openData(UCaseProps *cspProto,
-               const uint8_t *bin, int32_t length, UErrorCode *pErrorCode) {
-    UCaseProps *csp;
-    int32_t size;
-
-    cspProto->indexes=(const int32_t *)bin;
-    if( (length>=0 && length<16*4) ||
-        cspProto->indexes[UCASE_IX_INDEX_TOP]<16
-    ) {
-        /* length or indexes[] too short for minimum indexes[] length of 16 */
-        *pErrorCode=U_INVALID_FORMAT_ERROR;
-        return NULL;
-    }
-    size=cspProto->indexes[UCASE_IX_INDEX_TOP]*4;
-    if(length>=0) {
-        if(length>=size && length>=cspProto->indexes[UCASE_IX_LENGTH]) {
-            length-=size;
-        } else {
-            /* length too short for indexes[] or for the whole data length */
-            *pErrorCode=U_INVALID_FORMAT_ERROR;
-            return NULL;
-        }
-    }
-    bin+=size;
-    /* from here on, assume that the sizes of the items fit into the total length */
-
-    /* unserialize the trie, after indexes[] */
-    size=cspProto->indexes[UCASE_IX_TRIE_SIZE];
-    utrie_unserialize(&cspProto->trie, bin, size, pErrorCode);
-    if(U_FAILURE(*pErrorCode)) {
-        return NULL;
-    }
-    bin+=size;
-
-    /* get exceptions[] */
-    size=2*cspProto->indexes[UCASE_IX_EXC_LENGTH];
-    cspProto->exceptions=(const uint16_t *)bin;
-    bin+=size;
-
-    /* get unfold[] */
-    size=2*cspProto->indexes[UCASE_IX_UNFOLD_LENGTH];
-    if(size!=0) {
-        cspProto->unfold=(const UChar *)bin;
-        bin+=size;
-    } else {
-        cspProto->unfold=NULL;
-    }
-
-    /* allocate, copy, and return the new UCaseProps */
-    csp=(UCaseProps *)uprv_malloc(sizeof(UCaseProps));
-    if(csp==NULL) {
-        *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
-        return NULL;
-    } else {
-        uprv_memcpy(csp, cspProto, sizeof(UCaseProps));
-        return csp;
-    }
-}
-
-U_CAPI UCaseProps * U_EXPORT2
-ucase_open(UErrorCode *pErrorCode) {
-    UCaseProps cspProto={ NULL }, *csp;
-
-    cspProto.mem=udata_openChoice(NULL, UCASE_DATA_TYPE, UCASE_DATA_NAME, isAcceptable, &cspProto, pErrorCode);
-    if(U_FAILURE(*pErrorCode)) {
-        return NULL;
-    }
-
-    csp=ucase_openData(
-            &cspProto,
-            udata_getMemory(cspProto.mem),
-            udata_getLength(cspProto.mem),
-            pErrorCode);
-    if(U_FAILURE(*pErrorCode)) {
-        udata_close(cspProto.mem);
-        return NULL;
-    } else {
-        return csp;
-    }
-}
-
-U_CAPI UCaseProps * U_EXPORT2
-ucase_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode) {
-    UCaseProps cspProto={ NULL };
-    const DataHeader *hdr;
-
-    if(U_FAILURE(*pErrorCode)) {
-        return NULL;
-    }
-    if(bin==NULL) {
-        *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
-        return NULL;
-    }
-
-    /* check the header */
-    if(length>=0 && length<20) {
-        *pErrorCode=U_INVALID_FORMAT_ERROR;
-        return NULL;
-    }
-    hdr=(const DataHeader *)bin;
-    if(
-        !(hdr->dataHeader.magic1==0xda && hdr->dataHeader.magic2==0x27 &&
-          hdr->info.isBigEndian==U_IS_BIG_ENDIAN &&
-          isAcceptable(&cspProto, UCASE_DATA_TYPE, UCASE_DATA_NAME, &hdr->info))
-    ) {
-        *pErrorCode=U_INVALID_FORMAT_ERROR;
-        return NULL;
-    }
-
-    bin+=hdr->dataHeader.headerSize;
-    if(length>=0) {
-        length-=hdr->dataHeader.headerSize;
-    }
-    return ucase_openData(&cspProto, bin, length, pErrorCode);
-}
-
-#endif
-
-U_CAPI void U_EXPORT2
-ucase_close(UCaseProps *csp) {
-    if(csp!=NULL) {
-#if !UCASE_HARDCODE_DATA
-        udata_close(csp->mem);
-#endif
-        uprv_free(csp);
-    }
-}
-
 /* UCaseProps singleton ----------------------------------------------------- */
 
-#if !UCASE_HARDCODE_DATA
-static UCaseProps *gCsp=NULL;
-static UCaseProps *gCspDummy=NULL;
-static UErrorCode gErrorCode=U_ZERO_ERROR;
-static int8_t gHaveData=0;
-#endif
-
-#if !UCASE_HARDCODE_DATA
-static UBool U_CALLCONV ucase_cleanup(void) {
-    ucase_close(gCsp);
-    gCsp=NULL;
-    ucase_close(gCspDummy);
-    gCspDummy=NULL;
-    gErrorCode=U_ZERO_ERROR;
-    gHaveData=0;
-    return TRUE;
-}
-#endif
-
 U_CAPI const UCaseProps * U_EXPORT2
-ucase_getSingleton(UErrorCode *pErrorCode) {
-#if UCASE_HARDCODE_DATA
-    if(U_FAILURE(*pErrorCode)) {
-        return NULL;
-    }
+ucase_getSingleton() {
     return &ucase_props_singleton;
-#else
-    int8_t haveData;
-
-    if(U_FAILURE(*pErrorCode)) {
-        return NULL;
-    }
-
-    UMTX_CHECK(NULL, gHaveData, haveData);
-
-    if(haveData>0) {
-        /* data was loaded */
-        return gCsp;
-    } else if(haveData<0) {
-        /* data loading failed */
-        *pErrorCode=gErrorCode;
-        return NULL;
-    } else /* haveData==0 */ {
-        /* load the data */
-        UCaseProps *csp=ucase_open(pErrorCode);
-        if(U_FAILURE(*pErrorCode)) {
-            gHaveData=-1;
-            gErrorCode=*pErrorCode;
-            return NULL;
-        }
-
-        /* set the static variables */
-        umtx_lock(NULL);
-        if(gCsp==NULL) {
-            gCsp=csp;
-            csp=NULL;
-            gHaveData=1;
-            ucln_common_registerCleanup(UCLN_COMMON_UCASE, ucase_cleanup);
-        }
-        umtx_unlock(NULL);
-
-        ucase_close(csp);
-        return gCsp;
-    }
-#endif
-}
-
-#if !UCASE_HARDCODE_DATA
-U_CAPI const UCaseProps * U_EXPORT2
-ucase_getDummy(UErrorCode *pErrorCode) {
-    UCaseProps *csp;
-
-    if(U_FAILURE(*pErrorCode)) {
-        return NULL;
-    }
-
-    UMTX_CHECK(NULL, gCspDummy, csp);
-
-    if(csp!=NULL) {
-        /* the dummy object was already created */
-        return csp;
-    } else /* csp==NULL */ {
-        /* create the dummy object */
-        int32_t *indexes;
-        
-        csp=(UCaseProps *)uprv_malloc(sizeof(UCaseProps)+UCASE_IX_TOP*4+UTRIE_DUMMY_SIZE);
-        if(csp==NULL) {
-            *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
-            return NULL;
-        }
-        uprv_memset(csp, 0, sizeof(UCaseProps)+UCASE_IX_TOP*4);
-
-        csp->indexes=indexes=(int32_t *)(csp+1);
-        indexes[UCASE_IX_INDEX_TOP]=UCASE_IX_TOP;
-
-        indexes[UCASE_IX_TRIE_SIZE]=
-            utrie_unserializeDummy(&csp->trie, indexes+UCASE_IX_TOP, UTRIE_DUMMY_SIZE, 0, 0, TRUE, pErrorCode);
-        if(U_FAILURE(*pErrorCode)) {
-            uprv_free(csp);
-            return NULL;
-        }
-
-        csp->formatVersion[0]=1;
-        csp->formatVersion[2]=UTRIE_SHIFT;
-        csp->formatVersion[3]=UTRIE_INDEX_SHIFT;
-
-        /* set the static variables */
-        umtx_lock(NULL);
-        if(gCspDummy==NULL) {
-            gCspDummy=csp;
-            csp=NULL;
-            ucln_common_registerCleanup(UCLN_COMMON_UCASE, ucase_cleanup);
-        }
-        umtx_unlock(NULL);
-
-        uprv_free(csp);
-        return gCspDummy;
-    }
 }
-#endif
 
 /* set of property starts for UnicodeSet ------------------------------------ */
 
 static UBool U_CALLCONV
-_enumPropertyStartsRange(const void *context, UChar32 start, UChar32 limit, uint32_t value) {
+_enumPropertyStartsRange(const void *context, UChar32 start, UChar32 end, uint32_t value) {
     /* add the start code point to the USet */
     const USetAdder *sa=(const USetAdder *)context;
     sa->add(sa->set, start);
@@ -341,7 +66,7 @@ ucase_addPropertyStarts(const UCaseProps *csp, const USetAdder *sa, UErrorCode *
     }
 
     /* add the start code point of each same-value range of the trie */
-    utrie_enum(&csp->trie, NULL, _enumPropertyStartsRange, sa);
+    utrie2_enum(&csp->trie, NULL, _enumPropertyStartsRange, sa);
 
     /* add code points with hardcoded properties, plus the ones following them */
 
@@ -355,10 +80,6 @@ ucase_addPropertyStarts(const UCaseProps *csp, const USetAdder *sa, UErrorCode *
 
 /* data access primitives --------------------------------------------------- */
 
-/* UTRIE_GET16() itself validates c */
-#define GET_PROPS(csp, c, result) \
-    UTRIE_GET16(&(csp)->trie, c, result);
-
 #define GET_EXCEPTIONS(csp, props) ((csp)->exceptions+((props)>>UCASE_EXC_SHIFT))
 
 #define PROPS_HAS_EXCEPTION(props) ((props)&UCASE_EXCEPTION)
@@ -383,24 +104,24 @@ static const uint8_t flagsOffset[256]={
     4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
 };
 
-#define HAS_SLOT(flags, index) ((flags)&(1<<(index)))
-#define SLOT_OFFSET(flags, index) flagsOffset[(flags)&((1<<(index))-1)]
+#define HAS_SLOT(flags, idx) ((flags)&(1<<(idx)))
+#define SLOT_OFFSET(flags, idx) flagsOffset[(flags)&((1<<(idx))-1)]
 
 /*
- * Get the value of an optional-value slot where HAS_SLOT(excWord, index).
+ * Get the value of an optional-value slot where HAS_SLOT(excWord, idx).
  *
  * @param excWord (in) initial exceptions word
- * @param index (in) desired slot index
+ * @param idx (in) desired slot index
  * @param pExc16 (in/out) const uint16_t * after excWord=*pExc16++;
  *               moved to the last uint16_t of the value, use +1 for beginning of next slot
  * @param value (out) int32_t or uint32_t output if hasSlot, otherwise not modified
  */
-#define GET_SLOT_VALUE(excWord, index, pExc16, value) \
+#define GET_SLOT_VALUE(excWord, idx, pExc16, value) \
     if(((excWord)&UCASE_EXC_DOUBLE_SLOTS)==0) { \
-        (pExc16)+=SLOT_OFFSET(excWord, index); \
+        (pExc16)+=SLOT_OFFSET(excWord, idx); \
         (value)=*pExc16; \
     } else { \
-        (pExc16)+=2*SLOT_OFFSET(excWord, index); \
+        (pExc16)+=2*SLOT_OFFSET(excWord, idx); \
         (value)=*pExc16++; \
         (value)=((value)<<16)|*pExc16; \
     }
@@ -409,8 +130,7 @@ static const uint8_t flagsOffset[256]={
 
 U_CAPI UChar32 U_EXPORT2
 ucase_tolower(const UCaseProps *csp, UChar32 c) {
-    uint16_t props;
-    GET_PROPS(csp, c, props);
+    uint16_t props=UTRIE2_GET16(&csp->trie, c);
     if(!PROPS_HAS_EXCEPTION(props)) {
         if(UCASE_GET_TYPE(props)>=UCASE_UPPER) {
             c+=UCASE_GET_DELTA(props);
@@ -427,8 +147,7 @@ ucase_tolower(const UCaseProps *csp, UChar32 c) {
 
 U_CAPI UChar32 U_EXPORT2
 ucase_toupper(const UCaseProps *csp, UChar32 c) {
-    uint16_t props;
-    GET_PROPS(csp, c, props);
+    uint16_t props=UTRIE2_GET16(&csp->trie, c);
     if(!PROPS_HAS_EXCEPTION(props)) {
         if(UCASE_GET_TYPE(props)==UCASE_LOWER) {
             c+=UCASE_GET_DELTA(props);
@@ -445,8 +164,7 @@ ucase_toupper(const UCaseProps *csp, UChar32 c) {
 
 U_CAPI UChar32 U_EXPORT2
 ucase_totitle(const UCaseProps *csp, UChar32 c) {
-    uint16_t props;
-    GET_PROPS(csp, c, props);
+    uint16_t props=UTRIE2_GET16(&csp->trie, c);
     if(!PROPS_HAS_EXCEPTION(props)) {
         if(UCASE_GET_TYPE(props)==UCASE_LOWER) {
             c+=UCASE_GET_DELTA(props);
@@ -454,15 +172,15 @@ ucase_totitle(const UCaseProps *csp, UChar32 c) {
     } else {
         const uint16_t *pe=GET_EXCEPTIONS(csp, props);
         uint16_t excWord=*pe++;
-        int32_t index;
+        int32_t idx;
         if(HAS_SLOT(excWord, UCASE_EXC_TITLE)) {
-            index=UCASE_EXC_TITLE;
+            idx=UCASE_EXC_TITLE;
         } else if(HAS_SLOT(excWord, UCASE_EXC_UPPER)) {
-            index=UCASE_EXC_UPPER;
+            idx=UCASE_EXC_UPPER;
         } else {
             return c;
         }
-        GET_SLOT_VALUE(excWord, index, pe, c);
+        GET_SLOT_VALUE(excWord, idx, pe, c);
     }
     return c;
 }
@@ -507,7 +225,7 @@ ucase_addCaseClosure(const UCaseProps *csp, UChar32 c, const USetAdder *sa) {
         break;
     }
 
-    GET_PROPS(csp, c, props);
+    props=UTRIE2_GET16(&csp->trie, c);
     if(!PROPS_HAS_EXCEPTION(props)) {
         if(UCASE_GET_TYPE(props)!=UCASE_NONE) {
             /* add the one simple case mapping, no matter what type it is */
@@ -524,15 +242,15 @@ ucase_addCaseClosure(const UCaseProps *csp, UChar32 c, const USetAdder *sa) {
         const uint16_t *pe0, *pe=GET_EXCEPTIONS(csp, props);
         const UChar *closure;
         uint16_t excWord=*pe++;
-        int32_t index, closureLength, fullLength, length;
+        int32_t idx, closureLength, fullLength, length;
 
         pe0=pe;
 
         /* add all simple case mappings */
-        for(index=UCASE_EXC_LOWER; index<=UCASE_EXC_TITLE; ++index) {
-            if(HAS_SLOT(excWord, index)) {
+        for(idx=UCASE_EXC_LOWER; idx<=UCASE_EXC_TITLE; ++idx) {
+            if(HAS_SLOT(excWord, idx)) {
                 pe=pe0;
-                GET_SLOT_VALUE(excWord, index, pe, c);
+                GET_SLOT_VALUE(excWord, idx, pe, c);
                 sa->add(sa->set, c);
             }
         }
@@ -579,8 +297,8 @@ ucase_addCaseClosure(const UCaseProps *csp, UChar32 c, const USetAdder *sa) {
         }
 
         /* add each code point in the closure string */
-        for(index=0; index<closureLength;) {
-            U16_NEXT_UNSAFE(closure, index, c);
+        for(idx=0; idx<closureLength;) {
+            U16_NEXT_UNSAFE(closure, idx, c);
             sa->add(sa->set, c);
         }
     }
@@ -676,35 +394,30 @@ ucase_addStringCaseClosure(const UCaseProps *csp, const UChar *s, int32_t length
 /** @return UCASE_NONE, UCASE_LOWER, UCASE_UPPER, UCASE_TITLE */
 U_CAPI int32_t U_EXPORT2
 ucase_getType(const UCaseProps *csp, UChar32 c) {
-    uint16_t props;
-    GET_PROPS(csp, c, props);
+    uint16_t props=UTRIE2_GET16(&csp->trie, c);
     return UCASE_GET_TYPE(props);
 }
 
-/** @return same as ucase_getType(), or <0 if c is case-ignorable */
+/** @return same as ucase_getType() and set bit 2 if c is case-ignorable */
 U_CAPI int32_t U_EXPORT2
 ucase_getTypeOrIgnorable(const UCaseProps *csp, UChar32 c) {
-    int32_t type;
-    uint16_t props;
-    GET_PROPS(csp, c, props);
-    type=UCASE_GET_TYPE(props);
-    if(type!=UCASE_NONE) {
-        return type;
-    } else if(
-        c==0x307 ||
-        (props&(UCASE_EXCEPTION|UCASE_CASE_IGNORABLE))==UCASE_CASE_IGNORABLE
-    ) {
-        return -1; /* case-ignorable */
-    } else {
-        return 0; /* c is neither cased nor case-ignorable */
+    uint16_t props=UTRIE2_GET16(&csp->trie, c);
+    int32_t type=UCASE_GET_TYPE(props);
+    if(props&UCASE_EXCEPTION) {
+        const uint16_t *pe=GET_EXCEPTIONS(csp, props);
+        if(*pe&UCASE_EXC_CASE_IGNORABLE) {
+            type|=4;
+        }
+    } else if(type==UCASE_NONE && (props&UCASE_CASE_IGNORABLE)) {
+        type|=4;
     }
+    return type;
 }
 
 /** @return UCASE_NO_DOT, UCASE_SOFT_DOTTED, UCASE_ABOVE, UCASE_OTHER_ACCENT */
 static U_INLINE int32_t
 getDotType(const UCaseProps *csp, UChar32 c) {
-    uint16_t props;
-    GET_PROPS(csp, c, props);
+    uint16_t props=UTRIE2_GET16(&csp->trie, c);
     if(!PROPS_HAS_EXCEPTION(props)) {
         return props&UCASE_DOT_MASK;
     } else {
@@ -720,8 +433,7 @@ ucase_isSoftDotted(const UCaseProps *csp, UChar32 c) {
 
 U_CAPI UBool U_EXPORT2
 ucase_isCaseSensitive(const UCaseProps *csp, UChar32 c) {
-    uint16_t props;
-    GET_PROPS(csp, c, props);
+    uint16_t props=UTRIE2_GET16(&csp->trie, c);
     return (UBool)((props&UCASE_SENSITIVE)!=0);
 }
 
@@ -901,24 +613,30 @@ ucase_getCaseLocale(const char *locale, int32_t *locCache) {
     return result;
 }
 
-/* Is followed by {case-ignorable}* cased  ? (dir determines looking forward/backward) */
+/*
+ * Is followed by
+ *   {case-ignorable}* cased
+ * ?
+ * (dir determines looking forward/backward)
+ * If a character is case-ignorable, it is skipped regardless of whether
+ * it is also cased or not.
+ */
 static UBool
 isFollowedByCasedLetter(const UCaseProps *csp, UCaseContextIterator *iter, void *context, int8_t dir) {
     UChar32 c;
-    uint16_t props;
 
     if(iter==NULL) {
         return FALSE;
     }
 
     for(/* dir!=0 sets direction */; (c=iter(context, dir))>=0; dir=0) {
-        GET_PROPS(csp, c, props);
-        if(UCASE_GET_TYPE(props)!=UCASE_NONE) {
-            return TRUE; /* followed by cased letter */
-        } else if(c==0x307 || (props&(UCASE_EXCEPTION|UCASE_CASE_IGNORABLE))==UCASE_CASE_IGNORABLE) {
+        int32_t type=ucase_getTypeOrIgnorable(csp, c);
+        if(type&4) {
             /* case-ignorable, continue with the loop */
+        } else if(type!=UCASE_NONE) {
+            return TRUE; /* followed by cased letter */
         } else {
-            return FALSE; /* not ignorable */
+            return FALSE; /* uncased and not case-ignorable */
         }
     }
 
@@ -1059,11 +777,8 @@ ucase_toFullLower(const UCaseProps *csp, UChar32 c,
                   const UChar **pString,
                   const char *locale, int32_t *locCache)
 {
-    UChar32 result;
-    uint16_t props;
-
-    result=c;
-    GET_PROPS(csp, c, props);
+    UChar32 result=c;
+    uint16_t props=UTRIE2_GET16(&csp->trie, c);
     if(!PROPS_HAS_EXCEPTION(props)) {
         if(UCASE_GET_TYPE(props)>=UCASE_UPPER) {
             result=c+UCASE_GET_DELTA(props);
@@ -1206,11 +921,8 @@ toUpperOrTitle(const UCaseProps *csp, UChar32 c,
                const UChar **pString,
                const char *locale, int32_t *locCache,
                UBool upperNotTitle) {
-    UChar32 result;
-    uint16_t props;
-
-    result=c;
-    GET_PROPS(csp, c, props);
+    UChar32 result=c;
+    uint16_t props=UTRIE2_GET16(&csp->trie, c);
     if(!PROPS_HAS_EXCEPTION(props)) {
         if(UCASE_GET_TYPE(props)==UCASE_LOWER) {
             result=c+UCASE_GET_DELTA(props);
@@ -1218,7 +930,7 @@ toUpperOrTitle(const UCaseProps *csp, UChar32 c,
     } else {
         const uint16_t *pe=GET_EXCEPTIONS(csp, props), *pe2;
         uint16_t excWord=*pe++;
-        int32_t full, index;
+        int32_t full, idx;
 
         pe2=pe;
 
@@ -1283,14 +995,14 @@ toUpperOrTitle(const UCaseProps *csp, UChar32 c,
         }
 
         if(!upperNotTitle && HAS_SLOT(excWord, UCASE_EXC_TITLE)) {
-            index=UCASE_EXC_TITLE;
+            idx=UCASE_EXC_TITLE;
         } else if(HAS_SLOT(excWord, UCASE_EXC_UPPER)) {
             /* here, titlecase is same as uppercase */
-            index=UCASE_EXC_UPPER;
+            idx=UCASE_EXC_UPPER;
         } else {
             return ~c;
         }
-        GET_SLOT_VALUE(excWord, index, pe2, result);
+        GET_SLOT_VALUE(excWord, idx, pe2, result);
     }
 
     return (result==c) ? ~result : result;
@@ -1356,8 +1068,7 @@ ucase_toFullTitle(const UCaseProps *csp, UChar32 c,
 /* return the simple case folding mapping for c */
 U_CAPI UChar32 U_EXPORT2
 ucase_fold(const UCaseProps *csp, UChar32 c, uint32_t options) {
-    uint16_t props;
-    GET_PROPS(csp, c, props);
+    uint16_t props=UTRIE2_GET16(&csp->trie, c);
     if(!PROPS_HAS_EXCEPTION(props)) {
         if(UCASE_GET_TYPE(props)>=UCASE_UPPER) {
             c+=UCASE_GET_DELTA(props);
@@ -1365,7 +1076,7 @@ ucase_fold(const UCaseProps *csp, UChar32 c, uint32_t options) {
     } else {
         const uint16_t *pe=GET_EXCEPTIONS(csp, props);
         uint16_t excWord=*pe++;
-        int32_t index;
+        int32_t idx;
         if(excWord&UCASE_EXC_CONDITIONAL_FOLD) {
             /* special case folding mappings, hardcoded */
             if((options&_FOLD_CASE_OPTIONS_MASK)==U_FOLD_CASE_DEFAULT) {
@@ -1389,13 +1100,13 @@ ucase_fold(const UCaseProps *csp, UChar32 c, uint32_t options) {
             }
         }
         if(HAS_SLOT(excWord, UCASE_EXC_FOLD)) {
-            index=UCASE_EXC_FOLD;
+            idx=UCASE_EXC_FOLD;
         } else if(HAS_SLOT(excWord, UCASE_EXC_LOWER)) {
-            index=UCASE_EXC_LOWER;
+            idx=UCASE_EXC_LOWER;
         } else {
             return c;
         }
-        GET_SLOT_VALUE(excWord, index, pe, c);
+        GET_SLOT_VALUE(excWord, idx, pe, c);
     }
     return c;
 }
@@ -1420,11 +1131,8 @@ ucase_toFullFolding(const UCaseProps *csp, UChar32 c,
                     const UChar **pString,
                     uint32_t options)
 {
-    UChar32 result;
-    uint16_t props;
-
-    result=c;
-    GET_PROPS(csp, c, props);
+    UChar32 result=c;
+    uint16_t props=UTRIE2_GET16(&csp->trie, c);
     if(!PROPS_HAS_EXCEPTION(props)) {
         if(UCASE_GET_TYPE(props)>=UCASE_UPPER) {
             result=c+UCASE_GET_DELTA(props);
@@ -1432,7 +1140,7 @@ ucase_toFullFolding(const UCaseProps *csp, UChar32 c,
     } else {
         const uint16_t *pe=GET_EXCEPTIONS(csp, props), *pe2;
         uint16_t excWord=*pe++;
-        int32_t full, index;
+        int32_t full, idx;
 
         pe2=pe;
 
@@ -1478,13 +1186,13 @@ ucase_toFullFolding(const UCaseProps *csp, UChar32 c,
         }
 
         if(HAS_SLOT(excWord, UCASE_EXC_FOLD)) {
-            index=UCASE_EXC_FOLD;
+            idx=UCASE_EXC_FOLD;
         } else if(HAS_SLOT(excWord, UCASE_EXC_LOWER)) {
-            index=UCASE_EXC_LOWER;
+            idx=UCASE_EXC_LOWER;
         } else {
             return ~c;
         }
-        GET_SLOT_VALUE(excWord, index, pe2, result);
+        GET_SLOT_VALUE(excWord, idx, pe2, result);
     }
 
     return (result==c) ? ~result : result;
@@ -1492,65 +1200,7 @@ ucase_toFullFolding(const UCaseProps *csp, UChar32 c,
 
 /* case mapping properties API ---------------------------------------------- */
 
-/* get the UCaseProps singleton, or else its dummy, once and for all */
-#if !UCASE_HARDCODE_DATA
-static const UCaseProps *
-getCaseProps() {
-    /*
-     * 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_CASE_PROPS() macro */
-    const UCaseProps *csp;
-    UErrorCode errorCode=U_ZERO_ERROR;
-
-    csp=ucase_getSingleton(&errorCode);
-    if(U_FAILURE(errorCode)) {
-        errorCode=U_ZERO_ERROR;
-        csp=ucase_getDummy(&errorCode);
-        if(U_FAILURE(errorCode)) {
-            return NULL;
-        }
-    }
-
-    return csp;
-}
-#endif
-
-/*
- * In ICU 3.0, most Unicode properties were loaded from uprops.icu.
- * ICU 3.2 adds ucase.icu for case mapping properties.
- * ICU 3.4 adds ubidi.icu for bidi/shaping properties and
- * removes case/bidi/shaping properties from uprops.icu.
- *
- * Loading of uprops.icu was never mutex-protected and required u_init()
- * for thread safety.
- * In order to maintain performance for all such properties,
- * ucase.icu and ubidi.icu are loaded lazily, without mutexing.
- * u_init() will try to load them for thread safety,
- * but u_init() will not fail if they are missing.
- *
- * uchar.c maintains a tri-state flag for (not loaded/loaded/failed to load)
- * and an error code for load failure.
- * Instead, here we try to load at most once.
- * If it works, we use the resulting singleton object.
- * If it fails, then we get a dummy object, which always works unless
- * we are seriously out of memory.
- * After the first try, we have a never-changing pointer to either the
- * real singleton or the dummy.
- *
- * This method is used in Unicode properties APIs (uchar.h) that
- * do not have a service object and also do not have an error code parameter.
- * Other API implementations get the singleton themselves
- * (with mutexing), store it in the service object, and report errors.
- */
-#if !UCASE_HARDCODE_DATA
-#define GET_CASE_PROPS() (gCsp!=NULL ? gCsp : getCaseProps())
-#else
 #define GET_CASE_PROPS() &ucase_props_singleton
-#endif
 
 /* public API (see uchar.h) */
 
@@ -1591,6 +1241,8 @@ u_foldCase(UChar32 c, uint32_t options) {
 U_CFUNC int32_t U_EXPORT2
 ucase_hasBinaryProperty(UChar32 c, UProperty which) {
     /* case mapping properties */
+    const UChar *resultString;
+    int32_t locCache;
     const UCaseProps *csp=GET_CASE_PROPS();
     if(csp==NULL) {
         return FALSE;
@@ -1604,6 +1256,38 @@ ucase_hasBinaryProperty(UChar32 c, UProperty which) {
         return ucase_isSoftDotted(csp, c);
     case UCHAR_CASE_SENSITIVE:
         return ucase_isCaseSensitive(csp, c);
+    case UCHAR_CASED:
+        return (UBool)(UCASE_NONE!=ucase_getType(csp, c));
+    case UCHAR_CASE_IGNORABLE:
+        return (UBool)(ucase_getTypeOrIgnorable(csp, c)>>2);
+    /*
+     * Note: The following Changes_When_Xyz are defined as testing whether
+     * the NFD form of the input changes when Xyz-case-mapped.
+     * However, this simpler implementation of these properties,
+     * ignoring NFD, passes the tests.
+     * The implementation needs to be changed if the tests start failing.
+     * When that happens, optimizations should be used to work with the
+     * per-single-code point ucase_toFullXyz() functions unless
+     * the NFD form has more than one code point,
+     * and the property starts set needs to be the union of the
+     * start sets for normalization and case mappings.
+     */
+    case UCHAR_CHANGES_WHEN_LOWERCASED:
+        locCache=UCASE_LOC_ROOT;
+        return (UBool)(ucase_toFullLower(csp, c, NULL, NULL, &resultString, "", &locCache)>=0);
+    case UCHAR_CHANGES_WHEN_UPPERCASED:
+        locCache=UCASE_LOC_ROOT;
+        return (UBool)(ucase_toFullUpper(csp, c, NULL, NULL, &resultString, "", &locCache)>=0);
+    case UCHAR_CHANGES_WHEN_TITLECASED:
+        locCache=UCASE_LOC_ROOT;
+        return (UBool)(ucase_toFullTitle(csp, c, NULL, NULL, &resultString, "", &locCache)>=0);
+    /* case UCHAR_CHANGES_WHEN_CASEFOLDED: -- in uprops.c */
+    case UCHAR_CHANGES_WHEN_CASEMAPPED:
+        locCache=UCASE_LOC_ROOT;
+        return (UBool)(
+            ucase_toFullLower(csp, c, NULL, NULL, &resultString, "", &locCache)>=0 ||
+            ucase_toFullUpper(csp, c, NULL, NULL, &resultString, "", &locCache)>=0 ||
+            ucase_toFullTitle(csp, c, NULL, NULL, &resultString, "", &locCache)>=0);
     default:
         return FALSE;
     }