From 71017d2330f7822807fe7a30cbd683647c0dfa13 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 10 Sep 2023 18:30:29 +0200 Subject: [PATCH] Strings::length() uses mbstring, iconv and then utf8_decode [Closes #299] --- src/Utils/Strings.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Utils/Strings.php b/src/Utils/Strings.php index 378ceee63..2a649ea7e 100644 --- a/src/Utils/Strings.php +++ b/src/Utils/Strings.php @@ -397,9 +397,11 @@ public static function findPrefix(array $strings): string */ public static function length(string $s): int { - return function_exists('mb_strlen') - ? mb_strlen($s, 'UTF-8') - : strlen(utf8_decode($s)); + return match (true) { + extension_loaded('mbstring') => mb_strlen($s, 'UTF-8'), + extension_loaded('iconv') => iconv_strlen($s, 'UTF-8'), + default => strlen(@utf8_decode($s)), // deprecated + }; }