-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Draft][Require RFC] mb_levenshtein function #16043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
af72b0b
[Draft][Require RFC] mb_levenshtein function
youkidearitai aa2b209
Delete unused variable
youkidearitai 4d8aa99
Fix out of memory
youkidearitai 4b4f8a0
Fix overflow (maybe)
youkidearitai 952af91
Update ext/mbstring/mbstring.c
youkidearitai f764cbf
Fix zero byte to zero codepoint
youkidearitai 8108bc2
Fix asan memory error
youkidearitai 3bedd87
Add test code and remove unnecessary code
youkidearitai 9233ecc
Add ISO-8859-1 pattern
youkidearitai cf56777
Update ext/mbstring/tests/mb_levenshtein.phpt
youkidearitai d27cfa0
Update test code using from KEINOS/mb_levenshtein
youkidearitai 4fbb4d4
Implove create random strings
youkidearitai 4f255f7
Fix mb_levenshtein to per codepoint
youkidearitai e4de70f
Add test case for variable selector
youkidearitai 283512b
Add test case of emoji.
youkidearitai 916887e
If testcase if failed, output to UTF-16.
youkidearitai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--TEST-- | ||
mb_levenshtein() function test | ||
--FILE-- | ||
youkidearitai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<?php | ||
|
||
echo '--- Equal ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein('12345', '12345')); | ||
|
||
echo '--- First string empty ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein('', 'xyz')); | ||
echo '--- Second string empty ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein('xyz', '')); | ||
echo '--- Both empty ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein('', '')); | ||
var_dump(mb_levenshtein('', '', 10, 10, 10)); | ||
|
||
echo '--- 1 character ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein('1', '2')); | ||
echo '--- 2 character swapped ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein('12', '21')); | ||
|
||
echo '--- Inexpensive deletion ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein('2121', '11', 2)); | ||
echo '--- Expensive deletion ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein('2121', '11', 2, 1, 5)); | ||
|
||
echo '--- Inexpensive insertion ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein('11', '2121')); | ||
echo '--- Expensive insertion ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein('11', '2121', 5)); | ||
|
||
echo '--- Expensive replacement ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein('111', '121', 2, 3, 2)); | ||
echo '--- Very expensive replacement ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein('111', '121', 2, 9, 2)); | ||
|
||
echo '--- 128 codepoints over ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein(str_repeat("a", 128) . "abc", str_repeat("a", 128) . "aaa")); | ||
echo '--- 128 codepoints over only $string1 ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein(str_repeat("a", 128) . "abc", "aaa")); | ||
echo '--- 128 codepoints over only $string2 ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein("abc", str_repeat("a", 128) . "aaa")); | ||
echo '--- 128 codepoints over Hiragana ---' . \PHP_EOL; | ||
var_dump(mb_levenshtein(str_repeat("あ", 128) . "あああ", str_repeat("あ", 128) . "あいう")); | ||
|
||
echo '--- 128 codepoints over Hiragana in Shift_JIS ---' . \PHP_EOL; | ||
$hiragana_a = mb_convert_encoding("あ", "SJIS", "UTF-8"); | ||
$hiragana_aiu = mb_convert_encoding("あいう", "SJIS", "UTF-8"); | ||
var_dump(mb_levenshtein(str_repeat($hiragana_a, 128 + 3), str_repeat($hiragana_a, 128) . $hiragana_aiu, encoding: "SJIS")); | ||
?> | ||
--EXPECT-- | ||
--- Equal --- | ||
int(0) | ||
--- First string empty --- | ||
int(3) | ||
--- Second string empty --- | ||
int(3) | ||
--- Both empty --- | ||
int(0) | ||
int(0) | ||
--- 1 character --- | ||
int(1) | ||
--- 2 character swapped --- | ||
int(2) | ||
--- Inexpensive deletion --- | ||
int(2) | ||
--- Expensive deletion --- | ||
int(10) | ||
--- Inexpensive insertion --- | ||
int(2) | ||
--- Expensive insertion --- | ||
int(10) | ||
--- Expensive replacement --- | ||
int(3) | ||
--- Very expensive replacement --- | ||
int(4) | ||
--- 128 codepoints over --- | ||
int(2) | ||
--- 128 codepoints over only $string1 --- | ||
int(128) | ||
--- 128 codepoints over only $string2 --- | ||
int(130) | ||
--- 128 codepoints over Hiragana --- | ||
int(2) | ||
--- 128 codepoints over Hiragana in Shift_JIS --- | ||
int(2) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.