]> granicus.if.org Git - php/commitdiff
Unicode support for strcmp()/strncmp().
authorAndrei Zmievski <andrei@php.net>
Fri, 19 Aug 2005 23:15:36 +0000 (23:15 +0000)
committerAndrei Zmievski <andrei@php.net>
Fri, 19 Aug 2005 23:15:36 +0000 (23:15 +0000)
Zend/zend_builtin_functions.c
Zend/zend_operators.c
Zend/zend_operators.h

index ec672a59b99f0641f85ad08f30d836eaf9b1ab87..d489fe9b7e2a731070ffae9a6d8f7fa394ffe2c8 100644 (file)
@@ -304,14 +304,19 @@ ZEND_NAMED_FUNCTION(zend_if_strlen)
    Binary safe string comparison */
 ZEND_FUNCTION(strcmp)
 {
-       zval **s1, **s2;
+       void *s1, *s2;
+       int32_t s1_len, s2_len;
+       zend_uchar s1_type, s2_type;
        
-       if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) {
-               ZEND_WRONG_PARAM_COUNT();
+       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_strcmp(s1, s1_len, s2, s2_len));
+       } else {
+               RETURN_LONG(zend_binary_strcmp(s1, s1_len, s2, s2_len));
        }
-       convert_to_string_ex(s1);
-       convert_to_string_ex(s2);
-       RETURN_LONG(zend_binary_zval_strcmp(*s1, *s2));
 }
 /* }}} */
 
@@ -320,15 +325,20 @@ ZEND_FUNCTION(strcmp)
    Binary safe string comparison */
 ZEND_FUNCTION(strncmp)
 {
-       zval **s1, **s2, **s3;
+       void *s1, *s2;
+       int32_t s1_len, s2_len;
+       long count;
+       zend_uchar s1_type, s2_type;
        
-       if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &s1, &s2, &s3) == FAILURE) {
-               ZEND_WRONG_PARAM_COUNT();
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "TTl", &s1, &s1_len,
+                                                         &s1_type, &s2, &s2_len, &s2_type, &count) == FAILURE) {
+               return;
+       }
+       if (s1_type == IS_UNICODE) {
+               RETURN_LONG(zend_u_binary_strncmp(s1, s1_len, s2, s2_len, count));
+       } else {
+               RETURN_LONG(zend_binary_strncmp(s1, s1_len, s2, s2_len, count));
        }
-       convert_to_string_ex(s1);
-       convert_to_string_ex(s2);
-       convert_to_long_ex(s3);
-       RETURN_LONG(zend_binary_zval_strncmp(*s1, *s2, *s3));
 }
 /* }}} */
 
index 78ddc45b578c007d154e962f5c6cceb60f1aba6f..6a711121af1c709d10ffe852141de4b5b363de4c 100644 (file)
@@ -2201,7 +2201,7 @@ ZEND_API int zend_u_binary_strcmp(UChar *s1, int32_t len1, UChar *s2, int32_t le
 {
        int retval;
        
-       retval = u_memcmpCodePointOrder(s1, s2, MIN(len1, len2));
+       retval = ZEND_NORMALIZE_BOOL(u_memcmpCodePointOrder(s1, s2, MIN(len1, len2)));
        if (!retval) {
                return (len1 - len2);
        } else {
@@ -2210,6 +2210,19 @@ ZEND_API int zend_u_binary_strcmp(UChar *s1, int32_t len1, UChar *s2, int32_t le
 }
 
 
+ZEND_API int zend_u_binary_strncmp(UChar *s1, int32_t len1, UChar *s2, int32_t len2, uint length)
+{
+       int retval;
+       
+       retval = ZEND_NORMALIZE_BOOL(u_memcmpCodePointOrder(s1, s2, MIN(length, MIN(len1, len2))));
+       if (!retval) {
+               return (MIN(length, len1) - MIN(length, len2));
+       } else {
+               return retval;
+       }
+}
+
+
 ZEND_API int zend_binary_strncmp(char *s1, uint len1, char *s2, uint len2, uint length)
 {
        int retval;
index 1cdea5aac631f1cdfd96e8f15e8bf9e29db10b01..33ec78bde4f24477465a91a5579b3377d95f220e 100644 (file)
@@ -288,6 +288,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 void zendi_smart_strcmp(zval *result, zval *s1, zval *s2);
 ZEND_API void zendi_u_smart_strcmp(zval *result, zval *s1, zval *s2);