]> granicus.if.org Git - php/commitdiff
Unicode support for strcasecmp().
authorAndrei Zmievski <andrei@php.net>
Mon, 22 Aug 2005 22:17:19 +0000 (22:17 +0000)
committerAndrei Zmievski <andrei@php.net>
Mon, 22 Aug 2005 22:17:19 +0000 (22:17 +0000)
Zend/zend_builtin_functions.c
Zend/zend_operators.c
Zend/zend_operators.h

index 486f84131a59d70935c81e5086c9d5604da11f41..f5164868bb6d98c84b213fe98fcaaaaa84c34a33 100644 (file)
@@ -347,14 +347,19 @@ ZEND_FUNCTION(strncmp)
    Binary safe case-insensitive string comparison */
 ZEND_FUNCTION(strcasecmp)
 {
-       zval **s1, **s2;
-       
-       if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) {
-               ZEND_WRONG_PARAM_COUNT();
+       void *s1, *s2;
+       int32_t s1_len, s2_len;
+       zend_uchar s1_type, s2_type;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "TT", &s1, &s1_len,
+                                                         &s1_type, &s2, &s2_len, &s2_type) == FAILURE) {
+               return;
+       }
+       if (s1_type == IS_UNICODE) {
+               RETURN_LONG(zend_u_binary_strcasecmp(s1, s1_len, s2, s2_len));
+       } else {
+               RETURN_LONG(zend_binary_strcasecmp(s1, s1_len, s2, s2_len));
        }
-       convert_to_string_ex(s1);
-       convert_to_string_ex(s2);
-       RETURN_LONG(zend_binary_zval_strcasecmp(*s1, *s2));
 }
 /* }}} */
 
index 6a711121af1c709d10ffe852141de4b5b363de4c..1422c71c882b38a276c26a9f94d61cd86e08c8fa 100644 (file)
@@ -2254,6 +2254,18 @@ ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2)
        return len1 - len2;
 }
 
+ZEND_API int zend_u_binary_strcasecmp(UChar *s1, int32_t len1, UChar *s2, int32_t len2)
+{
+       int retval;
+       UErrorCode status = U_ZERO_ERROR;
+       
+       retval = ZEND_NORMALIZE_BOOL(u_strCaseCompare(s1, len1, s2, len2, U_COMPARE_CODE_POINT_ORDER, &status));
+       if (!retval) {
+               return (len1 - len2);
+       } else {
+               return retval;
+       }
+}
 
 ZEND_API int zend_binary_strncasecmp(char *s1, uint len1, char *s2, uint len2, uint length)
 {
index 33ec78bde4f24477465a91a5579b3377d95f220e..e0d6ec11f79b8396d0a3a7e7f0ab54d82b0831cb 100644 (file)
@@ -289,6 +289,7 @@ ZEND_API int zend_binary_strncasecmp(char *s1, uint len1, char *s2, uint len2, u
 ZEND_API int zend_u_binary_zval_strcmp(zval *s1, zval *s2);
 ZEND_API int zend_u_binary_strcmp(UChar *s1, int32_t len1, UChar *s2, int32_t len2);
 ZEND_API int zend_u_binary_strncmp(UChar *s1, int32_t len1, UChar *s2, int32_t len2, uint length);
+ZEND_API int zend_u_binary_strcasecmp(UChar *s1, int32_t len1, UChar *s2, int32_t len2);
 
 ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2);
 ZEND_API void zendi_u_smart_strcmp(zval *result, zval *s1, zval *s2);