From 7ff9415260fdbc607bc92afc39fe540acf70f207 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Tue, 23 Nov 1999 22:52:17 +0000 Subject: [PATCH] ICU-165 added icu_stricmp() X-SVN-Rev: 248 --- icu4c/source/common/cstring.c | 43 +++++++++++++++++++++++++++++++---- icu4c/source/common/cstring.h | 10 ++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/icu4c/source/common/cstring.c b/icu4c/source/common/cstring.c index ebd01a3b41b..63ad7b3f01e 100644 --- a/icu4c/source/common/cstring.c +++ b/icu4c/source/common/cstring.c @@ -25,14 +25,12 @@ -#ifndef _CSTRING -#include "cstring.h" -#endif - #include #include #include +#include "utypes.h" #include "putil.h" +#include "cstring.h" char* T_CString_toLowerCase(char* str) @@ -95,4 +93,41 @@ T_CString_stringToInteger(const char *integerString, int32_t radix) } +U_CAPI int U_EXPORT2 +T_CString_stricmp(const char *str1, const char *str2) { + if(str1==NULL) { + if(str2==NULL) { + return 0; + } else { + return -1; + } + } else if(str2==NULL) { + return 1; + } else { + /* compare non-NULL strings lexically with lowercase */ + int rc; + unsigned char c1, c2; + for(;;) { + c1=(unsigned char)*str1; + c2=(unsigned char)*str2; + if(c1==0) { + if(c2==0) { + return 0; + } else { + return -1; + } + } else if(c2==0) { + return 1; + } else { + /* compare non-zero characters with lowercase */ + rc=(int)(unsigned char)icu_tolower(c1)-(int)(unsigned char)icu_tolower(c2); + if(rc!=0) { + return rc; + } + } + ++str1; + ++str2; + } + } +} diff --git a/icu4c/source/common/cstring.h b/icu4c/source/common/cstring.h index 0b6d9500298..a123f3bf488 100644 --- a/icu4c/source/common/cstring.h +++ b/icu4c/source/common/cstring.h @@ -48,6 +48,13 @@ #define icu_toupper(c) toupper(c) #define icu_tolower(c) tolower(c) #define icu_strtoul(str, end, base) strtoul(str, end, base) +#ifdef WIN32 +# define icu_stricmp(str1, str2) _stricmp(str1, str2) +#elif defined(POSIX) +# define icu_stricmp(str1, str2) strcasecmp(str1, str2) +#else +# define icu_stricmp(str1, str2) T_CString_stricmp(str1, str2) +#endif /*===========================================================================*/ /* Wide-character functions */ @@ -70,4 +77,7 @@ T_CString_integerToString(char *buffer, int32_t n, int32_t radix); U_CAPI int32_t U_EXPORT2 T_CString_stringToInteger(const char *integerString, int32_t radix); +U_CAPI int U_EXPORT2 +T_CString_stricmp(const char *str1, const char *str2); + #endif /* ! CSTRING_H */