1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-12 08:14:06 +02:00

Renamed toTitleCase

This commit is contained in:
Daniel St. Jules
2014-09-14 09:27:46 -07:00
parent 681463de87
commit c577684e0a
6 changed files with 36 additions and 10 deletions

View File

@@ -59,6 +59,7 @@ Tested and compatible with PHP 5.3+ and HHVM. Inspired by underscore.string.js.
* [titleize](#titleize) * [titleize](#titleize)
* [toAscii](#toascii) * [toAscii](#toascii)
* [toLowerCase](#tolowercase) * [toLowerCase](#tolowercase)
* [toTitleCase](#toTitleCase)
* [toSpaces](#tospaces) * [toSpaces](#tospaces)
* [toTabs](#totabs) * [toTabs](#totabs)
* [toUpperCase](#touppercase) * [toUpperCase](#touppercase)
@@ -852,6 +853,19 @@ S::create('FÒÔ BÀŘ', 'UTF-8')->toLowerCase();
S::toLowerCase('FÒÔ BÀŘ', 'UTF-8'); // 'fòô bàř' S::toLowerCase('FÒÔ BÀŘ', 'UTF-8'); // 'fòô bàř'
``` ```
#### toTitleCase
$stringy->toTitleCase()
S::toTitleCase(string $str [, string $encoding ])
Converts the first character of each word in the string to uppercase.
```php
S::create('fòô bàř', 'UTF-8')->toTitleCase();
S::toTitleCase('fòô bàř', 'UTF-8'); // 'Fòô Bàř'
```
#### toSpaces #### toSpaces
$stringy->toSpaces([ tabLength = 4 ]) $stringy->toSpaces([ tabLength = 4 ])

View File

@@ -324,15 +324,15 @@ class StaticStringy
} }
/** /**
* Uppercase the first character of each word in a string. * Converts the first character of each word in the string to uppercase.
* *
* @param string $str String to convert case * @param string $str String to convert case
* @param string $encoding The character encoding * @param string $encoding The character encoding
* @return string The title-cased string * @return string The title-cased string
*/ */
public static function toCaseTitle($str, $encoding = null) public static function toTitleCase($str, $encoding = null)
{ {
return (string) Stringy::create($str, $encoding)->toCaseTitle(); return (string) Stringy::create($str, $encoding)->toTitleCase();
} }
/** /**

View File

@@ -677,11 +677,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
} }
/** /**
* Uppercase the first character of each word in a string. * Converts the first character of each word in the string to uppercase.
* *
* @return Stringy Object with all characters of $str being title-cased * @return Stringy Object with all characters of $str being title-cased
*/ */
public function toCaseTitle() public function toTitleCase()
{ {
$str = mb_convert_case($this->str, MB_CASE_TITLE, $this->encoding); $str = mb_convert_case($this->str, MB_CASE_TITLE, $this->encoding);

View File

@@ -318,7 +318,7 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
); );
} }
public function toCaseTitleProvider() public function toTitleCaseProvider()
{ {
return array( return array(
array('Foo Bar', 'foo bar'), array('Foo Bar', 'foo bar'),

View File

@@ -245,11 +245,11 @@ class StaticStringyTestCase extends CommonTest
} }
/** /**
* @dataProvider toCaseTitleProvider() * @dataProvider toTitleCaseProvider()
*/ */
public function testToCaseTitle($expected, $str, $encoding = null) public function testToTitleCase($expected, $str, $encoding = null)
{ {
$result = S::toCaseTitle($str, $encoding); $result = S::toTitleCase($str, $encoding);
$this->assertInternalType('string', $result); $this->assertInternalType('string', $result);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }

View File

@@ -432,6 +432,18 @@ class StringyTestCase extends CommonTest
$this->assertEquals($str, $stringy); $this->assertEquals($str, $stringy);
} }
/**
* @dataProvider toTitleCaseProvider()
*/
public function testToTitleCase($expected, $str, $encoding = null)
{
$stringy = S::create($str, $encoding);
$result = $stringy->toTitleCase();
$this->assertInstanceOf('Stringy\Stringy', $result);
$this->assertEquals($expected, $result);
$this->assertEquals($str, $stringy);
}
/** /**
* @dataProvider toUpperCaseProvider() * @dataProvider toUpperCaseProvider()
*/ */