mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-12 00:04:11 +02:00
Cleanup and fixes for 1.0.0 Release
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
|
### 1.0.0 (2013-08-1)
|
||||||
|
|
||||||
|
* 1.0.0 release
|
||||||
|
* Added test coverage for Stringy::create and method chaining
|
||||||
|
* Added tests for returned type
|
||||||
|
* Fixed StaticStringy::replace(). It was returning a Stringy object instead of string
|
||||||
|
* Renamed standardize() to the more appropriate toAscii()
|
||||||
|
* Cleaned up comments and README
|
||||||
|
|
||||||
### 1.0.0-rc.1 (2013-07-28)
|
### 1.0.0-rc.1 (2013-07-28)
|
||||||
|
|
||||||
* Release candidate
|
* Release candidate
|
||||||
|
173
README.md
173
README.md
@@ -3,7 +3,6 @@
|
|||||||
A PHP library with a variety of string manipulation functions with multibyte support. Offers both OO method chaining and a procedural-style static wrapper. Compatible with PHP 5.3+. Inspired by underscore.string.js.
|
A PHP library with a variety of string manipulation functions with multibyte support. Offers both OO method chaining and a procedural-style static wrapper. Compatible with PHP 5.3+. Inspired by underscore.string.js.
|
||||||
|
|
||||||
[](https://travis-ci.org/danielstjules/Stringy)
|
[](https://travis-ci.org/danielstjules/Stringy)
|
||||||
[](https://packagist.org/packages/danielstjules/stringy)
|
|
||||||
[](https://packagist.org/packages/danielstjules/stringy)
|
[](https://packagist.org/packages/danielstjules/stringy)
|
||||||
|
|
||||||
* [Requiring/Loading](#requiringloading)
|
* [Requiring/Loading](#requiringloading)
|
||||||
@@ -44,13 +43,13 @@ A PHP library with a variety of string manipulation functions with multibyte sup
|
|||||||
* [safeTruncate](#safetruncate)
|
* [safeTruncate](#safetruncate)
|
||||||
* [shuffle](#shuffle)
|
* [shuffle](#shuffle)
|
||||||
* [slugify](#slugify)
|
* [slugify](#slugify)
|
||||||
* [standardize](#standardize)
|
|
||||||
* [startsWith](#startswith)
|
* [startsWith](#startswith)
|
||||||
* [substr](#substr)
|
* [substr](#substr)
|
||||||
* [surround](#surround)
|
* [surround](#surround)
|
||||||
* [swapCase](#swapcase)
|
* [swapCase](#swapcase)
|
||||||
* [tidy](#tidy)
|
* [tidy](#tidy)
|
||||||
* [titleize](#titleize)
|
* [titleize](#titleize)
|
||||||
|
* [toAscii](#toascii)
|
||||||
* [toSpaces](#tospaces)
|
* [toSpaces](#tospaces)
|
||||||
* [toTabs](#totabs)
|
* [toTabs](#totabs)
|
||||||
* [trim](#trim)
|
* [trim](#trim)
|
||||||
@@ -117,7 +116,7 @@ echo S::swapCase($string, 'UTF-8'); // 'fÒÔ bÀŘ''
|
|||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
In the list below, any static method other than S::create refers to a
|
In the list below, any static method other than S::create refers to a
|
||||||
method in Stringy\StaticStringy. For all others, they're found in Stringy\Stringy. Furthermore, all methods that return an object of type Stringy return a new object, and do not modify the original.
|
method in Stringy\StaticStringy. For all others, they're found in Stringy\Stringy. Furthermore, all methods that return a Stringy object or string do not modify the original.
|
||||||
|
|
||||||
*Note: If $encoding is not given, it defaults to mb_internal_encoding().*
|
*Note: If $encoding is not given, it defaults to mb_internal_encoding().*
|
||||||
|
|
||||||
@@ -127,7 +126,7 @@ $stringy->at(int $index)
|
|||||||
|
|
||||||
S::substr(int $index [, string $encoding ])
|
S::substr(int $index [, string $encoding ])
|
||||||
|
|
||||||
Gets the character of $str at $index, with indexes starting at 0.
|
Returns the character of the string at $index, with indexes starting at 0.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8')->at(6);
|
S::create('fòô bàř', 'UTF-8')->at(6);
|
||||||
@@ -140,9 +139,9 @@ $stringy->camelize();
|
|||||||
|
|
||||||
S::camelize(string $str [, string $encoding ])
|
S::camelize(string $str [, string $encoding ])
|
||||||
|
|
||||||
Returns a camelCase version of a supplied string, with multibyte support.
|
Returns a camelCase version of the supplied string. Trims surrounding
|
||||||
Trims surrounding spaces, capitalizes letters following digits, spaces,
|
spaces, capitalizes letters following digits, spaces, dashes and
|
||||||
dashes and underscores, and removes spaces, dashes, underscores.
|
underscores, and removes spaces, dashes, underscores.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('Camel-Case')->camelize();
|
S::create('Camel-Case')->camelize();
|
||||||
@@ -156,7 +155,7 @@ $stringy->collapseWhitespace()
|
|||||||
S::collapseWhitespace(string $str)
|
S::collapseWhitespace(string $str)
|
||||||
|
|
||||||
Trims the string and replaces consecutive whitespace characters with a
|
Trims the string and replaces consecutive whitespace characters with a
|
||||||
single space. This inclues tabs and newline characters.
|
single space. This includes tabs and newline characters.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create(' Ο συγγραφέας ')->collapseWhitespace();
|
S::create(' Ο συγγραφέας ')->collapseWhitespace();
|
||||||
@@ -169,7 +168,7 @@ $stringy->contains(string $needle)
|
|||||||
|
|
||||||
S::contains(string $haystack, string $needle [, string $encoding ])
|
S::contains(string $haystack, string $needle [, string $encoding ])
|
||||||
|
|
||||||
Returns true if $haystack contains $needle, false otherwise.
|
Returns true if the string contains $needle, false otherwise.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('Ο συγγραφέας είπε', 'UTF-8')->contains('συγγραφέας');
|
S::create('Ο συγγραφέας είπε', 'UTF-8')->contains('συγγραφέας');
|
||||||
@@ -182,7 +181,7 @@ $stringy->count(string $substring)
|
|||||||
|
|
||||||
S::count(string $str, string $substring [, string $encoding ])
|
S::count(string $str, string $substring [, string $encoding ])
|
||||||
|
|
||||||
Returns the number of occurences of $substring in $str. An alias for
|
Returns the number of occurrences of $substring in the given string. An alias for
|
||||||
mb_substr_count()
|
mb_substr_count()
|
||||||
|
|
||||||
```php
|
```php
|
||||||
@@ -192,14 +191,14 @@ S::count('Ο συγγραφέας είπε', 'α', 'UTF-8'); // 2
|
|||||||
|
|
||||||
#### create
|
#### create
|
||||||
|
|
||||||
$stringy = S::create(string $str, [, $encoding ])
|
S::create(string $str, [, $encoding ])
|
||||||
|
|
||||||
Creates a Stringy object and assigns both str and encoding properties
|
Creates a Stringy object and assigns both str and encoding properties
|
||||||
the supplied values. If $encoding is not specified, it defaults to
|
the supplied values. If $encoding is not specified, it defaults to
|
||||||
mb_internal_encoding(). It then returns the instantiated object.
|
mb_internal_encoding(). It then returns the initialized object.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8'); // 'fòô bàř'
|
$stringy = S::create('fòô bàř', 'UTF-8'); // 'fòô bàř'
|
||||||
```
|
```
|
||||||
|
|
||||||
#### dasherize
|
#### dasherize
|
||||||
@@ -208,10 +207,9 @@ $stringy->dasherize();
|
|||||||
|
|
||||||
S::dasherize(string $str [, string $encoding ])
|
S::dasherize(string $str [, string $encoding ])
|
||||||
|
|
||||||
Returns a lowercase and trimmed string seperated by dashes, with
|
Returns a lowercase and trimmed string separated by dashes. Dashes are
|
||||||
multibyte support. Dashes are inserted before uppercase characters
|
inserted before uppercase characters (with the exception of the first
|
||||||
(with the exception of the first character of the string), and in place
|
character of the string), and in place of spaces as well as underscores.
|
||||||
of spaces as well as underscores.
|
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('TestDCase')->dasherize();
|
S::create('TestDCase')->dasherize();
|
||||||
@@ -224,9 +222,9 @@ $stringy->endsWith(string $substring [, boolean $caseSensitive = true ])
|
|||||||
|
|
||||||
S::endsWith(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]])
|
S::endsWith(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]])
|
||||||
|
|
||||||
Returns true if the string $str ends with $substring, false otherwise.
|
Returns true if the string ends with $substring, false otherwise. By
|
||||||
By default, the comparison is case-sensitive, but can be made insensitive
|
default, the comparison is case-sensitive, but can be made insensitive by
|
||||||
by setting $caseSensitive to false.
|
setting $caseSensitive to false.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('FÒÔ bàřs', 'UTF-8')->endsWith('àřs', true);
|
S::create('FÒÔ bàřs', 'UTF-8')->endsWith('àřs', true);
|
||||||
@@ -239,7 +237,7 @@ $stringy->ensureLeft(string $substring)
|
|||||||
|
|
||||||
S::ensureLeft(string $substring [, string $encoding ])
|
S::ensureLeft(string $substring [, string $encoding ])
|
||||||
|
|
||||||
Ensures that $str begins with $substring.
|
Ensures that the string begins with $substring. If it doesn't, it's prepended.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('foobar')->ensureLeft('http://');
|
S::create('foobar')->ensureLeft('http://');
|
||||||
@@ -252,7 +250,7 @@ $stringy->ensureRight(string $substring)
|
|||||||
|
|
||||||
S::ensureRight(string $substring [, string $encoding ])
|
S::ensureRight(string $substring [, string $encoding ])
|
||||||
|
|
||||||
Ensures that $str ends with $substring.
|
Ensures that the string begins with $substring. If it doesn't, it's appended.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('foobar')->ensureRight('.com');
|
S::create('foobar')->ensureRight('.com');
|
||||||
@@ -265,7 +263,7 @@ $stringy->first(int $n)
|
|||||||
|
|
||||||
S::first(int $n [, string $encoding ])
|
S::first(int $n [, string $encoding ])
|
||||||
|
|
||||||
Gets the first $n characters of $str.
|
Returns the first $n characters of the string.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8')->first(3);
|
S::create('fòô bàř', 'UTF-8')->first(3);
|
||||||
@@ -278,8 +276,8 @@ $stringy->humanize()
|
|||||||
|
|
||||||
S::humanize(string $str [, string $encoding ])
|
S::humanize(string $str [, string $encoding ])
|
||||||
|
|
||||||
Capitalizes the first word of a string, replaces underscores with spaces,
|
Capitalizes the first word of the string, replaces underscores with
|
||||||
and strips '_id'.
|
spaces, and strips '_id'.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('author_id')->humanize();
|
S::create('author_id')->humanize();
|
||||||
@@ -292,7 +290,7 @@ $stringy->insert(int $index, string $substring)
|
|||||||
|
|
||||||
S::insert(string $str, int $index, string $substring [, string $encoding ])
|
S::insert(string $str, int $index, string $substring [, string $encoding ])
|
||||||
|
|
||||||
Inserts $substring into $str at the $index provided.
|
Inserts $substring into the string at the $index provided.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bà', 'UTF-8')->insert('ř', 6);
|
S::create('fòô bà', 'UTF-8')->insert('ř', 6);
|
||||||
@@ -305,7 +303,7 @@ $stringy->isAlpha()
|
|||||||
|
|
||||||
S::isAlpha(string $str [, string $encoding ])
|
S::isAlpha(string $str [, string $encoding ])
|
||||||
|
|
||||||
Returns true if $str contains only alphabetic chars, false otherwise.
|
Returns true if the string contains only alphabetic chars, false otherwise.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('丹尼爾', 'UTF-8')->isAlpha();
|
S::create('丹尼爾', 'UTF-8')->isAlpha();
|
||||||
@@ -318,7 +316,7 @@ $stringy->isAlphanumeric()
|
|||||||
|
|
||||||
S::isAlphanumeric(string $str [, string $encoding ])
|
S::isAlphanumeric(string $str [, string $encoding ])
|
||||||
|
|
||||||
Returns true if $str contains only alphabetic and numeric chars, false
|
Returns true if the string contains only alphabetic and numeric chars, false
|
||||||
otherwise.
|
otherwise.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
@@ -332,7 +330,7 @@ $stringy->isBlank()
|
|||||||
|
|
||||||
S::isBlank(string $str [, string $encoding ])
|
S::isBlank(string $str [, string $encoding ])
|
||||||
|
|
||||||
Returns true if $str contains only whitespace chars, false otherwise.
|
Returns true if the string contains only whitespace chars, false otherwise.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create("\n\t \v\f")->isBlank();
|
S::create("\n\t \v\f")->isBlank();
|
||||||
@@ -345,7 +343,7 @@ $stringy->isLowerCase()
|
|||||||
|
|
||||||
S::isLowerCase(string $str [, string $encoding ])
|
S::isLowerCase(string $str [, string $encoding ])
|
||||||
|
|
||||||
Returns true if $str contains only lower case chars, false otherwise.
|
Returns true if the string contains only lower case chars, false otherwise.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8')->isLowerCase();
|
S::create('fòô bàř', 'UTF-8')->isLowerCase();
|
||||||
@@ -358,7 +356,7 @@ $stringy->isUpperCase()
|
|||||||
|
|
||||||
S::isUpperCase(string $str [, string $encoding ])
|
S::isUpperCase(string $str [, string $encoding ])
|
||||||
|
|
||||||
Returns true if $str contains only upper case chars, false otherwise.
|
Returns true if the string contains only upper case chars, false otherwise.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('FÒÔBÀŘ',, 'UTF-8')->isUpperCase();
|
S::create('FÒÔBÀŘ',, 'UTF-8')->isUpperCase();
|
||||||
@@ -371,7 +369,7 @@ $stringy->last(int $n)
|
|||||||
|
|
||||||
S::last(int $n [, string $encoding ])
|
S::last(int $n [, string $encoding ])
|
||||||
|
|
||||||
Gets the last $n characters of $str.
|
Returns the last $n characters of the string.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8')->last(3);
|
S::create('fòô bàř', 'UTF-8')->last(3);
|
||||||
@@ -384,7 +382,7 @@ $stringy->length()
|
|||||||
|
|
||||||
S::length(string $str [, string $encoding ])
|
S::length(string $str [, string $encoding ])
|
||||||
|
|
||||||
Returns the length of $str. An alias for PHP's mb_strlen() function.
|
Returns the length of the string. An alias for PHP's mb_strlen() function.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8')->length();
|
S::create('fòô bàř', 'UTF-8')->length();
|
||||||
@@ -397,7 +395,7 @@ $stringy->longestCommonPrefix(string $otherStr)
|
|||||||
|
|
||||||
S::longestCommonPrefix(string $str, string $otherStr [, $encoding ])
|
S::longestCommonPrefix(string $str, string $otherStr [, $encoding ])
|
||||||
|
|
||||||
Finds the longest common prefix between $str and $otherStr.
|
Returns the longest common prefix between the string and $otherStr.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bar', 'UTF-8')->longestCommonPrefix('fòr bar');
|
S::create('fòô bar', 'UTF-8')->longestCommonPrefix('fòr bar');
|
||||||
@@ -410,7 +408,7 @@ $stringy->longestCommonSuffix(string $otherStr)
|
|||||||
|
|
||||||
S::longestCommonSuffix(string $str, string $otherStr [, $encoding ])
|
S::longestCommonSuffix(string $str, string $otherStr [, $encoding ])
|
||||||
|
|
||||||
Finds the longest common suffix between $str and $otherStr.
|
Returns the longest common suffix between the string and $otherStr.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8')->longestCommonSuffix('fòr bàř');
|
S::create('fòô bàř', 'UTF-8')->longestCommonSuffix('fòr bàř');
|
||||||
@@ -423,8 +421,8 @@ $stringy->longestCommonSubstring(string $otherStr)
|
|||||||
|
|
||||||
S::longestCommonSubstring(string $str, string $otherStr [, $encoding ])
|
S::longestCommonSubstring(string $str, string $otherStr [, $encoding ])
|
||||||
|
|
||||||
Finds the longest common substring between $str and $otherStr. In the
|
Returns the longest common substring between the string and $otherStr. In the
|
||||||
case of ties, returns that which occurs first.
|
case of ties, it returns that which occurs first.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('foo bar')->longestCommonSubstring('boo far');
|
S::create('foo bar')->longestCommonSubstring('boo far');
|
||||||
@@ -437,8 +435,7 @@ $stringy->lowerCaseFirst();
|
|||||||
|
|
||||||
S::lowerCaseFirst(string $str [, string $encoding ])
|
S::lowerCaseFirst(string $str [, string $encoding ])
|
||||||
|
|
||||||
Converts the first character of the supplied string to lower case, with
|
Converts the first character of the supplied string to lower case.
|
||||||
support for multibyte strings.
|
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('Σ test', 'UTF-8')->lowerCaseFirst();
|
S::create('Σ test', 'UTF-8')->lowerCaseFirst();
|
||||||
@@ -451,11 +448,11 @@ $stringy->pad(int $length [, string $padStr = ' ' [, string $padType = 'right' ]
|
|||||||
|
|
||||||
S::pad(string $str , int $length [, string $padStr = ' ' [, string $padType = 'right' [, string $encoding ]]])
|
S::pad(string $str , int $length [, string $padStr = ' ' [, string $padType = 'right' [, string $encoding ]]])
|
||||||
|
|
||||||
Pads a string to a given length with another string. If length is less
|
Pads the string to a given length with $padStr. If length is less than
|
||||||
than or equal to the length of $str, then no padding takes places. The
|
or equal to the length of the string, no padding takes places. The default
|
||||||
default string used for padding is a space, and the default type (one of
|
string used for padding is a space, and the default type (one of 'left',
|
||||||
'left', 'right', 'both') is 'right'. Throws an exception if $padType
|
'right', 'both') is 'right'. Throws an InvalidArgumentException if
|
||||||
isn't one of those 3 values.
|
$padType isn't one of those 3 values.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8')->pad( 10, '¬ø', 'left',);
|
S::create('fòô bàř', 'UTF-8')->pad( 10, '¬ø', 'left',);
|
||||||
@@ -469,7 +466,7 @@ $stringy->padBoth(int $length [, string $padStr = ' ' ])
|
|||||||
S::padBoth(string $str , int $length [, string $padStr = ' ' [, string $encoding ]])
|
S::padBoth(string $str , int $length [, string $padStr = ' ' [, string $encoding ]])
|
||||||
|
|
||||||
Returns a new string of a given length such that both sides of the string
|
Returns a new string of a given length such that both sides of the string
|
||||||
string are padded. Alias for pad($str, $length, $padStr, 'both', $encoding)
|
string are padded. Alias for pad() with a $padType of 'both'.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('foo bar')->padBoth(9, ' ');
|
S::create('foo bar')->padBoth(9, ' ');
|
||||||
@@ -483,7 +480,7 @@ $stringy->padLeft(int $length [, string $padStr = ' ' ])
|
|||||||
S::padLeft(string $str , int $length [, string $padStr = ' ' [, string $encoding ]])
|
S::padLeft(string $str , int $length [, string $padStr = ' ' [, string $encoding ]])
|
||||||
|
|
||||||
Returns a new string of a given length such that the beginning of the
|
Returns a new string of a given length such that the beginning of the
|
||||||
string is padded. Alias for pad($str, $length, $padStr, 'left', $encoding)
|
string is padded. Alias for pad() with a $padType of 'left'.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create($str, $encoding)->padLeft($length, $padStr);
|
S::create($str, $encoding)->padLeft($length, $padStr);
|
||||||
@@ -497,7 +494,7 @@ $stringy->padRight(int $length [, string $padStr = ' ' ])
|
|||||||
S::padRight(string $str , int $length [, string $padStr = ' ' [, string $encoding ]])
|
S::padRight(string $str , int $length [, string $padStr = ' ' [, string $encoding ]])
|
||||||
|
|
||||||
Returns a new string of a given length such that the end of the string is
|
Returns a new string of a given length such that the end of the string is
|
||||||
padded. Alias for pad($str, $length, $padStr, 'right', $encoding)
|
padded. Alias for pad() with a $padType of 'right'.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('foo bar')->padRight(10, '_*');
|
S::create('foo bar')->padRight(10, '_*');
|
||||||
@@ -510,7 +507,7 @@ $stringy->removeLeft(string $substring)
|
|||||||
|
|
||||||
S::removeLeft(string $str, string $substring [, string $encoding ])
|
S::removeLeft(string $str, string $substring [, string $encoding ])
|
||||||
|
|
||||||
Removes the prefix $substring if present.
|
Returns a new string with the prefix $substring removed, if it was present.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8')->removeLeft('fòô ');
|
S::create('fòô bàř', 'UTF-8')->removeLeft('fòô ');
|
||||||
@@ -523,7 +520,7 @@ $stringy->removeRight(string $substring)
|
|||||||
|
|
||||||
S::removeRight(string $str, string $substring [, string $encoding ])
|
S::removeRight(string $str, string $substring [, string $encoding ])
|
||||||
|
|
||||||
Removes the suffix $substring if present.
|
Returns a new string with the suffix $substring removed, if it was present.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8')->removeRight(' bàř');
|
S::create('fòô bàř', 'UTF-8')->removeRight(' bàř');
|
||||||
@@ -536,7 +533,7 @@ $stringy->replace(string $search, string $replace)
|
|||||||
|
|
||||||
S::replace(string $str, string $search, string $replace [, string $encoding ])
|
S::replace(string $str, string $search, string $replace [, string $encoding ])
|
||||||
|
|
||||||
Replaces all occurrences of $search with $replace in $str.
|
Returns a string with all occurrences of $search replaced with $replace.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř fòô bàř', 'UTF-8')->replace('fòô ', '');
|
S::create('fòô bàř fòô bàř', 'UTF-8')->replace('fòô ', '');
|
||||||
@@ -549,7 +546,7 @@ $stringy->reverse()
|
|||||||
|
|
||||||
S::reverse(string $str, [, string $encoding ])
|
S::reverse(string $str, [, string $encoding ])
|
||||||
|
|
||||||
Reverses a string. A multibyte version of strrev.
|
Returns a reversed string. A multibyte version of strrev().
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8')->reverse();
|
S::create('fòô bàř', 'UTF-8')->reverse();
|
||||||
@@ -578,8 +575,7 @@ $stringy->shuffle()
|
|||||||
|
|
||||||
S::shuffle(string $str [, string $encoding ])
|
S::shuffle(string $str [, string $encoding ])
|
||||||
|
|
||||||
A multibyte str_shuffle function. It randomizes the order of characters
|
A multibyte str_shuffle() function. It returns a string with its characters in random order.
|
||||||
in a string.
|
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8')->shuffle();
|
S::create('fòô bàř', 'UTF-8')->shuffle();
|
||||||
@@ -592,36 +588,23 @@ $stringy->slugify()
|
|||||||
|
|
||||||
S::slugify(string $str)
|
S::slugify(string $str)
|
||||||
|
|
||||||
Converts the supplied text into an URL slug. This includes replacing
|
Converts the string into an URL slug. This includes replacing non-ASCII
|
||||||
non-ASCII characters with their closest ASCII equivalents, removing
|
characters with their closest ASCII equivalents, removing non-alphanumeric
|
||||||
non-alphanumeric and non-ASCII characters, and replacing whitespace with
|
and non-ASCII characters, and replacing whitespace with dashes. The string
|
||||||
dashes. The string is also converted to lowercase.
|
is also converted to lowercase.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('Using strings like fòô bàř')->slugify();
|
S::create('Using strings like fòô bàř')->slugify();
|
||||||
S::slugify('Using strings like fòô bàř'); // 'using-strings-like-foo-bar'
|
S::slugify('Using strings like fòô bàř'); // 'using-strings-like-foo-bar'
|
||||||
```
|
```
|
||||||
|
|
||||||
#### standardize
|
|
||||||
|
|
||||||
$stringy->standardize()
|
|
||||||
|
|
||||||
S::standardize(string $str)
|
|
||||||
|
|
||||||
Converts some non-ASCII characters to their closest ASCII counterparts.
|
|
||||||
|
|
||||||
```php
|
|
||||||
S::create('fòô bàř')->standardize();
|
|
||||||
S::standardize('fòô bàř'); // 'foo bar'
|
|
||||||
```
|
|
||||||
|
|
||||||
#### startsWith
|
#### startsWith
|
||||||
|
|
||||||
$stringy->startsWith(string $substring [, boolean $caseSensitive = true ])
|
$stringy->startsWith(string $substring [, boolean $caseSensitive = true ])
|
||||||
|
|
||||||
S::startsWith(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]])
|
S::startsWith(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]])
|
||||||
|
|
||||||
Returns true if the string $str begins with $substring, false otherwise.
|
Returns true if the string begins with $substring, false otherwise.
|
||||||
By default, the comparison is case-sensitive, but can be made insensitive
|
By default, the comparison is case-sensitive, but can be made insensitive
|
||||||
by setting $caseSensitive to false.
|
by setting $caseSensitive to false.
|
||||||
|
|
||||||
@@ -636,7 +619,7 @@ $stringy->substr(int $start [, int $length ])
|
|||||||
|
|
||||||
S::substr(string $str, int $start [, int $length [, string $encoding ]])
|
S::substr(string $str, int $start [, int $length [, string $encoding ]])
|
||||||
|
|
||||||
Gets the substring of $str beginning at $start with the specified $length.
|
Returns the substring beginning at $start with the specified $length.
|
||||||
It differs from the mb_substr() function in that providing a $length of
|
It differs from the mb_substr() function in that providing a $length of
|
||||||
null will return the rest of the string, rather than an empty string.
|
null will return the rest of the string, rather than an empty string.
|
||||||
|
|
||||||
@@ -664,7 +647,7 @@ $stringy->swapCase();
|
|||||||
|
|
||||||
S::swapCase(string $str [, string $encoding ])
|
S::swapCase(string $str [, string $encoding ])
|
||||||
|
|
||||||
Returns a case swapped version of a string.
|
Returns a case swapped version of the string.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('Ντανιλ', 'UTF-8')->swapCase();
|
S::create('Ντανιλ', 'UTF-8')->swapCase();
|
||||||
@@ -677,8 +660,8 @@ $stringy->tidy()
|
|||||||
|
|
||||||
S::tidy(string $str)
|
S::tidy(string $str)
|
||||||
|
|
||||||
Replaces smart quotes, ellipsis characters, and dashes from Windows-1252
|
Returns a string with smart quotes, ellipsis characters, and dashes from
|
||||||
(and commonly used in Word documents) with their ASCII equivalents.
|
Windows-1252 (commonly used in Word documents) replaced by their ASCII equivalents.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('“I see…”')->tidy();
|
S::create('“I see…”')->tidy();
|
||||||
@@ -691,7 +674,7 @@ $stringy->titleize([ string $encoding ])
|
|||||||
|
|
||||||
S::titleize(string $str [, array $ignore [, string $encoding ]])
|
S::titleize(string $str [, array $ignore [, string $encoding ]])
|
||||||
|
|
||||||
Capitalizes the first letter of each word in a string, after trimming.
|
Returns a trimmed string with the first letter of each word capitalized.
|
||||||
Ignores the case of other letters, allowing for the use of acronyms.
|
Ignores the case of other letters, allowing for the use of acronyms.
|
||||||
Also accepts an array, $ignore, allowing you to list words not to be
|
Also accepts an array, $ignore, allowing you to list words not to be
|
||||||
capitalized.
|
capitalized.
|
||||||
@@ -703,13 +686,27 @@ S::titleize('i like to watch DVDs at home', $ignore, 'UTF-8');
|
|||||||
// 'I Like to Watch DVDs at Home'
|
// 'I Like to Watch DVDs at Home'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### toAscii
|
||||||
|
|
||||||
|
$stringy->toAscii()
|
||||||
|
|
||||||
|
S::toAscii(string $str)
|
||||||
|
|
||||||
|
Returns an ASCII version of the string. A set of non-ASCII characters are
|
||||||
|
replaced with their closest ASCII counterparts, and the rest are removed.
|
||||||
|
|
||||||
|
```php
|
||||||
|
S::create('fòô bàř')->toAscii();
|
||||||
|
S::toAscii('fòô bàř'); // 'foo bar'
|
||||||
|
```
|
||||||
|
|
||||||
#### toSpaces
|
#### toSpaces
|
||||||
|
|
||||||
$stringy->toSpaces([ tabLength = 4 ])
|
$stringy->toSpaces([ tabLength = 4 ])
|
||||||
|
|
||||||
S::toSpaces(string $str, [, int $tabLength = 4 ])
|
S::toSpaces(string $str, [, int $tabLength = 4 ])
|
||||||
|
|
||||||
Converts each tab in a string to some number of spaces, as defined by
|
Converts each tab in the string to some number of spaces, as defined by
|
||||||
$tabLength. By default, each tab is converted to 4 consecutive spaces.
|
$tabLength. By default, each tab is converted to 4 consecutive spaces.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
@@ -723,7 +720,7 @@ $stringy->toTabs([ tabLength = 4 ])
|
|||||||
|
|
||||||
S::toTabs(string $str, [, int $tabLength = 4 ])
|
S::toTabs(string $str, [, int $tabLength = 4 ])
|
||||||
|
|
||||||
Converts each occurence of some consecutive number of spaces, as defined
|
Converts each occurrence of some consecutive number of spaces, as defined
|
||||||
by $tabLength, to a tab. By default, each 4 consecutive spaces are
|
by $tabLength, to a tab. By default, each 4 consecutive spaces are
|
||||||
converted to a tab.
|
converted to a tab.
|
||||||
|
|
||||||
@@ -738,7 +735,7 @@ $stringy->trim()
|
|||||||
|
|
||||||
S::trim(string $str)
|
S::trim(string $str)
|
||||||
|
|
||||||
Trims $str. An alias for PHP's trim() function.
|
Returns the trimmed string. An alias for PHP's trim() function.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('fòô bàř', 'UTF-8')->trim();
|
S::create('fòô bàř', 'UTF-8')->trim();
|
||||||
@@ -751,7 +748,7 @@ $stringy->truncate(int $length, [, string $substring = '' ])
|
|||||||
|
|
||||||
S::truncate(string $str, int $length, [, string $substring = '' [, string $encoding ]])
|
S::truncate(string $str, int $length, [, string $substring = '' [, string $encoding ]])
|
||||||
|
|
||||||
Truncates $str to a given length. If $substring is provided, and
|
Truncates the string to a given length. If $substring is provided, and
|
||||||
truncating occurs, the string is further truncated so that the substring
|
truncating occurs, the string is further truncated so that the substring
|
||||||
may be appended without exceeding the desired length.
|
may be appended without exceeding the desired length.
|
||||||
|
|
||||||
@@ -766,10 +763,9 @@ $stringy->underscored();
|
|||||||
|
|
||||||
S::underscored(string $str [, string $encoding ])
|
S::underscored(string $str [, string $encoding ])
|
||||||
|
|
||||||
Returns a lowercase and trimmed string seperated by underscores, with
|
Returns a lowercase and trimmed string separated by underscores.
|
||||||
multibyte support. Underscores are inserted before uppercase characters
|
Underscores are inserted before uppercase characters (with the exception
|
||||||
(with the exception of the first character of the string), and in place
|
of the first character of the string), and in place of spaces as well as dashes.
|
||||||
of spaces as well as dashes.
|
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('TestUCase')->underscored();
|
S::create('TestUCase')->underscored();
|
||||||
@@ -782,9 +778,9 @@ $stringy->upperCamelize();
|
|||||||
|
|
||||||
S::upperCamelize(string $str [, string $encoding ])
|
S::upperCamelize(string $str [, string $encoding ])
|
||||||
|
|
||||||
Returns an UpperCamelCase version of a supplied string, with multibyte
|
Returns an UpperCamelCase version of the supplied string. It trims
|
||||||
support. Trims surrounding spaces, capitalizes letters following digits,
|
surrounding spaces, capitalizes letters following digits, spaces, dashes
|
||||||
spaces, dashes and underscores, and removes spaces, dashes, underscores.
|
and underscores, and removes spaces, dashes, underscores.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('Upper Camel-Case')->upperCamelize();
|
S::create('Upper Camel-Case')->upperCamelize();
|
||||||
@@ -797,8 +793,7 @@ $stringy->upperCaseFirst();
|
|||||||
|
|
||||||
S::upperCaseFirst(string $str [, string $encoding ])
|
S::upperCaseFirst(string $str [, string $encoding ])
|
||||||
|
|
||||||
Converts the first character of the supplied string to upper case, with
|
Converts the first character of the supplied string to upper case.
|
||||||
support for multibyte strings.
|
|
||||||
|
|
||||||
```php
|
```php
|
||||||
S::create('σ test', 'UTF-8')->upperCaseFirst();
|
S::create('σ test', 'UTF-8')->upperCaseFirst();
|
||||||
|
@@ -29,7 +29,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a camelCase version of a supplied string. Trims surrounding
|
* Returns a camelCase version of the supplied string. Trims surrounding
|
||||||
* spaces, capitalizes letters following digits, spaces, dashes and
|
* spaces, capitalizes letters following digits, spaces, dashes and
|
||||||
* underscores, and removes spaces, dashes, underscores.
|
* underscores, and removes spaces, dashes, underscores.
|
||||||
*
|
*
|
||||||
@@ -43,9 +43,9 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an UpperCamelCase version of a supplied string. Trims surrounding
|
* Returns an UpperCamelCase version of the supplied string. It trims
|
||||||
* spaces, capitalizes letters following digits, spaces, dashes and
|
* surrounding spaces, capitalizes letters following digits, spaces, dashes
|
||||||
* underscores, and removes spaces, dashes, underscores.
|
* and underscores, and removes spaces, dashes, underscores.
|
||||||
*
|
*
|
||||||
* @param string $str String to convert to UpperCamelCase
|
* @param string $str String to convert to UpperCamelCase
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
@@ -57,7 +57,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a lowercase and trimmed string seperated by dashes. Dashes are
|
* Returns a lowercase and trimmed string separated by dashes. Dashes are
|
||||||
* inserted before uppercase characters (with the exception of the first
|
* inserted before uppercase characters (with the exception of the first
|
||||||
* character of the string), and in place of spaces as well as underscores.
|
* character of the string), and in place of spaces as well as underscores.
|
||||||
*
|
*
|
||||||
@@ -71,7 +71,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a lowercase and trimmed string seperated by underscores.
|
* Returns a lowercase and trimmed string separated by underscores.
|
||||||
* Underscores are inserted before uppercase characters (with the exception
|
* Underscores are inserted before uppercase characters (with the exception
|
||||||
* of the first character of the string), and in place of spaces as well as
|
* of the first character of the string), and in place of spaces as well as
|
||||||
* dashes.
|
* dashes.
|
||||||
@@ -86,7 +86,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a case swapped version of a string.
|
* Returns a case swapped version of the string.
|
||||||
*
|
*
|
||||||
* @param string $str String to swap case
|
* @param string $str String to swap case
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
@@ -98,7 +98,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capitalizes the first letter of each word in a string, after trimming.
|
* Returns a trimmed string with the first letter of each word capitalized.
|
||||||
* Ignores the case of other letters, allowing for the use of acronyms.
|
* Ignores the case of other letters, allowing for the use of acronyms.
|
||||||
* Also accepts an array, $ignore, allowing you to list words not to be
|
* Also accepts an array, $ignore, allowing you to list words not to be
|
||||||
* capitalized.
|
* capitalized.
|
||||||
@@ -114,8 +114,8 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capitalizes the first word of a string, replaces underscores with spaces,
|
* Capitalizes the first word of the string, replaces underscores with
|
||||||
* and strips '_id'.
|
* spaces, and strips '_id'.
|
||||||
*
|
*
|
||||||
* @param string $str String to humanize
|
* @param string $str String to humanize
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
@@ -127,8 +127,9 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces smart quotes, ellipsis characters, and dashes from Windows-1252
|
* Returns a string with smart quotes, ellipsis characters, and dashes from
|
||||||
* (and commonly used in Word documents) with their ASCII equivalents.
|
* Windows-1252 (commonly used in Word documents) replaced by their ASCII
|
||||||
|
* equivalents.
|
||||||
*
|
*
|
||||||
* @param string $str String to remove special chars
|
* @param string $str String to remove special chars
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
@@ -141,7 +142,7 @@ class StaticStringy
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Trims the string and replaces consecutive whitespace characters with a
|
* Trims the string and replaces consecutive whitespace characters with a
|
||||||
* single space. This inclues tabs and newline characters.
|
* single space. This includes tabs and newline characters.
|
||||||
*
|
*
|
||||||
* @param string $str The string to cleanup whitespace
|
* @param string $str The string to cleanup whitespace
|
||||||
* @return string The trimmed string with condensed whitespace
|
* @return string The trimmed string with condensed whitespace
|
||||||
@@ -152,22 +153,23 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts some non-ASCII characters to their closest ASCII counterparts.
|
* Returns an ASCII version of the string. A set of non-ASCII characters are
|
||||||
|
* replaced with their closest ASCII counterparts, and the rest are removed.
|
||||||
*
|
*
|
||||||
* @param string $str A string with non-ASCII characters
|
* @param string $str A string with non-ASCII characters
|
||||||
* @return string The string after the replacements
|
* @return string A string containing only ASCII characters
|
||||||
*/
|
*/
|
||||||
public static function standardize($str)
|
public static function toAscii($str)
|
||||||
{
|
{
|
||||||
return $result = Stringy::create($str)->standardize()->str;
|
return $result = Stringy::create($str)->toAscii()->str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pads a string to a given length with another string. If length is less
|
* Pads the string to a given length with $padStr. If length is less than
|
||||||
* than or equal to the length of $str, then no padding takes places. The
|
* or equal to the length of the string, no padding takes places. The default
|
||||||
* default string used for padding is a space, and the default type (one of
|
* string used for padding is a space, and the default type (one of 'left',
|
||||||
* 'left', 'right', 'both') is 'right'. Throws an exception if $padType
|
* 'right', 'both') is 'right'. Throws an InvalidArgumentException if
|
||||||
* isn't one of those 3 values.
|
* $padType isn't one of those 3 values.
|
||||||
*
|
*
|
||||||
* @param string $str String to pad
|
* @param string $str String to pad
|
||||||
* @param int $length Desired string length after padding
|
* @param int $length Desired string length after padding
|
||||||
@@ -187,7 +189,7 @@ class StaticStringy
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new string of a given length such that the beginning of the
|
* Returns a new string of a given length such that the beginning of the
|
||||||
* string is padded. Alias for pad($str, $length, $padStr, 'left', $encoding)
|
* string is padded. Alias for pad() with a $padType of 'left'.
|
||||||
*
|
*
|
||||||
* @param string $str String to pad
|
* @param string $str String to pad
|
||||||
* @param int $length Desired string length after padding
|
* @param int $length Desired string length after padding
|
||||||
@@ -202,7 +204,7 @@ class StaticStringy
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new string of a given length such that the end of the string is
|
* Returns a new string of a given length such that the end of the string is
|
||||||
* padded. Alias for pad($str, $length, $padStr, 'right', $encoding)
|
* padded. Alias for pad() with a $padType of 'right'.
|
||||||
*
|
*
|
||||||
* @param string $str String to pad
|
* @param string $str String to pad
|
||||||
* @param int $length Desired string length after padding
|
* @param int $length Desired string length after padding
|
||||||
@@ -217,7 +219,7 @@ class StaticStringy
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new string of a given length such that both sides of the string
|
* Returns a new string of a given length such that both sides of the string
|
||||||
* string are padded. Alias for pad($str, $length, $padStr, 'both', $encoding)
|
* string are padded. Alias for pad() with a $padType of 'both'.
|
||||||
*
|
*
|
||||||
* @param string $str String to pad
|
* @param string $str String to pad
|
||||||
* @param int $length Desired string length after padding
|
* @param int $length Desired string length after padding
|
||||||
@@ -231,13 +233,13 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the string $str begins with $substring, false otherwise.
|
* Returns true if the string begins with $substring, false otherwise.
|
||||||
* By default, the comparison is case-sensitive, but can be made insensitive
|
* By default, the comparison is case-sensitive, but can be made insensitive
|
||||||
* by setting $caseSensitive to false.
|
* by setting $caseSensitive to false.
|
||||||
*
|
*
|
||||||
* @param string $str String to check the start of
|
* @param string $str String to check the start of
|
||||||
* @param string $substring The substring to look for
|
* @param string $substring The substring to look for
|
||||||
* @param bool $caseSensitive Whether or not to enfore case-sensitivity
|
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
* @return bool Whether or not $str starts with $substring
|
* @return bool Whether or not $str starts with $substring
|
||||||
*/
|
*/
|
||||||
@@ -249,13 +251,13 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the string $str ends with $substring, false otherwise.
|
* Returns true if the string ends with $substring, false otherwise. By
|
||||||
* By default, the comparison is case-sensitive, but can be made insensitive
|
* default, the comparison is case-sensitive, but can be made insensitive by
|
||||||
* by setting $caseSensitive to false.
|
* setting $caseSensitive to false.
|
||||||
*
|
*
|
||||||
* @param string $str String to check the end of
|
* @param string $str String to check the end of
|
||||||
* @param string $substring The substring to look for
|
* @param string $substring The substring to look for
|
||||||
* @param bool $caseSensitive Whether or not to enfore case-sensitivity
|
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
* @return bool Whether or not $str ends with $substring
|
* @return bool Whether or not $str ends with $substring
|
||||||
*/
|
*/
|
||||||
@@ -267,7 +269,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts each tab in a string to some number of spaces, as defined by
|
* Converts each tab in the string to some number of spaces, as defined by
|
||||||
* $tabLength. By default, each tab is converted to 4 consecutive spaces.
|
* $tabLength. By default, each tab is converted to 4 consecutive spaces.
|
||||||
*
|
*
|
||||||
* @param string $str String to convert tabs to spaces
|
* @param string $str String to convert tabs to spaces
|
||||||
@@ -280,7 +282,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts each occurence of some consecutive number of spaces, as defined
|
* Converts each occurrence of some consecutive number of spaces, as defined
|
||||||
* by $tabLength, to a tab. By default, each 4 consecutive spaces are
|
* by $tabLength, to a tab. By default, each 4 consecutive spaces are
|
||||||
* converted to a tab.
|
* converted to a tab.
|
||||||
*
|
*
|
||||||
@@ -294,10 +296,10 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the supplied text into an URL slug. This includes replacing
|
* Converts the string into an URL slug. This includes replacing non-ASCII
|
||||||
* non-ASCII characters with their closest ASCII equivalents, removing
|
* characters with their closest ASCII equivalents, removing non-alphanumeric
|
||||||
* non-alphanumeric and non-ASCII characters, and replacing whitespace with
|
* and non-ASCII characters, and replacing whitespace with dashes. The string
|
||||||
* dashes. The string is also converted to lowercase.
|
* is also converted to lowercase.
|
||||||
*
|
*
|
||||||
* @param string $str Text to transform into an URL slug
|
* @param string $str Text to transform into an URL slug
|
||||||
* @return string The corresponding URL slug
|
* @return string The corresponding URL slug
|
||||||
@@ -308,7 +310,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $haystack contains $needle, false otherwise.
|
* Returns true if the string contains $needle, false otherwise.
|
||||||
*
|
*
|
||||||
* @param string $haystack String being checked
|
* @param string $haystack String being checked
|
||||||
* @param string $needle Substring to look for
|
* @param string $needle Substring to look for
|
||||||
@@ -333,7 +335,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts $substring into $str at the $index provided.
|
* Inserts $substring into the string at the $index provided.
|
||||||
*
|
*
|
||||||
* @param string $str String to insert into
|
* @param string $str String to insert into
|
||||||
* @param string $substring String to be inserted
|
* @param string $substring String to be inserted
|
||||||
@@ -347,14 +349,14 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Truncates $str to a given length. If $substring is provided, and
|
* Truncates the string to a given length. If $substring is provided, and
|
||||||
* truncating occurs, the string is further truncated so that the substring
|
* truncating occurs, the string is further truncated so that the substring
|
||||||
* may be appended without exceeding the desired length.
|
* may be appended without exceeding the desired length.
|
||||||
*
|
*
|
||||||
* @param string $str String to truncate
|
* @param string $str String to truncate
|
||||||
* @param int $length Desired length of the truncated string
|
* @param int $length Desired length of the truncated string
|
||||||
* @param string $substring The substring to append if it can fit
|
* @param string $substring The substring to append if it can fit
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
* @return string The resulting string after truncating
|
* @return string The resulting string after truncating
|
||||||
*/
|
*/
|
||||||
public static function truncate($str, $length, $substring = '',
|
public static function truncate($str, $length, $substring = '',
|
||||||
@@ -370,10 +372,10 @@ class StaticStringy
|
|||||||
* is further truncated so that the substring may be appended without
|
* is further truncated so that the substring may be appended without
|
||||||
* exceeding the desired length.
|
* exceeding the desired length.
|
||||||
*
|
*
|
||||||
* @param string $str String to truncate
|
* @param string $str String to truncate
|
||||||
* @param int $length Desired length of the truncated string
|
* @param int $length Desired length of the truncated string
|
||||||
* @param string $substring The substring to append if it can fit
|
* @param string $substring The substring to append if it can fit
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
* @return string The resulting string after truncating
|
* @return string The resulting string after truncating
|
||||||
*/
|
*/
|
||||||
public static function safeTruncate($str, $length, $substring = '',
|
public static function safeTruncate($str, $length, $substring = '',
|
||||||
@@ -384,10 +386,10 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverses a string. A multibyte version of strrev.
|
* Returns a reversed string. A multibyte version of strrev().
|
||||||
*
|
*
|
||||||
* @param string $str String to reverse
|
* @param string $str String to reverse
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
* @return string The reversed string
|
* @return string The reversed string
|
||||||
*/
|
*/
|
||||||
public static function reverse($str, $encoding = null)
|
public static function reverse($str, $encoding = null)
|
||||||
@@ -396,8 +398,8 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A multibyte str_shuffle function. It randomizes the order of characters
|
* A multibyte str_shuffle() function. It returns a string with its
|
||||||
* in a string.
|
* characters in random order.
|
||||||
*
|
*
|
||||||
* @param string $str String to shuffle
|
* @param string $str String to shuffle
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
@@ -409,7 +411,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trims $str. An alias for PHP's trim() function.
|
* Returns the trimmed string. An alias for PHP's trim() function.
|
||||||
*
|
*
|
||||||
* @param string $str String to trim
|
* @param string $str String to trim
|
||||||
* @return string Trimmed $str
|
* @return string Trimmed $str
|
||||||
@@ -420,7 +422,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the longest common prefix between $str and $otherStr.
|
* Returns the longest common prefix between the string and $otherStr.
|
||||||
*
|
*
|
||||||
* @param string $str First string for comparison
|
* @param string $str First string for comparison
|
||||||
* @param string $otherStr Second string for comparison
|
* @param string $otherStr Second string for comparison
|
||||||
@@ -434,7 +436,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the longest common suffix between $str and $otherStr.
|
* Returns the longest common suffix between the string and $otherStr.
|
||||||
*
|
*
|
||||||
* @param string $str First string for comparison
|
* @param string $str First string for comparison
|
||||||
* @param string $otherStr Second string for comparison
|
* @param string $otherStr Second string for comparison
|
||||||
@@ -448,8 +450,8 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the longest common substring between $str and $otherStr. In the
|
* Returns the longest common substring between the string and $otherStr.
|
||||||
* case of ties, returns that which occurs first.
|
* In the case of ties, it returns that which occurs first.
|
||||||
*
|
*
|
||||||
* @param string $str First string for comparison
|
* @param string $str First string for comparison
|
||||||
* @param string $otherStr Second string for comparison
|
* @param string $otherStr Second string for comparison
|
||||||
@@ -464,7 +466,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the length of $str. An alias for PHP's mb_strlen() function.
|
* Returns the length of the string. An alias for PHP's mb_strlen() function.
|
||||||
*
|
*
|
||||||
* @param string $str The string to get the length of
|
* @param string $str The string to get the length of
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
@@ -476,13 +478,13 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the substring of $str beginning at $start with the specified $length.
|
* Returns the substring beginning at $start with the specified $length.
|
||||||
* It differs from the mb_substr() function in that providing a $length of
|
* It differs from the mb_substr() function in that providing a $length of
|
||||||
* null will return the rest of the string, rather than an empty string.
|
* null will return the rest of the string, rather than an empty string.
|
||||||
*
|
*
|
||||||
* @param string $str The string to get the length of
|
* @param string $str The string to get the length of
|
||||||
* @param int $start Position of the first character to use from str
|
* @param int $start Position of the first character to use
|
||||||
* @param int $length Maximum number of characters used
|
* @param int $length Maximum number of characters used
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
* @return string The substring of $str
|
* @return string The substring of $str
|
||||||
*/
|
*/
|
||||||
@@ -492,7 +494,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the character of $str at $index, with indexes starting at 0.
|
* Returns the character of the string at $index, with indexes starting at 0.
|
||||||
*
|
*
|
||||||
* @param string $str The string from which to get the char
|
* @param string $str The string from which to get the char
|
||||||
* @param int $index Position of the character
|
* @param int $index Position of the character
|
||||||
@@ -505,7 +507,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the first $n characters of $str.
|
* Returns the first $n characters of the string.
|
||||||
*
|
*
|
||||||
* @param string $str The string from which to get the substring
|
* @param string $str The string from which to get the substring
|
||||||
* @param int $n Number of chars to retrieve from the start
|
* @param int $n Number of chars to retrieve from the start
|
||||||
@@ -518,7 +520,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the last $n characters of $str.
|
* Returns the last $n characters of the string.
|
||||||
*
|
*
|
||||||
* @param string $str The string from which to get the substring
|
* @param string $str The string from which to get the substring
|
||||||
* @param int $n Number of chars to retrieve from the end
|
* @param int $n Number of chars to retrieve from the end
|
||||||
@@ -531,7 +533,8 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that $str begins with $substring.
|
* Ensures that the string begins with $substring. If it doesn't, it's
|
||||||
|
* prepended.
|
||||||
*
|
*
|
||||||
* @param string $str The string to modify
|
* @param string $str The string to modify
|
||||||
* @param string $substring The substring to add if not present
|
* @param string $substring The substring to add if not present
|
||||||
@@ -544,7 +547,8 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that $str ends with $substring.
|
* Ensures that the string begins with $substring. If it doesn't, it's
|
||||||
|
* appended.
|
||||||
*
|
*
|
||||||
* @param string $str The string to modify
|
* @param string $str The string to modify
|
||||||
* @param string $substring The substring to add if not present
|
* @param string $substring The substring to add if not present
|
||||||
@@ -557,7 +561,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the prefix $substring if present.
|
* Returns a new string with the prefix $substring removed, if it was present.
|
||||||
*
|
*
|
||||||
* @param string $str String from which to remove the prefix
|
* @param string $str String from which to remove the prefix
|
||||||
* @param string $substring The prefix to remove
|
* @param string $substring The prefix to remove
|
||||||
@@ -570,7 +574,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the suffix $substring if present.
|
* Returns a new string with the suffix $substring removed, if it was present.
|
||||||
*
|
*
|
||||||
* @param string $str String from which to remove the suffix
|
* @param string $str String from which to remove the suffix
|
||||||
* @param string $substring The suffix to remove
|
* @param string $substring The suffix to remove
|
||||||
@@ -583,7 +587,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str contains only alphabetic chars, false otherwise.
|
* Returns true if the string contains only alphabetic chars, false otherwise.
|
||||||
*
|
*
|
||||||
* @param string $str String to check
|
* @param string $str String to check
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
@@ -595,8 +599,8 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str contains only alphabetic and numeric chars, false
|
* Returns true if the string contains only alphabetic and numeric chars,
|
||||||
* otherwise.
|
* false otherwise.
|
||||||
*
|
*
|
||||||
* @param string $str String to check
|
* @param string $str String to check
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
@@ -608,7 +612,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str contains only whitespace chars, false otherwise.
|
* Returns true if the string contains only whitespace chars, false otherwise.
|
||||||
*
|
*
|
||||||
* @param string $str String to check
|
* @param string $str String to check
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
@@ -620,7 +624,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str contains only lower case chars, false otherwise.
|
* Returns true if the string contains only lower case chars, false otherwise.
|
||||||
*
|
*
|
||||||
* @param string $str String to check
|
* @param string $str String to check
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
@@ -632,7 +636,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str contains only upper case chars, false otherwise.
|
* Returns true if the string contains only upper case chars, false otherwise.
|
||||||
*
|
*
|
||||||
* @param string $str String to check
|
* @param string $str String to check
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
@@ -644,13 +648,13 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of occurences of $substring in $str. An alias for
|
* Returns the number of occurrences of $substring in the given string.
|
||||||
* mb_substr_count()
|
* An alias for mb_substr_count()
|
||||||
*
|
*
|
||||||
* @param string $str The haystack to search through
|
* @param string $str The string to search through
|
||||||
* @param string $substring The substring to search for
|
* @param string $substring The substring to search for
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
* @return int The number of $substring occurences
|
* @return int The number of $substring occurrences
|
||||||
*/
|
*/
|
||||||
public static function count($str, $substring, $encoding = null)
|
public static function count($str, $substring, $encoding = null)
|
||||||
{
|
{
|
||||||
@@ -658,7 +662,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces all occurrences of $search with $replace in $str.
|
* Returns a string with all occurrences of $search replaced with $replace.
|
||||||
*
|
*
|
||||||
* @param string $str The haystack to search through
|
* @param string $str The haystack to search through
|
||||||
* @param string $search The needle to search for
|
* @param string $search The needle to search for
|
||||||
@@ -668,6 +672,6 @@ class StaticStringy
|
|||||||
*/
|
*/
|
||||||
public static function replace($str, $search, $replace, $encoding = null)
|
public static function replace($str, $search, $replace, $encoding = null)
|
||||||
{
|
{
|
||||||
return Stringy::create($str, $encoding)->replace($search, $replace);
|
return Stringy::create($str, $encoding)->replace($search, $replace)->str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@ class Stringy
|
|||||||
/**
|
/**
|
||||||
* Creates a Stringy object and assigns both str and encoding properties
|
* Creates a Stringy object and assigns both str and encoding properties
|
||||||
* the supplied values. If $encoding is not specified, it defaults to
|
* the supplied values. If $encoding is not specified, it defaults to
|
||||||
* mb_internal_encoding(). It then returns the instantiated object.
|
* mb_internal_encoding(). It then returns the initialized object.
|
||||||
*
|
*
|
||||||
* @param string $str String to modify
|
* @param string $str String to modify
|
||||||
* @param string $encoding The character encoding
|
* @param string $encoding The character encoding
|
||||||
@@ -39,7 +39,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the first character of the string to upper case.
|
* Converts the first character of the supplied string to upper case.
|
||||||
*
|
*
|
||||||
* @return Stringy Object with the first character of $str being upper case
|
* @return Stringy Object with the first character of $str being upper case
|
||||||
*/
|
*/
|
||||||
@@ -71,9 +71,9 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the string to camelCase. Trims surrounding spaces, capitalizes
|
* Returns a camelCase version of the supplied string. Trims surrounding
|
||||||
* letters following digits, spaces, dashes and underscores, and removes
|
* spaces, capitalizes letters following digits, spaces, dashes and
|
||||||
* spaces, dashes, underscores.
|
* underscores, and removes spaces, dashes, underscores.
|
||||||
*
|
*
|
||||||
* @return Stringy Object with $str in camelCase
|
* @return Stringy Object with $str in camelCase
|
||||||
*/
|
*/
|
||||||
@@ -102,9 +102,9 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the string to UpperCamelCase. Trims surrounding spaces, capitalizes
|
* Returns an UpperCamelCase version of the supplied string. It trims
|
||||||
* letters following digits, spaces, dashes and underscores, and removes
|
* surrounding spaces, capitalizes letters following digits, spaces, dashes
|
||||||
* spaces, dashes, underscores.
|
* and underscores, and removes spaces, dashes, underscores.
|
||||||
*
|
*
|
||||||
* @return Stringy Object with $str in UpperCamelCase
|
* @return Stringy Object with $str in UpperCamelCase
|
||||||
*/
|
*/
|
||||||
@@ -114,8 +114,8 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the string to lowercase, trims it, and seperates is by dashes. Dashes
|
* Returns a lowercase and trimmed string separated by dashes. Dashes are
|
||||||
* are inserted before uppercase characters (with the exception of the first
|
* inserted before uppercase characters (with the exception of the first
|
||||||
* character of the string), and in place of spaces as well as underscores.
|
* character of the string), and in place of spaces as well as underscores.
|
||||||
*
|
*
|
||||||
* @return Stringy Object with a dasherized $str
|
* @return Stringy Object with a dasherized $str
|
||||||
@@ -137,7 +137,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets $str to a lowercase and trimmed string seperated by underscores.
|
* Returns a lowercase and trimmed string separated by underscores.
|
||||||
* Underscores are inserted before uppercase characters (with the exception
|
* Underscores are inserted before uppercase characters (with the exception
|
||||||
* of the first character of the string), and in place of spaces as well as
|
* of the first character of the string), and in place of spaces as well as
|
||||||
* dashes.
|
* dashes.
|
||||||
@@ -161,7 +161,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets $str to a case swapped version of the string.
|
* Returns a case swapped version of the string.
|
||||||
*
|
*
|
||||||
* @return Stringy Object whose $str has each character's case swapped
|
* @return Stringy Object whose $str has each character's case swapped
|
||||||
*/
|
*/
|
||||||
@@ -185,7 +185,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capitalizes the first letter of each word in $str, after trimming.
|
* Returns a trimmed string with the first letter of each word capitalized.
|
||||||
* Ignores the case of other letters, allowing for the use of acronyms.
|
* Ignores the case of other letters, allowing for the use of acronyms.
|
||||||
* Also accepts an array, $ignore, allowing you to list words not to be
|
* Also accepts an array, $ignore, allowing you to list words not to be
|
||||||
* capitalized.
|
* capitalized.
|
||||||
@@ -213,8 +213,8 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capitalizes the first word of $str, replaces underscores with spaces,
|
* Capitalizes the first word of the string, replaces underscores with
|
||||||
* and strips '_id'.
|
* spaces, and strips '_id'.
|
||||||
*
|
*
|
||||||
* @return Stringy Object with a humanized $str
|
* @return Stringy Object with a humanized $str
|
||||||
*/
|
*/
|
||||||
@@ -229,8 +229,9 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces smart quotes, ellipsis characters, and dashes from Windows-1252
|
* Returns a string with smart quotes, ellipsis characters, and dashes from
|
||||||
* (and commonly used in Word documents) with their ASCII equivalents.
|
* Windows-1252 (commonly used in Word documents) replaced by their ASCII
|
||||||
|
* equivalents.
|
||||||
*
|
*
|
||||||
* @return Stringy Object whose $str has those characters removed
|
* @return Stringy Object whose $str has those characters removed
|
||||||
*/
|
*/
|
||||||
@@ -247,10 +248,10 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trims $str and replaces consecutive whitespace characters with a single
|
* Trims the string and replaces consecutive whitespace characters with a
|
||||||
* space. This inclues tabs and newline characters.
|
* single space. This includes tabs and newline characters.
|
||||||
*
|
*
|
||||||
* @return Stringy Object with a trimmed $str with condensed whitespace
|
* @return Stringy Object with a trimmed $str and condensed whitespace
|
||||||
*/
|
*/
|
||||||
public function collapseWhitespace()
|
public function collapseWhitespace()
|
||||||
{
|
{
|
||||||
@@ -261,11 +262,12 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts some non-ASCII characters to their closest ASCII counterparts.
|
* Returns an ASCII version of the string. A set of non-ASCII characters are
|
||||||
|
* replaced with their closest ASCII counterparts, and the rest are removed.
|
||||||
*
|
*
|
||||||
* @return Stringy Object whose $str had those characters replaced
|
* @return Stringy Object whose $str contains only ASCII characters
|
||||||
*/
|
*/
|
||||||
public function standardize()
|
public function toAscii()
|
||||||
{
|
{
|
||||||
$stringy = self::create($this->str, $this->encoding);
|
$stringy = self::create($this->str, $this->encoding);
|
||||||
$charsArray = array(
|
$charsArray = array(
|
||||||
@@ -328,11 +330,11 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pads $str to a given length with another string. If length is less than
|
* Pads the string to a given length with $padStr. If length is less than
|
||||||
* or equal to the length of $str, then no padding takes places. The default
|
* or equal to the length of the string, no padding takes places. The default
|
||||||
* string used for padding is a space, and the default type (one of 'left',
|
* string used for padding is a space, and the default type (one of 'left',
|
||||||
* 'right', 'both') is 'right'. Throws an exception if $padType isn't one
|
* 'right', 'both') is 'right'. Throws an InvalidArgumentException if
|
||||||
* of those 3 values.
|
* $padType isn't one of those 3 values.
|
||||||
*
|
*
|
||||||
* @param int $length Desired string length after padding
|
* @param int $length Desired string length after padding
|
||||||
* @param string $padStr String used to pad, defaults to space
|
* @param string $padStr String used to pad, defaults to space
|
||||||
@@ -387,8 +389,8 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pads $str to a given length from the begining of the string.
|
* Returns a new string of a given length such that the beginning of the
|
||||||
* Alias for pad($length, $padStr, 'left')
|
* string is padded. Alias for pad() with a $padType of 'left'.
|
||||||
*
|
*
|
||||||
* @param int $length Desired string length after padding
|
* @param int $length Desired string length after padding
|
||||||
* @param string $padStr String used to pad, defaults to space
|
* @param string $padStr String used to pad, defaults to space
|
||||||
@@ -400,8 +402,8 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pads $str to a given length from the end of the string.
|
* Returns a new string of a given length such that the end of the string is
|
||||||
* Alias for pad($length, $padStr, 'left')
|
* padded. Alias for pad() with a $padType of 'right'.
|
||||||
*
|
*
|
||||||
* @param int $length Desired string length after padding
|
* @param int $length Desired string length after padding
|
||||||
* @param string $padStr String used to pad, defaults to space
|
* @param string $padStr String used to pad, defaults to space
|
||||||
@@ -413,8 +415,8 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pads $str to a given length such that both sides of the string string are
|
* Returns a new string of a given length such that both sides of the string
|
||||||
* padded. Alias for pad($str, $length, $padStr, 'both', $encoding)
|
* string are padded. Alias for pad() with a $padType of 'both'.
|
||||||
*
|
*
|
||||||
* @param int $length Desired string length after padding
|
* @param int $length Desired string length after padding
|
||||||
* @param string $padStr String used to pad, defaults to space
|
* @param string $padStr String used to pad, defaults to space
|
||||||
@@ -426,12 +428,12 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str begins with $substring, false otherwise. By default,
|
* Returns true if the string begins with $substring, false otherwise.
|
||||||
* the comparison is case-sensitive, but can be made insensitive by setting
|
* By default, the comparison is case-sensitive, but can be made insensitive
|
||||||
* $caseSensitive to false.
|
* by setting $caseSensitive to false.
|
||||||
*
|
*
|
||||||
* @param string $substring The substring to look for
|
* @param string $substring The substring to look for
|
||||||
* @param bool $caseSensitive Whether or not to enfore case-sensitivity
|
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||||
* @return bool Whether or not $str starts with $substring
|
* @return bool Whether or not $str starts with $substring
|
||||||
*/
|
*/
|
||||||
public function startsWith($substring, $caseSensitive = true)
|
public function startsWith($substring, $caseSensitive = true)
|
||||||
@@ -448,12 +450,12 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str ends with $substring, false otherwise. By default,
|
* Returns true if the string ends with $substring, false otherwise. By
|
||||||
* the comparison is case-sensitive, but can be made insensitive by setting
|
* default, the comparison is case-sensitive, but can be made insensitive by
|
||||||
* $caseSensitive to false.
|
* setting $caseSensitive to false.
|
||||||
*
|
*
|
||||||
* @param string $substring The substring to look for
|
* @param string $substring The substring to look for
|
||||||
* @param bool $caseSensitive Whether or not to enfore case-sensitivity
|
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||||
* @return bool Whether or not $str ends with $substring
|
* @return bool Whether or not $str ends with $substring
|
||||||
*/
|
*/
|
||||||
public function endsWith($substring, $caseSensitive = true)
|
public function endsWith($substring, $caseSensitive = true)
|
||||||
@@ -473,7 +475,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts each tab in $str to some number of spaces, as defined by
|
* Converts each tab in the string to some number of spaces, as defined by
|
||||||
* $tabLength. By default, each tab is converted to 4 consecutive spaces.
|
* $tabLength. By default, each tab is converted to 4 consecutive spaces.
|
||||||
*
|
*
|
||||||
* @param int $tabLength Number of spaces to replace each tab with
|
* @param int $tabLength Number of spaces to replace each tab with
|
||||||
@@ -490,7 +492,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts each occurence of some consecutive number of spaces, as defined
|
* Converts each occurrence of some consecutive number of spaces, as defined
|
||||||
* by $tabLength, to a tab. By default, each 4 consecutive spaces are
|
* by $tabLength, to a tab. By default, each 4 consecutive spaces are
|
||||||
* converted to a tab.
|
* converted to a tab.
|
||||||
*
|
*
|
||||||
@@ -508,7 +510,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts $str into an URL slug. This includes replacing non-ASCII
|
* Converts the string into an URL slug. This includes replacing non-ASCII
|
||||||
* characters with their closest ASCII equivalents, removing non-alphanumeric
|
* characters with their closest ASCII equivalents, removing non-alphanumeric
|
||||||
* and non-ASCII characters, and replacing whitespace with dashes. The string
|
* and non-ASCII characters, and replacing whitespace with dashes. The string
|
||||||
* is also converted to lowercase.
|
* is also converted to lowercase.
|
||||||
@@ -519,7 +521,7 @@ class Stringy
|
|||||||
{
|
{
|
||||||
$stringy = self::create($this->str, $this->encoding);
|
$stringy = self::create($this->str, $this->encoding);
|
||||||
|
|
||||||
$stringy->str = preg_replace('/[^a-zA-Z\d -]/u', '', $stringy->standardize());
|
$stringy->str = preg_replace('/[^a-zA-Z\d -]/u', '', $stringy->toAscii());
|
||||||
$stringy->str = $stringy->collapseWhitespace()->str;
|
$stringy->str = $stringy->collapseWhitespace()->str;
|
||||||
$stringy->str = str_replace(' ', '-', strtolower($stringy->str));
|
$stringy->str = str_replace(' ', '-', strtolower($stringy->str));
|
||||||
|
|
||||||
@@ -527,7 +529,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str contains $needle, false otherwise.
|
* Returns true if the string contains $needle, false otherwise.
|
||||||
*
|
*
|
||||||
* @param string $needle Substring to look for
|
* @param string $needle Substring to look for
|
||||||
* @return bool Whether or not $str contains $needle
|
* @return bool Whether or not $str contains $needle
|
||||||
@@ -555,7 +557,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts $substring into $str at the $index provided.
|
* Inserts $substring into the string at the $index provided.
|
||||||
*
|
*
|
||||||
* @param string $substring String to be inserted
|
* @param string $substring String to be inserted
|
||||||
* @param int $index The index at which to insert the substring
|
* @param int $index The index at which to insert the substring
|
||||||
@@ -576,7 +578,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Truncates $str to a given length. If $substring is provided, and
|
* Truncates the string to a given length. If $substring is provided, and
|
||||||
* truncating occurs, the string is further truncated so that the substring
|
* truncating occurs, the string is further truncated so that the substring
|
||||||
* may be appended without exceeding the desired length.
|
* may be appended without exceeding the desired length.
|
||||||
*
|
*
|
||||||
@@ -601,8 +603,8 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Truncates $str to a given length, while ensuring that it does not chop
|
* Truncates the string to a given length, while ensuring that it does not
|
||||||
* words. If $substring is provided, and truncating occurs, the string
|
* chop words. If $substring is provided, and truncating occurs, the string
|
||||||
* is further truncated so that the substring may be appended without
|
* is further truncated so that the substring may be appended without
|
||||||
* exceeding the desired length.
|
* exceeding the desired length.
|
||||||
*
|
*
|
||||||
@@ -635,7 +637,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverses $str. A multibyte version of strrev.
|
* Returns a reversed string. A multibyte version of strrev().
|
||||||
*
|
*
|
||||||
* @return Stringy Object with a reversed $str
|
* @return Stringy Object with a reversed $str
|
||||||
*/
|
*/
|
||||||
@@ -653,8 +655,8 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A multibyte str_shuffle function. It randomizes the order of characters
|
* A multibyte str_shuffle() function. It returns a string with its
|
||||||
* in $str.
|
* characters in random order.
|
||||||
*
|
*
|
||||||
* @return Stringy Object with a shuffled $str
|
* @return Stringy Object with a shuffled $str
|
||||||
*/
|
*/
|
||||||
@@ -672,7 +674,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trims $str. An alias for PHP's trim() function.
|
* Returns the trimmed string. An alias for PHP's trim() function.
|
||||||
*
|
*
|
||||||
* @return Stringy Object with a trimmed $str
|
* @return Stringy Object with a trimmed $str
|
||||||
*/
|
*/
|
||||||
@@ -682,7 +684,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the longest common prefix between $str and $otherStr.
|
* Returns the longest common prefix between the string and $otherStr.
|
||||||
*
|
*
|
||||||
* @param string $otherStr Second string for comparison
|
* @param string $otherStr Second string for comparison
|
||||||
* @return Stringy Object with its $str being the longest common prefix
|
* @return Stringy Object with its $str being the longest common prefix
|
||||||
@@ -706,7 +708,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the longest common suffix between $str and $otherStr.
|
* Returns the longest common suffix between the string and $otherStr.
|
||||||
*
|
*
|
||||||
* @param string $otherStr Second string for comparison
|
* @param string $otherStr Second string for comparison
|
||||||
* @return Stringy Object with its $str being the longest common suffix
|
* @return Stringy Object with its $str being the longest common suffix
|
||||||
@@ -730,8 +732,8 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the longest common substring between $str and $otherStr. In the
|
* Returns the longest common substring between the string and $otherStr.
|
||||||
* case of ties, returns that which occurs first.
|
* In the case of ties, it returns that which occurs first.
|
||||||
*
|
*
|
||||||
* @param string $otherStr Second string for comparison
|
* @param string $otherStr Second string for comparison
|
||||||
* @return Stringy Object with its $str being the longest common substring
|
* @return Stringy Object with its $str being the longest common substring
|
||||||
@@ -777,7 +779,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the length of $str. An alias for PHP's mb_strlen() function.
|
* Returns the length of the string. An alias for PHP's mb_strlen() function.
|
||||||
*
|
*
|
||||||
* @return int The number of characters in $str given the encoding
|
* @return int The number of characters in $str given the encoding
|
||||||
*/
|
*/
|
||||||
@@ -787,12 +789,12 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the substring of $str beginning at $start with the specified $length.
|
* Returns the substring beginning at $start with the specified $length.
|
||||||
* It differs from the mb_substr() function in that providing a $length of
|
* It differs from the mb_substr() function in that providing a $length of
|
||||||
* null will return the rest of the string, rather than an empty string.
|
* null will return the rest of the string, rather than an empty string.
|
||||||
*
|
*
|
||||||
* @param int $start Position of the first character to use from str
|
* @param int $start Position of the first character to use
|
||||||
* @param int $length Maximum number of characters used
|
* @param int $length Maximum number of characters used
|
||||||
* @return Stringy Object with its $str being the substring
|
* @return Stringy Object with its $str being the substring
|
||||||
*/
|
*/
|
||||||
public function substr($start, $length = null)
|
public function substr($start, $length = null)
|
||||||
@@ -811,10 +813,10 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the character of $str at $index, with indexes starting at 0.
|
* Returns the character of the string at $index, with indexes starting at 0.
|
||||||
*
|
*
|
||||||
* @param int $index Position of the character
|
* @param int $index Position of the character
|
||||||
* @return Stringy Object with its $str being the selected character
|
* @return Stringy The character at $index
|
||||||
*/
|
*/
|
||||||
public function at($index)
|
public function at($index)
|
||||||
{
|
{
|
||||||
@@ -822,7 +824,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the first $n characters of $str.
|
* Returns the first $n characters of the string.
|
||||||
*
|
*
|
||||||
* @param int $n Number of characters to retrieve from the start
|
* @param int $n Number of characters to retrieve from the start
|
||||||
* @return Stringy Object with its $str being the first $n chars
|
* @return Stringy Object with its $str being the first $n chars
|
||||||
@@ -841,7 +843,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the last $n characters of $str.
|
* Returns the last $n characters of the string.
|
||||||
*
|
*
|
||||||
* @param int $n Number of characters to retrieve from the end
|
* @param int $n Number of characters to retrieve from the end
|
||||||
* @return Stringy Object with its $str being the last $n chars
|
* @return Stringy Object with its $str being the last $n chars
|
||||||
@@ -860,7 +862,8 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that $str begins with $substring.
|
* Ensures that the string begins with $substring. If it doesn't, it's
|
||||||
|
* prepended.
|
||||||
*
|
*
|
||||||
* @param string $substring The substring to add if not present
|
* @param string $substring The substring to add if not present
|
||||||
* @return Stringy Object with its $str prefixed by the $substring
|
* @return Stringy Object with its $str prefixed by the $substring
|
||||||
@@ -876,7 +879,8 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that $str ends with $substring.
|
* Ensures that the string begins with $substring. If it doesn't, it's
|
||||||
|
* appended.
|
||||||
*
|
*
|
||||||
* @param string $substring The substring to add if not present
|
* @param string $substring The substring to add if not present
|
||||||
* @return Stringy Object with its $str suffixed by the $substring
|
* @return Stringy Object with its $str suffixed by the $substring
|
||||||
@@ -892,7 +896,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the prefix $substring if present.
|
* Returns a new string with the prefix $substring removed, if it was present.
|
||||||
*
|
*
|
||||||
* @param string $substring The prefix to remove
|
* @param string $substring The prefix to remove
|
||||||
* @return Stringy Object having a $str without the prefix $substring
|
* @return Stringy Object having a $str without the prefix $substring
|
||||||
@@ -910,7 +914,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the suffix $substring if present.
|
* Returns a new string with the suffix $substring removed, if it was present.
|
||||||
*
|
*
|
||||||
* @param string $substring The suffix to remove
|
* @param string $substring The suffix to remove
|
||||||
* @return Stringy Object having a $str without the suffix $substring
|
* @return Stringy Object having a $str without the suffix $substring
|
||||||
@@ -945,7 +949,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str contains only alphabetic chars, false otherwise.
|
* Returns true if the string contains only alphabetic chars, false otherwise.
|
||||||
*
|
*
|
||||||
* @return bool Whether or not $str contains only alphabetic chars
|
* @return bool Whether or not $str contains only alphabetic chars
|
||||||
*/
|
*/
|
||||||
@@ -955,8 +959,8 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str contains only alphabetic and numeric chars, false
|
* Returns true if the string contains only alphabetic and numeric chars,
|
||||||
* otherwise.
|
* false otherwise.
|
||||||
*
|
*
|
||||||
* @return bool Whether or not $str contains only alphanumeric chars
|
* @return bool Whether or not $str contains only alphanumeric chars
|
||||||
*/
|
*/
|
||||||
@@ -966,7 +970,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str contains only whitespace chars, false otherwise.
|
* Returns true if the string contains only whitespace chars, false otherwise.
|
||||||
*
|
*
|
||||||
* @return bool Whether or not $str contains only whitespace characters
|
* @return bool Whether or not $str contains only whitespace characters
|
||||||
*/
|
*/
|
||||||
@@ -976,7 +980,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str contains only lower case chars, false otherwise.
|
* Returns true if the string contains only lower case chars, false otherwise.
|
||||||
*
|
*
|
||||||
* @return bool Whether or not $str contains only lower case characters
|
* @return bool Whether or not $str contains only lower case characters
|
||||||
*/
|
*/
|
||||||
@@ -986,7 +990,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if $str contains only lower case chars, false otherwise.
|
* Returns true if the string contains only lower case chars, false otherwise.
|
||||||
*
|
*
|
||||||
* @return bool Whether or not $str contains only lower case characters
|
* @return bool Whether or not $str contains only lower case characters
|
||||||
*/
|
*/
|
||||||
@@ -996,11 +1000,11 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of occurences of $substring in $str. An alias for
|
* Returns the number of occurrences of $substring in the given string.
|
||||||
* mb_substr_count()
|
* An alias for mb_substr_count()
|
||||||
*
|
*
|
||||||
* @param string $substring The substring to search for
|
* @param string $substring The substring to search for
|
||||||
* @return int The number of $substring occurences
|
* @return int The number of $substring occurrences
|
||||||
*/
|
*/
|
||||||
public function count($substring)
|
public function count($substring)
|
||||||
{
|
{
|
||||||
@@ -1008,7 +1012,7 @@ class Stringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces all occurrences of $search with $replace in $str.
|
* Returns a string with all occurrences of $search replaced with $replace.
|
||||||
*
|
*
|
||||||
* @param string $search The needle to search for
|
* @param string $search The needle to search for
|
||||||
* @param string $replace The string to replace with
|
* @param string $replace The string to replace with
|
||||||
|
@@ -180,7 +180,7 @@ class CommonTest extends PHPUnit_Framework_TestCase
|
|||||||
return $testData;
|
return $testData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stringsForStandardize()
|
public function stringsForToAscii()
|
||||||
{
|
{
|
||||||
$testData = array(
|
$testData = array(
|
||||||
array('foo bar', 'fòô bàř'),
|
array('foo bar', 'fòô bàř'),
|
||||||
|
@@ -13,6 +13,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testUpperCaseFirst($expected, $str, $encoding = null)
|
public function testUpperCaseFirst($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::upperCaseFirst($str, $encoding);
|
$result = S::upperCaseFirst($str, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testLowerCaseFirst($expected, $str, $encoding = null)
|
public function testLowerCaseFirst($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::lowerCaseFirst($str, $encoding);
|
$result = S::lowerCaseFirst($str, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +33,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testCamelize($expected, $str, $encoding = null)
|
public function testCamelize($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::camelize($str, $encoding);
|
$result = S::camelize($str, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +43,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testUpperCamelize($expected, $str, $encoding = null)
|
public function testUpperCamelize($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::upperCamelize($str, $encoding);
|
$result = S::upperCamelize($str, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +53,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testDasherize($expected, $str, $encoding = null)
|
public function testDasherize($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::dasherize($str, $encoding);
|
$result = S::dasherize($str, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +63,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testUnderscored($expected, $str, $encoding = null)
|
public function testUnderscored($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::underscored($str, $encoding);
|
$result = S::underscored($str, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +73,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testSwapCase($expected, $str, $encoding = null)
|
public function testSwapCase($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::swapCase($str, $encoding);
|
$result = S::swapCase($str, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +84,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$encoding = null)
|
$encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::titleize($str, $ignore, $encoding);
|
$result = S::titleize($str, $ignore, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +94,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testHumanize($expected, $str, $encoding = null)
|
public function testHumanize($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::humanize($str, $encoding);
|
$result = S::humanize($str, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +104,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testTidy($expected, $str)
|
public function testTidy($expected, $str)
|
||||||
{
|
{
|
||||||
$result = S::tidy($str);
|
$result = S::tidy($str);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,15 +114,17 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testCollapseWhitespace($expected, $str)
|
public function testCollapseWhitespace($expected, $str)
|
||||||
{
|
{
|
||||||
$result = S::collapseWhitespace($str);
|
$result = S::collapseWhitespace($str);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider stringsForStandardize
|
* @dataProvider stringsForToAscii
|
||||||
*/
|
*/
|
||||||
public function testStandardize($expected, $str)
|
public function testToAscii($expected, $str)
|
||||||
{
|
{
|
||||||
$result = S::standardize($str);
|
$result = S::toAscii($str);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,6 +135,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$padType = 'right', $encoding = null)
|
$padType = 'right', $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::pad($str, $length, $padStr, $padType, $encoding);
|
$result = S::pad($str, $length, $padStr, $padType, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +146,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$encoding = null)
|
$encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::padLeft($str, $length, $padStr, $encoding);
|
$result = S::padLeft($str, $length, $padStr, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +157,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$encoding = null)
|
$encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::padRight($str, $length, $padStr, $encoding);
|
$result = S::padRight($str, $length, $padStr, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,6 +168,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$encoding = null)
|
$encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::padBoth($str, $length, $padStr, $encoding);
|
$result = S::padBoth($str, $length, $padStr, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,6 +179,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$caseSensitive = true, $encoding = null)
|
$caseSensitive = true, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::startsWith($str, $substring, $caseSensitive, $encoding);
|
$result = S::startsWith($str, $substring, $caseSensitive, $encoding);
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,6 +190,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$caseSensitive = true, $encoding = null)
|
$caseSensitive = true, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::endsWith($str, $substring, $caseSensitive, $encoding);
|
$result = S::endsWith($str, $substring, $caseSensitive, $encoding);
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,6 +200,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testToSpaces($expected, $str, $tabLength = 4)
|
public function testToSpaces($expected, $str, $tabLength = 4)
|
||||||
{
|
{
|
||||||
$result = S::toSpaces($str, $tabLength);
|
$result = S::toSpaces($str, $tabLength);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,6 +210,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testToTabs($expected, $str, $tabLength = 4)
|
public function testToTabs($expected, $str, $tabLength = 4)
|
||||||
{
|
{
|
||||||
$result = S::toTabs($str, $tabLength);
|
$result = S::toTabs($str, $tabLength);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +220,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testSlugify($expected, $str)
|
public function testSlugify($expected, $str)
|
||||||
{
|
{
|
||||||
$result = S::slugify($str);
|
$result = S::slugify($str);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,6 +230,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testContains($expected, $haystack, $needle, $encoding = null)
|
public function testContains($expected, $haystack, $needle, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::contains($haystack, $needle, $encoding);
|
$result = S::contains($haystack, $needle, $encoding);
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,6 +240,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testSurround($expected, $str, $substring)
|
public function testSurround($expected, $str, $substring)
|
||||||
{
|
{
|
||||||
$result = S::surround($str, $substring);
|
$result = S::surround($str, $substring);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,6 +251,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$encoding = null)
|
$encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::insert($str, $substring, $index, $encoding);
|
$result = S::insert($str, $substring, $index, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,6 +262,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$encoding = null)
|
$encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::truncate($str, $length, $substring, $encoding);
|
$result = S::truncate($str, $length, $substring, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +273,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$encoding = null)
|
$encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::safeTruncate($str, $length, $substring, $encoding);
|
$result = S::safeTruncate($str, $length, $substring, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,6 +283,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testReverse($expected, $str, $encoding = null)
|
public function testReverse($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::reverse($str, $encoding);
|
$result = S::reverse($str, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,6 +294,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
// We'll just make sure that the chars are present before/after shuffle
|
// We'll just make sure that the chars are present before/after shuffle
|
||||||
$result = S::shuffle($str, $encoding);
|
$result = S::shuffle($str, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals(count_chars($str), count_chars($result));
|
$this->assertEquals(count_chars($str), count_chars($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,6 +304,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testTrim($expected, $str)
|
public function testTrim($expected, $str)
|
||||||
{
|
{
|
||||||
$result = S::trim($str);
|
$result = S::trim($str);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,6 +315,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$encoding = null)
|
$encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::longestCommonPrefix($str, $otherStr, $encoding);
|
$result = S::longestCommonPrefix($str, $otherStr, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,6 +326,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$encoding = null)
|
$encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::longestCommonSuffix($str, $otherStr, $encoding);
|
$result = S::longestCommonSuffix($str, $otherStr, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,6 +337,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$encoding = null)
|
$encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::longestCommonSubstring($str, $otherStr, $encoding);
|
$result = S::longestCommonSubstring($str, $otherStr, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,6 +348,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$result = S::length($str, $encoding);
|
$result = S::length($str, $encoding);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
$this->assertInternalType('int', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -325,6 +358,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$encoding = null)
|
$encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::substr($str, $start, $length, $encoding);
|
$result = S::substr($str, $start, $length, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,6 +368,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testAt($expected, $str, $index, $encoding = null)
|
public function testAt($expected, $str, $index, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::at($str, $index, $encoding);
|
$result = S::at($str, $index, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,6 +378,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testFirst($expected, $str, $n, $encoding = null)
|
public function testFirst($expected, $str, $n, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::first($str, $n, $encoding);
|
$result = S::first($str, $n, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,6 +388,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testLast($expected, $str, $n, $encoding = null)
|
public function testLast($expected, $str, $n, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::last($str, $n, $encoding);
|
$result = S::last($str, $n, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,6 +398,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testEnsureLeft($expected, $str, $substring, $encoding = null)
|
public function testEnsureLeft($expected, $str, $substring, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::ensureLeft($str, $substring, $encoding);
|
$result = S::ensureLeft($str, $substring, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,6 +408,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testEnsureRight($expected, $str, $substring, $encoding = null)
|
public function testEnsureRight($expected, $str, $substring, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::ensureRight($str, $substring, $encoding);
|
$result = S::ensureRight($str, $substring, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,6 +418,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testRemoveLeft($expected, $str, $substring, $encoding = null)
|
public function testRemoveLeft($expected, $str, $substring, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::removeLeft($str, $substring, $encoding);
|
$result = S::removeLeft($str, $substring, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,6 +428,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testRemoveRight($expected, $str, $substring, $encoding = null)
|
public function testRemoveRight($expected, $str, $substring, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::removeRight($str, $substring, $encoding);
|
$result = S::removeRight($str, $substring, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,6 +438,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testIsAlpha($expected, $str, $encoding = null)
|
public function testIsAlpha($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::isAlpha($str, $encoding);
|
$result = S::isAlpha($str, $encoding);
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,6 +448,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testIsAlphanumeric($expected, $str, $encoding = null)
|
public function testIsAlphanumeric($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::isAlphanumeric($str, $encoding);
|
$result = S::isAlphanumeric($str, $encoding);
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,6 +458,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testIsBlank($expected, $str, $encoding = null)
|
public function testIsBlank($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::isBlank($str, $encoding);
|
$result = S::isBlank($str, $encoding);
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,6 +468,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testIsLowerCase($expected, $str, $encoding = null)
|
public function testIsLowerCase($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::isLowerCase($str, $encoding);
|
$result = S::isLowerCase($str, $encoding);
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,6 +478,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testIsUpperCase($expected, $str, $encoding = null)
|
public function testIsUpperCase($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::isUpperCase($str, $encoding);
|
$result = S::isUpperCase($str, $encoding);
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,6 +488,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
public function testCount($expected, $str, $substring, $encoding = null)
|
public function testCount($expected, $str, $substring, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::count($str, $substring, $encoding);
|
$result = S::count($str, $substring, $encoding);
|
||||||
|
$this->assertInternalType('int', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,6 +499,7 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
$encoding = null)
|
$encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::replace($str, $search, $replace, $encoding);
|
$result = S::replace($str, $search, $replace, $encoding);
|
||||||
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,12 +7,29 @@ use Stringy\Stringy as S;
|
|||||||
|
|
||||||
class StringyTestCase extends CommonTest
|
class StringyTestCase extends CommonTest
|
||||||
{
|
{
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$stringy = S::create('foo bar', 'UTF-8');
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
||||||
|
$this->assertEquals('foo bar', $stringy->str);
|
||||||
|
$this->assertEquals('UTF-8', $stringy->encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testChaining()
|
||||||
|
{
|
||||||
|
$stringy = S::create("Fòô Bàř", 'UTF-8');
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
||||||
|
$result = $stringy->collapseWhitespace()->swapCase()->upperCaseFirst();
|
||||||
|
$this->assertEquals('FÒÔ bÀŘ', $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider stringsForUpperCaseFirst
|
* @dataProvider stringsForUpperCaseFirst
|
||||||
*/
|
*/
|
||||||
public function testUpperCaseFirst($expected, $str, $encoding = null)
|
public function testUpperCaseFirst($expected, $str, $encoding = null)
|
||||||
{
|
{
|
||||||
$result = S::create($str, $encoding)->upperCaseFirst();
|
$result = S::create($str, $encoding)->upperCaseFirst();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +40,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->lowerCaseFirst();
|
$result = $stringy->lowerCaseFirst();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -34,6 +52,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->camelize();
|
$result = $stringy->camelize();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -45,6 +64,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->upperCamelize();
|
$result = $stringy->upperCamelize();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -56,6 +76,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->dasherize();
|
$result = $stringy->dasherize();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -67,6 +88,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->underscored();
|
$result = $stringy->underscored();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -78,6 +100,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->swapCase();
|
$result = $stringy->swapCase();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -90,6 +113,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->titleize($ignore);
|
$result = $stringy->titleize($ignore);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -101,6 +125,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->humanize();
|
$result = $stringy->humanize();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -112,6 +137,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str);
|
$stringy = S::create($str);
|
||||||
$result = $stringy->tidy();
|
$result = $stringy->tidy();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -123,17 +149,19 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str);
|
$stringy = S::create($str);
|
||||||
$result = $stringy->collapseWhitespace();
|
$result = $stringy->collapseWhitespace();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider stringsForStandardize
|
* @dataProvider stringsForToAscii
|
||||||
*/
|
*/
|
||||||
public function testStandardize($expected, $str)
|
public function testToAscii($expected, $str)
|
||||||
{
|
{
|
||||||
$stringy = S::create($str);
|
$stringy = S::create($str);
|
||||||
$result = $stringy->standardize();
|
$result = $stringy->toAscii();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -146,6 +174,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->pad($length, $padStr, $padType);
|
$result = $stringy->pad($length, $padStr, $padType);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -158,6 +187,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->padLeft($length, $padStr);
|
$result = $stringy->padLeft($length, $padStr);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -170,6 +200,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->padRight($length, $padStr);
|
$result = $stringy->padRight($length, $padStr);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -182,6 +213,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->padBoth($length, $padStr);
|
$result = $stringy->padBoth($length, $padStr);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -194,6 +226,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->startsWith($substring, $caseSensitive);
|
$result = $stringy->startsWith($substring, $caseSensitive);
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -206,6 +239,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->endsWith($substring, $caseSensitive);
|
$result = $stringy->endsWith($substring, $caseSensitive);
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -217,6 +251,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str);
|
$stringy = S::create($str);
|
||||||
$result = $stringy->toSpaces($tabLength);
|
$result = $stringy->toSpaces($tabLength);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -228,6 +263,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str);
|
$stringy = S::create($str);
|
||||||
$result = $stringy->toTabs($tabLength);
|
$result = $stringy->toTabs($tabLength);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -239,6 +275,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str);
|
$stringy = S::create($str);
|
||||||
$result = $stringy->slugify();
|
$result = $stringy->slugify();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -250,6 +287,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($haystack, $encoding);
|
$stringy = S::create($haystack, $encoding);
|
||||||
$result = $stringy->contains($needle);
|
$result = $stringy->contains($needle);
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($haystack, $stringy);
|
$this->assertEquals($haystack, $stringy);
|
||||||
}
|
}
|
||||||
@@ -261,6 +299,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str);
|
$stringy = S::create($str);
|
||||||
$result = $stringy->surround($substring);
|
$result = $stringy->surround($substring);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -273,6 +312,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->insert($substring, $index);
|
$result = $stringy->insert($substring, $index);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -285,6 +325,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->truncate($length, $substring);
|
$result = $stringy->truncate($length, $substring);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -296,6 +337,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->reverse();
|
$result = $stringy->reverse();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -308,6 +350,7 @@ class StringyTestCase extends CommonTest
|
|||||||
// We'll just make sure that the chars are present before/after shuffle
|
// We'll just make sure that the chars are present before/after shuffle
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->shuffle();
|
$result = $stringy->shuffle();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals(count_chars($str), count_chars($result));
|
$this->assertEquals(count_chars($str), count_chars($result));
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -319,6 +362,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str);
|
$stringy = S::create($str);
|
||||||
$result = $stringy->trim();
|
$result = $stringy->trim();
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -331,6 +375,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->longestCommonPrefix($otherStr);
|
$result = $stringy->longestCommonPrefix($otherStr);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -343,6 +388,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->longestCommonSubstring($otherStr);
|
$result = $stringy->longestCommonSubstring($otherStr);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -354,6 +400,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->length();
|
$result = $stringy->length();
|
||||||
|
$this->assertInternalType('int', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -366,6 +413,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->substr($start, $length);
|
$result = $stringy->substr($start, $length);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -377,6 +425,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->at($index);
|
$result = $stringy->at($index);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -388,6 +437,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->first($n);
|
$result = $stringy->first($n);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -399,6 +449,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->last($n);
|
$result = $stringy->last($n);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -410,6 +461,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->ensureLeft($substring);
|
$result = $stringy->ensureLeft($substring);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -421,6 +473,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->ensureRight($substring);
|
$result = $stringy->ensureRight($substring);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -432,6 +485,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->removeLeft($substring);
|
$result = $stringy->removeLeft($substring);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -443,6 +497,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->removeRight($substring);
|
$result = $stringy->removeRight($substring);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -454,6 +509,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->isAlpha();
|
$result = $stringy->isAlpha();
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -465,6 +521,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->isAlphanumeric();
|
$result = $stringy->isAlphanumeric();
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -476,6 +533,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->isBlank();
|
$result = $stringy->isBlank();
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -487,6 +545,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->isLowerCase();
|
$result = $stringy->isLowerCase();
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -498,6 +557,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->isUpperCase();
|
$result = $stringy->isUpperCase();
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -509,6 +569,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->count($substring);
|
$result = $stringy->count($substring);
|
||||||
|
$this->assertInternalType('int', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
@@ -521,6 +582,7 @@ class StringyTestCase extends CommonTest
|
|||||||
{
|
{
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
$result = $stringy->replace($search, $replace);
|
$result = $stringy->replace($search, $replace);
|
||||||
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user