diff options
Diffstat (limited to 'ext/mbstring/mbstring.c')
-rw-r--r-- | ext/mbstring/mbstring.c | 485 |
1 files changed, 291 insertions, 194 deletions
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 5707e1ca40..08ac6b9a29 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -56,15 +56,10 @@ #include "mb_gpc.h" #if HAVE_MBREGEX -#include "php_mbregex.h" -#endif - -#include "zend_multibyte.h" - -#if HAVE_ONIG -#include "php_onig_compat.h" -#include <oniguruma.h> -#undef UChar +# include "php_mbregex.h" +# include "php_onig_compat.h" +# include <oniguruma.h> +# undef UChar #if ONIGURUMA_VERSION_INT < 60800 typedef void OnigMatchParam; #define onig_new_match_param() (NULL) @@ -72,13 +67,15 @@ typedef void OnigMatchParam; #define onig_set_match_stack_limit_size_of_match_param(x, y) #define onig_free_match_param(x) #define onig_search_with_param(reg, str, end, start, range, region, option, mp) \ - onig_search(reg, str, end, start, range, region, option) +onig_search(reg, str, end, start, range, region, option) #define onig_match_with_param(re, str, end, at, region, option, mp) \ - onig_match(re, str, end, at, region, option) +onig_match(re, str, end, at, region, option) #endif -#elif HAVE_PCRE || HAVE_BUNDLED_PCRE -#include "ext/pcre/php_pcre.h" +#else +# include "ext/pcre/php_pcre.h" #endif + +#include "zend_multibyte.h" /* }}} */ #if HAVE_MBSTRING @@ -243,6 +240,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_output_handler, 0, 0, 2) ZEND_ARG_INFO(0, status) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_str_split, 0, 0, 1) + ZEND_ARG_INFO(0, str) + ZEND_ARG_INFO(0, split_length) + ZEND_ARG_INFO(0, encoding) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_strlen, 0, 0, 1) ZEND_ARG_INFO(0, str) ZEND_ARG_INFO(0, encoding) @@ -540,6 +543,7 @@ static const zend_function_entry mbstring_functions[] = { PHP_FE(mb_parse_str, arginfo_mb_parse_str) PHP_FE(mb_output_handler, arginfo_mb_output_handler) PHP_FE(mb_preferred_mime_name, arginfo_mb_preferred_mime_name) + PHP_FE(mb_str_split, arginfo_mb_str_split) PHP_FE(mb_strlen, arginfo_mb_strlen) PHP_FE(mb_strpos, arginfo_mb_strpos) PHP_FE(mb_strrpos, arginfo_mb_strrpos) @@ -694,24 +698,25 @@ static const sapi_post_entry mbstr_post_entries[] = { }; /* }}} */ -static const mbfl_encoding *php_mb_get_encoding(const char *encoding_name) { +static const mbfl_encoding *php_mb_get_encoding(zend_string *encoding_name) { if (encoding_name) { const mbfl_encoding *encoding; - if (MBSTRG(last_used_encoding_name) - && !strcasecmp(encoding_name, MBSTRG(last_used_encoding_name))) { + zend_string *last_encoding_name = MBSTRG(last_used_encoding_name); + if (last_encoding_name && (last_encoding_name == encoding_name + || !strcasecmp(ZSTR_VAL(encoding_name), ZSTR_VAL(last_encoding_name)))) { return MBSTRG(last_used_encoding); } - encoding = mbfl_name2encoding(encoding_name); + encoding = mbfl_name2encoding(ZSTR_VAL(encoding_name)); if (!encoding) { - php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", encoding_name); + php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", ZSTR_VAL(encoding_name)); return NULL; } - if (MBSTRG(last_used_encoding_name)) { - efree(MBSTRG(last_used_encoding_name)); + if (last_encoding_name) { + zend_string_release(last_encoding_name); } - MBSTRG(last_used_encoding_name) = estrdup(encoding_name); + MBSTRG(last_used_encoding_name) = zend_string_copy(encoding_name); MBSTRG(last_used_encoding) = encoding; return encoding; } else { @@ -943,8 +948,6 @@ static size_t php_mb_zend_encoding_converter(unsigned char **to, size_t *to_leng /* new encoding */ /* initialize string */ - mbfl_string_init(&string); - mbfl_string_init(&result); string.encoding = (const mbfl_encoding*)encoding_from; string.no_language = MBSTRG(language); string.val = (unsigned char*)from; @@ -967,6 +970,7 @@ static size_t php_mb_zend_encoding_converter(unsigned char **to, size_t *to_leng } mbfl_buffer_converter_flush(convd); + mbfl_string_init(&result); if (!mbfl_buffer_converter_result(convd, &result)) { mbfl_buffer_converter_delete(convd); return (size_t)-1; @@ -1013,7 +1017,7 @@ static void *_php_mb_compile_regex(const char *pattern); static int _php_mb_match_regex(void *opaque, const char *str, size_t str_len); static void _php_mb_free_regex(void *opaque); -#if HAVE_ONIG +#if HAVE_MBREGEX /* {{{ _php_mb_compile_regex */ static void *_php_mb_compile_regex(const char *pattern) { @@ -1059,7 +1063,7 @@ static void _php_mb_free_regex(void *opaque) onig_free((php_mb_regex_t *)opaque); } /* }}} */ -#elif HAVE_PCRE || HAVE_BUNDLED_PCRE +#else /* {{{ _php_mb_compile_regex */ static void *_php_mb_compile_regex(const char *pattern) { @@ -1755,7 +1759,7 @@ PHP_RSHUTDOWN_FUNCTION(mbstring) MBSTRG(http_input_identify_string) = NULL; if (MBSTRG(last_used_encoding_name)) { - efree(MBSTRG(last_used_encoding_name)); + zend_string_release(MBSTRG(last_used_encoding_name)); MBSTRG(last_used_encoding_name) = NULL; } @@ -1779,13 +1783,6 @@ PHP_MINFO_FUNCTION(mbstring) snprintf(tmp, sizeof(tmp), "%d.%d.%d", MBFL_VERSION_MAJOR, MBFL_VERSION_MINOR, MBFL_VERSION_TEENY); php_info_print_table_row(2, "libmbfl version", tmp); } -#if HAVE_ONIG - { - char tmp[256]; - snprintf(tmp, sizeof(tmp), "%d.%d.%d", ONIGURUMA_VERSION_MAJOR, ONIGURUMA_VERSION_MINOR, ONIGURUMA_VERSION_TEENY); - php_info_print_table_row(2, "oniguruma version", tmp); - } -#endif php_info_print_table_end(); php_info_print_table_start(); @@ -2154,14 +2151,15 @@ PHP_FUNCTION(mb_parse_str) const mbfl_encoding *detected; track_vars_array = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|z/", &encstr, &encstr_len, &track_vars_array) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|z", &encstr, &encstr_len, &track_vars_array) == FAILURE) { return; } if (track_vars_array != NULL) { - /* Clear out the array */ - zval_ptr_dtor(track_vars_array); - array_init(track_vars_array); + track_vars_array = zend_try_array_init(track_vars_array); + if (!track_vars_array) { + return; + } } encstr = estrndup(encstr, encstr_len); @@ -2305,21 +2303,187 @@ PHP_FUNCTION(mb_output_handler) } /* }}} */ +/* {{{ proto array mb_str_split(string str [, int split_length] [, string encoding]) + Convert a multibyte string to an array. If split_length is specified, + break the string down into chunks each split_length characters long. */ + +/* structure to pass split params to the callback */ +struct mbfl_split_params { + zval *return_value; /* php function return value structure pointer */ + mbfl_string *result_string; /* string to store result chunk */ + size_t mb_chunk_length; /* actual chunk length in chars */ + size_t split_length; /* split length in chars */ + mbfl_convert_filter *next_filter; /* widechar to encoding converter */ +}; + +/* callback function to fill split array */ +static int mbfl_split_output(int c, void *data) +{ + struct mbfl_split_params *params = (struct mbfl_split_params *)data; /* cast passed data */ + + (*params->next_filter->filter_function)(c, params->next_filter); /* decoder filter */ + + if(params->split_length == ++params->mb_chunk_length) { /* if current chunk size reached defined chunk size or last char reached */ + mbfl_convert_filter_flush(params->next_filter);/* concatenate separate decoded chars to the solid string */ + mbfl_memory_device *device = (mbfl_memory_device *)params->next_filter->data; /* chars container */ + mbfl_string *chunk = params->result_string; + mbfl_memory_device_result(device, chunk); /* make chunk */ + add_next_index_stringl(params->return_value, (const char *)chunk->val, chunk->len); /* add chunk to the array */ + efree(chunk->val); + params->mb_chunk_length = 0; /* reset mb_chunk size */ + } + return 0; +} + +PHP_FUNCTION(mb_str_split) +{ + zend_string *str, *encoding = NULL; + size_t mb_len, chunks, chunk_len; + const char *p, *last; /* pointer for the string cursor and last string char */ + mbfl_string string, result_string; + const mbfl_encoding *mbfl_encoding; + zend_long split_length = 1; + + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_STR(str) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(split_length) + Z_PARAM_STR(encoding) + ZEND_PARSE_PARAMETERS_END(); + + if (split_length <= 0) { + php_error_docref(NULL, E_WARNING, "The length of each segment must be greater than zero"); + RETURN_FALSE; + } + + /* fill mbfl_string structure */ + string.val = (unsigned char *) ZSTR_VAL(str); + string.len = ZSTR_LEN(str); + string.no_language = MBSTRG(language); + string.encoding = php_mb_get_encoding(encoding); + if (!string.encoding) { + RETURN_FALSE; + } + + p = ZSTR_VAL(str); /* string cursor pointer */ + last = ZSTR_VAL(str) + ZSTR_LEN(str); /* last string char pointer */ + + mbfl_encoding = string.encoding; + + /* first scenario: 1,2,4-bytes fixed width encodings (head part) */ + if (mbfl_encoding->flag & MBFL_ENCTYPE_SBCS) { /* 1 byte */ + mb_len = string.len; + chunk_len = (size_t)split_length; /* chunk length in bytes */ + } else if (mbfl_encoding->flag & (MBFL_ENCTYPE_WCS2BE | MBFL_ENCTYPE_WCS2LE)) { /* 2 bytes */ + mb_len = string.len / 2; + chunk_len = split_length * 2; + } else if (mbfl_encoding->flag & (MBFL_ENCTYPE_WCS4BE | MBFL_ENCTYPE_WCS4LE)) { /* 4 bytes */ + mb_len = string.len / 4; + chunk_len = split_length * 4; + } else if (mbfl_encoding->mblen_table != NULL) { + /* second scenario: variable width encodings with length table */ + char unsigned const *mbtab = mbfl_encoding->mblen_table; + + /* assume that we have 1-bytes characters */ + array_init_size(return_value, (string.len + split_length) / split_length); /* round up */ + + while (p < last) { /* split cycle work until the cursor has reached the last byte */ + char const *chunk_p = p; /* chunk first byte pointer */ + chunk_len = 0; /* chunk length in bytes */ + zend_long char_count; + + for (char_count = 0; char_count < split_length && p < last; ++char_count) { + char unsigned const m = mbtab[*(const unsigned char *)p]; /* single character length table */ + chunk_len += m; + p += m; + } + if (p >= last) chunk_len -= p - last; /* check if chunk is in bounds */ + add_next_index_stringl(return_value, chunk_p, chunk_len); + } + return; + } else { + /* third scenario: other multibyte encodings */ + mbfl_convert_filter *filter, *decoder; + + /* assume that we have 1-bytes characters */ + array_init_size(return_value, (string.len + split_length) / split_length); /* round up */ + + /* decoder filter to decode wchar to encoding */ + mbfl_memory_device device; + mbfl_memory_device_init(&device, split_length + 1, 0); + + decoder = mbfl_convert_filter_new( + &mbfl_encoding_wchar, + string.encoding, + mbfl_memory_device_output, + NULL, + &device); + /* if something wrong with the decoded */ + if (decoder == NULL) { + RETURN_FALSE; + } + + /* wchar filter */ + mbfl_string_init(&result_string); /* mbfl_string to store chunk in the callback */ + struct mbfl_split_params params = { /* init callback function params structure */ + .return_value = return_value, + .result_string = &result_string, + .mb_chunk_length = 0, + .split_length = (size_t)split_length, + .next_filter = decoder, + }; + + filter = mbfl_convert_filter_new( + string.encoding, + &mbfl_encoding_wchar, + mbfl_split_output, + NULL, + ¶ms); + /* if something wrong with the filter */ + if (filter == NULL){ + mbfl_convert_filter_delete(decoder); /* this will free allocated memory for the decoded */ + RETURN_FALSE; + } + + while (p < last - 1) { /* cycle each byte except last with callback function */ + (*filter->filter_function)(*p++, filter); + } + params.mb_chunk_length = split_length - 1; /* force to finish current chunk */ + (*filter->filter_function)(*p++, filter); /*process last char */ + + mbfl_convert_filter_delete(decoder); + mbfl_convert_filter_delete(filter); + return; + } + + /* first scenario: 1,2,4-bytes fixed width encodings (tail part) */ + chunks = (mb_len + split_length - 1) / split_length; /* (round up idiom) */ + array_init_size(return_value, chunks); + if (chunks != 0) { + zend_long i; + + for (i = 0; i < chunks - 1; p += chunk_len, ++i) { + add_next_index_stringl(return_value, p, chunk_len); + } + add_next_index_stringl(return_value, p, last - p); + } +} +/* }}} */ + /* {{{ proto int mb_strlen(string str [, string encoding]) Get character numbers of a string */ PHP_FUNCTION(mb_strlen) { size_t n; mbfl_string string; - char *str, *enc_name = NULL; - size_t str_len, enc_name_len; - - mbfl_string_init(&string); + char *str; + size_t str_len; + zend_string *enc_name = NULL; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STRING(str, str_len) Z_PARAM_OPTIONAL - Z_PARAM_STRING(enc_name, enc_name_len) + Z_PARAM_STR(enc_name) ZEND_PARSE_PARAMETERS_END(); string.val = (unsigned char *) str; @@ -2346,13 +2510,10 @@ PHP_FUNCTION(mb_strpos) int reverse = 0; zend_long offset = 0; mbfl_string haystack, needle; - char *enc_name = NULL; - size_t enc_name_len, n; - - mbfl_string_init(&haystack); - mbfl_string_init(&needle); + zend_string *enc_name = NULL; + size_t n; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &offset, &enc_name, &enc_name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|lS", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &offset, &enc_name) == FAILURE) { return; } @@ -2408,54 +2569,36 @@ PHP_FUNCTION(mb_strpos) PHP_FUNCTION(mb_strrpos) { mbfl_string haystack, needle; - char *enc_name = NULL; - size_t enc_name_len; + zend_string *enc_name = NULL; zval *zoffset = NULL; - zend_long offset = 0, str_flg, n; - char *enc_name2 = NULL; - size_t enc_name_len2; + zend_long offset = 0, n; - mbfl_string_init(&haystack); - mbfl_string_init(&needle); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|zs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &zoffset, &enc_name, &enc_name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|zS", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &zoffset, &enc_name) == FAILURE) { return; } if (zoffset) { if (Z_TYPE_P(zoffset) == IS_STRING) { - enc_name2 = Z_STRVAL_P(zoffset); - enc_name_len2 = Z_STRLEN_P(zoffset); - str_flg = 1; - - if (enc_name2 != NULL) { - switch (*enc_name2) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case ' ': - case '-': - case '.': - break; - default : - str_flg = 0; - break; - } - } - - if (str_flg) { - convert_to_long_ex(zoffset); - offset = Z_LVAL_P(zoffset); - } else { - enc_name = enc_name2; - enc_name_len = enc_name_len2; + switch (Z_STRVAL_P(zoffset)[0]) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case ' ': + case '-': + case '.': + convert_to_long_ex(zoffset); + offset = Z_LVAL_P(zoffset); + break; + default : + enc_name = Z_STR_P(zoffset); + break; } } else { convert_to_long_ex(zoffset); @@ -2494,10 +2637,9 @@ PHP_FUNCTION(mb_stripos) size_t n = (size_t) -1; zend_long offset = 0; mbfl_string haystack, needle; - const char *from_encoding = MBSTRG(current_internal_encoding)->mime_name; - size_t from_encoding_len; + zend_string *from_encoding = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &offset, &from_encoding, &from_encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|lS", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &offset, &from_encoding) == FAILURE) { return; } @@ -2523,10 +2665,9 @@ PHP_FUNCTION(mb_strripos) size_t n = (size_t) -1; zend_long offset = 0; mbfl_string haystack, needle; - const char *from_encoding = MBSTRG(current_internal_encoding)->mime_name; - size_t from_encoding_len; + zend_string *from_encoding = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &offset, &from_encoding, &from_encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|lS", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &offset, &from_encoding) == FAILURE) { return; } @@ -2546,14 +2687,10 @@ PHP_FUNCTION(mb_strstr) { size_t n; mbfl_string haystack, needle, result, *ret = NULL; - char *enc_name = NULL; - size_t enc_name_len; + zend_string *enc_name = NULL; zend_bool part = 0; - mbfl_string_init(&haystack); - mbfl_string_init(&needle); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &enc_name, &enc_name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bS", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &enc_name) == FAILURE) { return; } @@ -2601,14 +2738,10 @@ PHP_FUNCTION(mb_strrchr) { size_t n; mbfl_string haystack, needle, result, *ret = NULL; - char *enc_name = NULL; - size_t enc_name_len; + zend_string *enc_name = NULL; zend_bool part = 0; - mbfl_string_init(&haystack); - mbfl_string_init(&needle); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &enc_name, &enc_name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bS", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &enc_name) == FAILURE) { return; } @@ -2657,13 +2790,11 @@ PHP_FUNCTION(mb_strrchr) PHP_FUNCTION(mb_stristr) { zend_bool part = 0; - size_t from_encoding_len, n; + size_t n; mbfl_string haystack, needle, result, *ret = NULL; - const char *from_encoding = NULL; - mbfl_string_init(&haystack); - mbfl_string_init(&needle); + zend_string *from_encoding = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &from_encoding, &from_encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bS", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &from_encoding) == FAILURE) { return; } @@ -2711,13 +2842,10 @@ PHP_FUNCTION(mb_strrichr) { zend_bool part = 0; size_t n; - size_t from_encoding_len; mbfl_string haystack, needle, result, *ret = NULL; - const char *from_encoding = NULL; - mbfl_string_init(&haystack); - mbfl_string_init(&needle); + zend_string *from_encoding = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &from_encoding, &from_encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bS", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &from_encoding) == FAILURE) { return; } @@ -2760,13 +2888,9 @@ PHP_FUNCTION(mb_substr_count) { size_t n; mbfl_string haystack, needle; - char *enc_name = NULL; - size_t enc_name_len; - - mbfl_string_init(&haystack); - mbfl_string_init(&needle); + zend_string *enc_name = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|s", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &enc_name, &enc_name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|S", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &enc_name) == FAILURE) { return; } @@ -2794,18 +2918,18 @@ PHP_FUNCTION(mb_substr_count) Returns part of a string */ PHP_FUNCTION(mb_substr) { - char *str, *encoding = NULL; + char *str; + zend_string *encoding = NULL; zend_long from, len; size_t mblen, real_from, real_len; - size_t str_len, encoding_len; + size_t str_len; zend_bool len_is_null = 1; mbfl_string string, result, *ret; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l!s", &str, &str_len, &from, &len, &len_is_null, &encoding, &encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l!S", &str, &str_len, &from, &len, &len_is_null, &encoding) == FAILURE) { return; } - mbfl_string_init(&string); string.no_language = MBSTRG(language); string.encoding = php_mb_get_encoding(encoding); if (!string.encoding) { @@ -2865,15 +2989,12 @@ PHP_FUNCTION(mb_substr) Returns part of a string */ PHP_FUNCTION(mb_strcut) { - char *encoding = NULL; + zend_string *encoding = NULL; zend_long from, len; - size_t encoding_len; zend_bool len_is_null = 1; mbfl_string string, result, *ret; - mbfl_string_init(&string); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l!s", (char **)&string.val, &string.len, &from, &len, &len_is_null, &encoding, &encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l!S", (char **)&string.val, &string.len, &from, &len, &len_is_null, &encoding) == FAILURE) { return; } @@ -2928,12 +3049,9 @@ PHP_FUNCTION(mb_strwidth) { size_t n; mbfl_string string; - char *enc_name = NULL; - size_t enc_name_len; - - mbfl_string_init(&string); + zend_string *enc_name = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", (char **)&string.val, &string.len, &enc_name, &enc_name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|S", (char **)&string.val, &string.len, &enc_name) == FAILURE) { return; } @@ -2956,18 +3074,16 @@ PHP_FUNCTION(mb_strwidth) Trim the string in terminal width */ PHP_FUNCTION(mb_strimwidth) { - char *str, *trimmarker = NULL, *encoding = NULL; + char *str, *trimmarker = NULL; + zend_string *encoding = NULL; zend_long from, width, swidth; - size_t str_len, trimmarker_len, encoding_len; + size_t str_len, trimmarker_len; mbfl_string string, result, marker, *ret; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|ss", &str, &str_len, &from, &width, &trimmarker, &trimmarker_len, &encoding, &encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|sS", &str, &str_len, &from, &width, &trimmarker, &trimmarker_len, &encoding) == FAILURE) { return; } - mbfl_string_init(&string); - mbfl_string_init(&marker); - string.no_language = marker.no_language = MBSTRG(language); string.encoding = marker.encoding = php_mb_get_encoding(encoding); if (!string.encoding) { @@ -3045,8 +3161,6 @@ MBSTRING_API char *php_mb_convert_encoding_ex(const char *input, size_t length, } /* initialize string */ - mbfl_string_init(&string); - mbfl_string_init(&result); string.encoding = from_encoding; string.no_language = MBSTRG(language); string.val = (unsigned char *)input; @@ -3063,6 +3177,7 @@ MBSTRING_API char *php_mb_convert_encoding_ex(const char *input, size_t length, mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar)); /* do it */ + mbfl_string_init(&result); ret = mbfl_buffer_converter_feed_result(convd, &string, &result); if (ret) { if (output_len) { @@ -3172,7 +3287,7 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons ZVAL_COPY(&entry_tmp, entry); break; case IS_ARRAY: - chash = php_mb_convert_encoding_recursive(HASH_OF(entry), _to_encoding, _from_encodings); + chash = php_mb_convert_encoding_recursive(Z_ARRVAL_P(entry), _to_encoding, _from_encodings); if (chash) { ZVAL_ARR(&entry_tmp, chash); } else { @@ -3271,7 +3386,7 @@ PHP_FUNCTION(mb_convert_encoding) } } else { HashTable *tmp; - tmp = php_mb_convert_encoding_recursive(HASH_OF(input), arg_new, _from_encodings); + tmp = php_mb_convert_encoding_recursive(Z_ARRVAL_P(input), arg_new, _from_encodings); RETURN_ARR(tmp); } @@ -3291,17 +3406,17 @@ static char *mbstring_convert_case( Returns a case-folded version of sourcestring */ PHP_FUNCTION(mb_convert_case) { - const char *from_encoding = NULL; + zend_string *from_encoding = NULL; char *str; - size_t str_len, from_encoding_len; + size_t str_len; zend_long case_mode = 0; char *newstr; size_t ret_len; const mbfl_encoding *enc; RETVAL_FALSE; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|s!", &str, &str_len, - &case_mode, &from_encoding, &from_encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|S!", &str, &str_len, + &case_mode, &from_encoding) == FAILURE) { return; } @@ -3330,15 +3445,15 @@ PHP_FUNCTION(mb_convert_case) */ PHP_FUNCTION(mb_strtoupper) { - const char *from_encoding = NULL; + zend_string *from_encoding = NULL; char *str; - size_t str_len, from_encoding_len; + size_t str_len; char *newstr; size_t ret_len; const mbfl_encoding *enc; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!", &str, &str_len, - &from_encoding, &from_encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|S!", &str, &str_len, + &from_encoding) == FAILURE) { return; } @@ -3364,15 +3479,15 @@ PHP_FUNCTION(mb_strtoupper) */ PHP_FUNCTION(mb_strtolower) { - const char *from_encoding = NULL; + zend_string *from_encoding = NULL; char *str; - size_t str_len, from_encoding_len; + size_t str_len; char *newstr; size_t ret_len; const mbfl_encoding *enc; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!", &str, &str_len, - &from_encoding, &from_encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|S!", &str, &str_len, + &from_encoding) == FAILURE) { return; } @@ -3533,7 +3648,6 @@ PHP_FUNCTION(mb_encode_mimeheader) size_t linefeed_len; zend_long indent = 0; - mbfl_string_init(&string); string.no_language = MBSTRG(language); string.encoding = MBSTRG(current_internal_encoding); @@ -3584,7 +3698,6 @@ PHP_FUNCTION(mb_decode_mimeheader) { mbfl_string string, result, *ret; - mbfl_string_init(&string); string.no_language = MBSTRG(language); string.encoding = MBSTRG(current_internal_encoding); @@ -3612,12 +3725,9 @@ PHP_FUNCTION(mb_convert_kana) mbfl_string string, result, *ret; char *optstr = NULL; size_t optstr_len; - char *encname = NULL; - size_t encname_len; - - mbfl_string_init(&string); + zend_string *encname = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ss", (char **)&string.val, &string.len, &optstr, &optstr_len, &encname, &encname_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|sS", (char **)&string.val, &string.len, &optstr, &optstr_len, &encname) == FAILURE) { return; } @@ -3940,7 +4050,6 @@ php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type) return; } - mbfl_string_init(&string); string.no_language = MBSTRG(language); string.encoding = MBSTRG(current_internal_encoding); string.val = (unsigned char *)str; @@ -4778,7 +4887,7 @@ MBSTRING_API int php_mb_check_encoding_recursive(HashTable *vars, const zend_str } break; case IS_ARRAY: - if (!php_mb_check_encoding_recursive(HASH_OF(entry), enc)) { + if (!php_mb_check_encoding_recursive(Z_ARRVAL_P(entry), enc)) { valid = 0; break; } @@ -4834,7 +4943,7 @@ PHP_FUNCTION(mb_check_encoding) } break; case IS_ARRAY: - if (!php_mb_check_encoding_recursive(HASH_OF(input), enc)) { + if (!php_mb_check_encoding_recursive(Z_ARRVAL_P(input), enc)) { RETURN_FALSE; } break; @@ -4847,7 +4956,7 @@ PHP_FUNCTION(mb_check_encoding) /* }}} */ -static inline zend_long php_mb_ord(const char* str, size_t str_len, const char* enc_name) +static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string *enc_name) { const mbfl_encoding *enc; enum mbfl_no_encoding no_enc; @@ -4859,7 +4968,7 @@ static inline zend_long php_mb_ord(const char* str, size_t str_len, const char* no_enc = enc->no_encoding; if (php_mb_is_unsupported_no_encoding(no_enc)) { - php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", enc_name); + php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", ZSTR_VAL(enc_name)); return -1; } @@ -4902,16 +5011,15 @@ static inline zend_long php_mb_ord(const char* str, size_t str_len, const char* /* {{{ proto int|false mb_ord([string str[, string encoding]]) */ PHP_FUNCTION(mb_ord) { - char* str; + char *str; size_t str_len; - char* enc = NULL; - size_t enc_len; + zend_string *enc = NULL; zend_long cp; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STRING(str, str_len) Z_PARAM_OPTIONAL - Z_PARAM_STRING(enc, enc_len) + Z_PARAM_STR(enc) ZEND_PARSE_PARAMETERS_END(); cp = php_mb_ord(str, str_len, enc); @@ -4925,7 +5033,7 @@ PHP_FUNCTION(mb_ord) /* }}} */ -static inline zend_string *php_mb_chr(zend_long cp, const char *enc_name) +static inline zend_string *php_mb_chr(zend_long cp, zend_string *enc_name) { const mbfl_encoding *enc; enum mbfl_no_encoding no_enc; @@ -4940,7 +5048,7 @@ static inline zend_string *php_mb_chr(zend_long cp, const char *enc_name) no_enc = enc->no_encoding; if (php_mb_is_unsupported_no_encoding(no_enc)) { - php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", enc_name); + php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", ZSTR_VAL(enc_name)); return NULL; } @@ -5013,14 +5121,13 @@ static inline zend_string *php_mb_chr(zend_long cp, const char *enc_name) PHP_FUNCTION(mb_chr) { zend_long cp; - char* enc = NULL; - size_t enc_len; + zend_string *enc = NULL; zend_string* ret; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_LONG(cp) Z_PARAM_OPTIONAL - Z_PARAM_STRING(enc, enc_len) + Z_PARAM_STR(enc) ZEND_PARSE_PARAMETERS_END(); ret = php_mb_chr(cp, enc); @@ -5045,15 +5152,14 @@ PHP_FUNCTION(mb_scrub) const mbfl_encoding *enc; char* str; size_t str_len; - char *enc_name = NULL; - size_t enc_name_len; + zend_string *enc_name = NULL; char *ret; size_t ret_len; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STRING(str, str_len) Z_PARAM_OPTIONAL - Z_PARAM_STRING(enc_name, enc_name_len) + Z_PARAM_STR(enc_name) ZEND_PARSE_PARAMETERS_END(); enc = php_mb_get_encoding(enc_name); @@ -5183,7 +5289,7 @@ MBSTRING_API char *php_mb_safe_strrchr(const char *s, unsigned int c, size_t nby /* {{{ MBSTRING_API int php_mb_stripos() */ -MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t old_haystack_len, const char *old_needle, size_t old_needle_len, zend_long offset, const char *from_encoding) +MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t old_haystack_len, const char *old_needle, size_t old_needle_len, zend_long offset, zend_string *from_encoding) { size_t n = (size_t) -1; mbfl_string haystack, needle; @@ -5277,12 +5383,3 @@ static void php_mb_gpc_set_input_encoding(const zend_encoding *encoding) /* {{{ /* }}} */ #endif /* HAVE_MBSTRING */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ |