summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Zmievski <andrei@php.net>1999-12-11 20:00:40 +0000
committerAndrei Zmievski <andrei@php.net>1999-12-11 20:00:40 +0000
commit0c779c51c9ee0362106c04cdccb91a3bac478e70 (patch)
tree0b8cf7c61683782938c7359ca1386284ed241c23
parent33d82cb6d1dc8e1fc1a0e2e93c0a9a21cb55b46d (diff)
downloadphp-git-0c779c51c9ee0362106c04cdccb91a3bac478e70.tar.gz
(PHP php_implode) Made binary-safe.
@ Made implode() binary-safe (Andrei)
-rw-r--r--TODO1
-rw-r--r--ext/standard/string.c26
2 files changed, 13 insertions, 14 deletions
diff --git a/TODO b/TODO
index 742530eea6..e5d32e6e36 100644
--- a/TODO
+++ b/TODO
@@ -27,7 +27,6 @@ ext/standard
* advanced sort (Andrei)
* NOT binary safe:
strcspn()
- implode()
strtok()
basename()
dirname()
diff --git a/ext/standard/string.c b/ext/standard/string.c
index f0b58ea433..47896b913a 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -265,19 +265,17 @@ PHP_FUNCTION(explode)
PHPAPI void php_implode(pval *delim, pval *arr, pval *return_value)
{
pval **tmp;
- int len = 0, count = 0;
+ int len = 0, count = 0, target = 0;
/* convert everything to strings, and calculate length */
zend_hash_internal_pointer_reset(arr->value.ht);
while (zend_hash_get_current_data(arr->value.ht, (void **) &tmp) == SUCCESS) {
convert_to_string_ex(tmp);
- if ((*tmp)->type == IS_STRING && (*tmp)->value.str.val != undefined_variable_string) {
- len += (*tmp)->value.str.len;
- if (count>0) {
- len += delim->value.str.len;
- }
- count++;
+ len += (*tmp)->value.str.len;
+ if (count>0) {
+ len += delim->value.str.len;
}
+ count++;
zend_hash_move_forward(arr->value.ht);
}
@@ -287,12 +285,14 @@ PHPAPI void php_implode(pval *delim, pval *arr, pval *return_value)
return_value->value.str.val[len] = '\0';
zend_hash_internal_pointer_reset(arr->value.ht);
while (zend_hash_get_current_data(arr->value.ht, (void **) &tmp) == SUCCESS) {
- if ((*tmp)->type == IS_STRING && (*tmp)->value.str.val != undefined_variable_string) {
- count--;
- strcat(return_value->value.str.val, (*tmp)->value.str.val);
- if (count > 0) {
- strcat(return_value->value.str.val, delim->value.str.val);
- }
+ count--;
+ memcpy(return_value->value.str.val + target, (*tmp)->value.str.val,
+ (*tmp)->value.str.len);
+ target += (*tmp)->value.str.len;
+ if (count > 0) {
+ memcpy(return_value->value.str.val + target, delim->value.str.val,
+ delim->value.str.len);
+ target += delim->value.str.len;
}
zend_hash_move_forward(arr->value.ht);
}