andrei          Wed Aug  9 20:19:06 2006 UTC

  Modified files:              
    /php-src/ext/standard       string.c 
    /php-src    unicode-progress.txt 
  Log:
  Unicode support for str_shuffle().
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.571&r2=1.572&diff_format=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.571 php-src/ext/standard/string.c:1.572
--- php-src/ext/standard/string.c:1.571 Wed Aug  9 20:03:21 2006
+++ php-src/ext/standard/string.c       Wed Aug  9 20:19:06 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: string.c,v 1.571 2006/08/09 20:03:21 andrei Exp $ */
+/* $Id: string.c,v 1.572 2006/08/09 20:19:06 andrei Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -6821,46 +6821,55 @@
 /* }}} */
 
 
-static void php_string_shuffle(char *str, long len TSRMLS_DC)
+static void php_string_shuffle(zstr str, int len, zend_uchar str_type 
TSRMLS_DC)
 {
-       long n_elems, rnd_idx, n_left;
+       int rnd_idx, n_left;
        char temp;
+       UChar u_temp;
        /* The implementation is stolen from array_data_shuffle       */
        /* Thus the characteristics of the randomization are the same */
-       n_elems = len;
 
-       if (n_elems <= 1) {
+       if (len <= 1) {
                return;
        }
 
-       n_left = n_elems;
+       n_left = len;
 
        while (--n_left) {
                rnd_idx = php_rand(TSRMLS_C);
                RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
-               if (rnd_idx != n_left) {
-                       temp = str[n_left];
-                       str[n_left] = str[rnd_idx];
-                       str[rnd_idx] = temp;
+               if (str_type == IS_UNICODE) {
+                       if (rnd_idx != n_left) {
+                               u_temp = str.u[n_left];
+                               str.u[n_left] = str.u[rnd_idx];
+                               str.u[rnd_idx] = u_temp;
+                       }
+               } else {
+                       if (rnd_idx != n_left) {
+                               temp = str.s[n_left];
+                               str.s[n_left] = str.s[rnd_idx];
+                               str.s[rnd_idx] = temp;
+                       }
                }
        }
 }
 
 
-/* {{{ proto void str_shuffle(string str)
+/* {{{ proto void str_shuffle(string str) U
    Shuffles string. One permutation of all possible is created */
 PHP_FUNCTION(str_shuffle)
 {
-       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 (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &str, 
&str_len, &str_type) == FAILURE) {
+               return;
        }
 
-       convert_to_string_ex(arg);
-       RETVAL_ZVAL(*arg, 1, 0);
-       if (Z_STRLEN_P(return_value) > 1) {
-               php_string_shuffle(Z_STRVAL_P(return_value), (long) 
Z_STRLEN_P(return_value) TSRMLS_CC);
+       RETVAL_ZSTRL(str, str_len, str_type, 1);
+       if (Z_UNILEN_P(return_value) > 1) {
+               php_string_shuffle(Z_UNIVAL_P(return_value), 
Z_UNILEN_P(return_value), Z_TYPE_P(return_value) TSRMLS_CC);
        }
 }
 /* }}} */
http://cvs.php.net/viewvc.cgi/php-src/unicode-progress.txt?r1=1.40&r2=1.41&diff_format=u
Index: php-src/unicode-progress.txt
diff -u php-src/unicode-progress.txt:1.40 php-src/unicode-progress.txt:1.41
--- php-src/unicode-progress.txt:1.40   Wed Aug  9 20:03:22 2006
+++ php-src/unicode-progress.txt        Wed Aug  9 20:19:06 2006
@@ -52,9 +52,6 @@
         Params API, IS_UNICODE upgrade. Case-folding should be handled
         similar to stristr().
 
-    str_shuffle()
-        Params API, IS_UNICODE support
-
     str_split()
         IS_UNICODE support, split on codepoint level.
 
@@ -194,6 +191,7 @@
     str_pad()
     str_repeat()
     str_rot13()
+    str_shuffle()
     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