From f4190c00c74a6b6ed6467f16cf0f2688e2f92a3a Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Sat, 12 Jan 2002 00:11:09 +0000 Subject: [PATCH] ICU-1611 add and test u_enumCharTypes X-SVN-Rev: 7434 --- icu4c/source/common/uchar.c | 33 ++++++++++++++++++ icu4c/source/common/unicode/uchar.h | 51 +++++++++++++++++++++++++--- icu4c/source/test/cintltst/cucdtst.c | 38 +++++++++++++++++++++ 3 files changed, 118 insertions(+), 4 deletions(-) diff --git a/icu4c/source/common/uchar.c b/icu4c/source/common/uchar.c index d46db051b9c..48c442b21d6 100644 --- a/icu4c/source/common/uchar.c +++ b/icu4c/source/common/uchar.c @@ -423,6 +423,39 @@ u_charType(UChar32 c) { return (int8_t)GET_CATEGORY(props); } +/* Enumerate all code points with their general categories. */ +struct _EnumTypeCallback { + UCharEnumTypeRange *enumRange; + const void *context; +}; + +static uint32_t U_CALLCONV +_enumTypeValue(const void *context, uint32_t value) { + /* access the general category from the 32-bit properties, and those from the 16-bit trie value */ + return GET_CATEGORY(props32Table[value]); +} + +static UBool U_CALLCONV +_enumTypeRange(const void *context, UChar32 start, UChar32 limit, uint32_t value) { + /* just cast the value to UCharCategory */ + return ((struct _EnumTypeCallback *)context)-> + enumRange(((struct _EnumTypeCallback *)context)->context, + start, limit, (UCharCategory)value); +} + +U_CAPI void U_EXPORT2 +u_enumCharTypes(UCharEnumTypeRange *enumRange, const void *context) { + struct _EnumTypeCallback callback; + + if(enumRange==NULL || !HAVE_DATA) { + return; + } + + callback.enumRange=enumRange; + callback.context=context; + utrie_enum(&propsTrie, _enumTypeValue, _enumTypeRange, &callback); +} + /* Checks if ch is a lower case letter.*/ U_CAPI UBool U_EXPORT2 u_islower(UChar32 c) { diff --git a/icu4c/source/common/unicode/uchar.h b/icu4c/source/common/unicode/uchar.h index c230525c57b..41cf973e64b 100644 --- a/icu4c/source/common/unicode/uchar.h +++ b/icu4c/source/common/unicode/uchar.h @@ -24,6 +24,9 @@ #define UCHAR_H #include "unicode/utypes.h" + +U_CDECL_BEGIN + /*==========================================================================*/ /* Unicode version number */ /*==========================================================================*/ @@ -995,6 +998,48 @@ u_charCellWidth(UChar32 c); U_CAPI int8_t U_EXPORT2 u_charType(UChar32 c); +/** + * Callback from u_enumCharTypes(), is called for each contiguous range + * of code points c (where start<=ctest[count-1][0]) { + log_err("error: u_enumCharTypes() has range [U+%04lx, U+%04lx[ with %ld after it should have stopped\n", + start, limit, (long)type); + return FALSE; + } + return TRUE; +} + /* tests for several properties */ static void TestUnicodeData() { @@ -658,6 +693,9 @@ static void TestUnicodeData() ++c; } } + + /* test u_enumCharTypes() */ + u_enumCharTypes(enumTypeRange, "a1"); } /*internal functions ----*/