]> granicus.if.org Git - icu/commitdiff
ICU-9000 use our own implementation of uprv_stricmp() and uprv_strnicmp() to make...
authorMarkus Scherer <markus.icu@gmail.com>
Thu, 15 Dec 2011 00:04:40 +0000 (00:04 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Thu, 15 Dec 2011 00:04:40 +0000 (00:04 +0000)
X-SVN-Rev: 31118

icu4c/source/common/cstring.c
icu4c/source/common/cstring.h
icu4c/source/common/uloc_tag.c
icu4c/source/test/cintltst/ccapitst.c
icu4c/source/test/cintltst/cstrtest.c

index e308709a9cd9f53e4173cf84fe77e7d75ff5d7f9..3af959eb7d0718942851da3e7662a66de420963e 100644 (file)
@@ -228,9 +228,9 @@ T_CString_stringToInteger(const char *integerString, int32_t radix)
     return uprv_strtoul(integerString, &end, radix);
 
 }
-    
+
 U_CAPI int U_EXPORT2
-T_CString_stricmp(const char *str1, const char *str2) {
+uprv_stricmp(const char *str1, const char *str2) {
     if(str1==NULL) {
         if(str2==NULL) {
             return 0;
@@ -269,7 +269,7 @@ T_CString_stricmp(const char *str1, const char *str2) {
 }
 
 U_CAPI int U_EXPORT2
-T_CString_strnicmp(const char *str1, const char *str2, uint32_t n) {
+uprv_strnicmp(const char *str1, const char *str2, uint32_t n) {
     if(str1==NULL) {
         if(str2==NULL) {
             return 0;
index f67394428a60b04743904245f9c42fc6707144d3..e7cea641bbb52704ac6fcc5334bd48b5b8954f04 100644 (file)
@@ -70,21 +70,6 @@ uprv_ebcdictolower(char c);
 #define uprv_strtod(source, end) U_STANDARD_CPP_NAMESPACE strtod(source, end)
 #define uprv_strtoul(str, end, base) U_STANDARD_CPP_NAMESPACE strtoul(str, end, base)
 #define uprv_strtol(str, end, base) U_STANDARD_CPP_NAMESPACE strtol(str, end, base)
-#if U_PLATFORM == U_PF_WINDOWS
-#   if defined(__BORLANDC__)
-#       define uprv_stricmp(str1, str2) U_STANDARD_CPP_NAMESPACE stricmp(str1, str2)
-#       define uprv_strnicmp(str1, str2, n) U_STANDARD_CPP_NAMESPACE strnicmp(str1, str2, n)
-#   else
-#       define uprv_stricmp(str1, str2) U_STANDARD_CPP_NAMESPACE _stricmp(str1, str2)
-#       define uprv_strnicmp(str1, str2, n) U_STANDARD_CPP_NAMESPACE _strnicmp(str1, str2, n)
-#   endif
-#elif defined(POSIX) 
-#   define uprv_stricmp(str1, str2) U_STANDARD_CPP_NAMESPACE strcasecmp(str1, str2) 
-#   define uprv_strnicmp(str1, str2, n) U_STANDARD_CPP_NAMESPACE strncasecmp(str1, str2, n) 
-#else
-#   define uprv_stricmp(str1, str2) T_CString_stricmp(str1, str2)
-#   define uprv_strnicmp(str1, str2, n) T_CString_strnicmp(str1, str2, n)
-#endif
 
 /* Conversion from a digit to the character with radix base from 2-19 */
 /* May need to use U_UPPER_ORDINAL*/
@@ -119,10 +104,18 @@ T_CString_int64ToString(char *buffer, int64_t n, uint32_t radix);
 U_CAPI int32_t U_EXPORT2
 T_CString_stringToInteger(const char *integerString, int32_t radix);
 
+/**
+ * Case-insensitive, language-independent string comparison
+ * limited to the ASCII character repertoire.
+ */
 U_CAPI int U_EXPORT2
-T_CString_stricmp(const char *str1, const char *str2);
+uprv_stricmp(const char *str1, const char *str2);
 
+/**
+ * Case-insensitive, language-independent string comparison
+ * limited to the ASCII character repertoire.
+ */
 U_CAPI int U_EXPORT2
-T_CString_strnicmp(const char *str1, const char *str2, uint32_t n);
+uprv_strnicmp(const char *str1, const char *str2, uint32_t n);
 
 #endif /* ! CSTRING_H */
index 1f69754462187de8f20449c42a271c88e8527933..e477ce39a09ff93fa2722efbbaa2167e4fd48501 100644 (file)
@@ -2064,7 +2064,7 @@ ultag_parse(const char* tag, int32_t tagLen, int32_t* parsedLen, UErrorCode* sta
 
     /* check if the tag is grandfathered */
     for (i = 0; GRANDFATHERED[i] != NULL; i += 2) {
-        if (T_CString_stricmp(GRANDFATHERED[i], tagBuf) == 0) {
+        if (uprv_stricmp(GRANDFATHERED[i], tagBuf) == 0) {
             /* a grandfathered tag is always longer than its preferred mapping */
             int32_t newTagLength = uprv_strlen(GRANDFATHERED[i+1]);
             if (tagLen < newTagLength) {
index 52035fa44f40e4285e5482a67604cfaf8210aabb..ccaafd653086271cd966deab5922fe9d405bb831 100644 (file)
 #include "cmemory.h"  /* for UAlignedMemory */
 #include "cintltst.h"
 #include "ccapitst.h"
-
-/* for not including "cstring.h" -begin*/    
-#if U_PLATFORM_USES_ONLY_WIN32_API
-#   define ctest_stricmp(str1, str2) U_STANDARD_CPP_NAMESPACE _stricmp(str1, str2)
-#elif defined(POSIX) 
-#   define ctest_stricmp(str1, str2) U_STANDARD_CPP_NAMESPACE strcasecmp(str1, str2) 
-#else
-#   define ctest_stricmp(str1, str2) T_CString_stricmp(str1, str2)
-#endif
-
-static 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)tolower(c1)-(int)(unsigned char)tolower(c2);
-                if(rc!=0) {
-                    return rc;
-                }
-            }
-            ++str1;
-            ++str2;
-        }
-    }
-}
-/* for not including "cstring.h"  -end*/    
+#include "cstring.h"
 
 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
 
@@ -607,7 +560,7 @@ static void TestConvert()
         {
             log_verbose("getName o.k. %s\n", ucnv_getName(myConverter, &err));
         }
-        if (ctest_stricmp(ucnv_getName(myConverter, &err), CodePagesToTest[codepage_index]))
+        if (uprv_stricmp(ucnv_getName(myConverter, &err), CodePagesToTest[codepage_index]))
             log_err("getName failed\n");
         else 
             log_verbose("getName ok\n");
index afef9d33ad147150d56d11f54c4b251c3f267ac7..7ab989ab359bb372d79be2a744262da9618abccf 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-* Copyright (C) 1998-2010, International Business Machines Corporation 
+* Copyright (C) 1998-2011, International Business Machines Corporation
 * and others.  All Rights Reserved.
 **********************************************************************
 *
@@ -107,26 +107,26 @@ static void TestAPI(void)
     }
 
     uprv_strcpy(src, "this is lower case");
-    if(T_CString_stricmp(src, "THIS is lower CASE") != 0){
-        log_err("FAIL: *****T_CString_stricmp() failed.");
+    if(uprv_stricmp(src, "THIS is lower CASE") != 0){
+        log_err("FAIL: *****uprv_stricmp() failed.");
     }
-    if((intValue=T_CString_stricmp(NULL, "first string is null") )!= -1){
-        log_err("FAIL: T_CString_stricmp() where the first string is null failed. Expected: -1, returned %d\n", intValue);
+    if((intValue=uprv_stricmp(NULL, "first string is null") )!= -1){
+        log_err("FAIL: uprv_stricmp() where the first string is null failed. Expected: -1, returned %d\n", intValue);
     }
-    if((intValue=T_CString_stricmp("second string is null", NULL)) != 1){
-        log_err("FAIL: T_CString_stricmp() where the second string is null failed. Expected: 1, returned %d\n", intValue);
+    if((intValue=uprv_stricmp("second string is null", NULL)) != 1){
+        log_err("FAIL: uprv_stricmp() where the second string is null failed. Expected: 1, returned %d\n", intValue);
     }
-    if((intValue=T_CString_stricmp(NULL, NULL)) != 0){
-        log_err("FAIL: T_CString_stricmp(NULL, NULL) failed.  Expected:  0, returned %d\n", intValue);;
+    if((intValue=uprv_stricmp(NULL, NULL)) != 0){
+        log_err("FAIL: uprv_stricmp(NULL, NULL) failed.  Expected:  0, returned %d\n", intValue);;
     }
-    if((intValue=T_CString_stricmp("", "")) != 0){
-        log_err("FAIL: T_CString_stricmp(\"\", \"\") failed.  Expected:  0, returned %d\n", intValue);;
+    if((intValue=uprv_stricmp("", "")) != 0){
+        log_err("FAIL: uprv_stricmp(\"\", \"\") failed.  Expected:  0, returned %d\n", intValue);;
     }
-    if((intValue=T_CString_stricmp("", "abc")) != -1){
-        log_err("FAIL: T_CString_stricmp(\"\", \"abc\") failed.  Expected: -1, returned %d\n", intValue);
+    if((intValue=uprv_stricmp("", "abc")) != -1){
+        log_err("FAIL: uprv_stricmp(\"\", \"abc\") failed.  Expected: -1, returned %d\n", intValue);
     }
-    if((intValue=T_CString_stricmp("abc", "")) != 1){
-        log_err("FAIL: T_CString_stricmp(\"abc\", \"\") failed.  Expected: 1, returned %d\n", intValue);
+    if((intValue=uprv_stricmp("abc", "")) != 1){
+        log_err("FAIL: uprv_stricmp(\"abc\", \"\") failed.  Expected: 1, returned %d\n", intValue);
     }
 
     temp=uprv_strdup("strdup");
@@ -136,26 +136,26 @@ static void TestAPI(void)
     uprv_free((char *)temp);
   
     uprv_strcpy(src, "this is lower case");
-    if(T_CString_strnicmp(src, "THIS", 4 ) != 0){
-        log_err("FAIL: *****T_CString_strnicmp() failed.");
+    if(uprv_strnicmp(src, "THIS", 4 ) != 0){
+        log_err("FAIL: *****uprv_strnicmp() failed.");
     }
-    if((intValue=T_CString_strnicmp(NULL, "first string is null", 10) )!= -1){
-        log_err("FAIL: T_CString_strnicmp() where the first string is null failed. Expected: -1, returned %d\n", intValue);
+    if((intValue=uprv_strnicmp(NULL, "first string is null", 10) )!= -1){
+        log_err("FAIL: uprv_strnicmp() where the first string is null failed. Expected: -1, returned %d\n", intValue);
     }
-    if((intValue=T_CString_strnicmp("second string is null", NULL, 10)) != 1){
-        log_err("FAIL: T_CString_strnicmp() where the second string is null failed. Expected: 1, returned %d\n", intValue);
+    if((intValue=uprv_strnicmp("second string is null", NULL, 10)) != 1){
+        log_err("FAIL: uprv_strnicmp() where the second string is null failed. Expected: 1, returned %d\n", intValue);
     }
-    if((intValue=T_CString_strnicmp(NULL, NULL, 10)) != 0){
-        log_err("FAIL: T_CString_strnicmp(NULL, NULL, 10) failed.  Expected:  0, returned %d\n", intValue);;
+    if((intValue=uprv_strnicmp(NULL, NULL, 10)) != 0){
+        log_err("FAIL: uprv_strnicmp(NULL, NULL, 10) failed.  Expected:  0, returned %d\n", intValue);;
     }
-    if((intValue=T_CString_strnicmp("", "", 10)) != 0){
-        log_err("FAIL: T_CString_strnicmp(\"\", \"\") failed.  Expected:  0, returned %d\n", intValue);;
+    if((intValue=uprv_strnicmp("", "", 10)) != 0){
+        log_err("FAIL: uprv_strnicmp(\"\", \"\") failed.  Expected:  0, returned %d\n", intValue);;
     }
-    if((intValue=T_CString_strnicmp("", "abc", 10)) != -1){
-        log_err("FAIL: T_CString_stricmp(\"\", \"abc\", 10) failed.  Expected: -1, returned %d\n", intValue);
+    if((intValue=uprv_strnicmp("", "abc", 10)) != -1){
+        log_err("FAIL: uprv_stricmp(\"\", \"abc\", 10) failed.  Expected: -1, returned %d\n", intValue);
     }
-    if((intValue=T_CString_strnicmp("abc", "", 10)) != 1){
-        log_err("FAIL: T_CString_strnicmp(\"abc\", \"\", 10) failed.  Expected: 1, returned %d\n", intValue);
+    if((intValue=uprv_strnicmp("abc", "", 10)) != 1){
+        log_err("FAIL: uprv_strnicmp(\"abc\", \"\", 10) failed.  Expected: 1, returned %d\n", intValue);
     }
     
 }