andrei          Wed Aug  9 20:03:22 2006 UTC

  Modified files:              
    /php-src/ext/standard       string.c 
    /php-src    unicode-progress.txt 
  Log:
  Upgrade str_rot13() to work with IS_UNICODE type.
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.570&r2=1.571&diff_format=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.570 php-src/ext/standard/string.c:1.571
--- php-src/ext/standard/string.c:1.570 Wed Aug  9 18:15:06 2006
+++ php-src/ext/standard/string.c       Wed Aug  9 20:03:21 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: string.c,v 1.570 2006/08/09 18:15:06 fmk Exp $ */
+/* $Id: string.c,v 1.571 2006/08/09 20:03:21 andrei Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -3741,7 +3741,9 @@
                }
 
                for (i = 0; i < len; i++) {
-                       tmp_str[i] = xlat[str[i]];
+                       if (str[i] < 256) {
+                               tmp_str[i] = xlat[str[i]];
+                       }
                }
 
                *outlen = len;
@@ -3753,13 +3755,15 @@
                HashTable *tmp_hash;
                int minlen = 128*1024, maxlen;
                zval *tmp;
+               UChar x[2] = { 0, };
 
                tmp_hash = emalloc(sizeof(HashTable));
                zend_hash_init(tmp_hash, 0, NULL, NULL, 0);
 
                /* Loop over the two strings and prepare the hash entries */
                MAKE_STD_ZVAL(tmp);
-               ZVAL_UNICODEL(tmp, "X", 1, 1);
+               x[0] = (UChar) 0x58 /*'X'*/;
+               ZVAL_UNICODEL(tmp, x, 1, 1);
                minlen = maxlen = 1;
                zend_u_hash_add(tmp_hash, IS_UNICODE, ZSTR("a"), 2, &tmp, 
sizeof(zval *), NULL);
 
@@ -6783,21 +6787,36 @@
 
 static char rot13_from[] = 
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
 static char rot13_to[] = 
"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM";
+U_STRING_DECL(u_rot13_from, rot13_from, sizeof(rot13_from)-1);
+U_STRING_DECL(u_rot13_to, rot13_to, sizeof(rot13_to)-1);
 
-/* {{{ proto string str_rot13(string str)
+/* {{{ proto string str_rot13(string str) U
    Perform the rot13 transform on a string */
 PHP_FUNCTION(str_rot13)
 {
-       zval **arg;
+       static int did_init_strings = FALSE;
+       zstr str;
+       int str_len;
+       zend_uchar str_type;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg)) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &str, 
&str_len, &str_type) == FAILURE) {
+               return;
+       }
+
+       if (!did_init_strings) {
+               U_STRING_INIT(u_rot13_from, rot13_from, sizeof(rot13_from)-1);
+               U_STRING_INIT(u_rot13_to, rot13_to, sizeof(rot13_to)-1);
+               did_init_strings = TRUE;
        }
 
-       convert_to_string_ex(arg);
-       RETVAL_ZVAL(*arg, 1, 0);
 
-       php_strtr(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value), 
rot13_from, rot13_to, 52);
+       if (str_type == IS_UNICODE) {
+               RETVAL_UNICODEL(str.u, str_len, 0);
+               Z_USTRVAL_P(return_value) = 
php_u_strtr(Z_USTRVAL_P(return_value), Z_USTRLEN_P(return_value), u_rot13_from, 
52, u_rot13_to, 52, 52, &Z_USTRLEN_P(return_value));
+       } else {
+               RETVAL_STRINGL(str.s, str_len, 1);
+               php_strtr(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value), 
rot13_from, rot13_to, 52);
+       }
 }
 /* }}} */
 
http://cvs.php.net/viewvc.cgi/php-src/unicode-progress.txt?r1=1.39&r2=1.40&diff_format=u
Index: php-src/unicode-progress.txt
diff -u php-src/unicode-progress.txt:1.39 php-src/unicode-progress.txt:1.40
--- php-src/unicode-progress.txt:1.39   Wed Aug  9 17:40:21 2006
+++ php-src/unicode-progress.txt        Wed Aug  9 20:03:22 2006
@@ -52,9 +52,6 @@
         Params API, IS_UNICODE upgrade. Case-folding should be handled
         similar to stristr().
 
-    str_rot13()
-        Params API, IS_UNICODE support
-
     str_shuffle()
         Params API, IS_UNICODE support
 
@@ -196,6 +193,7 @@
     similar_text()
     str_pad()
     str_repeat()
+    str_rot13()
     strcspn()
     strip_tags()
     stripcslashes()

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

Reply via email to