mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-09-02 09:33:10 +02:00
Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
edbda419cb | ||
|
e8afcffc7c | ||
|
986260239d | ||
|
841600867d | ||
|
845e8d693d | ||
|
b35270671c | ||
|
0aab4361bf | ||
|
df777da6ac | ||
|
ded4d41d44 | ||
|
569736327a | ||
|
6f2e2851ac | ||
|
553bf37acb | ||
|
916f79221e | ||
|
d71d4f0ad6 | ||
|
de93eab01f | ||
|
9b6404d5c3 | ||
|
27a4f11f2e | ||
|
46de78bda9 | ||
|
cb14fc2e6b | ||
|
090a15f2fd | ||
|
d80347e72a | ||
|
0491ed8db8 | ||
|
eb445b55ef | ||
|
91b153d30e | ||
|
9ebdf88b71 | ||
|
0607751e17 | ||
|
6507f0ac44 | ||
|
4e214a5195 | ||
|
fcc2969210 | ||
|
30d1742082 |
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,3 +1,18 @@
|
||||
### 2.4.0 (2017-03-02)
|
||||
|
||||
* Add startsWithAny
|
||||
* Add endsWithAny
|
||||
* Add stripWhitespace
|
||||
* Fix error handling for unsupported encodings
|
||||
* Change private methods to protected for extending class
|
||||
* Fix safeTruncate for strings without spaces
|
||||
* Additional char support in toAscii, e.g. full width chars and wide
|
||||
non-breaking space
|
||||
|
||||
### 2.3.2 (2016-05-02)
|
||||
|
||||
* Improve support without mbstring
|
||||
|
||||
### 2.3.1 (2016-03-21)
|
||||
|
||||
* Always use root namespace for mbstring functions
|
||||
|
239
README.md
239
README.md
@@ -21,83 +21,128 @@ s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
|
||||
* [Class methods](#class-methods)
|
||||
* [create](#createmixed-str--encoding-)
|
||||
* [Instance methods](#instance-methods)
|
||||
* [append](#appendstring-string)
|
||||
* [at](#atint-index)
|
||||
* [between](#betweenstring-start-string-end--int-offset)
|
||||
* [camelize](#camelize)
|
||||
* [chars](#chars)
|
||||
* [collapseWhitespace](#collapsewhitespace)
|
||||
* [contains](#containsstring-needle--boolean-casesensitive--true-)
|
||||
* [containsAll](#containsallarray-needles--boolean-casesensitive--true-)
|
||||
* [containsAny](#containsanyarray-needles--boolean-casesensitive--true-)
|
||||
* [countSubstr](#countsubstrstring-substring--boolean-casesensitive--true-)
|
||||
* [dasherize](#dasherize)
|
||||
* [delimit](#delimitint-delimiter)
|
||||
* [endsWith](#endswithstring-substring--boolean-casesensitive--true-)
|
||||
* [ensureLeft](#ensureleftstring-substring)
|
||||
* [ensureRight](#ensurerightstring-substring)
|
||||
* [first](#firstint-n)
|
||||
* [getEncoding](#getencoding)
|
||||
* [hasLowerCase](#haslowercase)
|
||||
* [hasUpperCase](#hasuppercase)
|
||||
* [htmlDecode](#htmldecode)
|
||||
* [htmlEncode](#htmlencode)
|
||||
* [humanize](#humanize)
|
||||
* [indexOf](#indexofstring-needle--offset--0-)
|
||||
* [indexOfLast](#indexoflaststring-needle--offset--0-)
|
||||
* [insert](#insertint-index-string-substring)
|
||||
* [isAlpha](#isalpha)
|
||||
* [isAlphanumeric](#isalphanumeric)
|
||||
* [isBase64](#isbase64)
|
||||
* [isBlank](#isblank)
|
||||
* [isHexadecimal](#ishexadecimal)
|
||||
* [isJson](#isjson)
|
||||
* [isLowerCase](#islowercase)
|
||||
* [isSerialized](#isserialized)
|
||||
* [isUpperCase](#isuppercase)
|
||||
* [last](#last)
|
||||
* [length](#length)
|
||||
* [lines](#lines)
|
||||
* [longestCommonPrefix](#longestcommonprefixstring-otherstr)
|
||||
* [longestCommonSuffix](#longestcommonsuffixstring-otherstr)
|
||||
* [longestCommonSubstring](#longestcommonsubstringstring-otherstr)
|
||||
* [lowerCaseFirst](#lowercasefirst)
|
||||
* [pad](#padint-length--string-padstr-----string-padtype--right-)
|
||||
* [padBoth](#padbothint-length--string-padstr----)
|
||||
* [padLeft](#padleftint-length--string-padstr----)
|
||||
* [padRight](#padrightint-length--string-padstr----)
|
||||
* [prepend](#prependstring-string)
|
||||
* [regexReplace](#regexreplacestring-pattern-string-replacement--string-options--msr)
|
||||
* [removeLeft](#removeleftstring-substring)
|
||||
* [removeRight](#removerightstring-substring)
|
||||
* [repeat](#repeatmultiplier)
|
||||
* [replace](#replacestring-search-string-replacement)
|
||||
* [reverse](#reverse)
|
||||
* [safeTruncate](#safetruncateint-length--string-substring---)
|
||||
* [shuffle](#shuffle)
|
||||
* [slugify](#slugify-string-replacement----)
|
||||
* [startsWith](#startswithstring-substring--boolean-casesensitive--true-)
|
||||
* [slice](#sliceint-start--int-end-)
|
||||
* [split](#splitstring-pattern--int-limit-)
|
||||
* [substr](#substrint-start--int-length-)
|
||||
* [surround](#surroundstring-substring)
|
||||
* [swapCase](#swapcase)
|
||||
* [tidy](#tidy)
|
||||
* [titleize](#titleize-array-ignore)
|
||||
* [toAscii](#toascii)
|
||||
* [toBoolean](#toboolean)
|
||||
* [toLowerCase](#tolowercase)
|
||||
* [toSpaces](#tospaces-tablength--4-)
|
||||
* [toTabs](#totabs-tablength--4-)
|
||||
* [toTitleCase](#totitlecase)
|
||||
* [toUpperCase](#touppercase)
|
||||
* [trim](#trim-string-chars)
|
||||
* [trimLeft](#trimleft-string-chars)
|
||||
* [trimRight](#trimright-string-chars)
|
||||
* [truncate](#truncateint-length--string-substring---)
|
||||
* [underscored](#underscored)
|
||||
* [upperCamelize](#uppercamelize)
|
||||
* [upperCaseFirst](#uppercasefirst)
|
||||
<table>
|
||||
<tr>
|
||||
<td>[append](#appendstring-string)</td>
|
||||
<td>[at](#atint-index)</td>
|
||||
<td>[between](#betweenstring-start-string-end--int-offset)</td>
|
||||
<td>[camelize](#camelize)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[chars](#chars)</td>
|
||||
<td>[collapseWhitespace](#collapsewhitespace)</td>
|
||||
<td>[contains](#containsstring-needle--boolean-casesensitive--true-)</td>
|
||||
<td>[containsAll](#containsallarray-needles--boolean-casesensitive--true-)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[containsAny](#containsanyarray-needles--boolean-casesensitive--true-)</td>
|
||||
<td>[countSubstr](#countsubstrstring-substring--boolean-casesensitive--true-)</td>
|
||||
<td>[dasherize](#dasherize)</td>
|
||||
<td>[delimit](#delimitint-delimiter)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[endsWith](#endswithstring-substring--boolean-casesensitive--true-)</td>
|
||||
<td>[endsWithAny](#endsWithAnystring-substrings--boolean-casesensitive--true-)</td>
|
||||
<td>[ensureLeft](#ensureleftstring-substring)</td>
|
||||
<td>[ensureRight](#ensurerightstring-substring)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[first](#firstint-n)</td>
|
||||
<td>[getEncoding](#getencoding)</td>
|
||||
<td>[hasLowerCase](#haslowercase)</td>
|
||||
<td>[hasUpperCase](#hasuppercase)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[htmlDecode](#htmldecode)</td>
|
||||
<td>[htmlEncode](#htmlencode)</td>
|
||||
<td>[humanize](#humanize)</td>
|
||||
<td>[indexOf](#indexofstring-needle--offset--0-)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[indexOfLast](#indexoflaststring-needle--offset--0-)</td>
|
||||
<td>[insert](#insertint-index-string-substring)</td>
|
||||
<td>[isAlpha](#isalpha)</td>
|
||||
<td>[isAlphanumeric](#isalphanumeric)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[isBase64](#isbase64)</td>
|
||||
<td>[isBlank](#isblank)</td>
|
||||
<td>[isHexadecimal](#ishexadecimal)</td>
|
||||
<td>[isJson](#isjson)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[isLowerCase](#islowercase)</td>
|
||||
<td>[isSerialized](#isserialized)</td>
|
||||
<td>[isUpperCase](#isuppercase)</td>
|
||||
<td>[last](#last)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[length](#length)</td>
|
||||
<td>[lines](#lines)</td>
|
||||
<td>[longestCommonPrefix](#longestcommonprefixstring-otherstr)</td>
|
||||
<td>[longestCommonSuffix](#longestcommonsuffixstring-otherstr)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[longestCommonSubstring](#longestcommonsubstringstring-otherstr)</td>
|
||||
<td>[lowerCaseFirst](#lowercasefirst)</td>
|
||||
<td>[pad](#padint-length--string-padstr-----string-padtype--right-)</td>
|
||||
<td>[padBoth](#padbothint-length--string-padstr----)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[padLeft](#padleftint-length--string-padstr----)</td>
|
||||
<td>[padRight](#padrightint-length--string-padstr----)</td>
|
||||
<td>[prepend](#prependstring-string)</td>
|
||||
<td>[regexReplace](#regexreplacestring-pattern-string-replacement--string-options--msr)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[removeLeft](#removeleftstring-substring)</td>
|
||||
<td>[removeRight](#removerightstring-substring)</td>
|
||||
<td>[repeat](#repeatmultiplier)</td>
|
||||
<td>[replace](#replacestring-search-string-replacement)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[reverse](#reverse)</td>
|
||||
<td>[safeTruncate](#safetruncateint-length--string-substring---)</td>
|
||||
<td>[shuffle](#shuffle)</td>
|
||||
<td>[slugify](#slugify-string-replacement----)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[startsWith](#startswithstring-substring--boolean-casesensitive--true-)</td>
|
||||
<td>[startsWithAny](#startswithanystring-substrings--boolean-casesensitive--true-)</td>
|
||||
<td>[slice](#sliceint-start--int-end-)</td>
|
||||
<td>[split](#splitstring-pattern--int-limit-)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[stripWhitespace](#stripwhitespace)</td>
|
||||
<td>[substr](#substrint-start--int-length-)</td>
|
||||
<td>[surround](#surroundstring-substring)</td>
|
||||
<td>[swapCase](#swapcase)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[tidy](#tidy)</td>
|
||||
<td>[titleize](#titleize-array-ignore)</td>
|
||||
<td>[toAscii](#toascii)</td>
|
||||
<td>[toBoolean](#toboolean)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[toLowerCase](#tolowercase)</td>
|
||||
<td>[toSpaces](#tospaces-tablength--4-)</td>
|
||||
<td>[toTabs](#totabs-tablength--4-)</td>
|
||||
<td>[toTitleCase](#totitlecase)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[toUpperCase](#touppercase)</td>
|
||||
<td>[trim](#trim-string-chars)</td>
|
||||
<td>[trimLeft](#trimleft-string-chars)</td>
|
||||
<td>[trimRight](#trimright-string-chars)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[truncate](#truncateint-length--string-substring---)</td>
|
||||
<td>[underscored](#underscored)</td>
|
||||
<td>[upperCamelize](#uppercamelize)</td>
|
||||
<td>[upperCaseFirst](#uppercasefirst)</td>
|
||||
</tr>
|
||||
</table>
|
||||
* [Extensions](#extensions)
|
||||
* [Tests](#tests)
|
||||
* [License](#license)
|
||||
@@ -131,7 +176,7 @@ in your composer.json file:
|
||||
|
||||
```json
|
||||
"require": {
|
||||
"danielstjules/stringy": "~2.3"
|
||||
"danielstjules/stringy": "~2.4"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -239,9 +284,9 @@ integer, boolean, etc.
|
||||
```php
|
||||
use Stringy\StaticStringy as S;
|
||||
|
||||
// Translates to Stringy::create('fòôbàř', 'UTF-8')->slice(0, 3);
|
||||
// Translates to Stringy::create('fòôbàř')->slice(0, 3);
|
||||
// Returns a Stringy object with the string "fòô"
|
||||
S::slice('fòôbàř', 0, 3, 'UTF-8');
|
||||
S::slice('fòôbàř', 0, 3);
|
||||
```
|
||||
|
||||
## Class methods
|
||||
@@ -255,7 +300,7 @@ then returns the initialized object. Throws an InvalidArgumentException
|
||||
if the first argument is an array or object without a __toString method.
|
||||
|
||||
```php
|
||||
$stringy = S::create('fòôbàř', 'UTF-8'); // 'fòôbàř'
|
||||
$stringy = S::create('fòôbàř'); // 'fòôbàř'
|
||||
```
|
||||
|
||||
## Instance Methods
|
||||
@@ -391,6 +436,16 @@ setting $caseSensitive to false.
|
||||
s('fòôbàř')->endsWith('bàř', true); // true
|
||||
```
|
||||
|
||||
##### endsWithAny(string[] $substrings [, boolean $caseSensitive = true ])
|
||||
|
||||
Returns true if the string ends with any of $substrings, false otherwise.
|
||||
By default, the comparison is case-sensitive, but can be made insensitive
|
||||
by setting $caseSensitive to false.
|
||||
|
||||
```php
|
||||
s('fòôbàř')->endsWith(['bàř', 'baz'], true); // true
|
||||
```
|
||||
|
||||
##### ensureLeft(string $substring)
|
||||
|
||||
Ensures that the string begins with $substring. If it doesn't, it's prepended.
|
||||
@@ -420,7 +475,7 @@ s('fòôbàř')->first(3); // 'fòô'
|
||||
Returns the encoding used by the Stringy object.
|
||||
|
||||
```php
|
||||
s('fòôbàř', 'UTF-8')->getEncoding(); // 'UTF-8'
|
||||
s('fòôbàř')->getEncoding(); // 'UTF-8'
|
||||
```
|
||||
|
||||
##### hasLowerCase()
|
||||
@@ -773,6 +828,16 @@ by setting $caseSensitive to false.
|
||||
s('FÒÔbàřbaz')->startsWith('fòôbàř', false); // true
|
||||
```
|
||||
|
||||
##### startsWithAny(string[] $substrings [, boolean $caseSensitive = true ])
|
||||
|
||||
Returns true if the string begins with any of $substrings, false
|
||||
otherwise. By default the comparison is case-sensitive, but can be made
|
||||
insensitive by setting $caseSensitive to false.
|
||||
|
||||
```php
|
||||
s('FÒÔbàřbaz')->startsWith(['fòô', 'bàř'], false); // true
|
||||
```
|
||||
|
||||
##### slice(int $start [, int $end ])
|
||||
|
||||
Returns the substring beginning at $start, and up to, but not including
|
||||
@@ -794,6 +859,16 @@ results.
|
||||
s('foo,bar,baz')->split(',', 2); // ['foo', 'bar']
|
||||
```
|
||||
|
||||
##### stripWhitespace()
|
||||
|
||||
Strip all whitespace characters. This includes tabs and newline
|
||||
characters, as well as multibyte whitespace such as the thin space
|
||||
and ideographic space.
|
||||
|
||||
```php
|
||||
s(' Ο συγγραφέας ')->stripWhitespace(); // 'Οσυγγραφέας'
|
||||
```
|
||||
|
||||
##### substr(int $start [, int $length ])
|
||||
|
||||
Returns the substring beginning at $start with the specified $length.
|
||||
|
417
src/Stringy.php
417
src/Stringy.php
@@ -64,7 +64,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
*
|
||||
* @param mixed $str Value to modify, after being cast to string
|
||||
* @param string $encoding The character encoding
|
||||
* @return Stringy A Stringy object
|
||||
* @return static A Stringy object
|
||||
* @throws \InvalidArgumentException if an array or object without a
|
||||
* __toString method is passed as the first argument
|
||||
*/
|
||||
@@ -87,7 +87,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Returns a new string with $string appended.
|
||||
*
|
||||
* @param string $string The string to append
|
||||
* @return Stringy Object with appended $string
|
||||
* @return static Object with appended $string
|
||||
*/
|
||||
public function append($string)
|
||||
{
|
||||
@@ -98,7 +98,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Returns the character at $index, with indexes starting at 0.
|
||||
*
|
||||
* @param int $index Position of the character
|
||||
* @return Stringy The character at $index
|
||||
* @return static The character at $index
|
||||
*/
|
||||
public function at($index)
|
||||
{
|
||||
@@ -111,9 +111,9 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* search for the start string.
|
||||
*
|
||||
* @param string $start Delimiter marking the start of the substring
|
||||
* @param string $end Delimiter marketing the end of the substring
|
||||
* @param string $end Delimiter marking the end of the substring
|
||||
* @param int $offset Index from which to begin the search
|
||||
* @return Stringy Object whose $str has been converted to an URL slug
|
||||
* @return static Object whose $str is a substring between $start and $end
|
||||
*/
|
||||
public function between($start, $end, $offset = 0)
|
||||
{
|
||||
@@ -136,7 +136,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* capitalizes letters following digits, spaces, dashes and underscores,
|
||||
* and removes spaces, dashes, as well as underscores.
|
||||
*
|
||||
* @return Stringy Object with $str in camelCase
|
||||
* @return static Object with $str in camelCase
|
||||
*/
|
||||
public function camelize()
|
||||
{
|
||||
@@ -187,7 +187,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* single space. This includes tabs and newline characters, as well as
|
||||
* multibyte whitespace such as the thin space and ideographic space.
|
||||
*
|
||||
* @return Stringy Object with a trimmed $str and condensed whitespace
|
||||
* @return static Object with a trimmed $str and condensed whitespace
|
||||
*/
|
||||
public function collapseWhitespace()
|
||||
{
|
||||
@@ -298,7 +298,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* inserted before uppercase characters (with the exception of the first
|
||||
* character of the string), and in place of spaces as well as underscores.
|
||||
*
|
||||
* @return Stringy Object with a dasherized $str
|
||||
* @return static Object with a dasherized $str
|
||||
*/
|
||||
public function dasherize()
|
||||
{
|
||||
@@ -312,19 +312,18 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* and underscores. Alpha delimiters are not converted to lowercase.
|
||||
*
|
||||
* @param string $delimiter Sequence used to separate parts of the string
|
||||
* @return Stringy Object with a delimited $str
|
||||
* @return static Object with a delimited $str
|
||||
*/
|
||||
public function delimit($delimiter)
|
||||
{
|
||||
// Save current regex encoding so we can reset it after
|
||||
$regexEncoding = \mb_regex_encoding();
|
||||
\mb_regex_encoding($this->encoding);
|
||||
$regexEncoding = $this->regexEncoding();
|
||||
$this->regexEncoding($this->encoding);
|
||||
|
||||
$str = \mb_ereg_replace('\B([A-Z])', '-\1', $this->trim());
|
||||
$str = $this->eregReplace('\B([A-Z])', '-\1', $this->trim());
|
||||
$str = \mb_strtolower($str, $this->encoding);
|
||||
$str = \mb_ereg_replace('[-_\s]+', $delimiter, $str);
|
||||
$str = $this->eregReplace('[-_\s]+', $delimiter, $str);
|
||||
|
||||
\mb_regex_encoding($regexEncoding);
|
||||
$this->regexEncoding($regexEncoding);
|
||||
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
@@ -354,12 +353,37 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
return (string) $substring === $endOfStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string ends with any of $substrings, false otherwise.
|
||||
* By default, the comparison is case-sensitive, but can be made insensitive
|
||||
* by setting $caseSensitive to false.
|
||||
*
|
||||
* @param string[] $substrings Substrings to look for
|
||||
* @param bool $caseSensitive Whether or not to enforce
|
||||
* case-sensitivity
|
||||
* @return bool Whether or not $str ends with $substring
|
||||
*/
|
||||
public function endsWithAny($substrings, $caseSensitive = true)
|
||||
{
|
||||
if (empty($substrings)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($substrings as $substring) {
|
||||
if ($this->endsWith($substring, $caseSensitive)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the string begins with $substring. If it doesn't, it's
|
||||
* prepended.
|
||||
*
|
||||
* @param string $substring The substring to add if not present
|
||||
* @return Stringy Object with its $str prefixed by the $substring
|
||||
* @return static Object with its $str prefixed by the $substring
|
||||
*/
|
||||
public function ensureLeft($substring)
|
||||
{
|
||||
@@ -377,7 +401,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* appended.
|
||||
*
|
||||
* @param string $substring The substring to add if not present
|
||||
* @return Stringy Object with its $str suffixed by the $substring
|
||||
* @return static Object with its $str suffixed by the $substring
|
||||
*/
|
||||
public function ensureRight($substring)
|
||||
{
|
||||
@@ -394,7 +418,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Returns the first $n characters of the string.
|
||||
*
|
||||
* @param int $n Number of characters to retrieve from the start
|
||||
* @return Stringy Object with its $str being the first $n chars
|
||||
* @return static Object with its $str being the first $n chars
|
||||
*/
|
||||
public function first($n)
|
||||
{
|
||||
@@ -460,7 +484,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* http://php.net/manual/en/function.html-entity-decode.php
|
||||
*
|
||||
* @param int|null $flags Optional flags
|
||||
* @return Stringy Object with the resulting $str after being html decoded.
|
||||
* @return static Object with the resulting $str after being html decoded.
|
||||
*/
|
||||
public function htmlDecode($flags = ENT_COMPAT)
|
||||
{
|
||||
@@ -475,7 +499,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* for a list of flags.
|
||||
*
|
||||
* @param int|null $flags Optional flags
|
||||
* @return Stringy Object with the resulting $str after being html encoded.
|
||||
* @return static Object with the resulting $str after being html encoded.
|
||||
*/
|
||||
public function htmlEncode($flags = ENT_COMPAT)
|
||||
{
|
||||
@@ -488,7 +512,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Capitalizes the first word of the string, replaces underscores with
|
||||
* spaces, and strips '_id'.
|
||||
*
|
||||
* @return Stringy Object with a humanized $str
|
||||
* @return static Object with a humanized $str
|
||||
*/
|
||||
public function humanize()
|
||||
{
|
||||
@@ -533,7 +557,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
*
|
||||
* @param string $substring String to be inserted
|
||||
* @param int $index The index at which to insert the substring
|
||||
* @return Stringy Object with the resulting $str after the insertion
|
||||
* @return static Object with the resulting $str after the insertion
|
||||
*/
|
||||
public function insert($substring, $index)
|
||||
{
|
||||
@@ -660,7 +684,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Returns the last $n characters of the string.
|
||||
*
|
||||
* @param int $n Number of characters to retrieve from the end
|
||||
* @return Stringy Object with its $str being the last $n chars
|
||||
* @return static Object with its $str being the last $n chars
|
||||
*/
|
||||
public function last($n)
|
||||
{
|
||||
@@ -688,11 +712,11 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Splits on newlines and carriage returns, returning an array of Stringy
|
||||
* objects corresponding to the lines in the string.
|
||||
*
|
||||
* @return Stringy[] An array of Stringy objects
|
||||
* @return static[] An array of Stringy objects
|
||||
*/
|
||||
public function lines()
|
||||
{
|
||||
$array = \mb_split('[\r\n]{1,2}', $this->str);
|
||||
$array = $this->split('[\r\n]{1,2}', $this->str);
|
||||
for ($i = 0; $i < count($array); $i++) {
|
||||
$array[$i] = static::create($array[$i], $this->encoding);
|
||||
}
|
||||
@@ -704,7 +728,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Returns the longest common prefix between the string and $otherStr.
|
||||
*
|
||||
* @param string $otherStr Second string for comparison
|
||||
* @return Stringy Object with its $str being the longest common prefix
|
||||
* @return static Object with its $str being the longest common prefix
|
||||
*/
|
||||
public function longestCommonPrefix($otherStr)
|
||||
{
|
||||
@@ -729,7 +753,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Returns the longest common suffix between the string and $otherStr.
|
||||
*
|
||||
* @param string $otherStr Second string for comparison
|
||||
* @return Stringy Object with its $str being the longest common suffix
|
||||
* @return static Object with its $str being the longest common suffix
|
||||
*/
|
||||
public function longestCommonSuffix($otherStr)
|
||||
{
|
||||
@@ -755,7 +779,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* In the case of ties, it returns that which occurs first.
|
||||
*
|
||||
* @param string $otherStr Second string for comparison
|
||||
* @return Stringy Object with its $str being the longest common substring
|
||||
* @return static Object with its $str being the longest common substring
|
||||
*/
|
||||
public function longestCommonSubstring($otherStr)
|
||||
{
|
||||
@@ -802,7 +826,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
/**
|
||||
* Converts the first character of the string to lower case.
|
||||
*
|
||||
* @return Stringy Object with the first character of $str being lower case
|
||||
* @return static Object with the first character of $str being lower case
|
||||
*/
|
||||
public function lowerCaseFirst()
|
||||
{
|
||||
@@ -895,7 +919,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* @param int $length Desired string length after padding
|
||||
* @param string $padStr String used to pad, defaults to space
|
||||
* @param string $padType One of 'left', 'right', 'both'
|
||||
* @return Stringy Object with a padded $str
|
||||
* @return static Object with a padded $str
|
||||
* @throws /InvalidArgumentException If $padType isn't one of 'right',
|
||||
* 'left' or 'both'
|
||||
*/
|
||||
@@ -922,7 +946,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
*
|
||||
* @param int $length Desired string length after padding
|
||||
* @param string $padStr String used to pad, defaults to space
|
||||
* @return Stringy String with padding applied
|
||||
* @return static String with padding applied
|
||||
*/
|
||||
public function padBoth($length, $padStr = ' ')
|
||||
{
|
||||
@@ -938,7 +962,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
*
|
||||
* @param int $length Desired string length after padding
|
||||
* @param string $padStr String used to pad, defaults to space
|
||||
* @return Stringy String with left padding
|
||||
* @return static String with left padding
|
||||
*/
|
||||
public function padLeft($length, $padStr = ' ')
|
||||
{
|
||||
@@ -951,7 +975,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
*
|
||||
* @param int $length Desired string length after padding
|
||||
* @param string $padStr String used to pad, defaults to space
|
||||
* @return Stringy String with right padding
|
||||
* @return static String with right padding
|
||||
*/
|
||||
public function padRight($length, $padStr = ' ')
|
||||
{
|
||||
@@ -962,7 +986,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Returns a new string starting with $string.
|
||||
*
|
||||
* @param string $string The string to append
|
||||
* @return Stringy Object with appended $string
|
||||
* @return static Object with appended $string
|
||||
*/
|
||||
public function prepend($string)
|
||||
{
|
||||
@@ -979,15 +1003,15 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* @param string $pattern The regular expression pattern
|
||||
* @param string $replacement The string to replace with
|
||||
* @param string $options Matching conditions to be used
|
||||
* @return Stringy Object with the resulting $str after the replacements
|
||||
* @return static Object with the resulting $str after the replacements
|
||||
*/
|
||||
public function regexReplace($pattern, $replacement, $options = 'msr')
|
||||
{
|
||||
$regexEncoding = \mb_regex_encoding();
|
||||
\mb_regex_encoding($this->encoding);
|
||||
$regexEncoding = $this->regexEncoding();
|
||||
$this->regexEncoding($this->encoding);
|
||||
|
||||
$str = \mb_ereg_replace($pattern, $replacement, $this->str, $options);
|
||||
\mb_regex_encoding($regexEncoding);
|
||||
$str = $this->eregReplace($pattern, $replacement, $this->str, $options);
|
||||
$this->regexEncoding($regexEncoding);
|
||||
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
@@ -996,7 +1020,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Returns a new string with the prefix $substring removed, if present.
|
||||
*
|
||||
* @param string $substring The prefix to remove
|
||||
* @return Stringy Object having a $str without the prefix $substring
|
||||
* @return static Object having a $str without the prefix $substring
|
||||
*/
|
||||
public function removeLeft($substring)
|
||||
{
|
||||
@@ -1014,7 +1038,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Returns a new string with the suffix $substring removed, if present.
|
||||
*
|
||||
* @param string $substring The suffix to remove
|
||||
* @return Stringy Object having a $str without the suffix $substring
|
||||
* @return static Object having a $str without the suffix $substring
|
||||
*/
|
||||
public function removeRight($substring)
|
||||
{
|
||||
@@ -1032,7 +1056,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Returns a repeated string given a multiplier. An alias for str_repeat.
|
||||
*
|
||||
* @param int $multiplier The number of times to repeat the string
|
||||
* @return Stringy Object with a repeated str
|
||||
* @return static Object with a repeated str
|
||||
*/
|
||||
public function repeat($multiplier)
|
||||
{
|
||||
@@ -1046,7 +1070,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
*
|
||||
* @param string $search The needle to search for
|
||||
* @param string $replacement The string to replace with
|
||||
* @return Stringy Object with the resulting $str after the replacements
|
||||
* @return static Object with the resulting $str after the replacements
|
||||
*/
|
||||
public function replace($search, $replacement)
|
||||
{
|
||||
@@ -1056,7 +1080,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
/**
|
||||
* Returns a reversed string. A multibyte version of strrev().
|
||||
*
|
||||
* @return Stringy Object with a reversed $str
|
||||
* @return static Object with a reversed $str
|
||||
*/
|
||||
public function reverse()
|
||||
{
|
||||
@@ -1079,7 +1103,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
*
|
||||
* @param int $length Desired length of the truncated string
|
||||
* @param string $substring The substring to append if it can fit
|
||||
* @return Stringy Object with the resulting $str after truncating
|
||||
* @return static Object with the resulting $str after truncating
|
||||
*/
|
||||
public function safeTruncate($length, $substring = '')
|
||||
{
|
||||
@@ -1099,7 +1123,9 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
if (mb_strpos($stringy->str, ' ', $length - 1, $encoding) != $length) {
|
||||
// Find pos of the last occurrence of a space, get up to that
|
||||
$lastPos = \mb_strrpos($truncated, ' ', 0, $encoding);
|
||||
$truncated = \mb_substr($truncated, 0, $lastPos, $encoding);
|
||||
if ($lastPos !== false) {
|
||||
$truncated = \mb_substr($truncated, 0, $lastPos, $encoding);
|
||||
}
|
||||
}
|
||||
|
||||
$stringy->str = $truncated . $substring;
|
||||
@@ -1111,7 +1137,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* A multibyte str_shuffle() function. It returns a string with its
|
||||
* characters in random order.
|
||||
*
|
||||
* @return Stringy Object with a shuffled $str
|
||||
* @return static Object with a shuffled $str
|
||||
*/
|
||||
public function shuffle()
|
||||
{
|
||||
@@ -1134,7 +1160,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* is also converted to lowercase.
|
||||
*
|
||||
* @param string $replacement The string used to replace whitespace
|
||||
* @return Stringy Object whose $str has been converted to an URL slug
|
||||
* @return static Object whose $str has been converted to an URL slug
|
||||
*/
|
||||
public function slugify($replacement = '-')
|
||||
{
|
||||
@@ -1171,6 +1197,31 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
return (string) $substring === $startOfStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string begins with any of $substrings, false
|
||||
* otherwise. By default the comparison is case-sensitive, but can be made
|
||||
* insensitive by setting $caseSensitive to false.
|
||||
*
|
||||
* @param string[] $substrings Substrings to look for
|
||||
* @param bool $caseSensitive Whether or not to enforce
|
||||
* case-sensitivity
|
||||
* @return bool Whether or not $str starts with $substring
|
||||
*/
|
||||
public function startsWithAny($substrings, $caseSensitive = true)
|
||||
{
|
||||
if (empty($substrings)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($substrings as $substring) {
|
||||
if ($this->startsWith($substring, $caseSensitive)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the substring beginning at $start, and up to, but not including
|
||||
* the index specified by $end. If $end is omitted, the function extracts
|
||||
@@ -1179,7 +1230,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
*
|
||||
* @param int $start Initial index from which to begin extraction
|
||||
* @param int $end Optional index at which to end extraction
|
||||
* @return Stringy Object with its $str being the extracted substring
|
||||
* @return static Object with its $str being the extracted substring
|
||||
*/
|
||||
public function slice($start, $end = null)
|
||||
{
|
||||
@@ -1193,9 +1244,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
$length = $end - $start;
|
||||
}
|
||||
|
||||
$str = \mb_substr($this->str, $start, $length, $this->encoding);
|
||||
|
||||
return static::create($str, $this->encoding);
|
||||
return $this->substr($start, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1205,7 +1254,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
*
|
||||
* @param string $pattern The regex with which to split the string
|
||||
* @param int $limit Optional maximum number of results to return
|
||||
* @return Stringy[] An array of Stringy objects
|
||||
* @return static[] An array of Stringy objects
|
||||
*/
|
||||
public function split($pattern, $limit = null)
|
||||
{
|
||||
@@ -1214,19 +1263,30 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
}
|
||||
|
||||
// mb_split errors when supplied an empty pattern in < PHP 5.4.13
|
||||
// and current versions of HHVM (3.8 and below)
|
||||
// and HHVM < 3.8
|
||||
if ($pattern === '') {
|
||||
return array(static::create($this->str, $this->encoding));
|
||||
}
|
||||
|
||||
$regexEncoding = \mb_regex_encoding();
|
||||
\mb_regex_encoding($this->encoding);
|
||||
$regexEncoding = $this->regexEncoding();
|
||||
$this->regexEncoding($this->encoding);
|
||||
|
||||
// mb_split returns the remaining unsplit string in the last index when
|
||||
// supplying a limit
|
||||
$limit = ($limit > 0) ? $limit += 1 : -1;
|
||||
$array = \mb_split($pattern, $this->str, $limit);
|
||||
\mb_regex_encoding($regexEncoding);
|
||||
|
||||
static $functionExists;
|
||||
if ($functionExists === null) {
|
||||
$functionExists = function_exists('\mb_split');
|
||||
}
|
||||
|
||||
if ($functionExists) {
|
||||
$array = \mb_split($pattern, $this->str, $limit);
|
||||
} else if ($this->supportsEncoding()) {
|
||||
$array = \preg_split("/$pattern/", $this->str, $limit);
|
||||
}
|
||||
|
||||
$this->regexEncoding($regexEncoding);
|
||||
|
||||
if ($limit > 0 && count($array) === $limit) {
|
||||
array_pop($array);
|
||||
@@ -1239,6 +1299,18 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip all whitespace characters. This includes tabs and newline
|
||||
* characters, as well as multibyte whitespace such as the thin space
|
||||
* and ideographic space.
|
||||
*
|
||||
* @return static Object with whitespace stripped
|
||||
*/
|
||||
public function stripWhitespace()
|
||||
{
|
||||
return $this->regexReplace('[[:space:]]+', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the substring beginning at $start with the specified $length.
|
||||
* It differs from the mb_substr() function in that providing a $length of
|
||||
@@ -1246,7 +1318,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
*
|
||||
* @param int $start Position of the first character to use
|
||||
* @param int $length Maximum number of characters used
|
||||
* @return Stringy Object with its $str being the substring
|
||||
* @return static Object with its $str being the substring
|
||||
*/
|
||||
public function substr($start, $length = null)
|
||||
{
|
||||
@@ -1260,7 +1332,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Surrounds $str with the given substring.
|
||||
*
|
||||
* @param string $substring The substring to add to both sides
|
||||
* @return Stringy Object whose $str had the substring both prepended and
|
||||
* @return static Object whose $str had the substring both prepended and
|
||||
* appended
|
||||
*/
|
||||
public function surround($substring)
|
||||
@@ -1273,7 +1345,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
/**
|
||||
* Returns a case swapped version of the string.
|
||||
*
|
||||
* @return Stringy Object whose $str has each character's case swapped
|
||||
* @return static Object whose $str has each character's case swapped
|
||||
*/
|
||||
public function swapCase()
|
||||
{
|
||||
@@ -1300,7 +1372,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Windows-1252 (commonly used in Word documents) replaced by their ASCII
|
||||
* equivalents.
|
||||
*
|
||||
* @return Stringy Object whose $str has those characters removed
|
||||
* @return static Object whose $str has those characters removed
|
||||
*/
|
||||
public function tidy()
|
||||
{
|
||||
@@ -1325,7 +1397,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* capitalized.
|
||||
*
|
||||
* @param array $ignore An array of words not to capitalize
|
||||
* @return Stringy Object with a titleized $str
|
||||
* @return static Object with a titleized $str
|
||||
*/
|
||||
public function titleize($ignore = null)
|
||||
{
|
||||
@@ -1356,7 +1428,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
*
|
||||
* @param bool $removeUnsupported Whether or not to remove the
|
||||
* unsupported characters
|
||||
* @return Stringy Object whose $str contains only ASCII characters
|
||||
* @return static Object whose $str contains only ASCII characters
|
||||
*/
|
||||
public function toAscii($removeUnsupported = true)
|
||||
{
|
||||
@@ -1411,7 +1483,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Converts all characters in the string to lowercase. An alias for PHP's
|
||||
* mb_strtolower().
|
||||
*
|
||||
* @return Stringy Object with all characters of $str being lowercase
|
||||
* @return static Object with all characters of $str being lowercase
|
||||
*/
|
||||
public function toLowerCase()
|
||||
{
|
||||
@@ -1425,7 +1497,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* $tabLength. By default, each tab is converted to 4 consecutive spaces.
|
||||
*
|
||||
* @param int $tabLength Number of spaces to replace each tab with
|
||||
* @return Stringy Object whose $str has had tabs switched to spaces
|
||||
* @return static Object whose $str has had tabs switched to spaces
|
||||
*/
|
||||
public function toSpaces($tabLength = 4)
|
||||
{
|
||||
@@ -1441,7 +1513,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* are converted to a tab.
|
||||
*
|
||||
* @param int $tabLength Number of spaces to replace with a tab
|
||||
* @return Stringy Object whose $str has had spaces switched to tabs
|
||||
* @return static Object whose $str has had spaces switched to tabs
|
||||
*/
|
||||
public function toTabs($tabLength = 4)
|
||||
{
|
||||
@@ -1454,7 +1526,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
/**
|
||||
* Converts the first character of each word in the string to uppercase.
|
||||
*
|
||||
* @return Stringy Object with all characters of $str being title-cased
|
||||
* @return static Object with all characters of $str being title-cased
|
||||
*/
|
||||
public function toTitleCase()
|
||||
{
|
||||
@@ -1467,7 +1539,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* Converts all characters in the string to uppercase. An alias for PHP's
|
||||
* mb_strtoupper().
|
||||
*
|
||||
* @return Stringy Object with all characters of $str being uppercase
|
||||
* @return static Object with all characters of $str being uppercase
|
||||
*/
|
||||
public function toUpperCase()
|
||||
{
|
||||
@@ -1482,7 +1554,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* string of characters to strip instead of the defaults.
|
||||
*
|
||||
* @param string $chars Optional string of characters to strip
|
||||
* @return Stringy Object with a trimmed $str
|
||||
* @return static Object with a trimmed $str
|
||||
*/
|
||||
public function trim($chars = null)
|
||||
{
|
||||
@@ -1497,7 +1569,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* string of characters to strip instead of the defaults.
|
||||
*
|
||||
* @param string $chars Optional string of characters to strip
|
||||
* @return Stringy Object with a trimmed $str
|
||||
* @return static Object with a trimmed $str
|
||||
*/
|
||||
public function trimLeft($chars = null)
|
||||
{
|
||||
@@ -1512,7 +1584,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* string of characters to strip instead of the defaults.
|
||||
*
|
||||
* @param string $chars Optional string of characters to strip
|
||||
* @return Stringy Object with a trimmed $str
|
||||
* @return static Object with a trimmed $str
|
||||
*/
|
||||
public function trimRight($chars = null)
|
||||
{
|
||||
@@ -1528,7 +1600,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
*
|
||||
* @param int $length Desired length of the truncated string
|
||||
* @param string $substring The substring to append if it can fit
|
||||
* @return Stringy Object with the resulting $str after truncating
|
||||
* @return static Object with the resulting $str after truncating
|
||||
*/
|
||||
public function truncate($length, $substring = '')
|
||||
{
|
||||
@@ -1553,7 +1625,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* of the first character of the string), and in place of spaces as well as
|
||||
* dashes.
|
||||
*
|
||||
* @return Stringy Object with an underscored $str
|
||||
* @return static Object with an underscored $str
|
||||
*/
|
||||
public function underscored()
|
||||
{
|
||||
@@ -1565,7 +1637,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* surrounding spaces, capitalizes letters following digits, spaces, dashes
|
||||
* and underscores, and removes spaces, dashes, underscores.
|
||||
*
|
||||
* @return Stringy Object with $str in UpperCamelCase
|
||||
* @return static Object with $str in UpperCamelCase
|
||||
*/
|
||||
public function upperCamelize()
|
||||
{
|
||||
@@ -1575,7 +1647,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
/**
|
||||
* Converts the first character of the supplied string to upper case.
|
||||
*
|
||||
* @return Stringy Object with the first character of $str being upper case
|
||||
* @return static Object with the first character of $str being upper case
|
||||
*/
|
||||
public function upperCaseFirst()
|
||||
{
|
||||
@@ -1599,64 +1671,68 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
if (isset($charsArray)) return $charsArray;
|
||||
|
||||
return $charsArray = array(
|
||||
'0' => array('°', '₀', '۰'),
|
||||
'1' => array('¹', '₁', '۱'),
|
||||
'2' => array('²', '₂', '۲'),
|
||||
'3' => array('³', '₃', '۳'),
|
||||
'4' => array('⁴', '₄', '۴', '٤'),
|
||||
'5' => array('⁵', '₅', '۵', '٥'),
|
||||
'6' => array('⁶', '₆', '۶', '٦'),
|
||||
'7' => array('⁷', '₇', '۷'),
|
||||
'8' => array('⁸', '₈', '۸'),
|
||||
'9' => array('⁹', '₉', '۹'),
|
||||
'0' => array('°', '₀', '۰', '0'),
|
||||
'1' => array('¹', '₁', '۱', '1'),
|
||||
'2' => array('²', '₂', '۲', '2'),
|
||||
'3' => array('³', '₃', '۳', '3'),
|
||||
'4' => array('⁴', '₄', '۴', '٤', '4'),
|
||||
'5' => array('⁵', '₅', '۵', '٥', '5'),
|
||||
'6' => array('⁶', '₆', '۶', '٦', '6'),
|
||||
'7' => array('⁷', '₇', '۷', '7'),
|
||||
'8' => array('⁸', '₈', '۸', '8'),
|
||||
'9' => array('⁹', '₉', '۹', '9'),
|
||||
'a' => array('à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ',
|
||||
'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å',
|
||||
'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ',
|
||||
'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά',
|
||||
'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ',
|
||||
'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا'),
|
||||
'b' => array('б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ'),
|
||||
'c' => array('ç', 'ć', 'č', 'ĉ', 'ċ'),
|
||||
'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا', 'a'),
|
||||
'b' => array('б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ', 'b'),
|
||||
'c' => array('ç', 'ć', 'č', 'ĉ', 'ċ', 'c'),
|
||||
'd' => array('ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ',
|
||||
'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ'),
|
||||
'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ', 'd'),
|
||||
'e' => array('é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ',
|
||||
'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ',
|
||||
'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э',
|
||||
'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ'),
|
||||
'f' => array('ф', 'φ', 'ف', 'ƒ', 'ფ'),
|
||||
'g' => array('ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ'),
|
||||
'h' => array('ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ'),
|
||||
'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ', 'e'),
|
||||
'f' => array('ф', 'φ', 'ف', 'ƒ', 'ფ', 'f'),
|
||||
'g' => array('ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ',
|
||||
'g'),
|
||||
'h' => array('ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ', 'h'),
|
||||
'i' => array('í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į',
|
||||
'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ',
|
||||
'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ',
|
||||
'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი',
|
||||
'इ', 'ی'),
|
||||
'j' => array('ĵ', 'ј', 'Ј', 'ჯ', 'ج'),
|
||||
'k' => array('ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک'),
|
||||
'l' => array('ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ'),
|
||||
'm' => array('м', 'μ', 'م', 'မ', 'მ'),
|
||||
'इ', 'ی', 'i'),
|
||||
'j' => array('ĵ', 'ј', 'Ј', 'ჯ', 'ج', 'j'),
|
||||
'k' => array('ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ',
|
||||
'ک', 'k'),
|
||||
'l' => array('ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ',
|
||||
'l'),
|
||||
'm' => array('м', 'μ', 'م', 'မ', 'მ', 'm'),
|
||||
'n' => array('ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န',
|
||||
'ნ'),
|
||||
'ნ', 'n'),
|
||||
'o' => array('ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ',
|
||||
'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő',
|
||||
'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό',
|
||||
'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ'),
|
||||
'p' => array('п', 'π', 'ပ', 'პ', 'پ'),
|
||||
'q' => array('ყ'),
|
||||
'r' => array('ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ'),
|
||||
'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ', 'o'),
|
||||
'p' => array('п', 'π', 'ပ', 'პ', 'پ', 'p'),
|
||||
'q' => array('ყ', 'q'),
|
||||
'r' => array('ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ', 'r'),
|
||||
's' => array('ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ',
|
||||
'ſ', 'ს'),
|
||||
'ſ', 'ს', 's'),
|
||||
't' => array('ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ',
|
||||
'თ', 'ტ'),
|
||||
'თ', 'ტ', 't'),
|
||||
'u' => array('ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ',
|
||||
'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ',
|
||||
'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ'),
|
||||
'v' => array('в', 'ვ', 'ϐ'),
|
||||
'w' => array('ŵ', 'ω', 'ώ', 'ဝ', 'ွ'),
|
||||
'x' => array('χ', 'ξ'),
|
||||
'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ', 'u',
|
||||
'ў'),
|
||||
'v' => array('в', 'ვ', 'ϐ', 'v'),
|
||||
'w' => array('ŵ', 'ω', 'ώ', 'ဝ', 'ွ', 'w'),
|
||||
'x' => array('χ', 'ξ', 'x'),
|
||||
'y' => array('ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ',
|
||||
'ϋ', 'ύ', 'ΰ', 'ي', 'ယ'),
|
||||
'z' => array('ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ'),
|
||||
'ϋ', 'ύ', 'ΰ', 'ي', 'ယ', 'y'),
|
||||
'z' => array('ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ', 'z'),
|
||||
'aa' => array('ع', 'आ', 'آ'),
|
||||
'ae' => array('ä', 'æ', 'ǽ'),
|
||||
'ai' => array('ऐ'),
|
||||
@@ -1691,41 +1767,45 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Å', 'Ā', 'Ą',
|
||||
'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ',
|
||||
'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ',
|
||||
'Ὰ', 'Ά', 'ᾼ', 'А', 'Ǻ', 'Ǎ'),
|
||||
'B' => array('Б', 'Β', 'ब'),
|
||||
'C' => array('Ç','Ć', 'Č', 'Ĉ', 'Ċ'),
|
||||
'D' => array('Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'),
|
||||
'Ὰ', 'Ά', 'ᾼ', 'А', 'Ǻ', 'Ǎ', 'A'),
|
||||
'B' => array('Б', 'Β', 'ब', 'B'),
|
||||
'C' => array('Ç','Ć', 'Č', 'Ĉ', 'Ċ', 'C'),
|
||||
'D' => array('Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ',
|
||||
'D'),
|
||||
'E' => array('É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ',
|
||||
'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ',
|
||||
'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э',
|
||||
'Є', 'Ə'),
|
||||
'F' => array('Ф', 'Φ'),
|
||||
'G' => array('Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ'),
|
||||
'H' => array('Η', 'Ή', 'Ħ'),
|
||||
'Є', 'Ə', 'E'),
|
||||
'F' => array('Ф', 'Φ', 'F'),
|
||||
'G' => array('Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ', 'G'),
|
||||
'H' => array('Η', 'Ή', 'Ħ', 'H'),
|
||||
'I' => array('Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į',
|
||||
'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ',
|
||||
'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ'),
|
||||
'K' => array('К', 'Κ'),
|
||||
'L' => array('Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', 'ल'),
|
||||
'M' => array('М', 'Μ'),
|
||||
'N' => array('Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν'),
|
||||
'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ',
|
||||
'I'),
|
||||
'J' => array('J'),
|
||||
'K' => array('К', 'Κ', 'K'),
|
||||
'L' => array('Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', 'ल', 'L'),
|
||||
'M' => array('М', 'Μ', 'M'),
|
||||
'N' => array('Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν', 'N'),
|
||||
'O' => array('Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ',
|
||||
'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ø', 'Ō', 'Ő',
|
||||
'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ',
|
||||
'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ'),
|
||||
'P' => array('П', 'Π'),
|
||||
'R' => array('Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ'),
|
||||
'S' => array('Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ'),
|
||||
'T' => array('Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ'),
|
||||
'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ', 'O'),
|
||||
'P' => array('П', 'Π', 'P'),
|
||||
'Q' => array('Q'),
|
||||
'R' => array('Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ', 'R'),
|
||||
'S' => array('Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ', 'S'),
|
||||
'T' => array('Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ', 'T'),
|
||||
'U' => array('Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ',
|
||||
'Ự', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У', 'Ǔ', 'Ǖ',
|
||||
'Ǘ', 'Ǚ', 'Ǜ'),
|
||||
'V' => array('В'),
|
||||
'W' => array('Ω', 'Ώ', 'Ŵ'),
|
||||
'X' => array('Χ', 'Ξ'),
|
||||
'Ǘ', 'Ǚ', 'Ǜ', 'U', 'Ў'),
|
||||
'V' => array('В', 'V'),
|
||||
'W' => array('Ω', 'Ώ', 'Ŵ', 'W'),
|
||||
'X' => array('Χ', 'Ξ', 'X'),
|
||||
'Y' => array('Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ',
|
||||
'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ'),
|
||||
'Z' => array('Ź', 'Ž', 'Ż', 'З', 'Ζ'),
|
||||
'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ', 'Y'),
|
||||
'Z' => array('Ź', 'Ž', 'Ż', 'З', 'Ζ', 'Z'),
|
||||
'AE' => array('Ä', 'Æ', 'Ǽ'),
|
||||
'CH' => array('Ч'),
|
||||
'DJ' => array('Ђ'),
|
||||
@@ -1752,7 +1832,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
"\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84",
|
||||
"\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87",
|
||||
"\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A",
|
||||
"\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"),
|
||||
"\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80",
|
||||
"\xEF\xBE\xA0"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1763,9 +1844,9 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* @param int $left Length of left padding
|
||||
* @param int $right Length of right padding
|
||||
* @param string $padStr String used to pad
|
||||
* @return Stringy String with padding applied
|
||||
* @return static String with padding applied
|
||||
*/
|
||||
private function applyPadding($left = 0, $right = 0, $padStr = ' ')
|
||||
protected function applyPadding($left = 0, $right = 0, $padStr = ' ')
|
||||
{
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
$length = \mb_strlen($padStr, $stringy->encoding);
|
||||
@@ -1793,14 +1874,64 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
* @param string $pattern Regex pattern to match against
|
||||
* @return bool Whether or not $str matches the pattern
|
||||
*/
|
||||
private function matchesPattern($pattern)
|
||||
protected function matchesPattern($pattern)
|
||||
{
|
||||
$regexEncoding = \mb_regex_encoding();
|
||||
\mb_regex_encoding($this->encoding);
|
||||
$regexEncoding = $this->regexEncoding();
|
||||
$this->regexEncoding($this->encoding);
|
||||
|
||||
$match = \mb_ereg_match($pattern, $this->str);
|
||||
\mb_regex_encoding($regexEncoding);
|
||||
$this->regexEncoding($regexEncoding);
|
||||
|
||||
return $match;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for mb_ereg_replace with a fallback to preg_replace if the
|
||||
* mbstring module is not installed.
|
||||
*/
|
||||
protected function eregReplace($pattern, $replacement, $string, $option = 'msr')
|
||||
{
|
||||
static $functionExists;
|
||||
if ($functionExists === null) {
|
||||
$functionExists = function_exists('\mb_split');
|
||||
}
|
||||
|
||||
if ($functionExists) {
|
||||
return \mb_ereg_replace($pattern, $replacement, $string, $option);
|
||||
} else if ($this->supportsEncoding()) {
|
||||
$option = str_replace('r', '', $option);
|
||||
return \preg_replace("/$pattern/u$option", $replacement, $string);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for mb_regex_encoding which default to a noop if the mbstring
|
||||
* module is not installed.
|
||||
*/
|
||||
protected function regexEncoding()
|
||||
{
|
||||
static $functionExists;
|
||||
|
||||
if ($functionExists === null) {
|
||||
$functionExists = function_exists('\mb_regex_encoding');
|
||||
}
|
||||
|
||||
if ($functionExists) {
|
||||
$args = func_get_args();
|
||||
return call_user_func_array('\mb_regex_encoding', $args);
|
||||
}
|
||||
}
|
||||
|
||||
protected function supportsEncoding()
|
||||
{
|
||||
$supported = array('UTF-8' => true, 'ASCII' => true);
|
||||
|
||||
if (isset($supported[$this->encoding])) {
|
||||
return true;
|
||||
} else {
|
||||
throw new \RuntimeException('Stringy method requires the ' .
|
||||
'mbstring module for encodings other than ASCII and UTF-8. ' .
|
||||
'Encoding used: ' . $this->encoding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -844,6 +844,36 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider startsWithProviderAny()
|
||||
*/
|
||||
public function testStartsWithAny($expected, $str, $substrings,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->startsWithAny($substrings, $caseSensitive);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
public function startsWithProviderAny()
|
||||
{
|
||||
return array(
|
||||
array(true, 'foo bars', array('foo bar')),
|
||||
array(true, 'FOO bars', array('foo bar'), false),
|
||||
array(true, 'FOO bars', array('foo bar', 'foo BAR'), false),
|
||||
array(true, 'FÒÔ bàřs', array('foo bar', 'fòô bàř'), false, 'UTF-8'),
|
||||
array(true, 'fòô bàřs', array('foo bar', 'fòô BÀŘ'), false, 'UTF-8'),
|
||||
array(false, 'foo bar', array('bar')),
|
||||
array(false, 'foo bar', array('foo bars')),
|
||||
array(false, 'FOO bar', array('foo bars')),
|
||||
array(false, 'FOO bars', array('foo BAR')),
|
||||
array(false, 'FÒÔ bàřs', array('fòô bàř'), true, 'UTF-8'),
|
||||
array(false, 'fòô bàřs', array('fòô BÀŘ'), true, 'UTF-8'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider endsWithProvider()
|
||||
*/
|
||||
@@ -874,6 +904,36 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider endsWithAnyProvider()
|
||||
*/
|
||||
public function testEndsWithAny($expected, $str, $substrings,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->endsWithAny($substrings, $caseSensitive);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
public function endsWithAnyProvider()
|
||||
{
|
||||
return array(
|
||||
array(true, 'foo bars', array('foo', 'o bars')),
|
||||
array(true, 'FOO bars', array('foo', 'o bars'), false),
|
||||
array(true, 'FOO bars', array('foo', 'o BARs'), false),
|
||||
array(true, 'FÒÔ bàřs', array('foo', 'ô bàřs'), false, 'UTF-8'),
|
||||
array(true, 'fòô bàřs', array('foo', 'ô BÀŘs'), false, 'UTF-8'),
|
||||
array(false, 'foo bar', array('foo')),
|
||||
array(false, 'foo bar', array('foo', 'foo bars')),
|
||||
array(false, 'FOO bar', array('foo', 'foo bars')),
|
||||
array(false, 'FOO bars', array('foo', 'foo BARS')),
|
||||
array(false, 'FÒÔ bàřs', array('fòô', 'fòô bàřs'), true, 'UTF-8'),
|
||||
array(false, 'fòô bàřs', array('fòô', 'fòô BÀŘS'), true, 'UTF-8'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider toBooleanProvider()
|
||||
*/
|
||||
@@ -1349,18 +1409,18 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
|
||||
array('Test foo...', 'Test foo bar', 11, '...'),
|
||||
array('Test...', 'Test foo bar', 8, '...'),
|
||||
array('Test...', 'Test foo bar', 7, '...'),
|
||||
array('...', 'Test foo bar', 4, '...'),
|
||||
array('T...', 'Test foo bar', 4, '...'),
|
||||
array('Test....', 'Test foo bar', 11, '....'),
|
||||
array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'),
|
||||
array('Test fòô', 'Test fòô bàř', 11, '', 'UTF-8'),
|
||||
array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'),
|
||||
array('Test', 'Test fòô bàř', 7, '', 'UTF-8'),
|
||||
array('Test', 'Test fòô bàř', 4, '', 'UTF-8'),
|
||||
array('Test fòô bàř', 'Test fòô bàř', 12, 'ϰϰ', 'UTF-8'),
|
||||
array('Test fòôϰϰ', 'Test fòô bàř', 11, 'ϰϰ', 'UTF-8'),
|
||||
array('Testϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'),
|
||||
array('Testϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'),
|
||||
array('ϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'),
|
||||
array('Tëst fòô bàř', 'Tëst fòô bàř', 12, '', 'UTF-8'),
|
||||
array('Tëst fòô', 'Tëst fòô bàř', 11, '', 'UTF-8'),
|
||||
array('Tëst fòô', 'Tëst fòô bàř', 8, '', 'UTF-8'),
|
||||
array('Tëst', 'Tëst fòô bàř', 7, '', 'UTF-8'),
|
||||
array('Tëst', 'Tëst fòô bàř', 4, '', 'UTF-8'),
|
||||
array('Tëst fòô bàř', 'Tëst fòô bàř', 12, 'ϰϰ', 'UTF-8'),
|
||||
array('Tëst fòôϰϰ', 'Tëst fòô bàř', 11, 'ϰϰ', 'UTF-8'),
|
||||
array('Tëstϰϰ', 'Tëst fòô bàř', 8, 'ϰϰ', 'UTF-8'),
|
||||
array('Tëstϰϰ', 'Tëst fòô bàř', 7, 'ϰϰ', 'UTF-8'),
|
||||
array('Tëϰϰ', 'Tëst fòô bàř', 4, 'ϰϰ', 'UTF-8'),
|
||||
array('What are your plans...', 'What are your plans today?', 22, '...')
|
||||
);
|
||||
}
|
||||
@@ -1727,6 +1787,36 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stripWhitespaceProvider()
|
||||
*/
|
||||
public function testStripWhitespace($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->stripWhitespace();
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
public function stripWhitespaceProvider()
|
||||
{
|
||||
return array(
|
||||
array('foobar', ' foo bar '),
|
||||
array('teststring', 'test string'),
|
||||
array('Οσυγγραφέας', ' Ο συγγραφέας '),
|
||||
array('123', ' 123 '),
|
||||
array('', ' ', 'UTF-8'), // no-break space (U+00A0)
|
||||
array('', ' ', 'UTF-8'), // spaces U+2000 to U+200A
|
||||
array('', ' ', 'UTF-8'), // narrow no-break space (U+202F)
|
||||
array('', ' ', 'UTF-8'), // medium mathematical space (U+205F)
|
||||
array('', ' ', 'UTF-8'), // ideographic space (U+3000)
|
||||
array('123', ' 1 2 3 ', 'UTF-8'),
|
||||
array('', ' '),
|
||||
array('', ''),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider substrProvider()
|
||||
*/
|
||||
|
Reference in New Issue
Block a user