Improve matching weights

This commit is contained in:
jrenslin committed 2026-10-14 11:38:34 +02:00
1 parent be53dd93af
commit e9ba4bf4e1
1 file changed
+26 -2
+26 -2
View File
@@ -10,14 +10,15 @@ declare(strict_types = 1);
* Provides lists for categorizing misspelled sizes.
*/
final class MDConcWeights implements MDImporterConcordanceListInterface {
/**
* Require a function for getting the concordance target.
* Matches.
*
* @param string $input Input string.
*
* @return MDWeightUnit|false
*/
public static function getConcordanceTarget(string $input):MDWeightUnit|false {
private static function _match(string $input):MDWeightUnit|false {
return match($input) {
@@ -34,4 +35,27 @@ final class MDConcWeights implements MDImporterConcordanceListInterface {
};
}
/**
* Require a function for getting the concordance target.
*
* @param string $input Input string.
*
* @return MDWeightUnit|false
*/
public static function getConcordanceTarget(string $input):MDWeightUnit|false {
try {
return self::_match($input);
}
catch (MDInvalidWeightUnit $e) {
if (is_numeric($input) || is_numeric(strtr($input, ['.' => '', ',' => '']))) {
return false;
}
return self::_match(trim($input));
}
}
}