andrei          Thu Aug  3 23:09:29 2006 UTC

  Modified files:              
    /php-src    unicode-progress.txt unicode-todo.txt 
    /php-src/ext/standard       array.c php_string.h string.c 
  Log:
  - Adjusted php_u_strtoupper/php_u_strtolower/php_u_strtotitle API to be
    more sane.
  - Upgrade strtoupper(), strtolower(), strtotitle() to use params API.
  
  
http://cvs.php.net/viewvc.cgi/php-src/unicode-progress.txt?r1=1.35&r2=1.36&diff_format=u
Index: php-src/unicode-progress.txt
diff -u php-src/unicode-progress.txt:1.35 php-src/unicode-progress.txt:1.36
--- php-src/unicode-progress.txt:1.35   Thu Aug  3 21:46:16 2006
+++ php-src/unicode-progress.txt        Thu Aug  3 23:09:29 2006
@@ -123,9 +123,6 @@
     strrev()
         Params API
 
-    strtoupper(), strtolower(), strtotitle()
-        Params API
-
     strtr()
         Check on Derick's progress.
 
@@ -226,6 +223,8 @@
     strspn()
     strstr()
     strtok()
+    strtolower()
+    strtoupper()
     substr()
     substr_count()
     substr_replace()
http://cvs.php.net/viewvc.cgi/php-src/unicode-todo.txt?r1=1.21&r2=1.22&diff_format=u
Index: php-src/unicode-todo.txt
diff -u php-src/unicode-todo.txt:1.21 php-src/unicode-todo.txt:1.22
--- php-src/unicode-todo.txt:1.21       Wed Aug  2 19:54:48 2006
+++ php-src/unicode-todo.txt    Thu Aug  3 23:09:29 2006
@@ -43,3 +43,5 @@
 
 * UG(unicode) is turned off during MINIT() currently. We need to figure out
   a way to avoid turning it off.
+
+* USTR_MAKE("") should be EMPTY_STR
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/array.c?r1=1.379&r2=1.380&diff_format=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.379 php-src/ext/standard/array.c:1.380
--- php-src/ext/standard/array.c:1.379  Wed Aug  2 07:54:41 2006
+++ php-src/ext/standard/array.c        Thu Aug  3 23:09:29 2006
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: array.c,v 1.379 2006/08/02 07:54:41 dmitry Exp $ */
+/* $Id: array.c,v 1.380 2006/08/03 23:09:29 andrei Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -2827,12 +2827,11 @@
                                efree(new_key.s);
                                break;
                        case HASH_KEY_IS_UNICODE:
-                               new_key.u = eustrndup(string_key.u, str_key_len 
- 1);
                                str_len = str_key_len - 1;
                                if (change_to_upper)
-                                       new_key.u = 
php_u_strtoupper(&new_key.u, &str_len, UG(default_locale));
+                                       new_key.u = 
php_u_strtoupper(string_key.u, &str_len, UG(default_locale));
                                else
-                                       new_key.u = 
php_u_strtolower(&new_key.u, &str_len, UG(default_locale));
+                                       new_key.u = 
php_u_strtolower(string_key.u, &str_len, UG(default_locale));
                                zend_u_hash_update(Z_ARRVAL_P(return_value), 
IS_UNICODE, new_key, str_len+1, entry, sizeof(entry), NULL);
                                efree(new_key.u);
                                break;
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/php_string.h?r1=1.97&r2=1.98&diff_format=u
Index: php-src/ext/standard/php_string.h
diff -u php-src/ext/standard/php_string.h:1.97 
php-src/ext/standard/php_string.h:1.98
--- php-src/ext/standard/php_string.h:1.97      Wed Mar 22 10:20:20 2006
+++ php-src/ext/standard/php_string.h   Thu Aug  3 23:09:29 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_string.h,v 1.97 2006/03/22 10:20:20 derick Exp $ */
+/* $Id: php_string.h,v 1.98 2006/08/03 23:09:29 andrei Exp $ */
 
 /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
 
@@ -118,8 +118,8 @@
 
 PHPAPI char *php_strtoupper(char *s, size_t len);
 PHPAPI char *php_strtolower(char *s, size_t len);
-PHPAPI UChar *php_u_strtoupper(UChar **s, int *len, const char *locale);
-PHPAPI UChar *php_u_strtolower(UChar **s, int *len, const char *locale);
+PHPAPI UChar *php_u_strtoupper(UChar *s, int *len, const char *locale);
+PHPAPI UChar *php_u_strtolower(UChar *s, int *len, const char *locale);
 PHPAPI char *php_strtr(char *str, int len, char *str_from, char *str_to, int 
trlen);
 PHPAPI UChar *php_u_addslashes(UChar *str, int length, int *new_length, int 
freeit TSRMLS_DC);
 PHPAPI UChar *php_u_addslashes_ex(UChar *str, int length, int *new_length, int 
freeit, int ignore_sybase TSRMLS_DC);
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.559&r2=1.560&diff_format=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.559 php-src/ext/standard/string.c:1.560
--- php-src/ext/standard/string.c:1.559 Thu Aug  3 21:46:16 2006
+++ php-src/ext/standard/string.c       Thu Aug  3 23:09:29 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: string.c,v 1.559 2006/08/03 21:46:16 andrei Exp $ */
+/* $Id: string.c,v 1.560 2006/08/03 23:09:29 andrei Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -1489,7 +1489,7 @@
 
 /* {{{ php_u_strtoupper
  */
-PHPAPI UChar* php_u_strtoupper(UChar **s, int *len, const char* locale)
+PHPAPI UChar* php_u_strtoupper(UChar *s, int *len, const char* locale)
 {
        UChar *dest = NULL;
        int dest_len;
@@ -1499,22 +1499,20 @@
        while (1) {
                status = U_ZERO_ERROR;
                dest = eurealloc(dest, dest_len+1);
-               dest_len = u_strToUpper(dest, dest_len, *s, *len, locale, 
&status);
+               dest_len = u_strToUpper(dest, dest_len, s, *len, locale, 
&status);
                if (status != U_BUFFER_OVERFLOW_ERROR) {
                        break;
                }
        }
 
        if (U_SUCCESS(status)) {
-               efree(*s);
                dest[dest_len] = 0;
-               *s = dest;
                *len = dest_len;
+               return dest;
        } else {
                efree(dest);
+               return NULL;
        }
-
-       return *s;
 }
 /* }}} */
 
@@ -1522,19 +1520,23 @@
    Makes a string uppercase */
 PHP_FUNCTION(strtoupper)
 {
-       zval **arg;
+       zstr str;
+       int str_len;
+       zend_uchar str_type;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg)) {
-               WRONG_PARAM_COUNT;
-       }
-       if (Z_TYPE_PP(arg) != IS_STRING && Z_TYPE_PP(arg) != IS_UNICODE) {
-               convert_to_text_ex(arg);
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &str, 
&str_len, &str_type) == FAILURE) {
+               return;
        }
 
-       RETVAL_ZVAL(*arg, 1, 0);
-       if (Z_TYPE_P(return_value) == IS_UNICODE) {
-               php_u_strtoupper(&Z_USTRVAL_P(return_value), 
&Z_USTRLEN_P(return_value), UG(default_locale));
+       if (str_type == IS_UNICODE) {
+               UChar *result;
+               if ((result = php_u_strtoupper(str.u, &str_len, 
UG(default_locale)))) {
+                       RETURN_UNICODEL(result, str_len, 0);
+               } else {
+                       RETURN_EMPTY_UNICODE();
+               }
        } else {
+               RETVAL_STRINGL(str.s, str_len, 1);
                php_strtoupper(Z_STRVAL_P(return_value), 
Z_STRLEN_P(return_value));
        }
 }
@@ -1542,7 +1544,7 @@
 
 /* {{{ php_u_strtolower
  */
-PHPAPI UChar *php_u_strtolower(UChar **s, int *len, const char* locale)
+PHPAPI UChar *php_u_strtolower(UChar *s, int *len, const char* locale)
 {
        UChar *dest = NULL;
        int dest_len;
@@ -1552,21 +1554,20 @@
        while (1) {
                status = U_ZERO_ERROR;
                dest = eurealloc(dest, dest_len+1);
-               dest_len = u_strToLower(dest, dest_len, *s, *len, locale, 
&status);
+               dest_len = u_strToLower(dest, dest_len, s, *len, locale, 
&status);
                if (status != U_BUFFER_OVERFLOW_ERROR) {
                        break;
                }
        }
 
        if (U_SUCCESS(status)) {
-               efree(*s);
                dest[dest_len] = 0;
-               *s = dest;
                *len = dest_len;
+               return dest;
        } else {
                efree(dest);
+               return NULL;
        }
-       return *s;
 }
 /* }}} */
 
@@ -1591,19 +1592,23 @@
    Makes a string lowercase */
 PHP_FUNCTION(strtolower)
 {
-       zval **str;
+       zstr str;
+       int str_len;
+       zend_uchar str_type;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str)) {
-               WRONG_PARAM_COUNT;
-       }
-       if (Z_TYPE_PP(str) != IS_STRING && Z_TYPE_PP(str) != IS_UNICODE) {
-               convert_to_text_ex(str);
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &str, 
&str_len, &str_type) == FAILURE) {
+               return;
        }
 
-       RETVAL_ZVAL(*str, 1, 0);
-       if (Z_TYPE_P(return_value) == IS_UNICODE) {
-               php_u_strtolower(&Z_USTRVAL_P(return_value), 
&Z_USTRLEN_P(return_value), UG(default_locale));
+       if (str_type == IS_UNICODE) {
+               UChar *result;
+               if ((result = php_u_strtolower(str.u, &str_len, 
UG(default_locale)))) {
+                       RETURN_UNICODEL(result, str_len, 0);
+               } else {
+                       RETURN_EMPTY_UNICODE();
+               }
        } else {
+               RETVAL_STRINGL(str.s, str_len, 1);
                php_strtolower(Z_STRVAL_P(return_value), 
Z_STRLEN_P(return_value));
        }
 }
@@ -1620,7 +1625,7 @@
 
 /* {{{ php_u_strtotitle
  */
-PHPAPI UChar* php_u_strtotitle(UChar **s, int32_t *len, const char* locale)
+PHPAPI UChar* php_u_strtotitle(UChar *s, int32_t *len, const char* locale)
 {
        UChar *dest = NULL;
        int32_t dest_len;
@@ -1628,11 +1633,11 @@
        UBreakIterator *brkiter;
 
        dest_len = *len;
-       brkiter = ubrk_open(UBRK_WORD, locale, *s, *len, &status);
+       brkiter = ubrk_open(UBRK_WORD, locale, s, *len, &status);
        while (1) {
                status = U_ZERO_ERROR;
                dest = eurealloc(dest, dest_len+1);
-               dest_len = u_strToTitle(dest, dest_len, *s, *len, NULL, locale, 
&status);
+               dest_len = u_strToTitle(dest, dest_len, s, *len, NULL, locale, 
&status);
                if (status != U_BUFFER_OVERFLOW_ERROR) {
                        break;
                }
@@ -1640,15 +1645,13 @@
        ubrk_close(brkiter);
 
        if (U_SUCCESS(status)) {
-               efree(*s);
                dest[dest_len] = 0;
-               *s = dest;
                *len = dest_len;
+               return dest;
        } else {
                efree(dest);
+               return NULL;
        }
-
-       return *s;
 }
 /* }}} */
 
@@ -1657,26 +1660,29 @@
    Makes a string titlecase */
 PHP_FUNCTION(strtotitle)
 {
-       zval **str;
+       zstr str;
+       int str_len;
+       zend_uchar str_type;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str)) {
-               WRONG_PARAM_COUNT;
-       }
-       if (Z_TYPE_PP(str) != IS_STRING && Z_TYPE_PP(str) != IS_UNICODE) {
-               convert_to_text_ex(str);
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &str, 
&str_len, &str_type) == FAILURE) {
+               return;
        }
 
-       if (Z_TYPE_PP(str) == IS_UNICODE && !Z_USTRLEN_PP(str)) {
+       if (str_type == IS_UNICODE && str_len == 0) {
                RETURN_EMPTY_UNICODE();
-       } else if (!Z_STRLEN_PP(str)) {
+       } else if (str_len == 0) {
                RETURN_EMPTY_STRING();
        }
 
-       if (Z_TYPE_PP(str) == IS_UNICODE) {
-               RETVAL_ZVAL(*str, 1, 0);
-               php_u_strtotitle(&Z_USTRVAL_P(return_value), 
&Z_USTRLEN_P(return_value), UG(default_locale));
+       if (str_type == IS_UNICODE) {
+               UChar *result;
+               if ((result = php_u_strtotitle(str.u, &str_len, 
UG(default_locale)))) {
+                       RETURN_UNICODEL(result, str_len, 0);
+               } else {
+                       RETURN_EMPTY_UNICODE();
+               }
        } else {
-               ZVAL_STRINGL(return_value, Z_STRVAL_PP(str), Z_STRLEN_PP(str), 
1);
+               RETVAL_STRINGL(str.s, str_len, 1);
                php_ucwords(return_value);
        }
 }
@@ -2460,10 +2466,8 @@
                }
                needle_len = Z_UNILEN_P(needle);
                if (Z_TYPE_P(haystack) == IS_UNICODE) {
-                       haystack_dup = eustrndup(Z_USTRVAL_P(haystack), 
haystack_len);
-                       php_u_strtolower((UChar **)&haystack_dup, 
&haystack_len, UG(default_locale));
-                       needle_dup = eustrndup(Z_USTRVAL_P(needle), needle_len);
-                       php_u_strtolower((UChar **)&needle_dup, &needle_len, 
UG(default_locale));
+                       haystack_dup = php_u_strtolower(Z_USTRVAL_P(haystack), 
&haystack_len, UG(default_locale));
+                       needle_dup = php_u_strtolower(Z_USTRVAL_P(needle), 
&needle_len, UG(default_locale));
                        found = zend_u_memnstr((UChar *)haystack_dup + offset,
                                                                   (UChar 
*)needle_dup, needle_len,
                                                                   (UChar 
*)haystack_dup + haystack_len);
@@ -2508,8 +2512,7 @@
                                u_needle_char[needle_len++] = U16_TRAIL(ch);
                                u_needle_char[needle_len]   = 0;
                        }
-                       haystack_dup = eustrndup(Z_USTRVAL_P(haystack), 
haystack_len);
-                       php_u_strtolower((UChar **)&haystack_dup, 
&haystack_len, UG(default_locale));
+                       haystack_dup = php_u_strtolower(haystack_dup, 
&haystack_len, UG(default_locale));
                        found = zend_u_memnstr((UChar *)haystack_dup + offset,
                                                                   (UChar 
*)u_needle_char, needle_len,
                                                                   (UChar 
*)haystack_dup + haystack_len);
@@ -3923,26 +3926,24 @@
    Reverse a string */
 PHP_FUNCTION(strrev)
 {
-       zval **str;
+       zstr str;
+       int str_len;
+       zend_uchar str_type;
        char *s, *e, *n = NULL, *p;
        int32_t i, x1, x2;
        UChar32 ch;
        UChar *u_s, *u_n = NULL, *u_p;
 
-       if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &str) == FAILURE) {
-               WRONG_PARAM_COUNT;
-       }
-
-       if (Z_TYPE_PP(str) != IS_UNICODE && Z_TYPE_PP(str) != IS_STRING) {
-               convert_to_text_ex(str);
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &str, 
&str_len, &str_type) == FAILURE) {
+               return;
        }
 
-       if (Z_TYPE_PP(str) == IS_UNICODE) {
-               u_n = eumalloc(Z_USTRLEN_PP(str)+1);
+       if (str_type == IS_UNICODE) {
+               u_n = eumalloc(str_len+1);
                u_p = u_n;
-               u_s = Z_USTRVAL_PP(str);
+               u_s = str.u;
 
-               i = Z_USTRLEN_PP(str);
+               i = str_len;
                while (i > 0) {
                        U16_PREV(u_s, 0, i, ch);
                        if (u_getCombiningClass(ch) == 0) {
@@ -3954,17 +3955,17 @@
                                } while (u_getCombiningClass(ch) != 0);
                                x1 = i;
                                while (x1 <= x2) {
-                                       U16_NEXT(u_s, x1, Z_USTRLEN_PP(str), 
ch);
+                                       U16_NEXT(u_s, x1, str_len, ch);
                                        u_p += zend_codepoint_to_uchar(ch, u_p);
                                }
                        }
                }
                *u_p = 0;
        } else {
-               n = emalloc(Z_STRLEN_PP(str)+1);
+               n = emalloc(str_len+1);
                p = n;
-               s = Z_STRVAL_PP(str);
-               e = s + Z_STRLEN_PP(str);
+               s = str.s;
+               e = s + str_len;
 
                while (--e >= s) {
                        *(p++) = *e;
@@ -3972,10 +3973,10 @@
                *p = '\0';
        }
 
-       if (Z_TYPE_PP(str) == IS_UNICODE) {
-               RETVAL_UNICODEL(u_n, Z_USTRLEN_PP(str), 0);
+       if (str_type == IS_UNICODE) {
+               RETVAL_UNICODEL(u_n, str_len, 0);
        } else {
-               RETVAL_STRINGL(n, Z_STRLEN_PP(str), 0);
+               RETVAL_STRINGL(n, str_len, 0);
        }
 }
 /* }}} */
@@ -5603,8 +5604,7 @@
        buf = eustrndup(rbuf, len);
        rp = rbuf;
        if (allow_len != 0) {
-               allow = eustrndup(allow, allow_len);
-               php_u_strtolower(&allow, &allow_len, UG(default_locale));
+               allow = php_u_strtolower(allow, &allow_len, UG(default_locale));
                tbuf = eumalloc(PHP_TAG_BUF_SIZE+1);
                tp = tbuf;
        }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to