Skip to content

Commit 8f2e544

Browse files
committed
Add locale for grapheme_levenshtein function
1 parent 8938426 commit 8f2e544

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

ext/intl/grapheme/grapheme_string.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,8 @@ PHP_FUNCTION(grapheme_levenshtein)
934934
zend_long cost_ins = 1;
935935
zend_long cost_rep = 1;
936936
zend_long cost_del = 1;
937+
char *locale = "";
938+
size_t locale_len = 0;
937939

938940
ZEND_PARSE_PARAMETERS_START(2, 5)
939941
Z_PARAM_STR(string1)
@@ -942,6 +944,7 @@ PHP_FUNCTION(grapheme_levenshtein)
942944
Z_PARAM_LONG(cost_ins)
943945
Z_PARAM_LONG(cost_rep)
944946
Z_PARAM_LONG(cost_del)
947+
Z_PARAM_STRING_OR_NULL(locale, locale_len)
945948
ZEND_PARSE_PARAMETERS_END();
946949

947950
if (cost_ins <= 0 || cost_ins > UINT_MAX / 4) {
@@ -1058,7 +1061,7 @@ PHP_FUNCTION(grapheme_levenshtein)
10581061
RETVAL_FALSE;
10591062
goto out_bi2;
10601063
}
1061-
UCollator *collator = ucol_open("", &ustatus);
1064+
UCollator *collator = ucol_open(locale, &ustatus);
10621065
if (U_FAILURE(ustatus)) {
10631066
intl_error_set_code(NULL, ustatus);
10641067

ext/intl/php_intl.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ function grapheme_stristr(string $haystack, string $needle, bool $beforeNeedle =
447447

448448
function grapheme_str_split(string $string, int $length = 1): array|false {}
449449

450-
function grapheme_levenshtein(string $string1, string $string2, int $insertion_cost = 1, int $replacement_cost = 1, int $deletion_cost = 1): int|false {}
450+
function grapheme_levenshtein(string $string1, string $string2, int $insertion_cost = 1, int $replacement_cost = 1, int $deletion_cost = 1, ?string $locale = null): int|false {}
451451

452452
/** @param int $next */
453453
function grapheme_extract(string $haystack, int $size, int $type = GRAPHEME_EXTR_COUNT, int $offset = 0, &$next = null): string|false {}

ext/intl/php_intl_arginfo.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/intl/tests/grapheme_levenshtein.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ try {
8080
} catch (ValueError $e) {
8181
echo $e->getMessage() . PHP_EOL;
8282
}
83+
84+
echo '--- Locale string ---' . \PHP_EOL;
85+
var_dump(grapheme_stripos("i", "\u{0130}", 0, "tr_TR"));
86+
var_dump(grapheme_stripos("i", "\u{0130}", 0, "en_US"));
8387
?>
8488
--EXPECTF--
8589
--- Equal ---
@@ -126,3 +130,6 @@ int(0)
126130
grapheme_levenshtein(): Argument #3 ($insertion_cost) must be greater than 0 and less than or equal to %d
127131
grapheme_levenshtein(): Argument #4 ($replacement_cost) must be greater than 0 and less than or equal to %d
128132
grapheme_levenshtein(): Argument #5 ($deletion_cost) must be greater than 0 and less than or equal to %d
133+
--- Locale string ---
134+
int(0)
135+
bool(false)

0 commit comments

Comments
 (0)