cvs: /php4/ext/standard basic_functions.c php3_string.h string.c
| From: | Andrei Zmievski | Date: | Wed, 27 Oct 1999 22:06:38 +0000 |
| Subject: | cvs: /php4/ext/standard basic_functions.c php3_string.h string.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-5737@lists.php.net to get a copy of this message | ||
andrei Wed Oct 27 18:06:38 1999 EDT
Modified files:
/php4/ext/standard basic_functions.c php3_string.h string.c
Log:
(PHP str_repeat) New function.
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.110 php4/ext/standard/basic_functions.c:1.111
--- php4/ext/standard/basic_functions.c:1.110 Wed Oct 27 14:30:40 1999
+++ php4/ext/standard/basic_functions.c Wed Oct 27 18:06:05 1999
@@ -166,6 +166,7 @@
PHP_FE(addcslashes, NULL)
PHP_FE(chop, NULL)
PHP_FE(str_replace, NULL)
+ PHP_FE(str_repeat, NULL)
PHP_FE(chunk_split, NULL)
PHP_FE(trim, NULL)
PHP_FE(ltrim, NULL)
Index: php4/ext/standard/php3_string.h
diff -u php4/ext/standard/php3_string.h:1.18 php4/ext/standard/php3_string.h:1.19
--- php4/ext/standard/php3_string.h:1.18 Sat Oct 16 12:35:18 1999
+++ php4/ext/standard/php3_string.h Wed Oct 27 18:06:05 1999
@@ -29,7 +29,7 @@
*/
-/* $Id: php3_string.h,v 1.18 1999/10/16 16:35:18 andrei Exp $ */
+/* $Id: php3_string.h,v 1.19 1999/10/27 22:06:05 andrei Exp $ */
/* Synced with php3 revision 1.43 1999-06-16 [ssb] */
@@ -84,6 +84,7 @@
PHP_FUNCTION(bin2hex);
PHP_FUNCTION(similar_text);
PHP_FUNCTION(strip_tags);
+PHP_FUNCTION(str_repeat);
extern PHPAPI char *php_strtoupper(char *s);
extern PHPAPI char *php_strtolower(char *s);
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.52 php4/ext/standard/string.c:1.53
--- php4/ext/standard/string.c:1.52 Sat Oct 16 12:35:18 1999
+++ php4/ext/standard/string.c Wed Oct 27 18:06:05 1999
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string.c,v 1.52 1999/10/16 16:35:18 andrei Exp $ */
+/* $Id: string.c,v 1.53 1999/10/27 22:06:05 andrei Exp $ */
/* Synced with php3 revision 1.193 1999-06-16 [ssb] */
@@ -2052,6 +2052,50 @@
efree(buf);
if(allow) efree(tbuf);
}
+
+/* {{{ proto string str_repeat(string input, int mult)
+ Returns the input string repeat mult times */
+PHP_FUNCTION(str_repeat)
+{
+ zval **input_str; /* Input string */
+ zval **mult; /* Multiplier */
+ char *result; /* Resulting string */
+ int result_len; /* Length of the resulting string */
+ int i;
+
+ if (ARG_COUNT(ht) != 2 || getParametersEx(2, &input_str, &mult) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ /* Make sure we're dealing with proper types */
+ convert_to_string_ex(input_str);
+ convert_to_long_ex(mult);
+
+ if ((*mult)->value.lval < 1) {
+ php_error(E_WARNING, "Second argument to %s() has to be greater than 0",
+ get_active_function_name());
+ return;
+ }
+
+ /* Don't waste our time if it's empty */
+ if ((*input_str)->value.str.len == 0)
+ RETURN_STRINGL(empty_string, 0, 1);
+
+ /* Initialize the result string */
+ result_len = (*input_str)->value.str.len * (*mult)->value.lval;
+ result = (char *)emalloc(result_len + 1);
+
+ /* Copy the input string into the result as many times as necessary */
+ for (i=0; i<(*mult)->value.lval; i++) {
+ memcpy(result + (*input_str)->value.str.len * i,
+ (*input_str)->value.str.val,
+ (*input_str)->value.str.len);
+ }
+ result[result_len] = '\0';
+
+ RETURN_STRINGL(result, result_len + 1, 0);
+}
+/* }}} */
/*
* Local variables: