php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch substr_insert.patch for *General Issues Bug #39962Patch version 2011-08-23 14:05 UTC Return to Bug #39962 | Download this patchThis patch is obsolete Obsoleted by patches:
Developer: datibbaw@php.netIndex: string.c =================================================================== --- string.c (revision 315071) +++ string.c (working copy) @@ -2543,6 +2543,43 @@ } /* }}} */ +/* {{{ proto string substr_insert(string str, string insert [, int start]) + Inserts a string into another string */ +PHP_FUNCTION(substr_insert) +{ + char *str, *insert, *result; + int str_len, insert_len, result_len; + long start = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &str, &str_len, &insert, &insert_len, &start) == FAILURE) { + return; + } + + if (start < 0) { + start = str_len + start; + if (start < 0) { + start = 0; + } + } else if (start > str_len) { + start = str_len; + } + + result_len = str_len + insert_len; + result = emalloc(result_len + 1); + + if (start) { + memcpy(result, str, start); + } + memcpy((result + start), insert, insert_len); + if (from != str_len) { + memcpy((result + start + insert_len), (str + start), str_len - start); + } + result[result_len] = '\0'; + + RETURN_STRINGL(result, result_len, 0); +} +/* }}} */ + /* {{{ proto string quotemeta(string str) Quotes meta characters */ PHP_FUNCTION(quotemeta) @@ -5271,17 +5308,25 @@ { char *s1, *s2; int s1_len, s2_len; - long offset, len=0; + long offset, len = 0; zend_bool cs=0; uint cmp_len; + zval **zlen = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl|lb", &s1, &s1_len, &s2, &s2_len, &offset, &len, &cs) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl|Zb", &s1, &s1_len, &s2, &s2_len, &offset, &zlen, &cs) == FAILURE) { RETURN_FALSE; } - if (ZEND_NUM_ARGS() >= 4 && len <= 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The length must be greater than zero"); - RETURN_FALSE; + if (ZEND_NUM_ARGS() >= 4 && Z_TYPE_PP(zlen) != IS_NULL) { + if (Z_ISREF_PP(zlen)) { + SEPARATE_ZVAL(zlen); + } + convert_to_long_ex(zlen); + len = Z_LVAL_PP(zlen); + if (len <= 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The length must be greater than zero"); + RETURN_FALSE; + } } if (offset < 0) { Index: basic_functions.c =================================================================== --- basic_functions.c (revision 315071) +++ basic_functions.c (working copy) @@ -2296,6 +2296,12 @@ ZEND_ARG_INFO(0, length) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_substr_insert, 0, 0, 3) + ZEND_ARG_INFO(0, str) + ZEND_ARG_INFO(0, insert) + ZEND_ARG_INFO(0, start) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO(arginfo_quotemeta, 0) ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO() @@ -2773,6 +2779,8 @@ PHP_FE(substr, arginfo_substr) PHP_FE(substr_replace, arginfo_substr_replace) + PHP_FE(substr_insert, + arginfo_substr_insert) PHP_FE(quotemeta, arginfo_quotemeta) PHP_FE(ucfirst, arginfo_ucfirst) PHP_FE(lcfirst, arginfo_lcfirst) Index: php_string.h =================================================================== --- php_string.h (revision 315071) +++ php_string.h (working copy) @@ -83,6 +83,7 @@ PHP_FUNCTION(strip_tags); PHP_FUNCTION(str_repeat); PHP_FUNCTION(substr_replace); +PHP_FUNCTION(substr_insert); PHP_FUNCTION(strnatcmp); PHP_FUNCTION(strnatcasecmp); PHP_FUNCTION(substr_count); |
Copyright © 2001-2024 The PHP Group All rights reserved. |
Last updated: Fri Dec 27 08:01:28 2024 UTC |