diff options
Diffstat (limited to 'ext/mbstring/php_unicode.c')
-rw-r--r-- | ext/mbstring/php_unicode.c | 103 |
1 files changed, 47 insertions, 56 deletions
diff --git a/ext/mbstring/php_unicode.c b/ext/mbstring/php_unicode.c index 4fa650d894..d0cf9f55e5 100644 --- a/ext/mbstring/php_unicode.c +++ b/ext/mbstring/php_unicode.c @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | @@ -30,14 +28,7 @@ all copies or substantial portions of the Software. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "php.h" -#include "php_ini.h" - -#if HAVE_MBSTRING /* include case folding data generated from the official UnicodeData.txt file */ #include "mbstring.h" @@ -251,53 +242,60 @@ static inline unsigned php_unicode_tofold_simple(unsigned code, enum mbfl_no_enc return code; } -static inline unsigned php_unicode_tolower_full( - unsigned code, enum mbfl_no_encoding enc, unsigned *out) { +static inline void php_unicode_tolower_full(unsigned code, enum mbfl_no_encoding enc, + mbfl_convert_filter* next_filter) { code = php_unicode_tolower_raw(code, enc); if (UNEXPECTED(code > 0xffffff)) { unsigned len = code >> 24; const unsigned *p = &_uccase_extra_table[code & 0xffffff]; - memcpy(out, p + 1, len * sizeof(unsigned)); - return len; + while (len--) { + (next_filter->filter_function)(*++p, next_filter); + } + } else { + (next_filter->filter_function)(code, next_filter); } - *out = code; - return 1; } -static inline unsigned php_unicode_toupper_full( - unsigned code, enum mbfl_no_encoding enc, unsigned *out) { + +static inline void php_unicode_toupper_full(unsigned code, enum mbfl_no_encoding enc, + mbfl_convert_filter* next_filter) { code = php_unicode_toupper_raw(code, enc); if (UNEXPECTED(code > 0xffffff)) { unsigned len = code >> 24; const unsigned *p = &_uccase_extra_table[code & 0xffffff]; - memcpy(out, p + 1, len * sizeof(unsigned)); - return len; + while (len--) { + (next_filter->filter_function)(*++p, next_filter); + } + } else { + (next_filter->filter_function)(code, next_filter); } - *out = code; - return 1; } -static inline unsigned php_unicode_totitle_full( - unsigned code, enum mbfl_no_encoding enc, unsigned *out) { + +static inline void php_unicode_totitle_full(unsigned code, enum mbfl_no_encoding enc, + mbfl_convert_filter* next_filter) { code = php_unicode_totitle_raw(code, enc); if (UNEXPECTED(code > 0xffffff)) { unsigned len = code >> 24; const unsigned *p = &_uccase_extra_table[code & 0xffffff]; - memcpy(out, p + 1, len * sizeof(unsigned)); - return len; + while (len--) { + (next_filter->filter_function)(*++p, next_filter); + } + } else { + (next_filter->filter_function)(code, next_filter); } - *out = code; - return 1; } -static inline unsigned php_unicode_tofold_full( - unsigned code, enum mbfl_no_encoding enc, unsigned *out) { + +static inline void php_unicode_tofold_full(unsigned code, enum mbfl_no_encoding enc, + mbfl_convert_filter* next_filter) { code = php_unicode_tofold_raw(code, enc); if (UNEXPECTED(code > 0xffffff)) { unsigned len = code >> 24; const unsigned *p = &_uccase_extra_table[code & 0xffffff]; - memcpy(out, p + 1, len * sizeof(unsigned)); - return len; + while (len--) { + (next_filter->filter_function)(*++p, next_filter); + } + } else { + (next_filter->filter_function)(code, next_filter); } - *out = code; - return 1; } struct convert_case_data { @@ -310,8 +308,7 @@ struct convert_case_data { static int convert_case_filter(int c, void *void_data) { struct convert_case_data *data = (struct convert_case_data *) void_data; - unsigned out[3]; - unsigned len, i; + unsigned code; /* Handle invalid characters early, as we assign special meaning to * codepoints above 0xffffff. */ @@ -322,30 +319,30 @@ static int convert_case_filter(int c, void *void_data) switch (data->case_mode) { case PHP_UNICODE_CASE_UPPER_SIMPLE: - out[0] = php_unicode_toupper_simple(c, data->no_encoding); - len = 1; + code = php_unicode_toupper_simple(c, data->no_encoding); + (data->next_filter->filter_function)(code, data->next_filter); break; case PHP_UNICODE_CASE_UPPER: - len = php_unicode_toupper_full(c, data->no_encoding, out); + php_unicode_toupper_full(c, data->no_encoding, data->next_filter); break; case PHP_UNICODE_CASE_LOWER_SIMPLE: - out[0] = php_unicode_tolower_simple(c, data->no_encoding); - len = 1; + code = php_unicode_tolower_simple(c, data->no_encoding); + (data->next_filter->filter_function)(code, data->next_filter); break; case PHP_UNICODE_CASE_LOWER: - len = php_unicode_tolower_full(c, data->no_encoding, out); + php_unicode_tolower_full(c, data->no_encoding, data->next_filter); break; case PHP_UNICODE_CASE_FOLD: - len = php_unicode_tofold_full(c, data->no_encoding, out); + php_unicode_tofold_full(c, data->no_encoding, data->next_filter); break; case PHP_UNICODE_CASE_FOLD_SIMPLE: - out[0] = php_unicode_tofold_simple(c, data->no_encoding); - len = 1; + code = php_unicode_tofold_simple(c, data->no_encoding); + (data->next_filter->filter_function)(code, data->next_filter); break; case PHP_UNICODE_CASE_TITLE_SIMPLE: @@ -353,17 +350,17 @@ static int convert_case_filter(int c, void *void_data) { if (data->title_mode) { if (data->case_mode == PHP_UNICODE_CASE_TITLE_SIMPLE) { - out[0] = php_unicode_tolower_simple(c, data->no_encoding); - len = 1; + code = php_unicode_tolower_simple(c, data->no_encoding); + (data->next_filter->filter_function)(code, data->next_filter); } else { - len = php_unicode_tolower_full(c, data->no_encoding, out); + php_unicode_tolower_full(c, data->no_encoding, data->next_filter); } } else { if (data->case_mode == PHP_UNICODE_CASE_TITLE_SIMPLE) { - out[0] = php_unicode_totitle_simple(c, data->no_encoding); - len = 1; + code = php_unicode_totitle_simple(c, data->no_encoding); + (data->next_filter->filter_function)(code, data->next_filter); } else { - len = php_unicode_totitle_full(c, data->no_encoding, out); + php_unicode_totitle_full(c, data->no_encoding, data->next_filter); } } if (!php_unicode_is_case_ignorable(c)) { @@ -374,9 +371,6 @@ static int convert_case_filter(int c, void *void_data) EMPTY_SWITCH_DEFAULT_CASE() } - for (i = 0; i < len; i++) { - (*data->next_filter->filter_function)(out[i], data->next_filter); - } return 0; } @@ -444,6 +438,3 @@ MBSTRING_API char *php_unicode_convert_case( *ret_len = result.len; return (char *) result.val; } - - -#endif /* HAVE_MBSTRING */ |