diff --git a/ext/intl/grapheme/grapheme_string.c b/ext/intl/grapheme/grapheme_string.c index 34dd2ed369cfc..b71daa0dddf57 100644 --- a/ext/intl/grapheme/grapheme_string.c +++ b/ext/intl/grapheme/grapheme_string.c @@ -81,19 +81,22 @@ PHP_FUNCTION(grapheme_strlen) /* {{{ Find position of first occurrence of a string within another */ PHP_FUNCTION(grapheme_strpos) { - char *haystack, *needle; - size_t haystack_len, needle_len; + char *haystack, *needle, *locale = ""; + size_t haystack_len, needle_len, locale_len; const char *found; zend_long loffset = 0; int32_t offset = 0; + zend_long strength = UCOL_DEFAULT_STRENGTH; size_t noffset = 0; zend_long ret_pos; - ZEND_PARSE_PARAMETERS_START(2, 3) + ZEND_PARSE_PARAMETERS_START(2, 5) Z_PARAM_STRING(haystack, haystack_len) Z_PARAM_STRING(needle, needle_len) Z_PARAM_OPTIONAL Z_PARAM_LONG(loffset) + Z_PARAM_STRING(locale, locale_len) + Z_PARAM_LONG(strength) ZEND_PARSE_PARAMETERS_END(); if ( OUTSIDE_STRING(loffset, haystack_len) ) { @@ -121,7 +124,7 @@ PHP_FUNCTION(grapheme_strpos) } /* do utf16 part of the strpos */ - ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* fIgnoreCase */, 0 /* last */ ); + ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* fIgnoreCase */, 0, locale, strength /* last */ ); if ( ret_pos >= 0 ) { RETURN_LONG(ret_pos); @@ -134,19 +137,22 @@ PHP_FUNCTION(grapheme_strpos) /* {{{ Find position of first occurrence of a string within another, ignoring case differences */ PHP_FUNCTION(grapheme_stripos) { - char *haystack, *needle; - size_t haystack_len, needle_len; + char *haystack, *needle, *locale = ""; + size_t haystack_len, needle_len, locale_len = 0; const char *found; zend_long loffset = 0; int32_t offset = 0; + zend_long strength = UCOL_SECONDARY; zend_long ret_pos; int is_ascii; - ZEND_PARSE_PARAMETERS_START(2, 3) + ZEND_PARSE_PARAMETERS_START(2, 5) Z_PARAM_STRING(haystack, haystack_len) Z_PARAM_STRING(needle, needle_len) Z_PARAM_OPTIONAL Z_PARAM_LONG(loffset) + Z_PARAM_STRING(locale, locale_len) + Z_PARAM_LONG(strength) ZEND_PARSE_PARAMETERS_END(); if ( OUTSIDE_STRING(loffset, haystack_len) ) { @@ -185,7 +191,7 @@ PHP_FUNCTION(grapheme_stripos) } /* do utf16 part of the strpos */ - ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* fIgnoreCase */, 0 /*last */ ); + ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* fIgnoreCase */, 0, locale, strength /*last */ ); if ( ret_pos >= 0 ) { RETURN_LONG(ret_pos); @@ -200,17 +206,21 @@ PHP_FUNCTION(grapheme_stripos) PHP_FUNCTION(grapheme_strrpos) { char *haystack, *needle; - size_t haystack_len, needle_len; + char *locale = ""; + size_t haystack_len, needle_len, locale_len; zend_long loffset = 0; int32_t offset = 0; + zend_long strength = UCOL_DEFAULT_STRENGTH; zend_long ret_pos; int is_ascii; - ZEND_PARSE_PARAMETERS_START(2, 3) + ZEND_PARSE_PARAMETERS_START(2, 5) Z_PARAM_STRING(haystack, haystack_len) Z_PARAM_STRING(needle, needle_len) Z_PARAM_OPTIONAL Z_PARAM_LONG(loffset) + Z_PARAM_STRING(locale, locale_len) + Z_PARAM_LONG(strength) ZEND_PARSE_PARAMETERS_END(); if ( OUTSIDE_STRING(loffset, haystack_len) ) { @@ -242,7 +252,7 @@ PHP_FUNCTION(grapheme_strrpos) /* else we need to continue via utf16 */ } - ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* f_ignore_case */, 1/* last */); + ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* f_ignore_case */, 1, locale, strength /* last */); if ( ret_pos >= 0 ) { RETURN_LONG(ret_pos); @@ -257,18 +267,21 @@ PHP_FUNCTION(grapheme_strrpos) /* {{{ Find position of last occurrence of a string within another, ignoring case */ PHP_FUNCTION(grapheme_strripos) { - char *haystack, *needle; - size_t haystack_len, needle_len; + char *haystack, *needle, *locale = ""; + size_t haystack_len, needle_len, locale_len = 0; zend_long loffset = 0; int32_t offset = 0; + zend_long strength = UCOL_SECONDARY; zend_long ret_pos; int is_ascii; - ZEND_PARSE_PARAMETERS_START(2, 3) + ZEND_PARSE_PARAMETERS_START(2, 5) Z_PARAM_STRING(haystack, haystack_len) Z_PARAM_STRING(needle, needle_len) Z_PARAM_OPTIONAL Z_PARAM_LONG(loffset) + Z_PARAM_STRING(locale, locale_len) + Z_PARAM_LONG(strength) ZEND_PARSE_PARAMETERS_END(); if ( OUTSIDE_STRING(loffset, haystack_len) ) { @@ -309,7 +322,7 @@ PHP_FUNCTION(grapheme_strripos) /* else we need to continue via utf16 */ } - ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* f_ignore_case */, 1 /*last */); + ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* f_ignore_case */, 1, locale, strength /*last */); if ( ret_pos >= 0 ) { RETURN_LONG(ret_pos); @@ -324,13 +337,14 @@ PHP_FUNCTION(grapheme_strripos) /* {{{ Returns part of a string */ PHP_FUNCTION(grapheme_substr) { - char *str; + char *str, *locale = ""; zend_string *u8_sub_str; UChar *ustr; - size_t str_len; + size_t str_len, locale_len; int32_t ustr_len; zend_long lstart = 0, length = 0; int32_t start = 0; + zend_long strength = UCOL_DEFAULT; int iter_val; UErrorCode status; unsigned char u_break_iterator_buffer[U_BRK_SAFECLONE_BUFFERSIZE]; @@ -339,11 +353,13 @@ PHP_FUNCTION(grapheme_substr) int32_t (*iter_func)(UBreakIterator *); bool no_length = true; - ZEND_PARSE_PARAMETERS_START(2, 3) + ZEND_PARSE_PARAMETERS_START(2, 5) Z_PARAM_STRING(str, str_len) Z_PARAM_LONG(lstart) Z_PARAM_OPTIONAL Z_PARAM_LONG_OR_NULL(length, no_length) + Z_PARAM_STRING(locale, locale_len) + Z_PARAM_LONG(strength) ZEND_PARSE_PARAMETERS_END(); if (lstart < INT32_MIN || lstart > INT32_MAX) { @@ -537,17 +553,26 @@ PHP_FUNCTION(grapheme_substr) /* {{{ strstr_common_handler */ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_case) { - char *haystack, *needle; + char *haystack, *needle, *locale = ""; const char *found; - size_t haystack_len, needle_len; + size_t haystack_len, needle_len, locale_len = 0; int32_t ret_pos, uchar_pos; + zend_long strength; bool part = false; - ZEND_PARSE_PARAMETERS_START(2, 3) + if (f_ignore_case) { + strength = UCOL_SECONDARY; + } else { + strength = UCOL_DEFAULT_STRENGTH; + } + + ZEND_PARSE_PARAMETERS_START(2, 5) Z_PARAM_STRING(haystack, haystack_len) Z_PARAM_STRING(needle, needle_len) Z_PARAM_OPTIONAL Z_PARAM_BOOL(part) + Z_PARAM_STRING(locale, locale_len) + Z_PARAM_LONG(strength) ZEND_PARSE_PARAMETERS_END(); if ( !f_ignore_case ) { @@ -574,7 +599,7 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas } /* need to work in utf16 */ - ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, 0, &uchar_pos, f_ignore_case, 0 /*last */ ); + ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, 0, &uchar_pos, f_ignore_case, 0, locale, strength /*last */ ); if ( ret_pos < 0 ) { RETURN_FALSE; @@ -919,14 +944,19 @@ PHP_FUNCTION(grapheme_levenshtein) zend_long cost_ins = 1; zend_long cost_rep = 1; zend_long cost_del = 1; + char *locale = ""; + size_t locale_len = 0; + zend_long strength = UCOL_DEFAULT_STRENGTH; - ZEND_PARSE_PARAMETERS_START(2, 5) + ZEND_PARSE_PARAMETERS_START(2, 7) Z_PARAM_STR(string1) Z_PARAM_STR(string2) Z_PARAM_OPTIONAL Z_PARAM_LONG(cost_ins) Z_PARAM_LONG(cost_rep) Z_PARAM_LONG(cost_del) + Z_PARAM_STRING(locale, locale_len) + Z_PARAM_LONG(strength) ZEND_PARSE_PARAMETERS_END(); if (cost_ins <= 0 || cost_ins > UINT_MAX / 4) { @@ -1043,7 +1073,7 @@ PHP_FUNCTION(grapheme_levenshtein) RETVAL_FALSE; goto out_bi2; } - UCollator *collator = ucol_open("", &ustatus); + UCollator *collator = ucol_open(locale, &ustatus); if (U_FAILURE(ustatus)) { intl_error_set_code(NULL, ustatus); @@ -1051,6 +1081,7 @@ PHP_FUNCTION(grapheme_levenshtein) RETVAL_FALSE; goto out_collator; } + ucol_setStrength(collator, strength); zend_long *p1, *p2, *tmp; p1 = safe_emalloc((size_t) strlen_2 + 1, sizeof(zend_long), 0); diff --git a/ext/intl/grapheme/grapheme_util.c b/ext/intl/grapheme/grapheme_util.c index 501b9dfb221d0..7ba52605f9d19 100644 --- a/ext/intl/grapheme/grapheme_util.c +++ b/ext/intl/grapheme/grapheme_util.c @@ -94,7 +94,7 @@ void grapheme_substr_ascii(char *str, size_t str_len, int32_t f, int32_t l, char /* {{{ grapheme_strpos_utf16 - strrpos using utf16*/ -int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int32_t *puchar_pos, int f_ignore_case, int last) +int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int32_t *puchar_pos, int f_ignore_case, int last, char* locale, int32_t strength) { UChar *uhaystack = NULL, *uneedle = NULL; int32_t uhaystack_len = 0, uneedle_len = 0, char_pos, ret_pos, offset_pos = 0; @@ -136,16 +136,14 @@ int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, } status = U_ZERO_ERROR; - src = usearch_open(uneedle, uneedle_len, uhaystack, uhaystack_len, "", bi, &status); + src = usearch_open(uneedle, uneedle_len, uhaystack, uhaystack_len, locale, bi, &status); STRPOS_CHECK_STATUS(status, "Error creating search object"); - if(f_ignore_case) { - UCollator *coll = usearch_getCollator(src); - status = U_ZERO_ERROR; - ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_SECONDARY, &status); - STRPOS_CHECK_STATUS(status, "Error setting collation strength"); - usearch_reset(src); - } + UCollator *coll = usearch_getCollator(src); + ucol_setAttribute(coll, UCOL_STRENGTH, strength, &status); + STRPOS_CHECK_STATUS(status, "Error setting collation strength"); + status = U_ZERO_ERROR; + usearch_reset(src); if(offset != 0) { offset_pos = grapheme_get_haystack_offset(bi, offset); diff --git a/ext/intl/grapheme/grapheme_util.h b/ext/intl/grapheme/grapheme_util.h index d03194621acf3..42ee9eb64911d 100644 --- a/ext/intl/grapheme/grapheme_util.h +++ b/ext/intl/grapheme/grapheme_util.h @@ -25,8 +25,8 @@ zend_long grapheme_ascii_check(const unsigned char *day, size_t len); void grapheme_substr_ascii(char *str, size_t str_len, int32_t f, int32_t l, char **sub_str, int32_t *sub_str_len); zend_long grapheme_strrpos_ascii(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset); -int32_t grapheme_strrpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int f_ignore_case); -int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int *puchar_pos, int f_ignore_case, int last); +int32_t grapheme_strrpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int f_ignore_case, char* locale, int32_t strength); +int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int *puchar_pos, int f_ignore_case, int last, char* locale, int32_t strength); int32_t grapheme_split_string(const UChar *text, int32_t text_length, int boundary_array[], int boundary_array_len ); diff --git a/ext/intl/php_intl.stub.php b/ext/intl/php_intl.stub.php index dfb05a2b50ac5..5599d0c2844af 100644 --- a/ext/intl/php_intl.stub.php +++ b/ext/intl/php_intl.stub.php @@ -166,6 +166,16 @@ * @cvalue UIDNA_ERROR_CONTEXTJ */ const IDNA_ERROR_CONTEXTJ = UNKNOWN; +/** + * @var int + * @cvalue UCOL_DEFAULT_STRENGTH + */ +const UCOL_DEFAULT_STRENGTH = UNKNOWN; +/** + * @var int + * @cvalue UCOL_SECONDARY + */ +const UCOL_SECONDARY = UNKNOWN; class IntlException extends Exception { @@ -431,23 +441,23 @@ function numfmt_get_error_message(NumberFormatter $formatter): string {} function grapheme_strlen(string $string): int|false|null {} -function grapheme_strpos(string $haystack, string $needle, int $offset = 0): int|false {} +function grapheme_strpos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): int|false {} -function grapheme_stripos(string $haystack, string $needle, int $offset = 0): int|false {} +function grapheme_stripos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_SECONDARY): int|false {} -function grapheme_strrpos(string $haystack, string $needle, int $offset = 0): int|false {} +function grapheme_strrpos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): int|false {} -function grapheme_strripos(string $haystack, string $needle, int $offset = 0): int|false {} +function grapheme_strripos(string $haystack, string $needle, int $offset = 0, string $locale = "", int $strength = UCOL_SECONDARY): int|false {} -function grapheme_substr(string $string, int $offset, ?int $length = null): string|false {} +function grapheme_substr(string $string, int $offset, ?int $length = null, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): string|false {} -function grapheme_strstr(string $haystack, string $needle, bool $beforeNeedle = false): string|false {} +function grapheme_strstr(string $haystack, string $needle, bool $beforeNeedle = false, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): string|false {} -function grapheme_stristr(string $haystack, string $needle, bool $beforeNeedle = false): string|false {} +function grapheme_stristr(string $haystack, string $needle, bool $beforeNeedle = false, string $locale = "", int $strength = UCOL_SECONDARY): string|false {} function grapheme_str_split(string $string, int $length = 1): array|false {} -function grapheme_levenshtein(string $string1, string $string2, int $insertion_cost = 1, int $replacement_cost = 1, int $deletion_cost = 1): int|false {} +function grapheme_levenshtein(string $string1, string $string2, int $insertion_cost = 1, int $replacement_cost = 1, int $deletion_cost = 1, string $locale = "", int $strength = UCOL_DEFAULT_STRENGTH): int|false {} /** @param int $next */ function grapheme_extract(string $haystack, int $size, int $type = GRAPHEME_EXTR_COUNT, int $offset = 0, &$next = null): string|false {} diff --git a/ext/intl/php_intl_arginfo.h b/ext/intl/php_intl_arginfo.h index b710084910733..8ac55cb2161ba 100644 --- a/ext/intl/php_intl_arginfo.h +++ b/ext/intl/php_intl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 0d5b028a1ab8f35e8ee1b51ce3141b6ef782af28 */ + * Stub hash: 148713dbf0ac8ed207c03cd3f996c97565d85db6 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_intlcal_create_instance, 0, 0, IntlCalendar, 1) ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, timezone, "null") @@ -462,27 +462,45 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_strpos, 0, 2, MAY_BE_LO ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, offset, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 0, "\"\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, strength, IS_LONG, 0, "UCOL_DEFAULT_STRENGTH") ZEND_END_ARG_INFO() -#define arginfo_grapheme_stripos arginfo_grapheme_strpos +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_stripos, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, offset, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 0, "\"\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, strength, IS_LONG, 0, "UCOL_SECONDARY") +ZEND_END_ARG_INFO() #define arginfo_grapheme_strrpos arginfo_grapheme_strpos -#define arginfo_grapheme_strripos arginfo_grapheme_strpos +#define arginfo_grapheme_strripos arginfo_grapheme_stripos ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_substr, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 0, "\"\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, strength, IS_LONG, 0, "UCOL_DEFAULT_STRENGTH") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_strstr, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, beforeNeedle, _IS_BOOL, 0, "false") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 0, "\"\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, strength, IS_LONG, 0, "UCOL_DEFAULT_STRENGTH") ZEND_END_ARG_INFO() -#define arginfo_grapheme_stristr arginfo_grapheme_strstr +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_stristr, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, beforeNeedle, _IS_BOOL, 0, "false") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 0, "\"\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, strength, IS_LONG, 0, "UCOL_SECONDARY") +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_str_split, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) @@ -495,6 +513,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_levenshtein, 0, 2, MAY_ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, insertion_cost, IS_LONG, 0, "1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, replacement_cost, IS_LONG, 0, "1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, deletion_cost, IS_LONG, 0, "1") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 0, "\"\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, strength, IS_LONG, 0, "UCOL_DEFAULT_STRENGTH") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_extract, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) @@ -1220,6 +1240,8 @@ static void register_php_intl_symbols(int module_number) REGISTER_LONG_CONSTANT("IDNA_ERROR_INVALID_ACE_LABEL", UIDNA_ERROR_INVALID_ACE_LABEL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IDNA_ERROR_BIDI", UIDNA_ERROR_BIDI, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IDNA_ERROR_CONTEXTJ", UIDNA_ERROR_CONTEXTJ, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UCOL_DEFAULT_STRENGTH", UCOL_DEFAULT_STRENGTH, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UCOL_SECONDARY", UCOL_SECONDARY, CONST_PERSISTENT); zend_attribute *attribute_Deprecated_func_intlcal_set_0 = zend_add_function_attribute(zend_hash_str_find_ptr(CG(function_table), "intlcal_set", sizeof("intlcal_set") - 1), ZSTR_KNOWN(ZEND_STR_DEPRECATED_CAPITALIZED), 2); diff --git a/ext/intl/tests/grapheme_levenshtein.phpt b/ext/intl/tests/grapheme_levenshtein.phpt index 4ff7dbb607bcd..7cfb489ea1c3c 100644 --- a/ext/intl/tests/grapheme_levenshtein.phpt +++ b/ext/intl/tests/grapheme_levenshtein.phpt @@ -58,6 +58,14 @@ $nabe = '邊'; $nabe_E0100 = "邊󠄀"; var_dump(grapheme_levenshtein($nabe, $nabe_E0100)); +// variable $nabe and $nabe_E0101 is different because that is IVS. +// $nabe_E0101 is variable selector in U+908A U+E0101. +// grapheme_levenshtein can catches different only match strength is Collator::IDENTICAL. +// So result is maybe 1. +$nabe = '邊'; +$nabe_E0101 = "\u{908A}\u{E0101}"; +var_dump(grapheme_levenshtein($nabe, $nabe_E0101, strength: Collator::IDENTICAL)); + // combining character var_dump(grapheme_levenshtein("\u{0065}\u{0301}", "\u{00e9}")); @@ -80,6 +88,7 @@ try { } catch (ValueError $e) { echo $e->getMessage() . PHP_EOL; } + ?> --EXPECTF-- --- Equal --- @@ -121,6 +130,7 @@ int(2) --- Variable selector --- int(1) int(0) +int(1) int(0) --- Corner case --- grapheme_levenshtein(): Argument #3 ($insertion_cost) must be greater than 0 and less than or equal to %d diff --git a/ext/intl/tests/grapheme_stripos_locale_dependency.phpt b/ext/intl/tests/grapheme_stripos_locale_dependency.phpt new file mode 100644 index 0000000000000..e868e6f085c03 --- /dev/null +++ b/ext/intl/tests/grapheme_stripos_locale_dependency.phpt @@ -0,0 +1,14 @@ +--TEST-- +grapheme_stripos() function locale dependency test +--EXTENSIONS-- +intl +--FILE-- + +--EXPECT-- +int(0) +int(0) +bool(false) diff --git a/ext/intl/tests/grapheme_stristr_locale_dependency.phpt b/ext/intl/tests/grapheme_stristr_locale_dependency.phpt new file mode 100644 index 0000000000000..ea329f7d18c15 --- /dev/null +++ b/ext/intl/tests/grapheme_stristr_locale_dependency.phpt @@ -0,0 +1,15 @@ +--TEST-- +grapheme_stristr() function locale dependency test +--EXTENSIONS-- +intl +--FILE-- + +--EXPECT-- +string(3) "abc" +string(1) "i" +bool(false) + diff --git a/ext/intl/tests/grapheme_strripos_locale_dependency.phpt b/ext/intl/tests/grapheme_strripos_locale_dependency.phpt new file mode 100644 index 0000000000000..aecc74b5ab001 --- /dev/null +++ b/ext/intl/tests/grapheme_strripos_locale_dependency.phpt @@ -0,0 +1,14 @@ +--TEST-- +grapheme_strripos() function locale dependency test +--EXTENSIONS-- +intl +--FILE-- + +--EXPECT-- +int(0) +int(0) +bool(false)