Skip to content

Commit

Permalink
[10.x] Add Str::transliterate to Stringable (#49065)
Browse files Browse the repository at this point in the history
* Add Str::transliterate to Stringable

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
dwightwatson and taylorotwell authored Nov 21, 2023
1 parent c3844dc commit 276d6eb
Show file tree
Hide file tree
Showing 2 changed files with 18 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 @@ -797,6 +797,18 @@ public function title()
return new static(Str::title($this->value));
}

/**
* Transliterate a string to its closest ASCII representation.
*
* @param string|null $unknown
* @param bool|null $strict
* @return static
*/
public function transliterate($unknown = '?', $strict = false)
{
return new static(Str::transliterate($this->value, $unknown, $strict));
}

/**
* Convert the given string to title case for each word.
*
Expand Down
6 changes: 6 additions & 0 deletions tests/Support/SupportStringableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,12 @@ public function testAscii()
$this->assertSame('u', (string) $this->stringable('ü')->ascii());
}

public function testTransliterate()
{
$this->assertSame('HHH', (string) $this->stringable('🎂🚧🏆')->transliterate('H'));
$this->assertSame('Hello', (string) $this->stringable('🎂')->transliterate('Hello'));
}

public function testNewLine()
{
$this->assertSame('Laravel'.PHP_EOL, (string) $this->stringable('Laravel')->newLine());
Expand Down

0 comments on commit 276d6eb

Please sign in to comment.