]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/uchar.c
ICU-57163.0.1.tar.gz
[apple/icu.git] / icuSources / common / uchar.c
index 75754a9e88be1ab2383c4c3f3502e8787fe54ff6..57e00afc10f8b124052cbfdbaf65ea800de39f6a 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ********************************************************************************
-*   Copyright (C) 1996-2008, International Business Machines
+*   Copyright (C) 1996-2014, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 ********************************************************************************
 *
 #include "unicode/uchar.h"
 #include "unicode/uscript.h"
 #include "unicode/udata.h"
-#include "umutex.h"
+#include "uassert.h"
 #include "cmemory.h"
 #include "ucln_cmn.h"
-#include "utrie.h"
+#include "utrie2.h"
 #include "udataswp.h"
-#include "unormimp.h" /* JAMO_L_BASE etc. */
 #include "uprops.h"
+#include "ustr_imp.h"
 
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
-
-/* dynamically loaded Unicode character properties -------------------------- */
-
-#define UCHAR_HARDCODE_DATA 1
-
-#if UCHAR_HARDCODE_DATA
-
-/* uchar_props_data.c is machine-generated by genprops --csource */
-#include "uchar_props_data.c"
-
-#else
-
-/*
- * loaded uprops.dat -
- * for a description of the file format, see icu/source/tools/genprops/store.c
- */
-static const char DATA_NAME[] = "uprops";
-static const char DATA_TYPE[] = "icu";
-
-static UDataMemory *propsData=NULL;
-static UErrorCode dataErrorCode=U_ZERO_ERROR;
-
-static uint8_t formatVersion[4]={ 0, 0, 0, 0 };
-static UVersionInfo dataVersion={ 0, 0, 0, 0 };
-
-static UTrie propsTrie={ 0 }, propsVectorsTrie={ 0 };
-static const uint32_t *pData32=NULL, *propsVectors=NULL;
-static int32_t countPropsVectors=0, propsVectorsColumns=0;
-
-static int8_t havePropsData=0;     /*  == 0   ->  Data has not been loaded.
-                                    *   < 0   ->  Error occured attempting to load data.
-                                    *   > 0   ->  Data has been successfully loaded.
-                                    */
-
-/* index values loaded from uprops.dat */
-static int32_t indexes[UPROPS_INDEX_COUNT];
-
-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]==0x55 &&   /* dataFormat="UPro" */
-        pInfo->dataFormat[1]==0x50 &&
-        pInfo->dataFormat[2]==0x72 &&
-        pInfo->dataFormat[3]==0x6f &&
-        pInfo->formatVersion[0]==4 &&
-        pInfo->formatVersion[2]==UTRIE_SHIFT &&
-        pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT
-    ) {
-        uprv_memcpy(formatVersion, pInfo->formatVersion, 4);
-        uprv_memcpy(dataVersion, pInfo->dataVersion, 4);
-        return TRUE;
-    } else {
-        return FALSE;
-    }
-}
-
-static UBool U_CALLCONV uchar_cleanup(void)
-{
-    if (propsData) {
-        udata_close(propsData);
-        propsData=NULL;
-    }
-    pData32=NULL;
-    propsVectors=NULL;
-    countPropsVectors=0;
-    uprv_memset(dataVersion, 0, U_MAX_VERSION_LENGTH);
-    dataErrorCode=U_ZERO_ERROR;
-    havePropsData=0;
-
-    return TRUE;
-}
-
-struct UCharProps {
-    UDataMemory *propsData;
-    UTrie propsTrie, propsVectorsTrie;
-    const uint32_t *pData32;
-};
-typedef struct UCharProps UCharProps;
-
-/* open uprops.icu */
-static void
-_openProps(UCharProps *ucp, UErrorCode *pErrorCode) {
-    const uint32_t *p;
-    int32_t length;
-
-    ucp->propsData=udata_openChoice(NULL, DATA_TYPE, DATA_NAME, isAcceptable, NULL, pErrorCode);
-    if(U_FAILURE(*pErrorCode)) {
-        return;
-    }
-
-    ucp->pData32=p=(const uint32_t *)udata_getMemory(ucp->propsData);
-
-    /* unserialize the trie; it is directly after the int32_t indexes[UPROPS_INDEX_COUNT] */
-    length=(int32_t)p[UPROPS_PROPS32_INDEX]*4;
-    length=utrie_unserialize(&ucp->propsTrie, (const uint8_t *)(p+UPROPS_INDEX_COUNT), length-64, pErrorCode);
-    if(U_FAILURE(*pErrorCode)) {
-        return;
-    }
-
-    /* unserialize the properties vectors trie */
-    length=(int32_t)(p[UPROPS_ADDITIONAL_VECTORS_INDEX]-p[UPROPS_ADDITIONAL_TRIE_INDEX])*4;
-    if(length>0) {
-        length=utrie_unserialize(&ucp->propsVectorsTrie, (const uint8_t *)(p+p[UPROPS_ADDITIONAL_TRIE_INDEX]), length, pErrorCode);
-    }
-    if(length<=0 || U_FAILURE(*pErrorCode)) {
-        /*
-         * length==0:
-         * Allow the properties vectors trie to be missing -
-         * also requires propsVectorsColumns=indexes[UPROPS_ADDITIONAL_VECTORS_COLUMNS_INDEX]
-         * to be zero so that this trie is never accessed.
-         */
-        uprv_memset(&ucp->propsVectorsTrie, 0, sizeof(ucp->propsVectorsTrie));
-    }
-}
-
-#endif
-
-#if !UCHAR_HARDCODE_DATA
-static int8_t
-uprv_loadPropsData(UErrorCode *pErrorCode) {
-    /* load Unicode character properties data from file if necessary */
-
-    /*
-     * This lazy intialization with double-checked locking (without mutex protection for
-     * haveNormData==0) is transiently unsafe under certain circumstances.
-     * Check the readme and use u_init() if necessary.
-     */
-    if(havePropsData==0) {
-        UCharProps ucp={ NULL };
-
-        if(U_FAILURE(*pErrorCode)) {
-            return havePropsData;
-        }
-
-        /* open the data outside the mutex block */
-        _openProps(&ucp, pErrorCode);
-
-        if(U_SUCCESS(*pErrorCode)) {
-            /* in the mutex block, set the data for this process */
-            umtx_lock(NULL);
-            if(propsData==NULL) {
-                propsData=ucp.propsData;
-                ucp.propsData=NULL;
-                pData32=ucp.pData32;
-                ucp.pData32=NULL;
-                uprv_memcpy(&propsTrie, &ucp.propsTrie, sizeof(propsTrie));
-                uprv_memcpy(&propsVectorsTrie, &ucp.propsVectorsTrie, sizeof(propsVectorsTrie));
-            }
-
-            /* initialize some variables */
-            uprv_memcpy(indexes, pData32, sizeof(indexes));
-
-            /* additional properties */
-            if(indexes[UPROPS_ADDITIONAL_VECTORS_INDEX]!=0) {
-                propsVectors=pData32+indexes[UPROPS_ADDITIONAL_VECTORS_INDEX];
-                countPropsVectors=indexes[UPROPS_RESERVED_INDEX]-indexes[UPROPS_ADDITIONAL_VECTORS_INDEX];
-                propsVectorsColumns=indexes[UPROPS_ADDITIONAL_VECTORS_COLUMNS_INDEX];
-            }
-
-            havePropsData=1;
-            umtx_unlock(NULL);
-        } else {
-            dataErrorCode=*pErrorCode;
-            havePropsData=-1;
-        }
-        ucln_common_registerCleanup(UCLN_COMMON_UCHAR, uchar_cleanup);
-
-        /* if a different thread set it first, then close the extra data */
-        udata_close(ucp.propsData); /* NULL if it was set correctly */
-    }
-
-    return havePropsData;
-}
-
-static int8_t 
-loadPropsData(void) {
-    UErrorCode   errorCode = U_ZERO_ERROR;
-    int8_t       retVal    = uprv_loadPropsData(&errorCode);
-    return retVal;
-}
-
-#endif
+/* uchar_props_data.h is machine-generated by genprops --csource */
+#define INCLUDED_FROM_UCHAR_C
+#include "uchar_props_data.h"
 
 /* constants and macros for access to the data ------------------------------ */
 
 /* getting a uint32_t properties word from the data */
-#if UCHAR_HARDCODE_DATA
-
-#define GET_PROPS(c, result) UTRIE_GET16(&propsTrie, c, result);
-
-#else
-
-#define HAVE_DATA (havePropsData>0 || loadPropsData()>0)
-#define GET_PROPS_UNSAFE(c, result) \
-    UTRIE_GET16(&propsTrie, c, result);
-#define GET_PROPS(c, result) \
-    if(HAVE_DATA) { \
-        GET_PROPS_UNSAFE(c, result); \
-    } else { \
-        (result)=0; \
-    }
-
-#endif
+#define GET_PROPS(c, result) ((result)=UTRIE2_GET16(&propsTrie, c));
 
 U_CFUNC UBool
 uprv_haveProperties(UErrorCode *pErrorCode) {
     if(U_FAILURE(*pErrorCode)) {
         return FALSE;
     }
-#if !UCHAR_HARDCODE_DATA
-    if(havePropsData==0) {
-        uprv_loadPropsData(pErrorCode);
-    }
-    if(havePropsData<0) {
-        *pErrorCode=dataErrorCode;
-        return FALSE;
-    }
-#endif
     return TRUE;
 }
 
@@ -280,28 +70,24 @@ _enumTypeValue(const void *context, uint32_t value) {
 }
 
 static UBool U_CALLCONV
-_enumTypeRange(const void *context, UChar32 start, UChar32 limit, uint32_t value) {
+_enumTypeRange(const void *context, UChar32 start, UChar32 end, uint32_t value) {
     /* just cast the value to UCharCategory */
     return ((struct _EnumTypeCallback *)context)->
         enumRange(((struct _EnumTypeCallback *)context)->context,
-                  start, limit, (UCharCategory)value);
+                  start, end+1, (UCharCategory)value);
 }
 
 U_CAPI void U_EXPORT2
 u_enumCharTypes(UCharEnumTypeRange *enumRange, const void *context) {
     struct _EnumTypeCallback callback;
 
-    if(enumRange==NULL
-#if !UCHAR_HARDCODE_DATA
-        || !HAVE_DATA
-#endif
-    ) {
+    if(enumRange==NULL) {
         return;
     }
 
     callback.enumRange=enumRange;
     callback.context=context;
-    utrie_enum(&propsTrie, _enumTypeValue, _enumTypeRange, &callback);
+    utrie2_enum(&propsTrie, _enumTypeValue, _enumTypeRange, &callback);
 }
 
 /* Checks if ch is a lower case letter.*/
@@ -415,6 +201,10 @@ u_isISOControl(UChar32 c) {
 #define IS_THAT_CONTROL_SPACE(c) \
     (c<=0x9f && ((c>=TAB && c<=CR) || (c>=0x1c && c <=0x1f) || c==NL))
 
+/* Java has decided that U+0085 New Line is not whitespace any more. */
+#define IS_THAT_ASCII_CONTROL_SPACE(c) \
+    (c<=0x1f && c>=TAB && (c<=CR || c>=0x1c))
+
 /* Checks if the Unicode character is a space character.*/
 U_CAPI UBool U_EXPORT2
 u_isspace(UChar32 c) {
@@ -438,7 +228,7 @@ u_isWhitespace(UChar32 c) {
     return (UBool)(
                 ((CAT_MASK(props)&U_GC_Z_MASK)!=0 &&
                     c!=NBSP && c!=FIGURESP && c!=NNBSP) || /* exclude no-break spaces */
-                IS_THAT_CONTROL_SPACE(c)
+                IS_THAT_ASCII_CONTROL_SPACE(c)
            );
 }
 
@@ -547,7 +337,7 @@ u_isIDPart(UChar32 c) {
 U_CAPI UBool U_EXPORT2
 u_isIDIgnorable(UChar32 c) {
     if(c<=0x9f) {
-        return u_isISOControl(c) && !IS_THAT_CONTROL_SPACE(c);
+        return u_isISOControl(c) && !IS_THAT_ASCII_CONTROL_SPACE(c);
     } else {
         uint32_t props;
         GET_PROPS(c, props);
@@ -583,10 +373,11 @@ u_isJavaIDPart(UChar32 c) {
 U_CAPI int32_t U_EXPORT2
 u_charDigitValue(UChar32 c) {
     uint32_t props;
+    int32_t value;
     GET_PROPS(c, props);
-
-    if(GET_NUMERIC_TYPE(props)==1) {
-        return GET_NUMERIC_VALUE(props);
+    value=(int32_t)GET_NUMERIC_TYPE_VALUE(props)-UPROPS_NTV_DECIMAL_START;
+    if(value<=9) {
+        return value;
     } else {
         return -1;
     }
@@ -594,47 +385,32 @@ u_charDigitValue(UChar32 c) {
 
 U_CAPI double U_EXPORT2
 u_getNumericValue(UChar32 c) {
-    uint32_t props, numericType, numericValue;
+    uint32_t props;
+    int32_t ntv;
     GET_PROPS(c, props);
-    numericType=GET_NUMERIC_TYPE(props);
+    ntv=(int32_t)GET_NUMERIC_TYPE_VALUE(props);
 
-    if(numericType==0 || numericType>=UPROPS_NT_COUNT) {
+    if(ntv==UPROPS_NTV_NONE) {
         return U_NO_NUMERIC_VALUE;
-    }
-
-    numericValue=GET_NUMERIC_VALUE(props);
-
-    if(numericType<U_NT_COUNT) {
-        /* normal type, the value is stored directly */
-        return numericValue;
-    } else if(numericType==UPROPS_NT_FRACTION) {
-        /* fraction value */
-        int32_t numerator;
-        uint32_t denominator;
-
-        numerator=(int32_t)numericValue>>UPROPS_FRACTION_NUM_SHIFT;
-        denominator=(numericValue&UPROPS_FRACTION_DEN_MASK)+UPROPS_FRACTION_DEN_OFFSET;
-
-        if(numerator==0) {
-            numerator=-1;
-        }
-        return (double)numerator/(double)denominator;
-    } else /* numericType==UPROPS_NT_LARGE */ {
-        /* large value with exponent */
+    } else if(ntv<UPROPS_NTV_DIGIT_START) {
+        /* decimal digit */
+        return ntv-UPROPS_NTV_DECIMAL_START;
+    } else if(ntv<UPROPS_NTV_NUMERIC_START) {
+        /* other digit */
+        return ntv-UPROPS_NTV_DIGIT_START;
+    } else if(ntv<UPROPS_NTV_FRACTION_START) {
+        /* small integer */
+        return ntv-UPROPS_NTV_NUMERIC_START;
+    } else if(ntv<UPROPS_NTV_LARGE_START) {
+        /* fraction */
+        int32_t numerator=(ntv>>4)-12;
+        int32_t denominator=(ntv&0xf)+1;
+        return (double)numerator/denominator;
+    } else if(ntv<UPROPS_NTV_BASE60_START) {
+        /* large, single-significant-digit integer */
         double numValue;
-        int32_t mant, exp;
-
-        mant=(int32_t)numericValue>>UPROPS_LARGE_MANT_SHIFT;
-        exp=(int32_t)numericValue&UPROPS_LARGE_EXP_MASK;
-        if(mant==0) {
-            mant=1;
-            exp+=UPROPS_LARGE_EXP_OFFSET_EXTRA;
-        } else if(mant>9) {
-            return U_NO_NUMERIC_VALUE; /* reserved mantissa value */
-        } else {
-            exp+=UPROPS_LARGE_EXP_OFFSET;
-        }
-
+        int32_t mant=(ntv>>5)-14;
+        int32_t exp=(ntv&0x1f)+2;
         numValue=mant;
 
         /* multiply by 10^exp without math.h */
@@ -658,12 +434,35 @@ u_getNumericValue(UChar32 c) {
         }
 
         return numValue;
-    }
-}
+    } else if(ntv<UPROPS_NTV_RESERVED_START) {
+        /* sexagesimal (base 60) integer */
+        int32_t numValue=(ntv>>2)-0xbf;
+        int32_t exp=(ntv&3)+1;
 
-/* ICU 3.4: bidi/shaping properties moved to ubidi_props.c */
+        switch(exp) {
+        case 4:
+            numValue*=60*60*60*60;
+            break;
+        case 3:
+            numValue*=60*60*60;
+            break;
+        case 2:
+            numValue*=60*60;
+            break;
+        case 1:
+            numValue*=60;
+            break;
+        case 0:
+        default:
+            break;
+        }
 
-/* ICU 2.1: u_getCombiningClass() moved to unorm.cpp */
+        return numValue;
+    } else {
+        /* reserved */
+        return U_NO_NUMERIC_VALUE;
+    }
+}
 
 U_CAPI int32_t U_EXPORT2
 u_digit(UChar32 ch, int8_t radix) {
@@ -699,7 +498,7 @@ u_forDigit(int32_t digit, int8_t radix) {
     }
 }
 
-/* miscellaneous, and support for uprops.c ---------------------------------- */
+/* miscellaneous, and support for uprops.cpp -------------------------------- */
 
 U_CAPI void U_EXPORT2
 u_getUnicodeVersion(UVersionInfo versionArray) {
@@ -709,81 +508,33 @@ u_getUnicodeVersion(UVersionInfo versionArray) {
 }
 
 U_CFUNC uint32_t
-u_getUnicodeProperties(UChar32 c, int32_t column) {
-    uint16_t vecIndex;
+u_getMainProperties(UChar32 c) {
+    uint32_t props;
+    GET_PROPS(c, props);
+    return props;
+}
 
-    if(column==-1) {
-        uint32_t props;
-        GET_PROPS(c, props);
-        return props;
-    } else if(
-#if !UCHAR_HARDCODE_DATA
-               !HAVE_DATA || countPropsVectors==0 ||
-#endif
-               column<0 || column>=propsVectorsColumns
-    ) {
+U_CFUNC uint32_t
+u_getUnicodeProperties(UChar32 c, int32_t column) {
+    U_ASSERT(column>=0);
+    if(column>=propsVectorsColumns) {
         return 0;
     } else {
-        UTRIE_GET16(&propsVectorsTrie, c, vecIndex);
+        uint16_t vecIndex=UTRIE2_GET16(&propsVectorsTrie, c);
         return propsVectors[vecIndex+column];
     }
 }
 
 U_CFUNC int32_t
 uprv_getMaxValues(int32_t column) {
-#if !UCHAR_HARDCODE_DATA
-    if(HAVE_DATA) {
-#endif
-        switch(column) {
-        case 0:
-            return indexes[UPROPS_MAX_VALUES_INDEX];
-        case 2:
-            return indexes[UPROPS_MAX_VALUES_2_INDEX];
-        default:
-            return 0;
-        }
-#if !UCHAR_HARDCODE_DATA
-    } else {
+    switch(column) {
+    case 0:
+        return indexes[UPROPS_MAX_VALUES_INDEX];
+    case 2:
+        return indexes[UPROPS_MAX_VALUES_2_INDEX];
+    default:
         return 0;
     }
-#endif
-}
-
-/*
- * get Hangul Syllable Type
- * implemented here so that uchar.c (uhst_addPropertyStarts())
- * does not depend on uprops.c (u_getIntPropertyValue(c, UCHAR_HANGUL_SYLLABLE_TYPE))
- */
-U_CFUNC UHangulSyllableType
-uchar_getHST(UChar32 c) {
-    /* purely algorithmic; hardcode known characters, check for assigned new ones */
-    if(c<JAMO_L_BASE) {
-        /* U_HST_NOT_APPLICABLE */
-    } else if(c<=0x11ff) {
-        /* Jamo range */
-        if(c<=0x115f) {
-            /* Jamo L range, HANGUL CHOSEONG ... */
-            if(c==0x115f || c<=0x1159 || u_charType(c)==U_OTHER_LETTER) {
-                return U_HST_LEADING_JAMO;
-            }
-        } else if(c<=0x11a7) {
-            /* Jamo V range, HANGUL JUNGSEONG ... */
-            if(c<=0x11a2 || u_charType(c)==U_OTHER_LETTER) {
-                return U_HST_VOWEL_JAMO;
-            }
-        } else {
-            /* Jamo T range */
-            if(c<=0x11f9 || u_charType(c)==U_OTHER_LETTER) {
-                return U_HST_TRAILING_JAMO;
-            }
-        }
-    } else if((c-=HANGUL_BASE)<0) {
-        /* U_HST_NOT_APPLICABLE */
-    } else if(c<HANGUL_COUNT) {
-        /* Hangul syllable */
-        return c%JAMO_T_COUNT==0 ? U_HST_LV_SYLLABLE : U_HST_LVT_SYLLABLE;
-    }
-    return U_HST_NOT_APPLICABLE;
 }
 
 U_CAPI void U_EXPORT2
@@ -798,6 +549,7 @@ u_charAge(UChar32 c, UVersionInfo versionArray) {
 
 U_CAPI UScriptCode U_EXPORT2
 uscript_getScript(UChar32 c, UErrorCode *pErrorCode) {
+    uint32_t scriptX;
     if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
         return USCRIPT_INVALID_CODE;
     }
@@ -805,84 +557,92 @@ uscript_getScript(UChar32 c, UErrorCode *pErrorCode) {
         *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
         return USCRIPT_INVALID_CODE;
     }
-
-    return (UScriptCode)(u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_MASK);
-}
-
-U_CAPI UBlockCode U_EXPORT2
-ublock_getCode(UChar32 c) {
-    return (UBlockCode)((u_getUnicodeProperties(c, 0)&UPROPS_BLOCK_MASK)>>UPROPS_BLOCK_SHIFT);
+    scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK;
+    if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) {
+        return (UScriptCode)scriptX;
+    } else if(scriptX<UPROPS_SCRIPT_X_WITH_INHERITED) {
+        return USCRIPT_COMMON;
+    } else if(scriptX<UPROPS_SCRIPT_X_WITH_OTHER) {
+        return USCRIPT_INHERITED;
+    } else {
+        return (UScriptCode)scriptExtensions[scriptX&UPROPS_SCRIPT_MASK];
+    }
 }
 
-/* property starts for UnicodeSet ------------------------------------------- */
-
-/* for Hangul_Syllable_Type */
-U_CFUNC void U_EXPORT2
-uhst_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
-    UChar32 c;
-    int32_t value, value2;
-
-    if(U_FAILURE(*pErrorCode)) {
-        return;
+U_CAPI UBool U_EXPORT2
+uscript_hasScript(UChar32 c, UScriptCode sc) {
+    const uint16_t *scx;
+    uint32_t scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK;
+    if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) {
+        return sc==(UScriptCode)scriptX;
     }
 
-#if !UCHAR_HARDCODE_DATA
-    if(!HAVE_DATA) {
-        *pErrorCode=dataErrorCode;
-        return;
+    scx=scriptExtensions+(scriptX&UPROPS_SCRIPT_MASK);
+    if(scriptX>=UPROPS_SCRIPT_X_WITH_OTHER) {
+        scx=scriptExtensions+scx[1];
     }
-#endif
-
-    /* add code points with hardcoded properties, plus the ones following them */
-
-    /*
-     * Add Jamo type boundaries for UCHAR_HANGUL_SYLLABLE_TYPE.
-     * First, we add fixed boundaries for the blocks of Jamos.
-     * Then we check in loops to see where the current Unicode version
-     * actually stops assigning such Jamos. We start each loop
-     * at the end of the per-Jamo-block assignments in Unicode 4 or earlier.
-     * (These have not changed since Unicode 2.)
-     */
-    sa->add(sa->set, 0x1100);
-    value=U_HST_LEADING_JAMO;
-    for(c=0x115a; c<=0x115f; ++c) {
-        value2=uchar_getHST(c);
-        if(value!=value2) {
-            value=value2;
-            sa->add(sa->set, c);
-        }
+    if(sc>=USCRIPT_CODE_LIMIT) {
+        /* Guard against bogus input that would make us go past the Script_Extensions terminator. */
+        return FALSE;
+    }
+    while(sc>*scx) {
+        ++scx;
     }
+    return sc==(*scx&0x7fff);
+}
 
-    sa->add(sa->set, 0x1160);
-    value=U_HST_VOWEL_JAMO;
-    for(c=0x11a3; c<=0x11a7; ++c) {
-        value2=uchar_getHST(c);
-        if(value!=value2) {
-            value=value2;
-            sa->add(sa->set, c);
+U_CAPI int32_t U_EXPORT2
+uscript_getScriptExtensions(UChar32 c,
+                            UScriptCode *scripts, int32_t capacity,
+                            UErrorCode *pErrorCode) {
+    uint32_t scriptX;
+    int32_t length;
+    const uint16_t *scx;
+    uint16_t sx;
+    if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+        return 0;
+    }
+    if(capacity<0 || (capacity>0 && scripts==NULL)) {
+        *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+        return 0;
+    }
+    scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK;
+    if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) {
+        if(capacity==0) {
+            *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+        } else {
+            scripts[0]=(UScriptCode)scriptX;
         }
+        return 1;
     }
 
-    sa->add(sa->set, 0x11a8);
-    value=U_HST_TRAILING_JAMO;
-    for(c=0x11fa; c<=0x11ff; ++c) {
-        value2=uchar_getHST(c);
-        if(value!=value2) {
-            value=value2;
-            sa->add(sa->set, c);
+    scx=scriptExtensions+(scriptX&UPROPS_SCRIPT_MASK);
+    if(scriptX>=UPROPS_SCRIPT_X_WITH_OTHER) {
+        scx=scriptExtensions+scx[1];
+    }
+    length=0;
+    do {
+        sx=*scx++;
+        if(length<capacity) {
+            scripts[length]=(UScriptCode)(sx&0x7fff);
         }
+        ++length;
+    } while(sx<0x8000);
+    if(length>capacity) {
+        *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
     }
+    return length;
+}
 
-    /* Add Hangul type boundaries for UCHAR_HANGUL_SYLLABLE_TYPE. */
-    for(c=HANGUL_BASE; c<(HANGUL_BASE+HANGUL_COUNT); c+=JAMO_T_COUNT) {
-        sa->add(sa->set, c);
-        sa->add(sa->set, c+1);
-    }
-    sa->add(sa->set, c);
+U_CAPI UBlockCode U_EXPORT2
+ublock_getCode(UChar32 c) {
+    return (UBlockCode)((u_getUnicodeProperties(c, 0)&UPROPS_BLOCK_MASK)>>UPROPS_BLOCK_SHIFT);
 }
 
+/* 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);
@@ -897,15 +657,8 @@ uchar_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
         return;
     }
 
-#if !UCHAR_HARDCODE_DATA
-    if(!HAVE_DATA) {
-        *pErrorCode=dataErrorCode;
-        return;
-    }
-#endif
-
     /* add the start code point of each same-value range of the main trie */
-    utrie_enum(&propsTrie, NULL, _enumPropertyStartsRange, sa);
+    utrie2_enum(&propsTrie, NULL, _enumPropertyStartsRange, sa);
 
     /* add code points with hardcoded properties, plus the ones following them */
 
@@ -964,16 +717,9 @@ upropsvec_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
         return;
     }
 
-#if !UCHAR_HARDCODE_DATA
-    if(!HAVE_DATA) {
-        *pErrorCode=dataErrorCode;
-        return;
-    }
-#endif
-
     /* add the start code point of each same-value range of the properties vectors trie */
     if(propsVectorsColumns>0) {
         /* if propsVectorsColumns==0 then the properties vectors trie may not be there at all */
-        utrie_enum(&propsVectorsTrie, NULL, _enumPropertyStartsRange, sa);
+        utrie2_enum(&propsVectorsTrie, NULL, _enumPropertyStartsRange, sa);
     }
 }