Skip to content

Commit

Permalink
[10.x] Create fluent method convertCase (#48492)
Browse files Browse the repository at this point in the history
* 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.

* Adjust StyleCI

* formatting

* [10.x] Create fluent method convertCase

* [10.x] Return New Stringable

---------

Co-authored-by: Taylor Otwell <[email protected]>
Co-authored-by: rmunate <[email protected]>
  • Loading branch information
3 people authored and timacdonald committed Sep 22, 2023
1 parent 447edc2 commit f19c46f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Illuminate/Support/Stringable.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ public function containsAll($needles, $ignoreCase = false)
return Str::containsAll($this->value, $needles, $ignoreCase);
}

/**
* Convert the case of a string.
*
* @param int $mode
* @param string $encoding
* @return string
*/
public function convertCase(int $mode = MB_CASE_FOLD, ?string $encoding = 'UTF-8')
{
return new static(Str::convertCase($this->value, $mode, $encoding));
}

/**
* Get the parent directory's path.
*
Expand Down

0 comments on commit f19c46f

Please sign in to comment.