1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-11 07:44:12 +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)
* [toAscii](#toascii)
* [toLowerCase](#tolowercase)
* [toTitleCase](#toTitleCase)
* [toSpaces](#tospaces)
* [toTabs](#totabs)
* [toUpperCase](#touppercase)
@@ -852,6 +853,19 @@ S::create('FÒÔ BÀŘ', 'UTF-8')->toLowerCase();
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
$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 $encoding The character encoding
* @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
*/
public function toCaseTitle()
public function toTitleCase()
{
$str = mb_convert_case($this->str, MB_CASE_TITLE, $this->encoding);

View File

@@ -318,10 +318,10 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
);
}
public function toCaseTitleProvider()
public function toTitleCaseProvider()
{
return array(
array( 'Foo Bar', 'foo bar'),
array('Foo Bar', 'foo bar'),
array(' Foo_Bar ', ' foo_bar '),
array('Fòô Bàř', 'fòô bàř', 'UTF-8'),
array(' Fòô_Bàř ', ' fòô_bàř ', 'UTF-8'),

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->assertEquals($expected, $result);
}

View File

@@ -432,6 +432,18 @@ class StringyTestCase extends CommonTest
$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()
*/