]> granicus.if.org Git - php/commitdiff
Implement Unicode support for strncasecmp().
authorAndrei Zmievski <andrei@php.net>
Tue, 23 Aug 2005 22:05:22 +0000 (22:05 +0000)
committerAndrei Zmievski <andrei@php.net>
Tue, 23 Aug 2005 22:05:22 +0000 (22:05 +0000)
Zend/zend_builtin_functions.c
Zend/zend_operators.c
Zend/zend_operators.h

index 936dc5de119558f2e8cde1d9de90b8188f9621d4..38c22ea33883a018a781b65fc41cb7b2a4744b61 100644 (file)
@@ -378,7 +378,7 @@ ZEND_FUNCTION(strncasecmp)
                return;
        }
        if (s1_type == IS_UNICODE) {
-               RETURN_LONG(zend_u_binary_strcasecmp(s1, MIN(s1_len, len), s2, MIN(s2_len, len)));
+               RETURN_LONG(zend_u_binary_strncasecmp(s1, s1_len, s2, s2_len, len));
        } else {
                RETURN_LONG(zend_binary_strcasecmp(s1, MIN(s1_len, len), s2, MIN(s2_len, len)));
        }
index da2c22f993d8d1bdb6f1c3200b26c19dc0d7e8b8..5998453e5f567295eb7a975ca4a817fcd48f20e3 100644 (file)
@@ -2258,6 +2258,7 @@ 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)
 {
        UErrorCode status = U_ZERO_ERROR;
@@ -2265,6 +2266,7 @@ ZEND_API int zend_u_binary_strcasecmp(UChar *s1, int32_t len1, UChar *s2, int32_
        return ZEND_NORMALIZE_BOOL(result);
 }
 
+
 ZEND_API int zend_binary_strncasecmp(char *s1, uint len1, char *s2, uint len2, uint length)
 {
        int len;
@@ -2284,6 +2286,24 @@ ZEND_API int zend_binary_strncasecmp(char *s1, uint len1, char *s2, uint len2, u
 }
 
 
+/*
+ * Because we do not know UChar offsets for the passed-in limit of the number of
+ * codepoints to compare, we take a hit upfront by iterating over both strings
+ * until we find them. Then we can simply use u_strCaseCompare().
+ */
+ZEND_API int zend_u_binary_strncasecmp(UChar *s1, int32_t len1, UChar *s2, int32_t len2, uint length)
+{
+       UErrorCode status = U_ZERO_ERROR;
+       int32_t off1 = 0, off2 = 0;
+       int32_t result;
+
+       U16_FWD_N(s1, off1, len1, length);
+       U16_FWD_N(s2, off2, len2, length);
+       result = u_strCaseCompare(s1, off1, s2, off2, U_COMPARE_CODE_POINT_ORDER, &status);
+       return ZEND_NORMALIZE_BOOL(result);
+}
+
+
 ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2)
 {
        return zend_binary_strcmp(s1->value.str.val, s1->value.str.len, s2->value.str.val, s2->value.str.len);
index e0d6ec11f79b8396d0a3a7e7f0ab54d82b0831cb..73b89bf31971377a65a514cbf6bafbaff9630e92 100644 (file)
@@ -290,6 +290,7 @@ 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 int zend_u_binary_strncasecmp(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);