cvs: php-src / unicode-progress.txt /ext/standard string.c
| From: | Andrei Zmievski | Date: | Thu, 03 Aug 2006 21:46:16 +0000 |
| Subject: | cvs: php-src / unicode-progress.txt /ext/standard string.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-39750@lists.php.net to get a copy of this message | ||
andrei Thu Aug 3 21:46:16 2006 UTC
Modified files:
/php-src unicode-progress.txt
/php-src/ext/standard string.c
Log:
Update similar_text() to use params API.
http://cvs.php.net/viewvc.cgi/php-src/unicode-progress.txt?r1=1.34&r2=1.35&diff_format=u
Index: php-src/unicode-progress.txt
diff -u php-src/unicode-progress.txt:1.34 php-src/unicode-progress.txt:1.35
--- php-src/unicode-progress.txt:1.34 Wed Aug 2 21:51:43 2006
+++ php-src/unicode-progress.txt Thu Aug 3 21:46:16 2006
@@ -34,6 +34,7 @@
hebrev(), hebrevc()
Figure out if this is something we can use ICU for, internally.
+ Check with Zeev.
localeconv()
Params API, update to use *_rt_* API.
@@ -56,9 +57,6 @@
quotemeta()
Params API, IS_UNICODE upgrade
- similar_text()
- Params API
-
sscanf()
Params API. Rest - no idea yet.
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.558&r2=1.559&diff_format=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.558 php-src/ext/standard/string.c:1.559
--- php-src/ext/standard/string.c:1.558 Wed Aug 2 21:53:43 2006
+++ php-src/ext/standard/string.c Thu Aug 3 21:46:16 2006
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string.c,v 1.558 2006/08/02 21:53:43 andrei Exp $ */
+/* $Id: string.c,v 1.559 2006/08/03 21:46:16 andrei Exp $ */
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
@@ -4087,50 +4087,42 @@
Calculates the similarity between two strings */
PHP_FUNCTION(similar_text)
{
- zval **t1, **t2, **percent;
- int ac = ZEND_NUM_ARGS();
+ zstr t1, t2;
+ int t1_len, t2_len;
+ zend_uchar t1_type, t2_type;
+ zval *percent = NULL;
int sim;
- zend_uchar str_type;
- if (ac < 2 || ac > 3 || zend_get_parameters_ex(ac, &t1, &t2, &percent) ==
FAILURE) {
- WRONG_PARAM_COUNT;
- }
- if (Z_TYPE_PP(t1) != IS_UNICODE && Z_TYPE_PP(t1) != IS_STRING) {
- convert_to_text_ex(t1);
- }
- if (Z_TYPE_PP(t2) != IS_UNICODE && Z_TYPE_PP(t2) != IS_STRING) {
- convert_to_text_ex(t2);
- }
- str_type = zend_get_unified_string_type(2 TSRMLS_CC, Z_TYPE_PP(t1), Z_TYPE_PP(t2));
- if (str_type == (zend_uchar)-1) {
- zend_error(E_WARNING, "Cannot mix binary and Unicode parameters");
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "TT|z", &t1, &t1_len,
+ &t1_type, &t2, &t2_len, &t2_type, &percent) == FAILURE) {
return;
}
- convert_to_explicit_type_ex(t1, str_type);
- convert_to_explicit_type_ex(t2, str_type);
- if (ac > 2) {
- convert_to_double_ex(percent);
+
+ if (percent) {
+ zval_dtor(percent);
+ Z_TYPE_P(percent) = IS_DOUBLE;
}
- if (Z_UNILEN_PP(t1) + Z_UNILEN_PP(t2) == 0) {
- if (ac > 2) {
- Z_DVAL_PP(percent) = 0;
+ if (t1_len + t2_len == 0) {
+ if (percent) {
+ Z_DVAL_P(percent) = 0;
}
RETURN_LONG(0);
}
- if (str_type == IS_UNICODE) {
- sim = php_u_similar_char(Z_USTRVAL_PP(t1), Z_USTRLEN_PP(t1), Z_USTRVAL_PP(t2), Z_USTRLEN_PP(t2));
+ /* t1_type and t2_type are guaranteed to be the same */
+ if (t1_type == IS_UNICODE) {
+ sim = php_u_similar_char(t1.u, t1_len, t2.u, t2_len);
} else {
- sim = php_similar_char(Z_STRVAL_PP(t1), Z_STRLEN_PP(t1), Z_STRVAL_PP(t2), Z_STRLEN_PP(t2));
+ sim = php_similar_char(t1.s, t1_len, t2.s, t2_len);
}
- if (ac > 2) {
- if (str_type == IS_UNICODE) {
- Z_DVAL_PP(percent) = sim * 200.0 / (Z_USTRCPLEN_PP(t1) + Z_USTRCPLEN_PP(t2));
+ if (percent) {
+ if (t1_type == IS_UNICODE) {
+ Z_DVAL_P(percent) = sim * 200.0 / (u_countChar32(t1.u, t1_len) + u_countChar32(t2.u, t2_len));
} else {
- Z_DVAL_PP(percent) = sim * 200.0 / (Z_STRLEN_PP(t1) + Z_STRLEN_PP(t2));
+ Z_DVAL_P(percent) = sim * 200.0 / (t1_len + t2_len);
}
}