1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-09-01 17:12:42 +02:00

7 Commits
1.5.2 ... 1.6.0

Author SHA1 Message Date
Daniel St. Jules
7e91d1ead2 1.6.0 2014-09-14 10:58:46 -07:00
Daniel St. Jules
abf3e38c1c Updated logo 2014-09-14 10:49:26 -07:00
Daniel St. Jules
5a5c39d02b Fix readme 2014-09-14 09:49:26 -07:00
Daniel St. Jules
c577684e0a Renamed toTitleCase 2014-09-14 09:27:46 -07:00
Lucas Michot
681463de87 Add casetitle function 2014-09-14 14:16:09 +02:00
Daniel St. Jules
90de5cca00 Merge pull request #29 from GrahamCampbell/patch-1
Update .travis.yml
2014-07-09 22:21:03 -04:00
Graham Campbell
a0b7615210 Update .travis.yml 2014-07-09 18:18:00 +01:00
8 changed files with 77 additions and 5 deletions

View File

@@ -5,6 +5,3 @@ php:
- 5.4
- 5.3
- hhvm
matrix:
fast_finish: true

View File

@@ -1,3 +1,7 @@
### 1.6.0 (2014-09-14)
* Added toTitleCase
### 1.5.2 (2014-07-09)
* Announced support for HHVM

View File

@@ -1,4 +1,4 @@
![Stringy](http://danielstjules.com/stringy/logo.png)
![Stringy](http://danielstjules.com/github/stringy-logo.png)
A PHP library with a variety of string manipulation functions with multibyte
support. Offers both OO method chaining and a procedural-style static wrapper.
@@ -61,6 +61,7 @@ Tested and compatible with PHP 5.3+ and HHVM. Inspired by underscore.string.js.
* [toLowerCase](#tolowercase)
* [toSpaces](#tospaces)
* [toTabs](#totabs)
* [toTitleCase](#totitlecase)
* [toUpperCase](#touppercase)
* [trim](#trim)
* [truncate](#truncate)
@@ -77,7 +78,7 @@ If you're using Composer to manage dependencies, you can include the following
in your composer.json file:
"require": {
"danielstjules/stringy": ">=1.5.2"
"danielstjules/stringy": ">=1.6.0"
}
Then, after running `composer update` or `php composer.phar update`, you can
@@ -881,6 +882,19 @@ S::create(' fòô bàř')->toTabs();
S::toTabs(' fòô bàř'); // ' 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àř'
```
#### toUpperCase
$stringy->toUpperCase()

View File

@@ -323,6 +323,18 @@ class StaticStringy
return (string) Stringy::create($str, $encoding)->toLowerCase();
}
/**
* 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 toTitleCase($str, $encoding = null)
{
return (string) Stringy::create($str, $encoding)->toTitleCase();
}
/**
* Converts all characters in the string to uppercase. An alias for PHP's
* mb_strtoupper().

View File

@@ -676,6 +676,18 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
return self::create($str, $this->encoding);
}
/**
* 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 toTitleCase()
{
$str = mb_convert_case($this->str, MB_CASE_TITLE, $this->encoding);
return self::create($str, $this->encoding);
}
/**
* Converts all characters in the string to lowercase. An alias for PHP's
* mb_strtolower().

View File

@@ -318,6 +318,17 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
);
}
public function toTitleCaseProvider()
{
return array(
array('Foo Bar', 'foo bar'),
array(' Foo_Bar ', ' foo_bar '),
array('Fòô Bàř', 'fòô bàř', 'UTF-8'),
array(' Fòô_Bàř ', ' fòô_bàř ', 'UTF-8'),
array('Αυτοκίνητο Αυτοκίνητο', 'αυτοκίνητο αυτοκίνητο', 'UTF-8'),
);
}
public function toUpperCaseProvider()
{
return array(

View File

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

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()
*/