From fa0ee8d8343be0751b604a37ce07507235c26b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Km=C3=ADnek?= Date: Thu, 7 Sep 2023 10:43:38 +0200 Subject: [PATCH 1/2] feat: Remove deprecated utf8_decode --- src/Utils/Strings.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Utils/Strings.php b/src/Utils/Strings.php index 378ceee63..d9555f6cf 100644 --- a/src/Utils/Strings.php +++ b/src/Utils/Strings.php @@ -397,9 +397,14 @@ 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)); + if (!extension_loaded('iconv') && !extension_loaded('mbstring')) { + throw new Nette\NotSupportedException(__METHOD__ . '() requires ICONV or MBSTRING extensions, but none of them is loaded.'); + } + + return match(true): { + function_exists('mb_strlen'): mb_strlen($s, 'UTF-8'); + function_exists('iconv_strlen'): iconv_strlen($s, 'UTF-8'); + }; } From 9b7ad80bfdb9db3e3d7d14f776cb329ba99ea7af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Km=C3=ADnek?= Date: Thu, 7 Sep 2023 10:49:25 +0200 Subject: [PATCH 2/2] feat: Fix match syntax --- src/Utils/Strings.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Utils/Strings.php b/src/Utils/Strings.php index d9555f6cf..8d4bd4299 100644 --- a/src/Utils/Strings.php +++ b/src/Utils/Strings.php @@ -401,9 +401,9 @@ public static function length(string $s): int throw new Nette\NotSupportedException(__METHOD__ . '() requires ICONV or MBSTRING extensions, but none of them is loaded.'); } - return match(true): { - function_exists('mb_strlen'): mb_strlen($s, 'UTF-8'); - function_exists('iconv_strlen'): iconv_strlen($s, 'UTF-8'); + return match(true) { + function_exists('mb_strlen') => mb_strlen($s, 'UTF-8'), + function_exists('iconv_strlen') => iconv_strlen($s, 'UTF-8'), }; }