From c9da8c3932fab44d1fe0d5d455d5daed44259766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mauricio=20U=C3=B1ate=20Castro?= <91748598+rmunate@users.noreply.github.com> Date: Mon, 28 Aug 2023 18:11:25 -0500 Subject: [PATCH 1/3] Add method `Str::convertCase` This function, convertCase, serves the purpose of converting the case of a given string while taking into account multibyte characters and character encoding. It offers flexibility by allowing you to specify the conversion mode and character encoding, with sensible defaults provided for ease of use. Here's a breakdown of its functionality: String: You provide a string as the input, which is the text you want to change the case of. Conversion Mode (Optional): The function allows you to specify the conversion mode through the $mode parameter. By default, it uses MB_CASE_FOLD, which converts the string to lowercase. However, you can change this mode according to your requirements. Character Encoding (Optional): You can also specify the character encoding through the $encoding parameter. The default encoding is 'UTF-8,' but you can set it to a different encoding if needed. If no encoding is provided, it will use the internal encoding. Output: The function returns the converted string with the specified case and encoding. --- src/Illuminate/Support/Str.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 0d706d1920ca..0ae412e290d0 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -1548,4 +1548,19 @@ public static function flushCache() static::$camelCache = []; static::$studlyCache = []; } + + /** + * Convert the case of a string using multibyte support. + * + * @param string $string The input string to convert. + * @param int $mode The conversion mode (default: MB_CASE_FOLD). + * @param string $encoding The character encoding (default: null, which uses the internal encoding). + * @return string The converted string. + */ + public static function convertCase(string $string, int $mode = MB_CASE_FOLD, ?string $encoding = 'UTF-8') + { + // Use mb_convert_case to perform the case conversion. + // If $encoding is not provided, the internal encoding is used. + return mb_convert_case($string, $mode, $encoding); + } } From 05d9be035a75cbfd652051090e165d3a02d92be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mauricio=20U=C3=B1ate=20Castro?= <91748598+rmunate@users.noreply.github.com> Date: Mon, 28 Aug 2023 18:14:48 -0500 Subject: [PATCH 2/3] Adjust StyleCI --- src/Illuminate/Support/Str.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 0ae412e290d0..eb6b3d3c4002 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -1552,9 +1552,9 @@ public static function flushCache() /** * Convert the case of a string using multibyte support. * - * @param string $string The input string to convert. - * @param int $mode The conversion mode (default: MB_CASE_FOLD). - * @param string $encoding The character encoding (default: null, which uses the internal encoding). + * @param string $string The input string to convert. + * @param int $mode The conversion mode (default: MB_CASE_FOLD). + * @param string $encoding The character encoding (default: null, which uses the internal encoding). * @return string The converted string. */ public static function convertCase(string $string, int $mode = MB_CASE_FOLD, ?string $encoding = 'UTF-8') From eee32651f2952626dc0bba638746a4f0a2fc87bf Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 29 Aug 2023 08:43:37 -0500 Subject: [PATCH 3/3] formatting --- src/Illuminate/Support/Str.php | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index eb6b3d3c4002..a4e14666587e 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -284,6 +284,19 @@ public static function containsAll($haystack, $needles, $ignoreCase = false) return true; } + /** + * Convert the case of a string. + * + * @param string $string + * @param int $mode + * @param string $encoding + * @return string + */ + public static function convertCase(string $string, int $mode = MB_CASE_FOLD, ?string $encoding = 'UTF-8') + { + return mb_convert_case($string, $mode, $encoding); + } + /** * Determine if a given string ends with a given substring. * @@ -1548,19 +1561,4 @@ public static function flushCache() static::$camelCache = []; static::$studlyCache = []; } - - /** - * Convert the case of a string using multibyte support. - * - * @param string $string The input string to convert. - * @param int $mode The conversion mode (default: MB_CASE_FOLD). - * @param string $encoding The character encoding (default: null, which uses the internal encoding). - * @return string The converted string. - */ - public static function convertCase(string $string, int $mode = MB_CASE_FOLD, ?string $encoding = 'UTF-8') - { - // Use mb_convert_case to perform the case conversion. - // If $encoding is not provided, the internal encoding is used. - return mb_convert_case($string, $mode, $encoding); - } }