From e9ba4bf4e177d3cf86bc03d548afe681692504ab Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Wed, 14 Oct 2026 11:38:34 +0200 Subject: [PATCH] Improve matching weights --- src/MDConcWeights.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/MDConcWeights.php b/src/MDConcWeights.php index a626133..3a4654a 100644 --- a/src/MDConcWeights.php +++ b/src/MDConcWeights.php @@ -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)); + } + + } }