andrei Fri Aug 19 19:15:38 2005 EDT
Modified files:
/ZendEngine2 zend_builtin_functions.c zend_operators.c
zend_operators.h
Log:
Unicode support for strcmp()/strncmp().
http://cvs.php.net/diff.php/ZendEngine2/zend_builtin_functions.c?r1=1.284&r2=1.285&ty=u
Index: ZendEngine2/zend_builtin_functions.c
diff -u ZendEngine2/zend_builtin_functions.c:1.284
ZendEngine2/zend_builtin_functions.c:1.285
--- ZendEngine2/zend_builtin_functions.c:1.284 Fri Aug 19 09:20:14 2005
+++ ZendEngine2/zend_builtin_functions.c Fri Aug 19 19:15:36 2005
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_builtin_functions.c,v 1.284 2005/08/19 13:20:14 dmitry Exp $ */
+/* $Id: zend_builtin_functions.c,v 1.285 2005/08/19 23:15:36 andrei Exp $ */
#include "zend.h"
#include "zend_API.h"
@@ -304,14 +304,19 @@
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 @@
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));
}
/* }}} */
http://cvs.php.net/diff.php/ZendEngine2/zend_operators.c?r1=1.213&r2=1.214&ty=u
Index: ZendEngine2/zend_operators.c
diff -u ZendEngine2/zend_operators.c:1.213 ZendEngine2/zend_operators.c:1.214
--- ZendEngine2/zend_operators.c:1.213 Wed Aug 17 16:02:44 2005
+++ ZendEngine2/zend_operators.c Fri Aug 19 19:15:36 2005
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_operators.c,v 1.213 2005/08/17 20:02:44 helly Exp $ */
+/* $Id: zend_operators.c,v 1.214 2005/08/19 23:15:36 andrei Exp $ */
#include <ctype.h>
@@ -2201,7 +2201,7 @@
{
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_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;
http://cvs.php.net/diff.php/ZendEngine2/zend_operators.h?r1=1.97&r2=1.98&ty=u
Index: ZendEngine2/zend_operators.h
diff -u ZendEngine2/zend_operators.h:1.97 ZendEngine2/zend_operators.h:1.98
--- ZendEngine2/zend_operators.h:1.97 Thu Aug 18 18:33:23 2005
+++ ZendEngine2/zend_operators.h Fri Aug 19 19:15:36 2005
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_operators.h,v 1.97 2005/08/18 22:33:23 andrei Exp $ */
+/* $Id: zend_operators.h,v 1.98 2005/08/19 23:15:36 andrei Exp $ */
#ifndef ZEND_OPERATORS_H
#define ZEND_OPERATORS_H
@@ -288,6 +288,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 void zendi_smart_strcmp(zval *result, zval *s1, zval *s2);
ZEND_API void zendi_u_smart_strcmp(zval *result, zval *s1, zval *s2);
--
Zend Engine CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
|