added the grapheme_levenshtein polyfill (closes #555)#558
added the grapheme_levenshtein polyfill (closes #555)#558sudam802 wants to merge 2 commits intosymfony:1.xfrom
Conversation
|
|
||
| \define('SYMFONY_GRAPHEME_CLUSTER_RX', ((float) \PCRE_VERSION < 10 ? (float) \PCRE_VERSION >= 8.32 : (float) \PCRE_VERSION >= 10.39) ? '\X' : Grapheme::GRAPHEME_CLUSTER_RX); | ||
| \define('SYMFONY_GRAPHEME_CLUSTER_RX', | ||
| (false !== @preg_match('/\X/u', "a")) |
There was a problem hiding this comment.
This change looks suspicious to me. We were explicitly checking the PCRE version because older versions of PCRE also have a broken implementation of \X (there is even an open discussion mentioning that we might need to increase the bound from which we use the native feature)
| */ | ||
| public static function grapheme_levenshtein($string1, $string2, $insertion_cost = 1, $replacement_cost = 1, $deletion_cost = 1) | ||
| { | ||
| // Cast (PHP does this) |
There was a problem hiding this comment.
use native parameter types, so that PHP actually does it.
| if (\extension_loaded('intl') && !function_exists('grapheme_levenshtein')) { | ||
| function grapheme_levenshtein($string1, $string2, $insertion_cost = 1, $replacement_cost = 1, $deletion_cost = 1) | ||
| { | ||
| return Grapheme::grapheme_levenshtein($string1, $string2, $insertion_cost, $replacement_cost, $deletion_cost); |
There was a problem hiding this comment.
The implementation must be duplicated in the Php85 package if we want to provide it here, not call the other package.
|
|
||
| use Symfony\Polyfill\Intl\Grapheme\Grapheme; | ||
|
|
||
| return [ |
There was a problem hiding this comment.
this file does not make sense. It does not provide a phpt test, and we use PHPUnit tests anyway.
There was a problem hiding this comment.
I just wanted to make test file I'll look more deeper in this implementation
There was a problem hiding this comment.
the file you added is not a test file at all. It is not testing anything.
This PR implements the grapheme_levenshtein() function for:
Includes:
✔ Function implementation
✔ ICU-compatible segmentation
✔ Test file: tests/Intl/Grapheme/grapheme_levenshtein.phpt