From: Andrei Zmievski Date: Tue, 23 Aug 2005 22:05:22 +0000 (+0000) Subject: Implement Unicode support for strncasecmp(). X-Git-Tag: PRE_NEW_OCI8_EXTENSION~109 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ec65bc10398e5e7b81d8d6de459d889730193d31;p=php Implement Unicode support for strncasecmp(). --- diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 936dc5de11..38c22ea338 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -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))); } diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index da2c22f993..5998453e5f 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -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); diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index e0d6ec11f7..73b89bf319 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -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);