From 46749f4d0003252e16b0b40a4670a0aa500896bd Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Wed, 14 Dec 2011 23:43:56 +0000 Subject: [PATCH] ICU-8999 uprv_isASCIILetter() X-SVN-Rev: 31117 --- icu4c/source/common/cstring.c | 13 ++++++++++++- icu4c/source/common/cstring.h | 8 ++++++++ icu4c/source/common/uloc.cpp | 4 +--- icu4c/source/common/uloc_tag.c | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/icu4c/source/common/cstring.c b/icu4c/source/common/cstring.c index a5b2c6bbccd..e308709a9cd 100644 --- a/icu4c/source/common/cstring.c +++ b/icu4c/source/common/cstring.c @@ -1,7 +1,7 @@ /* ****************************************************************************** * -* Copyright (C) 1997-2003, International Business Machines +* Copyright (C) 1997-2011, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** @@ -46,6 +46,17 @@ * and the set of uppercase Latin letters is discontiguous as well. */ +U_CAPI UBool U_EXPORT2 +uprv_isASCIILetter(char c) { +#if U_CHARSET_FAMILY==U_EBCDIC_FAMILY + return + ('a'<=c && c<='i') || ('j'<=c && c<='r') || ('s'<=c && c<='z') || + ('A'<=c && c<='I') || ('J'<=c && c<='R') || ('S'<=c && c<='Z'); +#else + return ('a'<=c && c<='z') || ('A'<=c && c<='Z'); +#endif +} + U_CAPI char U_EXPORT2 uprv_toupper(char c) { #if U_CHARSET_FAMILY==U_EBCDIC_FAMILY diff --git a/icu4c/source/common/cstring.h b/icu4c/source/common/cstring.h index 811e2d82cf3..f67394428a6 100644 --- a/icu4c/source/common/cstring.h +++ b/icu4c/source/common/cstring.h @@ -41,6 +41,14 @@ #define uprv_strstr(s, c) U_STANDARD_CPP_NAMESPACE strstr(s, c) #define uprv_strrchr(s, c) U_STANDARD_CPP_NAMESPACE strrchr(s, c) +/** + * Is c an ASCII-repertoire letter a-z or A-Z? + * Note: The implementation is specific to whether ICU is compiled for + * an ASCII-based or EBCDIC-based machine. There just does not seem to be a better name for this. + */ +U_CAPI UBool U_EXPORT2 +uprv_isASCIILetter(char c); + U_CAPI char U_EXPORT2 uprv_toupper(char c); diff --git a/icu4c/source/common/uloc.cpp b/icu4c/source/common/uloc.cpp index 0bf53bbc27a..11a3a4f4887 100644 --- a/icu4c/source/common/uloc.cpp +++ b/icu4c/source/common/uloc.cpp @@ -1248,8 +1248,6 @@ ulocimp_getLanguage(const char *localeID, return i; } -#define ISASCIIALPHA(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z')) - U_CFUNC int32_t ulocimp_getScript(const char *localeID, char *script, int32_t scriptCapacity, @@ -1263,7 +1261,7 @@ ulocimp_getScript(const char *localeID, /* copy the second item as far as possible and count its length */ while(!_isTerminator(localeID[idLen]) && !_isIDSeparator(localeID[idLen]) - && ISASCIIALPHA(localeID[idLen])) { + && uprv_isASCIILetter(localeID[idLen])) { idLen++; } diff --git a/icu4c/source/common/uloc_tag.c b/icu4c/source/common/uloc_tag.c index 6b109ca7051..1f697544621 100644 --- a/icu4c/source/common/uloc_tag.c +++ b/icu4c/source/common/uloc_tag.c @@ -59,7 +59,7 @@ typedef struct ULanguageTag { #define LOCALE_KEYWORD_SEP ';' #define LOCALE_KEY_TYPE_SEP '=' -#define ISALPHA(c) (((c)>='A' && (c)<='Z') || ((c)>='a' && (c)<='z')) +#define ISALPHA(c) uprv_isASCIILetter(c) #define ISNUMERIC(c) ((c)>='0' && (c)<='9') static const char* EMPTY = ""; -- 2.40.0