[PHP-CVS] cvs: php4 /ext/standard basic_functions.c php_string.h string.c

2003-02-11 Thread Ilia Alshanetsky
iliaa   Tue Feb 11 17:47:26 2003 EDT

  Modified files:  
/php4/ext/standard  string.c php_string.h basic_functions.c 
  Log:
  Added strpbrk(), which is essentially a wrapper around C's strpbrk function
  that allows searching through a string for a character list.
  
  
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.355 php4/ext/standard/string.c:1.356
--- php4/ext/standard/string.c:1.355Sat Feb  8 10:26:17 2003
+++ php4/ext/standard/string.c  Tue Feb 11 17:47:25 2003
@@ -18,7 +18,7 @@
+--+
  */
 
-/* $Id: string.c,v 1.355 2003/02/08 15:26:17 sniper Exp $ */
+/* $Id: string.c,v 1.356 2003/02/11 22:47:25 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -4379,6 +4379,30 @@
 }
 /* }}} */
 
+/* {{{ proto array strpbrk(string haystack, string char_list)
+   Search a string for any of a set of characters */
+PHP_FUNCTION(strpbrk)
+{
+   char *haystack, *char_list;
+   int haystack_len, char_list_len;
+   char *p;
+   
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ss, haystack, 
+haystack_len, char_list, char_list_len) == FAILURE) {
+   RETURN_FALSE;
+   }
+
+   if (!char_list_len) {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, The character list cannot 
+be empty.);
+   RETURN_FALSE;   
+   }
+
+   if ((p = strpbrk(haystack, char_list))) {
+   RETURN_STRINGL(p, (haystack + haystack_len - p), 1);
+   } else {
+   RETURN_FALSE;
+   }
+}
+/* }}} */
 
 /*
  * Local variables:
Index: php4/ext/standard/php_string.h
diff -u php4/ext/standard/php_string.h:1.70 php4/ext/standard/php_string.h:1.71
--- php4/ext/standard/php_string.h:1.70 Fri Feb  7 16:36:18 2003
+++ php4/ext/standard/php_string.h  Tue Feb 11 17:47:26 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: php_string.h,v 1.70 2003/02/07 21:36:18 iliaa Exp $ */
+/* $Id: php_string.h,v 1.71 2003/02/11 22:47:26 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
 
@@ -88,6 +88,7 @@
 PHP_FUNCTION(str_shuffle);
 PHP_FUNCTION(str_word_count);
 PHP_FUNCTION(str_split);
+PHP_FUNCTION(strpbrk);
 #ifdef HAVE_STRCOLL
 PHP_FUNCTION(strcoll);
 #endif
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.576 
php4/ext/standard/basic_functions.c:1.577
--- php4/ext/standard/basic_functions.c:1.576   Sun Feb  9 15:43:05 2003
+++ php4/ext/standard/basic_functions.c Tue Feb 11 17:47:26 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: basic_functions.c,v 1.576 2003/02/09 20:43:05 iliaa Exp $ */
+/* $Id: basic_functions.c,v 1.577 2003/02/11 22:47:26 iliaa Exp $ */
 
 #include php.h
 #include php_streams.h
@@ -343,6 +343,7 @@
PHP_FE(str_shuffle,
 NULL)
PHP_FE(str_word_count, 
 NULL)
PHP_FE(str_split,  
 NULL)
+   PHP_FE(strpbrk,
+ NULL)
 
 #ifdef HAVE_STRCOLL
PHP_FE(strcoll,
 NULL)



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




[PHP-CVS] cvs: php4 /ext/standard basic_functions.c php_string.h string.c

2003-02-07 Thread Ilia Alshanetsky
iliaa   Fri Feb  7 16:36:18 2003 EDT

  Modified files:  
/php4/ext/standard  string.c php_string.h basic_functions.c 
  Log:
  Added str_split() function. This function can be used to break down a 
  string into an array.
  
  
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.353 php4/ext/standard/string.c:1.354
--- php4/ext/standard/string.c:1.353Thu Jan 30 15:09:19 2003
+++ php4/ext/standard/string.c  Fri Feb  7 16:36:18 2003
@@ -18,7 +18,7 @@
+--+
  */
 
-/* $Id: string.c,v 1.353 2003/01/30 20:09:19 pollita Exp $ */
+/* $Id: string.c,v 1.354 2003/02/07 21:36:18 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -37,6 +37,9 @@
 #ifdef HAVE_MONETARY_H
 # include monetary.h
 #endif
+
+#include math.h
+
 #include scanf.h
 #include zend_API.h
 #include zend_execute.h
@@ -4296,9 +4299,43 @@
 
RETURN_STRINGL(erealloc(str, str_len + 1), str_len, 0);
 }
-
 /* }}} */
 #endif
+
+/* {{{ proto array str_split(string str [, int split_length])
+   Convert a string to an array. If split_length is specified, break the string down 
+into chunks each split_length characters long. */
+PHP_FUNCTION(str_split) {
+   char *str;
+   int str_len;
+   long split_length = 1;
+   char *p;
+   int n_reg_segments;
+   
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|l, str, str_len, 
+split_length) == FAILURE) {
+   return;
+   }
+
+   if (split_length = 0) {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, The the length of each 
+segment must be greater then zero.);
+   RETURN_FALSE;
+   }
+
+   array_init(return_value);
+
+   n_reg_segments = floor(str_len / split_length);
+   p = str;
+
+   while (n_reg_segments--  0) {
+   add_next_index_stringl(return_value, p, split_length, 1);
+   p += split_length;
+   }
+
+   if (p != (str + str_len)) {
+   add_next_index_stringl(return_value, p, (str + str_len - p), 1);
+   }
+}
+/* }}} */
+
 
 /*
  * Local variables:
Index: php4/ext/standard/php_string.h
diff -u php4/ext/standard/php_string.h:1.69 php4/ext/standard/php_string.h:1.70
--- php4/ext/standard/php_string.h:1.69 Thu Jan 30 00:00:40 2003
+++ php4/ext/standard/php_string.h  Fri Feb  7 16:36:18 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: php_string.h,v 1.69 2003/01/30 05:00:40 pollita Exp $ */
+/* $Id: php_string.h,v 1.70 2003/02/07 21:36:18 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
 
@@ -87,6 +87,7 @@
 PHP_FUNCTION(sscanf);
 PHP_FUNCTION(str_shuffle);
 PHP_FUNCTION(str_word_count);
+PHP_FUNCTION(str_split);
 #ifdef HAVE_STRCOLL
 PHP_FUNCTION(strcoll);
 #endif
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.572 
php4/ext/standard/basic_functions.c:1.573
--- php4/ext/standard/basic_functions.c:1.572   Fri Feb  7 16:33:35 2003
+++ php4/ext/standard/basic_functions.c Fri Feb  7 16:36:18 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: basic_functions.c,v 1.572 2003/02/07 21:33:35 iliaa Exp $ */
+/* $Id: basic_functions.c,v 1.573 2003/02/07 21:36:18 iliaa Exp $ */
 
 #include php.h
 #include php_streams.h
@@ -342,6 +342,7 @@
PHP_FE(strrchr,
 NULL)
PHP_FE(str_shuffle,
 NULL)
PHP_FE(str_word_count, 
 NULL)
+   PHP_FE(str_split,  
+ NULL)
 
 #ifdef HAVE_STRCOLL
PHP_FE(strcoll,
 NULL)



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




[PHP-CVS] cvs: php4 /ext/standard basic_functions.c php_string.h string.c

2003-01-29 Thread Sara Golemon
pollita Thu Jan 30 00:00:42 2003 EDT

  Modified files:  
/php4/ext/standard  basic_functions.c php_string.h string.c 
  Log:
  Feature Request # 5919 - Addition of str_ireplace()
  Also removed deprecated BM str replace menthod
  Also rewrote php_str_to_str to use more processor/memory efficient method (ilia)
  
  
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.568 
php4/ext/standard/basic_functions.c:1.569
--- php4/ext/standard/basic_functions.c:1.568   Tue Jan 28 19:49:09 2003
+++ php4/ext/standard/basic_functions.c Thu Jan 30 00:00:40 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: basic_functions.c,v 1.568 2003/01/29 00:49:09 phanto Exp $ */
+/* $Id: basic_functions.c,v 1.569 2003/01/30 05:00:40 pollita Exp $ */
 
 #include php.h
 #include php_streams.h
@@ -361,6 +361,7 @@
PHP_FE(addcslashes,
 NULL)
PHP_FE(rtrim,  
 NULL)
PHP_FE(str_replace,
 NULL)
+   PHP_FE(str_ireplace,   
+ NULL)
PHP_FE(str_repeat, 
 NULL)
PHP_FE(count_chars,
 NULL)
PHP_FE(chunk_split,
 NULL)
Index: php4/ext/standard/php_string.h
diff -u php4/ext/standard/php_string.h:1.68 php4/ext/standard/php_string.h:1.69
--- php4/ext/standard/php_string.h:1.68 Tue Jan 28 19:07:01 2003
+++ php4/ext/standard/php_string.h  Thu Jan 30 00:00:40 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: php_string.h,v 1.68 2003/01/29 00:07:01 iliaa Exp $ */
+/* $Id: php_string.h,v 1.69 2003/01/30 05:00:40 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
 
@@ -27,6 +27,7 @@
 PHP_FUNCTION(strspn);
 PHP_FUNCTION(strcspn);
 PHP_FUNCTION(str_replace);
+PHP_FUNCTION(str_ireplace);
 PHP_FUNCTION(rtrim);
 PHP_FUNCTION(trim);
 PHP_FUNCTION(ltrim);
@@ -121,6 +122,8 @@
 PHPAPI char *php_basename(char *str, size_t  len , char *suffix, size_t sufflen);
 PHPAPI void php_dirname(char *str, int len);
 PHPAPI char *php_stristr(unsigned char *s, unsigned char *t, size_t s_len, size_t 
t_len);
+PHPAPI char *php_str_to_str_ex(char *haystack, int length, char *needle,
+   int needle_len, char *str, int str_len, int *_new_length, int 
+case_sensitivity);
 PHPAPI char *php_str_to_str(char *haystack, int length, char *needle,
int needle_len, char *str, int str_len, int *_new_length);
 PHPAPI char *php_trim(char *c, int len, char *what, int what_len, zval *return_value, 
int mode TSRMLS_DC);
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.351 php4/ext/standard/string.c:1.352
--- php4/ext/standard/string.c:1.351Fri Jan 24 08:18:08 2003
+++ php4/ext/standard/string.c  Thu Jan 30 00:00:41 2003
@@ -18,7 +18,7 @@
+--+
  */
 
-/* $Id: string.c,v 1.351 2003/01/24 13:18:08 andrey Exp $ */
+/* $Id: string.c,v 1.352 2003/01/30 05:00:41 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -2668,83 +2668,105 @@
 }
 /* }}} */
 
-/* {{{ boyer_str_to_str */
-static char *boyer_str_to_str(char *haystack, int length,
-   char *needle, int needle_len, char *str, 
-   int str_len, int *new_length)
-{
-   char *p, *pe, *cursor, *end, *r;
-   int off;
-   char jump_table[256];
-   smart_str result = {0};
+/* {{{ php_str_to_str_ex
+ */
+PHPAPI char *php_str_to_str_ex(char *haystack, int length, 
+   char *needle, int needle_len, char *str, int str_len, int *_new_length, int 
+case_sensitivity)
+{
+   char *new_str;
 
-   /*
-* We implement only the first half of the Boyer-Moore algorithm,
-* because the second half is too expensive to compute during run-time.
-* TODO: Split matching into compile-/match-stage.
-*/
-   
-   /* Prepare the jump_table which contains the skip offsets */
-   memset(jump_table, needle_len, 256);
-   
-   off = needle_len - 1;
-   
-   /* Calculate the default start where each comparison starts */
-   pe = needle + off;
+   if (needle_len  length) {
+   char *end, *haystack_dup, 

[PHP-CVS] cvs: php4 /ext/standard basic_functions.c php_string.h string.c

2002-10-18 Thread Ilia Alshanetsky
iliaa   Thu Oct 17 18:44:45 2002 EDT

  Modified files:  
/php4/ext/standard  basic_functions.c php_string.h string.c 
  Log:
  Renamed word_count to str_word_count to comply with naming conventions.
  Thanks Andi, for catching this oversight.
  
  
  
  
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.529 
php4/ext/standard/basic_functions.c:1.530
--- php4/ext/standard/basic_functions.c:1.529   Wed Oct 16 23:27:19 2002
+++ php4/ext/standard/basic_functions.c Thu Oct 17 18:44:43 2002
 -17,7 +17,7 
+--+
  */
 
-/* $Id: basic_functions.c,v 1.529 2002/10/17 03:27:19 iliaa Exp $ */
+/* $Id: basic_functions.c,v 1.530 2002/10/17 22:44:43 iliaa Exp $ */
 
 #include php.h
 #include php_streams.h
 -334,7 +334,7 
PHP_FE(stristr,
 NULL)
PHP_FE(strrchr,
 NULL)
PHP_FE(str_shuffle,
 NULL)
-   PHP_FE(word_count, 
 NULL)
+   PHP_FE(str_word_count, 
+ NULL)
 
 #ifdef HAVE_STRCOLL
PHP_FE(strcoll,
 NULL)
Index: php4/ext/standard/php_string.h
diff -u php4/ext/standard/php_string.h:1.64 php4/ext/standard/php_string.h:1.65
--- php4/ext/standard/php_string.h:1.64 Wed Oct 16 23:27:19 2002
+++ php4/ext/standard/php_string.h  Thu Oct 17 18:44:44 2002
 -17,7 +17,7 
+--+
 */
 
-/* $Id: php_string.h,v 1.64 2002/10/17 03:27:19 iliaa Exp $ */
+/* $Id: php_string.h,v 1.65 2002/10/17 22:44:44 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
 
 -83,7 +83,7 
 PHP_FUNCTION(str_pad);
 PHP_FUNCTION(sscanf);
 PHP_FUNCTION(str_shuffle);
-PHP_FUNCTION(word_count);
+PHP_FUNCTION(str_word_count);
 #ifdef HAVE_STRCOLL
 PHP_FUNCTION(strcoll);
 #endif
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.324 php4/ext/standard/string.c:1.325
--- php4/ext/standard/string.c:1.324Wed Oct 16 23:27:19 2002
+++ php4/ext/standard/string.c  Thu Oct 17 18:44:44 2002
 -18,7 +18,7 
+--+
  */
 
-/* $Id: string.c,v 1.324 2002/10/17 03:27:19 iliaa Exp $ */
+/* $Id: string.c,v 1.325 2002/10/17 22:44:44 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
 -4027,7 +4027,7 
 }
 /* }}} */
 
-/* {{{ proto void word_count(string str, [int format])
+/* {{{ proto void str_word_count(string str, [int format])
Counts the number of words inside a string. If format of 1 is specified,
then the function will return an array containing all the words
found inside the string. If format of 2 is specified, then the function
 -4038,7 +4038,7 
string containing alphabetic characters, which also may contain, but not start
with ' and - characters.
 */
-PHP_FUNCTION(word_count)
+PHP_FUNCTION(str_word_count)
 {
zval **str, **o_format;
char *s, *e, *p, *buf;



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




Re: [PHP-CVS] cvs: php4 /ext/standard basic_functions.c php_string.h string.c

2002-10-18 Thread Jon Parise
On Fri, Oct 18, 2002 at 12:22:10AM +0200, Andi Gutmans wrote:

 This should follow naming standards and start with str_
 
We also ready have 'wordwrap'.  This adds 'word_count'.  You suggest 
staying with 'str_'.  I think, whatever is decided, we should commit 
to using one notation.

-- 
Jon Parise ([EMAIL PROTECTED]) :: The PHP Project (http://www.php.net/)

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




[PHP-CVS] cvs: php4 /ext/standard basic_functions.c php_string.h string.c

2002-10-16 Thread Ilia Alshanetsky

iliaa   Wed Oct 16 23:27:19 2002 EDT

  Modified files:  
/php4/ext/standard  basic_functions.c php_string.h string.c 
  Log:
  Added word_count() function that allows counting of words inside a string.
  The function also allows the user to retrieve all the words from a string.
  
  
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.528 
php4/ext/standard/basic_functions.c:1.529
--- php4/ext/standard/basic_functions.c:1.528   Sun Oct  6 13:04:10 2002
+++ php4/ext/standard/basic_functions.c Wed Oct 16 23:27:19 2002
 -17,7 +17,7 
+--+
  */
 
-/* $Id: basic_functions.c,v 1.528 2002/10/06 17:04:10 rasmus Exp $ */
+/* $Id: basic_functions.c,v 1.529 2002/10/17 03:27:19 iliaa Exp $ */
 
 #include php.h
 #include php_streams.h
 -334,6 +334,7 
PHP_FE(stristr,
 NULL)
PHP_FE(strrchr,
 NULL)
PHP_FE(str_shuffle,
 NULL)
+   PHP_FE(word_count, 
+ NULL)
 
 #ifdef HAVE_STRCOLL
PHP_FE(strcoll,
 NULL)
Index: php4/ext/standard/php_string.h
diff -u php4/ext/standard/php_string.h:1.63 php4/ext/standard/php_string.h:1.64
--- php4/ext/standard/php_string.h:1.63 Fri Oct 11 10:48:25 2002
+++ php4/ext/standard/php_string.h  Wed Oct 16 23:27:19 2002
 -17,7 +17,7 
+--+
 */
 
-/* $Id: php_string.h,v 1.63 2002/10/11 14:48:25 iliaa Exp $ */
+/* $Id: php_string.h,v 1.64 2002/10/17 03:27:19 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
 
 -83,6 +83,7 
 PHP_FUNCTION(str_pad);
 PHP_FUNCTION(sscanf);
 PHP_FUNCTION(str_shuffle);
+PHP_FUNCTION(word_count);
 #ifdef HAVE_STRCOLL
 PHP_FUNCTION(strcoll);
 #endif
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.323 php4/ext/standard/string.c:1.324
--- php4/ext/standard/string.c:1.323Fri Oct 11 08:42:01 2002
+++ php4/ext/standard/string.c  Wed Oct 16 23:27:19 2002
 -18,7 +18,7 
+--+
  */
 
-/* $Id: string.c,v 1.323 2002/10/11 12:42:01 sander Exp $ */
+/* $Id: string.c,v 1.324 2002/10/17 03:27:19 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
 -4027,6 +4027,80 
 }
 /* }}} */
 
+/* {{{ proto void word_count(string str, [int format])
+   Counts the number of words inside a string. If format of 1 is specified,
+   then the function will return an array containing all the words
+   found inside the string. If format of 2 is specified, then the function
+   will return an associated array where the position of the word is the key
+   and the word itself is the value.
+   
+   For the purpose of this function, 'word' is defined as a locale dependent
+   string containing alphabetic characters, which also may contain, but not start
+   with ' and - characters.
+*/
+PHP_FUNCTION(word_count)
+{
+   zval **str, **o_format;
+   char *s, *e, *p, *buf;
+   int word_count = 0;
+   int type = 0;
+   int n_args = ZEND_NUM_ARGS();
+
+   if( n_args  2 || n_args  1 || zend_get_parameters_ex(n_args, str, 
+o_format) == FAILURE) {
+   WRONG_PARAM_COUNT;
+   }
+   
+   if (n_args == 2) {
+   convert_to_long_ex(o_format);
+   type = Z_LVAL_PP(o_format);
+   
+   if (type != 1  type != 2) {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, The specified 
+format parameter, '%d' is invalid., type);
+   RETURN_FALSE;
+   }
+   }
+
+   convert_to_string_ex(str);
+   
+   p = s = Z_STRVAL_PP(str);
+   e = Z_STRVAL_PP(str) + Z_STRLEN_PP(str);
+   
+   if (type == 1 || type == 2) {
+   array_init(return_value);
+   }
+   
+   while (p  e) {
+   if (isalpha(*p++)) {
+   s = p - 1;
+   while (isalpha(*p) || *p == '\'' || (*p == '-'  
+isalpha(*(p+1 {
+   p++;
+   }
+   
+   switch (type)
+   {
+   case 1:
+   buf = estrndup(s, (p-s));
+   add_next_index_stringl(return_value, buf, 

[PHP-CVS] cvs: php4 /ext/standard basic_functions.c php_string.h string.c

2002-09-25 Thread Andrey Hristov

andrey  Wed Sep 25 14:06:06 2002 EDT

  Modified files:  
/php4/ext/standard  basic_functions.c php_string.h string.c 
  Log:
  str_shuffle() function added. Like shuffle() for arrays - however the
  algorithm for creating the permutation is quite simple. More like 
  the implementation of shuffle() for 4.2.1 .
  
  
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.511 
php4/ext/standard/basic_functions.c:1.512
--- php4/ext/standard/basic_functions.c:1.511   Wed Sep 25 11:25:11 2002
+++ php4/ext/standard/basic_functions.c Wed Sep 25 14:06:05 2002
 -17,7 +17,7 
+--+
  */
 
-/* $Id: basic_functions.c,v 1.511 2002/09/25 15:25:11 wez Exp $ */
+/* $Id: basic_functions.c,v 1.512 2002/09/25 18:06:05 andrey Exp $ */
 
 #include php.h
 #include php_streams.h
 -329,6 +329,7 
PHP_FE(strstr, 
 NULL)
PHP_FE(stristr,
 NULL)
PHP_FE(strrchr,
 NULL)
+   PHP_FE(str_shuffle,
+ NULL)
 
 #ifdef HAVE_STRCOLL
PHP_FE(strcoll,
 NULL)
Index: php4/ext/standard/php_string.h
diff -u php4/ext/standard/php_string.h:1.60 php4/ext/standard/php_string.h:1.61
--- php4/ext/standard/php_string.h:1.60 Tue Aug 20 16:47:47 2002
+++ php4/ext/standard/php_string.h  Wed Sep 25 14:06:05 2002
 -17,7 +17,7 
+--+
 */
 
-/* $Id: php_string.h,v 1.60 2002/08/20 20:47:47 wez Exp $ */
+/* $Id: php_string.h,v 1.61 2002/09/25 18:06:05 andrey Exp $ */
 
 /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
 
 -82,6 +82,7 
 PHP_FUNCTION(substr_count);
 PHP_FUNCTION(str_pad);
 PHP_FUNCTION(sscanf);
+PHP_FUNCTION(str_shuffle);
 #ifdef HAVE_STRCOLL
 PHP_FUNCTION(strcoll);
 #endif
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.297 php4/ext/standard/string.c:1.298
--- php4/ext/standard/string.c:1.297Mon Sep 23 10:20:02 2002
+++ php4/ext/standard/string.c  Wed Sep 25 14:06:05 2002
 -18,7 +18,7 
+--+
  */
 
-/* $Id: string.c,v 1.297 2002/09/23 14:20:02 sebastian Exp $ */
+/* $Id: string.c,v 1.298 2002/09/25 18:06:05 andrey Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
 -3929,6 +3929,39 
zval_copy_ctor(return_value);
 
php_strtr(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value), rot13_from, 
rot13_to, 52);
+}
+/* }}} */
+
+
+static int php_string_shuffle(const void *a, const void *b TSRMLS_DC)
+{
+   long rnd;
+   rnd = php_rand(TSRMLS_C);
+   if (rnd % 3)
+   return 1;
+   else if (rnd % 5)
+   return 0;
+   else 
+   return -1;
+}
+
+/* {{{ proto string str_shuffle(string str)
+   Shuffles string. One permutation of all possible is created */
+PHP_FUNCTION(str_shuffle)
+{
+   /* Note : by using current php_string_shuffle for string  */
+   /* with 6 chars (6! permutations) about 2/3 of them are   */
+   /* computed for 6! calls for the function. So it isn't so */
+   /* unique. The ratio is the same for other lengths.   */
+   char *str;
+   int i, str_len;
+   
+   i = 0;
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s, str, str_len) == 
+FAILURE) {
+   RETURN_FALSE;
+   }
+   zend_qsort((void *)str, str_len, sizeof(char), php_string_shuffle TSRMLS_CC);
+   RETURN_STRINGL(str, str_len, 1);
 }
 /* }}} */
 



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