masugata Tue May 30 15:45:35 2006 UTC Modified files: (Branch: PHP_5_2) /php-src/ext/mbstring mbstring.c mbstring.h Log: added mb_strstr( ), mb_strrchr( ). http://cvs.php.net/viewcvs.cgi/php-src/ext/mbstring/mbstring.c?r1=1.224.2.22.2.4&r2=1.224.2.22.2.5&diff_format=u Index: php-src/ext/mbstring/mbstring.c diff -u php-src/ext/mbstring/mbstring.c:1.224.2.22.2.4 php-src/ext/mbstring/mbstring.c:1.224.2.22.2.5 --- php-src/ext/mbstring/mbstring.c:1.224.2.22.2.4 Tue May 30 15:43:09 2006 +++ php-src/ext/mbstring/mbstring.c Tue May 30 15:45:35 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mbstring.c,v 1.224.2.22.2.4 2006/05/30 15:43:09 masugata Exp $ */ +/* $Id: mbstring.c,v 1.224.2.22.2.5 2006/05/30 15:45:35 masugata Exp $ */ /* * PHP 4 Multibyte String module "mbstring" @@ -174,6 +174,8 @@ {MB_OVERLOAD_STRING, "strrpos", "mb_strrpos", "mb_orig_strrpos"}, {MB_OVERLOAD_STRING, "stripos", "mb_stripos", "mb_orig_stripos"}, {MB_OVERLOAD_STRING, "strripos", "mb_strripos", "mb_orig_stripos"}, + {MB_OVERLOAD_STRING, "strstr", "mb_strstr", "mb_orig_strstr"}, + {MB_OVERLOAD_STRING, "strrchr", "mb_strrchr", "mb_orig_strrchr"}, {MB_OVERLOAD_STRING, "substr", "mb_substr", "mb_orig_substr"}, {MB_OVERLOAD_STRING, "strtolower", "mb_strtolower", "mb_orig_strtolower"}, {MB_OVERLOAD_STRING, "strtoupper", "mb_strtoupper", "mb_orig_strtoupper"}, @@ -208,6 +210,8 @@ PHP_FE(mb_strrpos, NULL) PHP_FE(mb_stripos, NULL) PHP_FE(mb_strripos, NULL) + PHP_FE(mb_strstr, NULL) + PHP_FE(mb_strrchr, NULL) PHP_FE(mb_substr_count, NULL) PHP_FE(mb_substr, NULL) PHP_FE(mb_strcut, NULL) @@ -1733,6 +1737,130 @@ } /* }}} */ +/* {{{ proto string mb_strstr(string haystack, string needle[, bool part[, string encoding]]) + Finds first occurrence of a string within another */ +PHP_FUNCTION(mb_strstr) +{ + int n, len, mblen; + mbfl_string haystack, needle, result, *ret = NULL; + char *enc_name = NULL; + int enc_name_len; + zend_bool part = 0; + + mbfl_string_init(&haystack); + mbfl_string_init(&needle); + haystack.no_language = MBSTRG(current_language); + haystack.no_encoding = MBSTRG(current_internal_encoding); + needle.no_language = MBSTRG(current_language); + needle.no_encoding = MBSTRG(current_internal_encoding); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &enc_name, &enc_name_len) == FAILURE) { + RETURN_FALSE; + } + + if (enc_name != NULL) { + haystack.no_encoding = needle.no_encoding = mbfl_name2no_encoding(enc_name); + if (haystack.no_encoding == mbfl_no_encoding_invalid) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown encoding \"%s\"", enc_name); + RETURN_FALSE; + } + } + + if (haystack.len <= 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty haystack"); + RETURN_FALSE; + } + if (needle.len <= 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Empty needle"); + RETURN_FALSE; + } + n = mbfl_strpos(&haystack, &needle, 0, 0); + if (n >= 0) { + mblen = mbfl_strlen(&haystack); + if (part) { + ret = mbfl_substr(&haystack, &result, 0, n); + if (ret != NULL) { + RETVAL_STRINGL((char *)ret->val, ret->len, 0); + } else { + RETVAL_FALSE; + } + } else { + len = (mblen - n); + ret = mbfl_substr(&haystack, &result, n, len); + if (ret != NULL) { + RETVAL_STRINGL((char *)ret->val, ret->len, 0); + } else { + RETVAL_FALSE; + } + } + } else { + RETVAL_FALSE; + } +} +/* }}} */ + +/* {{{ proto string mb_strrchr(string haystack, string needle[, bool part[, string encoding]]) + Finds the last occurrence of a character in a string within another */ +PHP_FUNCTION(mb_strrchr) +{ + int n, len, mblen; + mbfl_string haystack, needle, result, *ret = NULL; + char *enc_name = NULL; + int enc_name_len; + zend_bool part = 0; + + mbfl_string_init(&haystack); + mbfl_string_init(&needle); + haystack.no_language = MBSTRG(current_language); + haystack.no_encoding = MBSTRG(current_internal_encoding); + needle.no_language = MBSTRG(current_language); + needle.no_encoding = MBSTRG(current_internal_encoding); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &enc_name, &enc_name_len) == FAILURE) { + RETURN_FALSE; + } + + if (enc_name != NULL) { + haystack.no_encoding = needle.no_encoding = mbfl_name2no_encoding(enc_name); + if (haystack.no_encoding == mbfl_no_encoding_invalid) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown encoding \"%s\"", enc_name); + RETURN_FALSE; + } + } + + if (haystack.len <= 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty haystack"); + RETURN_FALSE; + } + if (needle.len <= 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Empty needle"); + RETURN_FALSE; + } + n = mbfl_strpos(&haystack, &needle, 0, 1); + if (n >= 0) { + mblen = mbfl_strlen(&haystack); + if (part) { + ret = mbfl_substr(&haystack, &result, 0, n); + if (ret != NULL) { + RETVAL_STRINGL((char *)ret->val, ret->len, 0); + } else { + RETVAL_FALSE; + } + } else { + len = (mblen - n); + ret = mbfl_substr(&haystack, &result, n, len); + if (ret != NULL) { + RETVAL_STRINGL((char *)ret->val, ret->len, 0); + } else { + RETVAL_FALSE; + } + } + } else { + RETVAL_FALSE; + } +} +/* }}} */ + /* {{{ proto int mb_substr_count(string haystack, string needle [, string encoding]) Count the number of substring occurrences */ PHP_FUNCTION(mb_substr_count) http://cvs.php.net/viewcvs.cgi/php-src/ext/mbstring/mbstring.h?r1=1.66.2.4.2.2&r2=1.66.2.4.2.3&diff_format=u Index: php-src/ext/mbstring/mbstring.h diff -u php-src/ext/mbstring/mbstring.h:1.66.2.4.2.2 php-src/ext/mbstring/mbstring.h:1.66.2.4.2.3 --- php-src/ext/mbstring/mbstring.h:1.66.2.4.2.2 Tue May 30 15:43:09 2006 +++ php-src/ext/mbstring/mbstring.h Tue May 30 15:45:35 2006 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mbstring.h,v 1.66.2.4.2.2 2006/05/30 15:43:09 masugata Exp $ */ +/* $Id: mbstring.h,v 1.66.2.4.2.3 2006/05/30 15:45:35 masugata Exp $ */ /* * PHP 4 Multibyte String module "mbstring" (currently only for Japanese) @@ -106,6 +106,8 @@ PHP_FUNCTION(mb_strrpos); PHP_FUNCTION(mb_stripos); PHP_FUNCTION(mb_strripos); +PHP_FUNCTION(mb_strstr); +PHP_FUNCTION(mb_strrchr); PHP_FUNCTION(mb_substr_count); PHP_FUNCTION(mb_substr); PHP_FUNCTION(mb_strcut);
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php