PHPAPI zend_string *php_basename(const char *s, size_t len, char *suffix, size_t sufflen TSRMLS_DC);
PHPAPI size_t php_dirname(char *str, size_t len);
PHPAPI char *php_stristr(char *s, 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, int *replace_count);
-PHPAPI char *php_str_to_str(char *haystack, int length, char *needle,
- int needle_len, char *str, int str_len, int *_new_length);
+PHPAPI zend_string *php_str_to_str_ex(char *haystack, int length, char *needle,
+ int needle_len, char *str, int str_len, int case_sensitivity, int *replace_count);
+PHPAPI zend_string *php_str_to_str(char *haystack, int length, char *needle,
+ int needle_len, char *str, int str_len);
PHPAPI char *php_trim(char *c, int len, char *what, int what_len, zval *return_value, int mode TSRMLS_DC);
PHPAPI size_t php_strip_tags(char *rbuf, int len, int *state, char *allow, int allow_len);
PHPAPI size_t php_strip_tags_ex(char *rbuf, int len, int *stateptr, char *allow, int allow_len, zend_bool allow_tag_spaces);
/* {{{ 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, int *replace_count)
+PHPAPI zend_string *php_str_to_str_ex(char *haystack, int length,
+ char *needle, int needle_len, char *str, int str_len, int case_sensitivity, int *replace_count)
{
- char *new_str;
+ zend_string *new_str;
if (needle_len < length) {
char *end, *haystack_dup = NULL, *needle_dup = NULL;
char *e, *s, *p, *r;
if (needle_len == str_len) {
- new_str = estrndup(haystack, length);
- *_new_length = length;
+ new_str = STR_INIT(haystack, length, 0);
if (case_sensitivity) {
- end = new_str + length;
- for (p = new_str; (r = (char*)php_memnstr(p, needle, needle_len, end)); p = r + needle_len) {
+ end = new_str->val + length;
+ for (p = new_str->val; (r = (char*)php_memnstr(p, needle, needle_len, end)); p = r + needle_len) {
memcpy(r, str, str_len);
if (replace_count) {
(*replace_count)++;
php_strtolower(needle_dup, needle_len);
end = haystack_dup + length;
for (p = haystack_dup; (r = (char*)php_memnstr(p, needle_dup, needle_len, end)); p = r + needle_len) {
- memcpy(new_str + (r - haystack_dup), str, str_len);
+ memcpy(new_str->val + (r - haystack_dup), str, str_len);
if (replace_count) {
(*replace_count)++;
}
}
if (str_len < needle_len) {
- new_str = emalloc(length + 1);
+ new_str = STR_ALLOC(length, 0);
} else {
int count = 0;
char *o, *n, *endp;
if (needle_dup) {
efree(needle_dup);
}
- new_str = estrndup(haystack, length);
- if (_new_length) {
- *_new_length = length;
- }
+ new_str = STR_INIT(haystack, length, 0);
return new_str;
} else {
- new_str = safe_emalloc(count, str_len - needle_len, length + 1);
+ new_str = STR_ALLOC(count * (str_len - needle_len) + length, 0);
}
}
- e = s = new_str;
+ e = s = new_str->val;
if (case_sensitivity) {
end = haystack + length;
}
*e = '\0';
- *_new_length = e - s;
- new_str = erealloc(new_str, *_new_length + 1);
+ new_str = STR_REALLOC(new_str, e - s, 0);
return new_str;
}
} else if (needle_len > length) {
nothing_todo:
- *_new_length = length;
- new_str = estrndup(haystack, length);
+ new_str = STR_INIT(haystack, length, 0);
return new_str;
} else {
if (case_sensitivity && memcmp(haystack, needle, length)) {
efree(l_needle);
}
- *_new_length = str_len;
- new_str = estrndup(str, str_len);
+ new_str = STR_INIT(str, str_len, 0);
if (replace_count) {
(*replace_count)++;
/* {{{ php_str_to_str
*/
-PHPAPI char *php_str_to_str(char *haystack, int length,
- char *needle, int needle_len, char *str, int str_len, int *_new_length)
+PHPAPI zend_string *php_str_to_str(char *haystack, int length, char *needle, int needle_len, char *str, int str_len)
{
- return php_str_to_str_ex(haystack, length, needle, needle_len, str, str_len, _new_length, 1, NULL);
+ return php_str_to_str_ex(haystack, length, needle, needle_len, str, str_len, 1, NULL);
}
/* }}} */
case_sensitivity,
replace_count);
} else if (Z_STRLEN_P(search_entry) > 1) {
-//??? Z_STRVAL(temp_result) = php_str_to_str_ex(Z_STRVAL_P(result), Z_STRLEN_P(result),
-//??? Z_STRVAL_P(search_entry), Z_STRLEN_P(search_entry),
-//??? replace_value, replace_len, &Z_STRLEN(temp_result), case_sensitivity, replace_count);
+ ZVAL_STR(&temp_result, php_str_to_str_ex(Z_STRVAL_P(result), Z_STRLEN_P(result),
+ Z_STRVAL_P(search_entry), Z_STRLEN_P(search_entry),
+ replace_value, replace_len, case_sensitivity, replace_count));
}
STR_FREE(Z_STR_P(result));
case_sensitivity,
replace_count);
} else if (Z_STRLEN_P(search) > 1) {
-//??? Z_STRVAL_P(result) = php_str_to_str_ex(Z_STRVAL_P(subject), Z_STRLEN_P(subject),
-//??? Z_STRVAL_P(search), Z_STRLEN_P(search),
-//??? Z_STRVAL_P(replace), Z_STRLEN_P(replace), &Z_STRLEN_P(result), case_sensitivity, replace_count);
+ ZVAL_STR(result, php_str_to_str_ex(Z_STRVAL_P(subject), Z_STRLEN_P(subject),
+ Z_STRVAL_P(search), Z_STRLEN_P(search),
+ Z_STRVAL_P(replace), Z_STRLEN_P(replace), case_sensitivity, replace_count));
} else {
ZVAL_DUP(result, subject);
}
smart_str_appendl(buf, " => ", 4);
} else { /* string key */
- char *tmp_str;
- int tmp_len;
+ zend_string *tmp_str;
zend_string *key = php_addcslashes(hash_key->key->val, hash_key->key->len, 0, "'\\", 2 TSRMLS_CC);
- tmp_str = php_str_to_str_ex(key->val, key->len, "\0", 1, "' . \"\\0\" . '", 12, &tmp_len, 0, NULL);
+ tmp_str = php_str_to_str_ex(key->val, key->len, "\0", 1, "' . \"\\0\" . '", 12, 0, NULL);
buffer_append_spaces(buf, level + 1);
smart_str_appendc(buf, '\'');
- smart_str_appendl(buf, tmp_str, tmp_len);
+ smart_str_appendl(buf, tmp_str->val, tmp_str->len);
smart_str_appendl(buf, "' => ", 5);
- STR_RELEASE(key);
- efree(tmp_str);
+ STR_FREE(key);
+ STR_FREE(tmp_str);
}
php_var_export_ex(zv, level + 2, buf TSRMLS_CC);
char *tmp_str;
int tmp_len;
zend_string *class_name;
- zend_string *ztmp;
+ zend_string *ztmp, *ztmp2;
switch (Z_TYPE_P(struc)) {
case IS_BOOL:
break;
case IS_STRING:
ztmp = php_addcslashes(Z_STRVAL_P(struc), Z_STRLEN_P(struc), 0, "'\\", 2 TSRMLS_CC);
- tmp_str = php_str_to_str_ex(ztmp->val, ztmp->len, "\0", 1, "' . \"\\0\" . '", 12, &tmp_len, 0, NULL);
+ ztmp2 = php_str_to_str_ex(ztmp->val, ztmp->len, "\0", 1, "' . \"\\0\" . '", 12, 0, NULL);
smart_str_appendc(buf, '\'');
- smart_str_appendl(buf, tmp_str, tmp_len);
+ smart_str_appendl(buf, ztmp2->val, ztmp2->len);
smart_str_appendc(buf, '\'');
- STR_RELEASE(ztmp);
- efree(tmp_str);
+ STR_FREE(ztmp);
+ STR_FREE(ztmp2);
break;
case IS_ARRAY:
myht = Z_ARRVAL_P(struc);