From 185ac97303d4c4289462c7b37b498006c4700a70 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Sat, 1 Jun 2002 00:33:55 +0000 Subject: [PATCH] ICU-1923 add uprv_comparePropertyNames() to compare Unicode property [value] names loosely X-SVN-Rev: 8763 --- icu4c/source/common/uprops.c | 49 ++++++++++++++++++++++++++++++++++++ icu4c/source/common/uprops.h | 15 +++++++++++ 2 files changed, 64 insertions(+) diff --git a/icu4c/source/common/uprops.c b/icu4c/source/common/uprops.c index 75aa109306f..a552dee82d2 100644 --- a/icu4c/source/common/uprops.c +++ b/icu4c/source/common/uprops.c @@ -20,6 +20,7 @@ #include "unicode/utypes.h" #include "unicode/uchar.h" #include "unicode/uscript.h" +#include "cstring.h" #include "unormimp.h" #include "uprops.h" @@ -61,6 +62,54 @@ #define CGJ 0x34f +/** + * Unicode property names and property value names are compared + * "loosely". Property[Value]Aliases.txt say: + * "With loose matching of property names, the case distinctions, whitespace, + * and '_' are ignored." + * + * This function does just that, for ASCII (char *) name strings. + * It is almost identical to ucnv_compareNames() but also ignores + * ASCII White_Space characters (U+0009..U+000d). + * + * @internal + */ +U_CAPI int32_t U_EXPORT2 +uprv_comparePropertyNames(const char *name1, const char *name2) { + int32_t rc; + unsigned char c1, c2; + + for(;;) { + /* Ignore delimiters '-', '_', and ASCII White_Space */ + while((c1=(unsigned char)*name1)=='-' || c1=='_' || + c1==' ' || c1=='\t' || c1=='\n' || c1=='\v' || c1=='\f' || c1=='\r' + ) { + ++name1; + } + while((c2=(unsigned char)*name2)=='-' || c2=='_' || + c2==' ' || c2=='\t' || c2=='\n' || c2=='\v' || c2=='\f' || c2=='\r' + ) { + ++name2; + } + + /* If we reach the ends of both strings then they match */ + if((c1|c2)==0) { + return 0; + } + + /* Case-insensitive comparison */ + if(c1!=c2) { + rc=(int32_t)(unsigned char)uprv_tolower(c1)-(int32_t)(unsigned char)uprv_tolower(c2); + if(rc!=0) { + return rc; + } + } + + ++name1; + ++name2; + } +} + /* API functions ------------------------------------------------------------ */ U_CAPI void U_EXPORT2 diff --git a/icu4c/source/common/uprops.h b/icu4c/source/common/uprops.h index f61a5939442..92bab3fcfc5 100644 --- a/icu4c/source/common/uprops.h +++ b/icu4c/source/common/uprops.h @@ -147,4 +147,19 @@ enum UEAWidthCode { }; typedef enum UEAWidthCode UEAWidthCode; +/** + * Unicode property names and property value names are compared + * "loosely". Property[Value]Aliases.txt say: + * "With loose matching of property names, the case distinctions, whitespace, + * and '_' are ignored." + * + * This function does just that, for ASCII (char *) name strings. + * It is almost identical to ucnv_compareNames() but also ignores + * ASCII White_Space characters (U+0009..U+000d). + * + * @internal + */ +U_CAPI int32_t U_EXPORT2 +uprv_comparePropertyNames(const char *name1, const char *name2); + #endif