Date: 01/29/99
- Next message: Frank M. Kromann: "[PHP-DEV] inet_aton"
- Previous message: eschmid: "[PHP-DEV] CVS update: php3/doc/chapters"
- Next in thread: shane: "[PHP-DEV] CVS update: php3/functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Friday January 29, 1999 @ 3:28
Author: fmk
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv3426
Modified Files:
string.c php3_string.h
Log Message:
Making inmplode and explode calable from other modules
Index: php3/functions/string.c
diff -c php3/functions/string.c:1.172 php3/functions/string.c:1.173
*** php3/functions/string.c:1.172 Wed Jan 27 14:45:16 1999
--- php3/functions/string.c Fri Jan 29 03:28:13 1999
***************
*** 30,36 ****
*/
! /* $Id: string.c,v 1.172 1999/01/27 19:45:16 rasmus Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
--- 30,36 ----
*/
! /* $Id: string.c,v 1.173 1999/01/29 08:28:13 fmk Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
***************
*** 228,240 ****
}
/* }}} */
/* {{{ proto array explode(string separator, string str)
Split a string on string separator and return array of components */
void php3_explode(INTERNAL_FUNCTION_PARAMETERS)
{
pval *str, *delim;
- char *work_str, *p1, *p2;
- int i = 0;
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &delim, &str) == FAILURE) {
WRONG_PARAM_COUNT;
--- 228,258 ----
}
/* }}} */
+ void _php3_explode(pval *delim, pval *str, pval *return_value)
+ {
+ char *work_str, *p1, *p2;
+ int i = 0;
+
+ work_str = p1 = estrndup(str->value.str.val,str->value.str.len);
+ p2 = strstr(p1, delim->value.str.val);
+ if (p2 == NULL) {
+ add_index_string(return_value, i++, p1, 1);
+ } else do {
+ p2[0] = 0;
+ add_index_string(return_value, i++, p1, 1);
+ p1 = p2 + delim->value.str.len;
+ } while ((p2 = strstr(p1, delim->value.str.val)) && p2 != work_str);
+ if (p1 != work_str) {
+ add_index_string(return_value, i++, p1, 1);
+ }
+ efree(work_str);
+ }
+
/* {{{ proto array explode(string separator, string str)
Split a string on string separator and return array of components */
void php3_explode(INTERNAL_FUNCTION_PARAMETERS)
{
pval *str, *delim;
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &delim, &str) == FAILURE) {
WRONG_PARAM_COUNT;
***************
*** 247,299 ****
php3_error(E_WARNING,"Empty delimiter");
RETURN_FALSE;
}
if (array_init(return_value) == FAILURE) {
return;
- }
- work_str = p1 = estrndup(str->value.str.val,str->value.str.len);
- p2 = strstr(p1, delim->value.str.val);
- if (p2 == NULL) {
- add_index_string(return_value, i++, p1, 1);
- } else do {
- p2[0] = 0;
- add_index_string(return_value, i++, p1, 1);
- p1 = p2 + delim->value.str.len;
- } while ((p2 = strstr(p1, delim->value.str.val)) && p2 != work_str);
- if (p1 != work_str) {
- add_index_string(return_value, i++, p1, 1);
}
! efree(work_str);
}
/* }}} */
/* {{{ proto string join(array src, string glue)
An alias for implode */
/* }}} */
!
! /* {{{ proto string implode(array src, string glue)
! Join array elements placing glue string between items and return one string */
! void php3_implode(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *arg1, *arg2, *delim, *tmp, *arr;
int len = 0, count = 0;
TLS_VARS;
-
- if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (arg1->type == IS_ARRAY && arg2->type == IS_STRING) {
- arr = arg1;
- delim = arg2;
- } else if (arg2->type == IS_ARRAY) {
- convert_to_string(arg1);
- arr = arg2;
- delim = arg1;
- } else {
- php3_error(E_WARNING, "Bad arguments to %s()",
- GLOBAL(function_state).function_name);
- return;
- }
/* convert everything to strings, and calculate length */
_php3_hash_internal_pointer_reset(arr->value.ht);
--- 265,286 ----
php3_error(E_WARNING,"Empty delimiter");
RETURN_FALSE;
}
+
if (array_init(return_value) == FAILURE) {
return;
}
! _php3_explode(delim, str, return_value);
}
/* }}} */
/* {{{ proto string join(array src, string glue)
An alias for implode */
/* }}} */
! void _php3_implode(pval *delim, pval *arr, pval *return_value)
{
! pval *tmp;
int len = 0, count = 0;
TLS_VARS;
/* convert everything to strings, and calculate length */
_php3_hash_internal_pointer_reset(arr->value.ht);
***************
*** 327,333 ****
--- 314,347 ----
return_value->type = IS_STRING;
return_value->value.str.len = len;
}
+
+
+ /* {{{ proto string implode(array src, string glue)
+ Join array elements placing glue string between items and return one string */
+ void php3_implode(INTERNAL_FUNCTION_PARAMETERS)
+ {
+ pval *arg1, *arg2, *delim, *arr;
+
+ if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ if (arg1->type == IS_ARRAY && arg2->type == IS_STRING) {
+ arr = arg1;
+ delim = arg2;
+ } else if (arg2->type == IS_ARRAY) {
+ convert_to_string(arg1);
+ arr = arg2;
+ delim = arg1;
+ } else {
+ php3_error(E_WARNING, "Bad arguments to %s()",
+ GLOBAL(function_state).function_name);
+ return;
+ }
+ _php3_implode(delim, arr, return_value) ;
+ }
/* }}} */
+
#ifndef THREAD_SAFE
char *strtok_string;
Index: php3/functions/php3_string.h
diff -c php3/functions/php3_string.h:1.32 php3/functions/php3_string.h:1.33
*** php3/functions/php3_string.h:1.32 Fri Jan 22 16:24:43 1999
--- php3/functions/php3_string.h Fri Jan 29 03:28:13 1999
***************
*** 29,35 ****
*/
! /* $Id: php3_string.h,v 1.32 1999/01/22 21:24:43 rasmus Exp $ */
#ifndef _PHPSTRING_H
#define _PHPSTRING_H
--- 29,35 ----
*/
! /* $Id: php3_string.h,v 1.33 1999/01/29 08:28:13 fmk Exp $ */
#ifndef _PHPSTRING_H
#define _PHPSTRING_H
***************
*** 101,105 ****
--- 101,108 ----
char *needle, int needle_len, char *str, int str_len, int *_new_length);
#endif
extern PHPAPI void _php3_char_to_str(char *str,uint len,char from,char *to,int to_len,pval *result);
+
+ extern PHPAPI void _php3_implode(pval *delim, pval *arr, pval *return_value);
+ extern PHPAPI void _php3_explode(pval *delim, pval *str, pval *return_value);
#endif /* _PHPSTRING_H */
-- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe <email protected> For help: php-dev-help <email protected>
- Next message: Frank M. Kromann: "[PHP-DEV] inet_aton"
- Previous message: eschmid: "[PHP-DEV] CVS update: php3/doc/chapters"
- Next in thread: shane: "[PHP-DEV] CVS update: php3/functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

