ICU-165 added icu_stricmp()

X-SVN-Rev: 248
This commit is contained in:
Markus Scherer 1999-11-23 22:52:17 +00:00
parent c07aed7913
commit 7ff9415260
2 changed files with 49 additions and 4 deletions

View file

@ -25,14 +25,12 @@
#ifndef _CSTRING
#include "cstring.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#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;
}
}
}

View file

@ -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 */