php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch feature-49007.diff for Strings related Bug #49007Patch version 2011-02-27 10:10 UTC Return to Bug #49007 | Download this patchThis patch renders other patches obsolete Obsolete patches: Patch Revisions:Developer: jthijssen@noxlogic.nlIndex: ext/standard/string.c =================================================================== --- ext/standard/string.c (revision 308709) +++ ext/standard/string.c (working copy) @@ -715,11 +715,12 @@ * mode 3 : trim left and right * what indicates which chars are to be trimmed. NULL->default (' \t\n\r\v\0') */ -PHPAPI char *php_trim(char *c, int len, char *what, int what_len, zval *return_value, int mode TSRMLS_DC) +PHPAPI char *php_trim(char *c, int len, char *what, int what_len, int limit, zval *return_value, int mode TSRMLS_DC) { register int i; int trimmed = 0; char mask[256]; + int tlimit; if (what) { php_charmask((unsigned char*)what, what_len, mask TSRMLS_CC); @@ -728,9 +729,10 @@ } if (mode & 1) { - for (i = 0; i < len; i++) { + for (tlimit = limit, i = 0; tlimit && i < len; i++) { if (mask[(unsigned char)c[i]]) { trimmed++; + tlimit--; } else { break; } @@ -739,9 +741,10 @@ c += trimmed; } if (mode & 2) { - for (i = len - 1; i >= 0; i--) { + for (tlimit = limit, i = len - 1; tlimit && i >= 0; i--) { if (mask[(unsigned char)c[i]]) { len--; + tlimit--; } else { break; } @@ -765,12 +768,13 @@ char *str; char *what = NULL; int str_len, what_len = 0; + int limit = -1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str, &str_len, &what, &what_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sl", &str, &str_len, &what, &what_len, &limit) == FAILURE) { return; } - php_trim(str, str_len, what, what_len, return_value, mode TSRMLS_CC); + php_trim(str, str_len, what, what_len, limit, return_value, mode TSRMLS_CC); } /* }}} */ Index: ext/standard/tests/strings/trim_basic.phpt =================================================================== --- ext/standard/tests/strings/trim_basic.phpt (revision 308709) +++ ext/standard/tests/strings/trim_basic.phpt (working copy) @@ -3,7 +3,7 @@ --FILE-- <?php -/* Prototype : string trim ( string $str [, string $charlist ] ) +/* Prototype : string trim ( string $str [, string $charlist [, int limit = -1 ] ] ) * Description: Strip whitespace (or other characters) from the beginning and end of a string. * Source code: ext/standard/string.c */ Index: ext/standard/tests/strings/trim_variation1.phpt =================================================================== --- ext/standard/tests/strings/trim_variation1.phpt (revision 308709) +++ ext/standard/tests/strings/trim_variation1.phpt (working copy) @@ -3,7 +3,7 @@ --FILE-- <?php -/* Prototype : string trim ( string $str [, string $charlist ] ) +/* Prototype : string trim ( string $str [, string $charlist [, int limit = -1 ] ] ) * Description: Strip whitespace (or other characters) from the begining and end of a string. * Source code: ext/standard/string.c */ Index: ext/standard/tests/strings/trim_variation2.phpt =================================================================== --- ext/standard/tests/strings/trim_variation2.phpt (revision 308709) +++ ext/standard/tests/strings/trim_variation2.phpt (working copy) @@ -3,7 +3,7 @@ --FILE-- <?php -/* Prototype : string trim ( string $str [, string $charlist ] ) +/* Prototype : string trim ( string $str [, string $charlist [, int limit = -1 ] ] ) * Description: Strip whitespace (or other characters) from the begining and end of a string. * Source code: ext/standard/string.c */ Index: ext/standard/tests/strings/trim_error.phpt =================================================================== --- ext/standard/tests/strings/trim_error.phpt (revision 308709) +++ ext/standard/tests/strings/trim_error.phpt (working copy) @@ -3,7 +3,7 @@ --FILE-- <?php -/* Prototype : string trim ( string $str [, string $charlist ] ) +/* Prototype : string trim ( string $str [, string $charlist [, int limit = -1 ] ] ) * Description: Strip whitespace (or other characters) from the begining and end of a string. * Source code: ext/standard/string.c */ @@ -16,7 +16,7 @@ echo "\n-- Testing trim() function with more than expected no. of arguments --\n"; $extra_arg = 10; -var_dump( trim("Hello World", "Heo", $extra_arg) ); +var_dump( trim("Hello World", "Heo", -1, $extra_arg) ); $hello = " Hello World\n"; @@ -38,7 +38,7 @@ -- Testing trim() function with more than expected no. of arguments -- -Warning: trim() expects at most 2 parameters, 3 given in %s on line %d +Warning: trim() expects at most 3 parameters, 4 given in %s on line %d NULL -- Test trim function with various invalid charlists -- Index: ext/standard/http_fopen_wrapper.c =================================================================== --- ext/standard/http_fopen_wrapper.c (revision 308709) +++ ext/standard/http_fopen_wrapper.c (working copy) @@ -413,13 +413,13 @@ smart_str_0(&tmpstr); /* Remove newlines and spaces from start and end. there's at least one extra \r\n at the end that needs to go. */ if (tmpstr.c) { - tmp = php_trim(tmpstr.c, strlen(tmpstr.c), NULL, 0, NULL, 3 TSRMLS_CC); + tmp = php_trim(tmpstr.c, strlen(tmpstr.c), NULL, 0, -1, NULL, 3 TSRMLS_CC); smart_str_free(&tmpstr); } } if (Z_TYPE_PP(tmpzval) == IS_STRING && Z_STRLEN_PP(tmpzval)) { /* Remove newlines and spaces from start and end php_trim will estrndup() */ - tmp = php_trim(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval), NULL, 0, NULL, 3 TSRMLS_CC); + tmp = php_trim(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval), NULL, 0, -1, NULL, 3 TSRMLS_CC); } if (tmp && strlen(tmp) > 0) { char *s; @@ -449,7 +449,7 @@ } efree(tmp_c); - tmp_c = php_trim(tmp, strlen(tmp), NULL, 0, NULL, 3 TSRMLS_CC); + tmp_c = php_trim(tmp, strlen(tmp), NULL, 0, -1, NULL, 3 TSRMLS_CC); efree(tmp); tmp = tmp_c; } Index: ext/standard/mail.c =================================================================== --- ext/standard/mail.c (revision 308709) +++ ext/standard/mail.c (working copy) @@ -115,7 +115,7 @@ MAIL_ASCIIZ_CHECK(message, message_len); if (headers) { MAIL_ASCIIZ_CHECK(headers, headers_len); - headers_trimmed = php_trim(headers, headers_len, NULL, 0, NULL, 2 TSRMLS_CC); + headers_trimmed = php_trim(headers, headers_len, NULL, 0, -1, NULL, 2 TSRMLS_CC); } if (extra_cmd) { MAIL_ASCIIZ_CHECK(extra_cmd, extra_cmd_len); Index: ext/standard/php_string.h =================================================================== --- ext/standard/php_string.h (revision 308709) +++ ext/standard/php_string.h (working copy) @@ -132,7 +132,7 @@ 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 char *php_trim(char *c, int len, char *what, int what_len, zval *return_value, int mode TSRMLS_DC); +PHPAPI char *php_trim(char *c, int len, char *what, int what_len, int limit, 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); PHPAPI int php_char_to_str_ex(char *str, uint len, char from, char *to, int to_len, zval *result, int case_sensitivity, int *replace_count); Index: ext/curl/streams.c =================================================================== --- ext/curl/streams.c (revision 308709) +++ ext/curl/streams.c (working copy) @@ -353,10 +353,10 @@ } else if (Z_TYPE_PP(ctx_opt) == IS_STRING && Z_STRLEN_PP(ctx_opt)) { char *p, *token, *trimmed, *copy_ctx_opt; - copy_ctx_opt = php_trim(Z_STRVAL_PP(ctx_opt), Z_STRLEN_PP(ctx_opt), NULL, 0, NULL, 3 TSRMLS_CC); + copy_ctx_opt = php_trim(Z_STRVAL_PP(ctx_opt), Z_STRLEN_PP(ctx_opt), NULL, 0, -1, NULL, 3 TSRMLS_CC); p = php_strtok_r(copy_ctx_opt, "\r\n", &token); while (p) { - trimmed = php_trim(p, strlen(p), NULL, 0, NULL, 3 TSRMLS_CC); + trimmed = php_trim(p, strlen(p), NULL, 0, -1, NULL, 3 TSRMLS_CC); slist = curl_slist_append(slist, trimmed); efree(trimmed); p = php_strtok_r(NULL, "\r\n", &token); Index: ext/mbstring/mbstring.c =================================================================== --- ext/mbstring/mbstring.c (revision 308709) +++ ext/mbstring/mbstring.c (working copy) @@ -1363,7 +1363,7 @@ new_value = entry->orig_value; new_value_length = entry->orig_value_length; } - php_trim(new_value, new_value_length, NULL, 0, &tmp, 3 TSRMLS_CC); + php_trim(new_value, new_value_length, NULL, 0, -1, &tmp, 3 TSRMLS_CC); if (Z_STRLEN(tmp) > 0) { if (!(re = _php_mb_compile_regex(Z_STRVAL(tmp) TSRMLS_CC))) { Index: ext/simplexml/simplexml.c =================================================================== --- ext/simplexml/simplexml.c (revision 308709) +++ ext/simplexml/simplexml.c (working copy) @@ -485,7 +485,7 @@ trim_zv = *member; zval_copy_ctor(&trim_zv); convert_to_string(&trim_zv); - php_trim(Z_STRVAL(trim_zv), Z_STRLEN(trim_zv), NULL, 0, &tmp_zv, 3 TSRMLS_CC); + php_trim(Z_STRVAL(trim_zv), Z_STRLEN(trim_zv), NULL, 0, -1, &tmp_zv, 3 TSRMLS_CC); zval_dtor(&trim_zv); member = &tmp_zv; } |
Copyright © 2001-2025 The PHP Group All rights reserved. |
Last updated: Thu Jan 02 12:01:29 2025 UTC |