mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-09-01 17:12:42 +02:00
Compare commits
35 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 | ||
|
bd90918858 | ||
|
a2d1ec535a | ||
|
b953a85d2c | ||
|
e07a07a076 | ||
|
c4d785d29f |
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,4 +1,23 @@
|
||||
### 2.3.0 (2015-03-19)
|
||||
### 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
|
||||
|
||||
### 2.3.0 (2016-03-19)
|
||||
|
||||
* Add Persian characters in Stringy::charsArray()
|
||||
* Use symfony/polyfill-mbstring to avoid dependency on ext-mbstring
|
||||
|
242
README.md
242
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()
|
||||
@@ -686,7 +741,8 @@ to a lack of support in the bundled version of Oniguruma in PHP < 5.6,
|
||||
and current versions of HHVM (3.8 and below).
|
||||
|
||||
```php
|
||||
s('fòô ')->regexReplace('f[òô]+\s', 'bàř', 'msr'); // 'bàř'
|
||||
s('fòô ')->regexReplace('f[òô]+\s', 'bàř'); // 'bàř'
|
||||
s('fò')->regexReplace('(ò)', '\\1ô'); // 'fòô'
|
||||
```
|
||||
|
||||
##### removeLeft(string $substring)
|
||||
@@ -772,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
|
||||
@@ -793,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.
|
||||
|
539
src/Stringy.php
539
src/Stringy.php
File diff suppressed because it is too large
Load Diff
@@ -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()
|
||||
*/
|
||||
@@ -2372,6 +2462,7 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
|
||||
array('foo', 'bar', '[[:alpha:]]{3}', 'foo'),
|
||||
array('', '', '', '', 'msr', 'UTF-8'),
|
||||
array('bàř', 'fòô ', 'f[òô]+\s', 'bàř', 'msr', 'UTF-8'),
|
||||
array('fòô', 'fò', '(ò)', '\\1ô', 'msr', 'UTF-8'),
|
||||
array('fòô', 'bàř', '[[:alpha:]]{3}', 'fòô', 'msr', 'UTF-8')
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user