Add wrapper around levenstein that crops strings to the max allowed

length
This commit is contained in:
Joshua Ramon Enslin 2020-12-03 12:39:47 +01:00
parent 886acead63
commit 4c5097701f
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -430,4 +430,22 @@ final class MD_STD {
}
}
/**
* Wrapper around levenshtein(), that only compares the first 250
* characters (levenshtein can't handle more than 255).
*
* @param string $str1 First string.
* @param string $str2 Second string.
*
* @return integer
*/
public static function levenshtein(string $str1, string $str2):int {
if (\strlen($str1) > 250) $str1 = \substr($str1, 0, 250);
if (\strlen($str2) > 250) $str2 = \substr($str2, 0, 250);
return \levenshtein($str1, $str2);
}
}