Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Add method Str::convertCase #48224

Merged
merged 3 commits into from
Aug 29, 2023
Merged

[10.x] Add method Str::convertCase #48224

merged 3 commits into from
Aug 29, 2023

Conversation

rmunate
Copy link
Contributor

@rmunate rmunate commented Aug 28, 2023

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.

According to PR #48221 the already existing methods are not touched.

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.
@mpyw
Copy link
Contributor

mpyw commented Aug 29, 2023

Hi @rmunate,

Does this function really need to be implemented on the Str helper? I think calling the function directly would be sufficient.

Also, there seems to be a weak reason to have a default value of MB_CASE_FOLD for the method covertCase(). It seems to me that MB_CASE_FOLD is often used for your convenience, not for general use.

@taylorotwell taylorotwell merged commit 8984139 into laravel:10.x Aug 29, 2023
18 checks passed
@rmunate
Copy link
Contributor Author

rmunate commented Aug 29, 2023

Hi @mpyw

Yes, look at the situation is that currently the framework has some static functions that embed the native functions like mb_strtoupper and mb_strtolower (something similar to my proposal) among others but they do not allow selecting the encoding, this is "UTF-8" by default; In PR #48221 he proposed some adjustments but according to the Engineer @taylorotwell, he requests not to modify the current operation, now the ideal is to be able to provide this function to be able to work with other UTF-8, UTF-16, UTF-32, ISO encodings -8859-1, Windows-1252...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants