mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-31 16:51:57 +02:00
Compare commits
101 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4749c205db | ||
|
fe3368bd8b | ||
|
7763df3c3b | ||
|
397d2ca2f8 | ||
|
2c295fd15d | ||
|
9a5601efef | ||
|
e42f165471 | ||
|
1a2e771ff8 | ||
|
f9eab1b657 | ||
|
f9729788c4 | ||
|
f1009d0267 | ||
|
9d1073f4f5 | ||
|
c2a554253c | ||
|
3cf18e9e42 | ||
|
04b12c9500 | ||
|
b2386b6c33 | ||
|
1172a75d1e | ||
|
4ebf9aee3d | ||
|
61b986a3e6 | ||
|
2bd4be60bb | ||
|
0aa476d44c | ||
|
f63646dcba | ||
|
97e607dc5d | ||
|
a9a4ce461f | ||
|
9a0f0e16cb | ||
|
e9cd229808 | ||
|
4974407729 | ||
|
8a36b8d3f0 | ||
|
66c2a98e83 | ||
|
36c3fd05d2 | ||
|
f3bd5b6c62 | ||
|
dd34bc6f85 | ||
|
f490aa2894 | ||
|
40974608d4 | ||
|
8676bd9d9b | ||
|
f4327a2583 | ||
|
571dc93d1e | ||
|
62f6fd7b3a | ||
|
8b834482df | ||
|
08a72a72dd | ||
|
6a7b0391b2 | ||
|
d6fa00bb1c | ||
|
d1452263bd | ||
|
9da55d5d4f | ||
|
b515598227 | ||
|
28b65615d7 | ||
|
7b88b4f3da | ||
|
70e5b9c38b | ||
|
e0d50f0b8f | ||
|
c5365f256f | ||
|
401af084c7 | ||
|
773477cdd8 | ||
|
26444e4429 | ||
|
f3d32c79b0 | ||
|
98c1013623 | ||
|
91d8da4741 | ||
|
49cdd5b1e6 | ||
|
2fe42b46a1 | ||
|
9baa545f23 | ||
|
640fc5b26b | ||
|
d661047fb3 | ||
|
26fe399396 | ||
|
31c4ba145f | ||
|
5a1be9bf20 | ||
|
28c3db01c5 | ||
|
27ef5a8914 | ||
|
350d1e6f8e | ||
|
ce58c93fc2 | ||
|
d60422d197 | ||
|
3cc12c2ee7 | ||
|
8e16ad472d | ||
|
3f926c654a | ||
|
f8fc711ae1 | ||
|
628c467a67 | ||
|
24aa843639 | ||
|
bb6ea99c52 | ||
|
d1df244678 | ||
|
9a929d1860 | ||
|
583789b9e3 | ||
|
f00e3d5d80 | ||
|
c31e41f57a | ||
|
722f30d132 | ||
|
26a0fed52e | ||
|
1c0026ca00 | ||
|
da5ee7057d | ||
|
410ceac663 | ||
|
857650f278 | ||
|
bc11fce93e | ||
|
fc885d777d | ||
|
9d2863b983 | ||
|
037184e3d9 | ||
|
8ac1918386 | ||
|
7cb6709fd4 | ||
|
a663802c2c | ||
|
7e91d1ead2 | ||
|
abf3e38c1c | ||
|
5a5c39d02b | ||
|
c577684e0a | ||
|
681463de87 | ||
|
90de5cca00 | ||
|
a0b7615210 |
@@ -5,6 +5,3 @@ php:
|
||||
- 5.4
|
||||
- 5.3
|
||||
- hhvm
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
42
CHANGELOG.md
42
CHANGELOG.md
@@ -1,3 +1,45 @@
|
||||
### 1.10.0 (2015-07-22)
|
||||
|
||||
* Added trimLeft, trimRight
|
||||
* Added support for unicode whitespace to trim
|
||||
* Added delimit
|
||||
* Added indexOf and indexOfLast
|
||||
* Added htmlEncode and htmlDecode
|
||||
* Added "Ç" in toAscii()
|
||||
|
||||
### 1.9.0 (2015-02-09)
|
||||
|
||||
* Added hasUpperCase and hasLowerCase
|
||||
* Added $removeUnsupported parameter to toAscii()
|
||||
* Improved toAscii support with additional Unicode spaces, Vietnamese chars,
|
||||
and numerous other characters
|
||||
* Separated the charsArray from toAscii as a protected method that may be
|
||||
extended by inheriting classes
|
||||
* Chars array is cached for better performance
|
||||
|
||||
### 1.8.1 (2015-01-08)
|
||||
|
||||
* Optimized chars()
|
||||
* Added "ä Ä Ö Ü"" in toAscii()
|
||||
* Added support for Unicode spaces in toAscii()
|
||||
* Replaced instances of self::create() with static::create()
|
||||
* Added missing test cases for safeTruncate() and longestCommonSuffix()
|
||||
* Updated Stringy\create() to avoid collision when it already exists
|
||||
|
||||
### 1.8.0 (2015-01-03)
|
||||
|
||||
* Listed ext-mbstring in composer.json
|
||||
* Added Stringy\create function for PHP 5.6
|
||||
|
||||
### 1.7.0 (2014-10-14)
|
||||
|
||||
* Added containsAll and containsAny
|
||||
* Light cleanup
|
||||
|
||||
### 1.6.0 (2014-09-14)
|
||||
|
||||
* Added toTitleCase
|
||||
|
||||
### 1.5.2 (2014-07-09)
|
||||
|
||||
* Announced support for HHVM
|
||||
|
250
README.md
250
README.md
@@ -1,29 +1,39 @@
|
||||

|
||||

|
||||
|
||||
A PHP library with a variety of string manipulation functions with multibyte
|
||||
support. Offers both OO method chaining and a procedural-style static wrapper.
|
||||
Tested and compatible with PHP 5.3+ and HHVM. Inspired by underscore.string.js.
|
||||
A PHP string manipulation library with multibyte support. Offers both OO method
|
||||
chaining and a procedural-style static wrapper. Tested and compatible with
|
||||
PHP 5.3+ and HHVM. Inspired by underscore.string.js.
|
||||
|
||||
[](https://travis-ci.org/danielstjules/Stringy)
|
||||
[](https://travis-ci.org/danielstjules/Stringy)
|
||||
|
||||
* [Requiring/Loading](#requiringloading)
|
||||
* [OO and Procedural](#oo-and-procedural)
|
||||
* [Implemented Interfaces](#implemented-interfaces)
|
||||
* [PHP 5.6 Creation](#php-56-creation)
|
||||
* [Methods](#methods)
|
||||
* [at](#at)
|
||||
* [camelize](#camelize)
|
||||
* [chars](#chars)
|
||||
* [collapseWhitespace](#collapsewhitespace)
|
||||
* [contains](#contains)
|
||||
* [containsAll](#containsall)
|
||||
* [containsAny](#containsany)
|
||||
* [countSubstr](#countsubstr)
|
||||
* [create](#create)
|
||||
* [dasherize](#dasherize)
|
||||
* [delimit](#delimit)
|
||||
* [endsWith](#endswith)
|
||||
* [ensureLeft](#ensureleft)
|
||||
* [ensureRight](#ensureright)
|
||||
* [first](#first)
|
||||
* [getEncoding](#getencoding)
|
||||
* [hasLowerCase](#haslowercase)
|
||||
* [hasUpperCase](#hasuppercase)
|
||||
* [htmlDecode](#htmldecode)
|
||||
* [htmlEncode](#htmlencode)
|
||||
* [humanize](#humanize)
|
||||
* [indexOf](#indexof)
|
||||
* [indexOfLast](#indexoflast)
|
||||
* [insert](#insert)
|
||||
* [isAlpha](#isalpha)
|
||||
* [isAlphanumeric](#isalphanumeric)
|
||||
@@ -61,8 +71,11 @@ Tested and compatible with PHP 5.3+ and HHVM. Inspired by underscore.string.js.
|
||||
* [toLowerCase](#tolowercase)
|
||||
* [toSpaces](#tospaces)
|
||||
* [toTabs](#totabs)
|
||||
* [toTitleCase](#totitlecase)
|
||||
* [toUpperCase](#touppercase)
|
||||
* [trim](#trim)
|
||||
* [trimLeft](#trimLeft)
|
||||
* [trimRight](#trimRight)
|
||||
* [truncate](#truncate)
|
||||
* [underscored](#underscored)
|
||||
* [upperCamelize](#uppercamelize)
|
||||
@@ -76,9 +89,13 @@ Tested and compatible with PHP 5.3+ and HHVM. Inspired by underscore.string.js.
|
||||
If you're using Composer to manage dependencies, you can include the following
|
||||
in your composer.json file:
|
||||
|
||||
```json
|
||||
{
|
||||
"require": {
|
||||
"danielstjules/stringy": ">=1.5.2"
|
||||
"danielstjules/stringy": "~1.10"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then, after running `composer update` or `php composer.phar update`, you can
|
||||
load the class using Composer's autoloading:
|
||||
@@ -164,6 +181,21 @@ $stringy[3]; // OutOfBoundsException
|
||||
$stringy[2] = 'a'; // Exception
|
||||
```
|
||||
|
||||
## PHP 5.6 Creation
|
||||
|
||||
As of PHP 5.6, [`use function`](https://wiki.php.net/rfc/use_function) is
|
||||
available for importing functions. Stringy exposes a namespaced function,
|
||||
`Stringy\create`, which emits the same behaviour as `Stringy\Stringy::create()`.
|
||||
If running PHP 5.6, or another runtime that supports the `use function` syntax,
|
||||
you can take advantage of an even simpler API as seen below:
|
||||
|
||||
``` php
|
||||
use function Stringy\create as s;
|
||||
|
||||
// Instead of: S::create('Fòô Bàř', 'UTF-8')
|
||||
s('Fòô Bàř', 'UTF-8')->collapseWhitespace()->swapCase();
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
In the list below, any static method other than S::create refers to a method in
|
||||
@@ -244,6 +276,36 @@ S::create('Ο συγγραφέας είπε', 'UTF-8')->contains('συγγραφ
|
||||
S::contains('Ο συγγραφέας είπε', 'συγγραφέας', 'UTF-8'); // true
|
||||
```
|
||||
|
||||
#### containsAll
|
||||
|
||||
$stringy->containsAll(array $needles [, boolean $caseSensitive = true ])
|
||||
|
||||
S::containsAll(string $haystack, array $needles [, boolean $caseSensitive = true [, string $encoding ]])
|
||||
|
||||
Returns true if the string contains all $needles, false otherwise. By
|
||||
default the comparison is case-sensitive, but can be made insensitive by
|
||||
setting $caseSensitive to false.
|
||||
|
||||
```php
|
||||
S::create('Str contains foo and bar')->containsAll(array('foo', 'bar'));
|
||||
S::containsAll('Str contains foo and bar', array('foo', 'bar')); // true
|
||||
```
|
||||
|
||||
#### containsAny
|
||||
|
||||
$stringy->containsAny(array $needles [, boolean $caseSensitive = true ])
|
||||
|
||||
S::containsAny(string $haystack, array $needles [, boolean $caseSensitive = true [, string $encoding ]])
|
||||
|
||||
Returns true if the string contains any $needles, false otherwise. By
|
||||
default the comparison is case-sensitive, but can be made insensitive by
|
||||
setting $caseSensitive to false.
|
||||
|
||||
```php
|
||||
S::create('Str contains foo')->containsAny(array('foo', 'bar'));
|
||||
S::containsAny('Str contains foo', array('foo', 'bar')); // true
|
||||
```
|
||||
|
||||
#### countSubstr
|
||||
|
||||
$stringy->countSubstr(string $substring [, boolean $caseSensitive = true ])
|
||||
@@ -261,7 +323,7 @@ S::countSubstr('Ο συγγραφέας είπε', 'α', 'UTF-8'); // 2
|
||||
|
||||
#### create
|
||||
|
||||
S::create(mixed $str, [, $encoding ])
|
||||
S::create(mixed $str [, $encoding ])
|
||||
|
||||
Creates a Stringy object and assigns both str and encoding properties
|
||||
the supplied values. $str is cast to a string prior to assignment, and if
|
||||
@@ -288,6 +350,22 @@ S::create('TestDCase')->dasherize();
|
||||
S::dasherize('TestDCase'); // 'test-d-case'
|
||||
```
|
||||
|
||||
#### delimit
|
||||
|
||||
$stringy->delimit($delimiter);
|
||||
|
||||
S::delimit(string $str [, string $delimiter, string $encoding ])
|
||||
|
||||
Returns a lowercase and trimmed string separated by the given delimiter.
|
||||
Delimiters are inserted before uppercase characters (with the exception
|
||||
of the first character of the string), and in place of spaces, dashes,
|
||||
and underscores. Alpha delimiters are not converted to lowercase.
|
||||
|
||||
```php
|
||||
S::create('TestDCase')->delimit('>>');
|
||||
S::delimit('TestCase', '>>'); // 'test>>case'
|
||||
```
|
||||
|
||||
#### endsWith
|
||||
|
||||
$stringy->endsWith(string $substring [, boolean $caseSensitive = true ])
|
||||
@@ -352,6 +430,58 @@ Returns the encoding used by the Stringy object.
|
||||
S::create('fòô bàř', 'UTF-8')->getEncoding(); // 'UTF-8'
|
||||
```
|
||||
|
||||
#### hasLowerCase
|
||||
|
||||
$stringy->hasLowerCase()
|
||||
|
||||
S::hasLowerCase(string $str [, string $encoding ])
|
||||
|
||||
Returns true if the string contains a lower case char, false otherwise.
|
||||
|
||||
```php
|
||||
S::create('fòô bàř', 'UTF-8')->hasLowerCase();
|
||||
S::hasLowerCase('fòô bàř', 'UTF-8'); // true
|
||||
```
|
||||
|
||||
#### hasUpperCase
|
||||
|
||||
$stringy->hasUpperCase()
|
||||
|
||||
S::hasUpperCase(string $str [, string $encoding ])
|
||||
|
||||
Returns true if the string contains an upper case char, false otherwise.
|
||||
|
||||
```php
|
||||
S::create('fòô bàř', 'UTF-8')->hasUpperCase();
|
||||
S::hasUpperCase('fòô bàř', 'UTF-8'); // false
|
||||
```
|
||||
|
||||
#### htmlDecode
|
||||
|
||||
$stringy->htmlDecode()
|
||||
|
||||
S::htmlDecode(string $str [, int $flags, string $encoding ])
|
||||
|
||||
Convert all HTML entities to their applicable characters.
|
||||
|
||||
```php
|
||||
S::create('&')->htmlDecode();
|
||||
S::htmlDecode('&'); // '&'
|
||||
```
|
||||
|
||||
#### htmlEncode
|
||||
|
||||
$stringy->htmlEncode()
|
||||
|
||||
S::htmlEncode(string $str [, int $flags, string $encoding ])
|
||||
|
||||
Convert all applicable characters to HTML entities.
|
||||
|
||||
```php
|
||||
S::create('&')->htmlEncode();
|
||||
S::htmlEncode('&'); // '&'
|
||||
```
|
||||
|
||||
#### humanize
|
||||
|
||||
$stringy->humanize()
|
||||
@@ -366,6 +496,36 @@ S::create('author_id')->humanize();
|
||||
S::humanize('author_id'); // 'Author'
|
||||
```
|
||||
|
||||
#### indexOf
|
||||
|
||||
$stringy->indexOf(string $needle [, $offset = 0 ]);
|
||||
|
||||
S::indexOf(string $haystack , string $needle [, $offset = 0 [, $encoding = null ]])
|
||||
|
||||
Returns the index of the first occurrence of $needle in the string,
|
||||
and false if not found. Accepts an optional offset from which to begin
|
||||
the search.
|
||||
|
||||
```php
|
||||
S::create('string', 'UTF-8')->indexOf('ing');
|
||||
S::indexOf('string', 'ing'); // 3
|
||||
```
|
||||
|
||||
#### indexOfLast
|
||||
|
||||
$stringy->indexOfLast(string $needle [, $offset = 0 ]);
|
||||
|
||||
S::indexOfLast(string $haystack , string $needle [, $offset = 0 [, $encoding = null ]])
|
||||
|
||||
Returns the index of the last occurrence of $needle in the string,
|
||||
and false if not found. Accepts an optional offset from which to begin
|
||||
the search.
|
||||
|
||||
```php
|
||||
S::create('string', 'UTF-8')->indexOfLast('ing');
|
||||
S::indexOfLast('string string', 'ing'); // 10
|
||||
```
|
||||
|
||||
#### insert
|
||||
|
||||
$stringy->insert(int $index, string $substring)
|
||||
@@ -681,7 +841,7 @@ S::replace('fòô bàř fòô bàř', 'fòô ', '', 'UTF-8'); // 'bàř bàř'
|
||||
|
||||
$stringy->reverse()
|
||||
|
||||
S::reverse(string $str, [, string $encoding ])
|
||||
S::reverse(string $str [, string $encoding ])
|
||||
|
||||
Returns a reversed string. A multibyte version of strrev().
|
||||
|
||||
@@ -692,9 +852,9 @@ S::reverse('fòô bàř', 'UTF-8'); // 'řàb ôòf'
|
||||
|
||||
#### safeTruncate
|
||||
|
||||
$stringy->safeTruncate(int $length, [, string $substring = '' ])
|
||||
$stringy->safeTruncate(int $length [, string $substring = '' ])
|
||||
|
||||
S::safeTruncate(string $str, int $length, [, string $substring = '' [, string $encoding ]])
|
||||
S::safeTruncate(string $str, int $length [, string $substring = '' [, string $encoding ]])
|
||||
|
||||
Truncates the string to a given length, while ensuring that it does not
|
||||
split words. If $substring is provided, and truncating occurs, the
|
||||
@@ -828,10 +988,11 @@ S::titleize('i like to watch DVDs at home', $ignore, 'UTF-8');
|
||||
|
||||
$stringy->toAscii()
|
||||
|
||||
S::toAscii(string $str)
|
||||
S::toAscii(string $str [, boolean $removeUnsupported = true])
|
||||
|
||||
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.
|
||||
replaced with their closest ASCII counterparts, and the rest are removed
|
||||
unless instructed otherwise.
|
||||
|
||||
```php
|
||||
S::create('fòô bàř')->toAscii();
|
||||
@@ -856,7 +1017,7 @@ S::toLowerCase('FÒÔ BÀŘ', 'UTF-8'); // 'fòô bàř'
|
||||
|
||||
$stringy->toSpaces([ tabLength = 4 ])
|
||||
|
||||
S::toSpaces(string $str, [, int $tabLength = 4 ])
|
||||
S::toSpaces(string $str [, int $tabLength = 4 ])
|
||||
|
||||
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.
|
||||
@@ -870,7 +1031,7 @@ S::toSpaces(' String speech = "Hi"'); // ' String speech = "Hi"'
|
||||
|
||||
$stringy->toTabs([ tabLength = 4 ])
|
||||
|
||||
S::toTabs(string $str, [, int $tabLength = 4 ])
|
||||
S::toTabs(string $str [, int $tabLength = 4 ])
|
||||
|
||||
Converts each occurrence of some consecutive number of spaces, as defined
|
||||
by $tabLength, to a tab. By default, each 4 consecutive spaces are
|
||||
@@ -881,6 +1042,19 @@ S::create(' fòô bàř')->toTabs();
|
||||
S::toTabs(' fòô bàř'); // ' fòô bàř'
|
||||
```
|
||||
|
||||
#### toTitleCase
|
||||
|
||||
$stringy->toTitleCase()
|
||||
|
||||
S::toTitleCase(string $str [, string $encoding ])
|
||||
|
||||
Converts the first character of each word in the string to uppercase.
|
||||
|
||||
```php
|
||||
S::create('fòô bàř', 'UTF-8')->toTitleCase();
|
||||
S::toTitleCase('fòô bàř', 'UTF-8'); // 'Fòô Bàř'
|
||||
```
|
||||
|
||||
#### toUpperCase
|
||||
|
||||
$stringy->toUpperCase()
|
||||
@@ -897,22 +1071,54 @@ S::toUpperCase('fòô bàř', 'UTF-8'); // 'FÒÔ BÀŘ'
|
||||
|
||||
#### trim
|
||||
|
||||
$stringy->trim()
|
||||
$stringy->trim([, string $chars])
|
||||
|
||||
S::trim(string $str)
|
||||
S::trim(string $str [, string $chars [, string $encoding ]])
|
||||
|
||||
Returns the trimmed string. An alias for PHP's trim() function.
|
||||
Returns a string with whitespace removed from the start and end of the
|
||||
string. Supports the removal of unicode whitespace. Accepts an optional
|
||||
string of characters to strip instead of the defaults.
|
||||
|
||||
```php
|
||||
S::create('fòô bàř', 'UTF-8')->trim();
|
||||
S::trim(' fòô bàř '); // 'fòô bàř'
|
||||
S::create(' fòô bàř ', 'UTF-8')->trim();
|
||||
S::trim(' fòô bàř '); // 'fòô bàř'
|
||||
```
|
||||
|
||||
#### trimLeft
|
||||
|
||||
$stringy->trimLeft([, string $chars])
|
||||
|
||||
S::trimLeft(string $str [, string $chars [, string $encoding ]])
|
||||
|
||||
Returns a string with whitespace removed from the start of the string.
|
||||
Supports the removal of unicode whitespace. Accepts an optional
|
||||
string of characters to strip instead of the defaults.
|
||||
|
||||
```php
|
||||
S::create(' fòô bàř ', 'UTF-8')->trimLeft();
|
||||
S::trimLeft(' fòô bàř '); // 'fòô bàř '
|
||||
```
|
||||
|
||||
#### trimRight
|
||||
|
||||
$stringy->trimRight([, string $chars])
|
||||
|
||||
S::trimRight(string $str [, string $chars [, string $encoding ]])
|
||||
|
||||
Returns a string with whitespace removed from the end of the string.
|
||||
Supports the removal of unicode whitespace. Accepts an optional
|
||||
string of characters to strip instead of the defaults.
|
||||
|
||||
```php
|
||||
S::create(' fòô bàř ', 'UTF-8')->trimRight();
|
||||
S::trimRight(' fòô bàř '); // ' fòô bàř'
|
||||
```
|
||||
|
||||
#### truncate
|
||||
|
||||
$stringy->truncate(int $length, [, string $substring = '' ])
|
||||
$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 the string to a given length. If $substring is provided, and
|
||||
truncating occurs, the string is further truncated so that the substring
|
||||
@@ -972,6 +1178,8 @@ The following is a list of libraries that extend Stringy:
|
||||
|
||||
* [SliceableStringy](https://github.com/danielstjules/SliceableStringy):
|
||||
Python-like string slices in PHP
|
||||
* [SubStringy](https://github.com/TCB13/SubStringy):
|
||||
Advanced substring methods
|
||||
|
||||
## Tests
|
||||
|
||||
|
@@ -15,10 +15,11 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
"php": ">=5.3.0",
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.0.*"
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"support": {
|
||||
"issues": "https://github.com/danielstjules/Stringy/issues",
|
||||
@@ -26,6 +27,9 @@
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Stringy\\": "src/" },
|
||||
"files": ["src/Create.php"]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"classmap": [ "tests" ]
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,10 @@
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
<testsuite name="Stringy">
|
||||
<directory>tests</directory>
|
||||
<file>tests/CommonTest.php</file>
|
||||
<file>tests/StringyTest.php</file>
|
||||
<file>tests/StaticStringyTest.php</file>
|
||||
<file phpVersion="5.6.0">tests/CreateTest.php</file>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
19
src/Create.php
Normal file
19
src/Create.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Stringy;
|
||||
|
||||
if (!function_exists('Stringy\create')) {
|
||||
/**
|
||||
* Creates a Stringy object and returns it on success.
|
||||
*
|
||||
* @param mixed $str Value to modify, after being cast to string
|
||||
* @param string $encoding The character encoding
|
||||
* @return Stringy A Stringy object
|
||||
* @throws \InvalidArgumentException if an array or object without a
|
||||
* __toString method is passed as the first argument
|
||||
*/
|
||||
function create($str, $encoding = null)
|
||||
{
|
||||
return new Stringy($str, $encoding);
|
||||
}
|
||||
}
|
@@ -97,6 +97,22 @@ class StaticStringy
|
||||
return (string) Stringy::create($str, $encoding)->underscored();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a lowercase and trimmed string separated by the given delimiter.
|
||||
* Delimiters are inserted before uppercase characters (with the exception
|
||||
* of the first character of the string), and in place of spaces, dashes,
|
||||
* and underscores. Alpha delimiters are not converted to lowercase.
|
||||
*
|
||||
* @param string $str String to convert
|
||||
* @param string $delimiter Sequence used to separate parts of the string
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String with delimiter
|
||||
*/
|
||||
public static function delimit($str, $delimiter, $encoding = null)
|
||||
{
|
||||
return (string) Stringy::create($str, $encoding)->delimit($delimiter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a case swapped version of the string.
|
||||
*
|
||||
@@ -166,14 +182,17 @@ class StaticStringy
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* replaced with their closest ASCII counterparts, and the rest are removed
|
||||
* unless instructed otherwise.
|
||||
*
|
||||
* @param string $str A string with non-ASCII characters
|
||||
* @param string $str A string with non-ASCII characters
|
||||
* @param bool $removeUnsupported Whether or not to remove the
|
||||
* unsupported characters
|
||||
* @return string A string containing only ASCII characters
|
||||
*/
|
||||
public static function toAscii($str)
|
||||
public static function toAscii($str, $removeUnsupported = true)
|
||||
{
|
||||
return (string) Stringy::create($str)->toAscii();
|
||||
return (string) Stringy::create($str)->toAscii($removeUnsupported);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,6 +342,18 @@ class StaticStringy
|
||||
return (string) Stringy::create($str, $encoding)->toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first character of each word in the string to uppercase.
|
||||
*
|
||||
* @param string $str String to convert case
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The title-cased string
|
||||
*/
|
||||
public static function toTitleCase($str, $encoding = null)
|
||||
{
|
||||
return (string) Stringy::create($str, $encoding)->toTitleCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts all characters in the string to uppercase. An alias for PHP's
|
||||
* mb_strtoupper().
|
||||
@@ -370,6 +401,76 @@ class StaticStringy
|
||||
->contains($needle, $caseSensitive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains any $needles, false otherwise. By
|
||||
* default, the comparison is case-sensitive, but can be made insensitive
|
||||
* by setting $caseSensitive to false.
|
||||
*
|
||||
* @param string $haystack String being checked
|
||||
* @param array $needles Substrings to look for
|
||||
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $haystack contains any $needles
|
||||
*/
|
||||
public static function containsAny($haystack, $needles,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
return Stringy::create($haystack, $encoding)
|
||||
->containsAny($needles, $caseSensitive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains all $needles, false otherwise. By
|
||||
* default, the comparison is case-sensitive, but can be made insensitive
|
||||
* by setting $caseSensitive to false.
|
||||
*
|
||||
* @param string $haystack String being checked
|
||||
* @param array $needles Substrings to look for
|
||||
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $haystack contains all $needles
|
||||
*/
|
||||
public static function containsAll($haystack, $needles,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
return Stringy::create($haystack, $encoding)
|
||||
->containsAll($needles, $caseSensitive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first occurrence of $needle in the string,
|
||||
* and false if not found. Accepts an optional offset from which to begin
|
||||
* the search.
|
||||
*
|
||||
* @param string $haystack String to search
|
||||
* @param string $needle Substring to look for
|
||||
* @param int $offset Offset from which to search
|
||||
* @return int|bool The occurrence's index if found, otherwise false
|
||||
*/
|
||||
public static function indexOf($haystack, $needle, $offset = 0,
|
||||
$encoding = null)
|
||||
{
|
||||
return Stringy::create($haystack, $encoding)
|
||||
->indexOf($needle, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the last occurrence of $needle in the string,
|
||||
* and false if not found. Accepts an optional offset from which to begin
|
||||
* the search.
|
||||
*
|
||||
* @param string $haystack String to search
|
||||
* @param string $needle Substring to look for
|
||||
* @param int $offset Offset from which to search
|
||||
* @return int|bool The last occurrence's index if found, otherwise false
|
||||
*/
|
||||
public static function indexOfLast($haystack, $needle, $offset = 0,
|
||||
$encoding = null)
|
||||
{
|
||||
return Stringy::create($haystack, $encoding)
|
||||
->indexOfLast($needle, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds a string with the given substring.
|
||||
*
|
||||
@@ -428,7 +529,7 @@ class StaticStringy
|
||||
* @return string The resulting string after truncating
|
||||
*/
|
||||
public static function safeTruncate($str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
$encoding = null)
|
||||
{
|
||||
return (string) Stringy::create($str, $encoding)
|
||||
->safeTruncate($length, $substring);
|
||||
@@ -460,14 +561,48 @@ class StaticStringy
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the trimmed string. An alias for PHP's trim() function.
|
||||
* Returns a string with whitespace removed from the start and end of the
|
||||
* string. Supports the removal of unicode whitespace. Accepts an optional
|
||||
* string of characters to strip instead of the defaults.
|
||||
*
|
||||
* @param string $str String to trim
|
||||
* @param string $str String to trim
|
||||
* @param string $chars Optional string of characters to strip
|
||||
* @param string $encoding The character encoding
|
||||
* @return string Trimmed $str
|
||||
*/
|
||||
public static function trim($str)
|
||||
public static function trim($str, $chars = null, $encoding = null)
|
||||
{
|
||||
return trim($str);
|
||||
return (string) Stringy::create($str, $encoding)->trim($chars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string with whitespace removed from the start of the string.
|
||||
* Supports the removal of unicode whitespace. Accepts an optional
|
||||
* string of characters to strip instead of the defaults.
|
||||
*
|
||||
* @param string $str String to trim
|
||||
* @param string $chars Optional string of characters to strip
|
||||
* @param string $encoding The character encoding
|
||||
* @return string Trimmed $str
|
||||
*/
|
||||
public static function trimLeft($str, $chars = null, $encoding = null)
|
||||
{
|
||||
return (string) Stringy::create($str, $encoding)->trimLeft($chars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string with whitespace removed from the end of the string.
|
||||
* Supports the removal of unicode whitespace. Accepts an optional
|
||||
* string of characters to strip instead of the defaults.
|
||||
*
|
||||
* @param string $str String to trim
|
||||
* @param string $chars Optional string of characters to strip
|
||||
* @param string $encoding The character encoding
|
||||
* @return string Trimmed $str
|
||||
*/
|
||||
public static function trimRight($str, $chars = null, $encoding = null)
|
||||
{
|
||||
return (string) Stringy::create($str, $encoding)->trimRight($chars);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -635,6 +770,32 @@ class StaticStringy
|
||||
return (string) Stringy::create($str, $encoding)->removeRight($substring);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains a lower case char, false
|
||||
* otherwise.
|
||||
*
|
||||
* @param string $str String to check
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $str contains a lower case character.
|
||||
*/
|
||||
public static function hasLowerCase($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->hasLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains an upper case char, false
|
||||
* otherwise.
|
||||
*
|
||||
* @param string $str String to check
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $str contains an upper case character.
|
||||
*/
|
||||
public static function hasUpperCase($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->hasUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains only alphabetic chars, false
|
||||
* otherwise.
|
||||
@@ -767,7 +928,7 @@ class StaticStringy
|
||||
public static function replace($str, $search, $replacement, $encoding = null)
|
||||
{
|
||||
return (string) Stringy::create($str, $encoding)
|
||||
->replace($search,$replacement);
|
||||
->replace($search, $replacement);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -789,4 +950,30 @@ class StaticStringy
|
||||
return (string) Stringy::create($str, $encoding)
|
||||
->regexReplace($pattern, $replacement, $options, $encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all applicable characters to HTML entities.
|
||||
*
|
||||
* @param string $str The string to encode.
|
||||
* @param int|null $flags See http://php.net/manual/en/function.htmlentities.php
|
||||
* @param string $encoding The character encoding
|
||||
* @return Stringy Object with the resulting $str after being html encoded.
|
||||
*/
|
||||
public static function htmlEncode($str, $flags = ENT_COMPAT, $encoding = null)
|
||||
{
|
||||
return (string) Stringy::create($str, $encoding)->htmlEncode($flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all HTML entities to their applicable characters.
|
||||
*
|
||||
* @param string $str The string to decode.
|
||||
* @param int|null $flags See http://php.net/manual/en/function.html-entity-decode.php
|
||||
* @param string $encoding The character encoding
|
||||
* @return Stringy Object with the resulting $str after being html decoded.
|
||||
*/
|
||||
public static function htmlDecode($str, $flags = ENT_COMPAT, $encoding = null)
|
||||
{
|
||||
return (string) Stringy::create($str, $encoding)->htmlDecode($flags);
|
||||
}
|
||||
}
|
||||
|
551
src/Stringy.php
551
src/Stringy.php
@@ -4,8 +4,19 @@ namespace Stringy;
|
||||
|
||||
class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
{
|
||||
/**
|
||||
* An instance's string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $str;
|
||||
|
||||
/**
|
||||
* The string's encoding, which should be one of the mbstring module's
|
||||
* supported encodings.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $encoding;
|
||||
|
||||
/**
|
||||
@@ -26,7 +37,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
throw new \InvalidArgumentException(
|
||||
'Passed value cannot be an array'
|
||||
);
|
||||
} else if (is_object($str) && !method_exists($str, '__toString')) {
|
||||
} elseif (is_object($str) && !method_exists($str, '__toString')) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Passed object must have a __toString method'
|
||||
);
|
||||
@@ -105,7 +116,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
* @param mixed $offset The index to check
|
||||
* @return boolean Whether or not the index exists
|
||||
*/
|
||||
public function offsetExists($offset) {
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
$length = $this->length();
|
||||
$offset = (int) $offset;
|
||||
|
||||
@@ -127,7 +139,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
* @throws \OutOfBoundsException If the positive or negative offset does
|
||||
* not exist
|
||||
*/
|
||||
public function offsetGet($offset) {
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
$offset = (int) $offset;
|
||||
$length = $this->length();
|
||||
|
||||
@@ -146,7 +159,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
* @param mixed $value Value to set
|
||||
* @throws \Exception When called
|
||||
*/
|
||||
public function offsetSet($offset, $value) {
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
// Stringy is immutable, cannot directly set char
|
||||
throw new \Exception('Stringy object is immutable, cannot modify char');
|
||||
}
|
||||
@@ -158,7 +172,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
* @param mixed $offset The index of the character
|
||||
* @throws \Exception When called
|
||||
*/
|
||||
public function offsetUnset($offset) {
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
// Don't allow directly modifying the string
|
||||
throw new \Exception('Stringy object is immutable, cannot unset char');
|
||||
}
|
||||
@@ -171,7 +186,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
public function chars()
|
||||
{
|
||||
$chars = array();
|
||||
for ($i = 0; $i < $this->length(); $i++) {
|
||||
for ($i = 0, $l = $this->length(); $i < $l; $i++) {
|
||||
$chars[] = $this->at($i)->str;
|
||||
}
|
||||
|
||||
@@ -191,7 +206,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
|
||||
$str = mb_strtoupper($first, $this->encoding) . $rest;
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +222,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
|
||||
$str = mb_strtolower($first, $this->encoding) . $rest;
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,19 +235,19 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
public function camelize()
|
||||
{
|
||||
$encoding = $this->encoding;
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = $this->trim()->lowerCaseFirst();
|
||||
|
||||
$camelCase = preg_replace_callback(
|
||||
'/[-_\s]+(.)?/u',
|
||||
function($match) use ($encoding) {
|
||||
function ($match) use ($encoding) {
|
||||
return $match[1] ? mb_strtoupper($match[1], $encoding) : '';
|
||||
},
|
||||
$stringy->trim()->lowerCaseFirst()->str
|
||||
$stringy->str
|
||||
);
|
||||
|
||||
$stringy->str = preg_replace_callback(
|
||||
'/[\d]+(.)?/u',
|
||||
function($match) use ($encoding) {
|
||||
function ($match) use ($encoding) {
|
||||
return mb_strtoupper($match[0], $encoding);
|
||||
},
|
||||
$camelCase
|
||||
@@ -262,7 +277,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function dasherize()
|
||||
{
|
||||
return $this->applyDelimeter('-');
|
||||
return $this->delimit('-');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,28 +290,31 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function underscored()
|
||||
{
|
||||
return $this->applyDelimeter('_');
|
||||
return $this->delimit('_');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a lowercase and trimmed string separated by the given delimiter.
|
||||
* Delimiters are inserted before uppercase characters (with the exception
|
||||
* of the first character of the string), and in place of spaces, dashes,
|
||||
* 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
|
||||
*/
|
||||
protected function applyDelimeter($delimiter)
|
||||
public function delimit($delimiter)
|
||||
{
|
||||
// Save current regex encoding so we can reset it after
|
||||
$regexEncoding = mb_regex_encoding();
|
||||
mb_regex_encoding($this->encoding);
|
||||
|
||||
$str = mb_ereg_replace('\B([A-Z])', $delimiter .'\1', trim($this->str));
|
||||
$str = mb_ereg_replace('[-_\s]+', $delimiter, $str);
|
||||
$str = mb_ereg_replace('\B([A-Z])', '-\1', $this->trim());
|
||||
$str = mb_strtolower($str, $this->encoding);
|
||||
$str = mb_ereg_replace('[-_\s]+', $delimiter, $str);
|
||||
|
||||
mb_regex_encoding($regexEncoding);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -306,7 +324,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function swapCase()
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
$encoding = $stringy->encoding;
|
||||
|
||||
$stringy->str = preg_replace_callback(
|
||||
@@ -339,7 +357,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
|
||||
$buffer = preg_replace_callback(
|
||||
'/([\S]+)/u',
|
||||
function ($match) use (&$encoding, &$ignore) {
|
||||
function ($match) use ($encoding, $ignore) {
|
||||
if ($ignore && in_array($match[0], $ignore)) {
|
||||
return $match[0];
|
||||
} else {
|
||||
@@ -361,10 +379,9 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function humanize()
|
||||
{
|
||||
$str = str_replace('_id', '', $this->str);
|
||||
$str = str_replace('_', ' ', $str);
|
||||
$str = str_replace(array('_id', '_'), array('', ' '), $this->str);
|
||||
|
||||
return self::create($str, $this->encoding)->trim()->upperCaseFirst();
|
||||
return static::create($str, $this->encoding)->trim()->upperCaseFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -376,13 +393,19 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function tidy()
|
||||
{
|
||||
$str = $this->str;
|
||||
$str = preg_replace('/\x{2026}/u', '...', $str);
|
||||
$str = preg_replace('/[\x{201C}\x{201D}]/u', '"', $str);
|
||||
$str = preg_replace('/[\x{2018}\x{2019}]/u', "'", $str);
|
||||
$str = preg_replace('/[\x{2013}\x{2014}]/u', '-', $str);
|
||||
$str = preg_replace(array(
|
||||
'/\x{2026}/u',
|
||||
'/[\x{201C}\x{201D}]/u',
|
||||
'/[\x{2018}\x{2019}]/u',
|
||||
'/[\x{2013}\x{2014}]/u',
|
||||
), array(
|
||||
'...',
|
||||
'"',
|
||||
"'",
|
||||
'-',
|
||||
), $this->str);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,98 +422,161 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* replaced with their closest ASCII counterparts, and the rest are removed
|
||||
* unless instructed otherwise.
|
||||
*
|
||||
* @param bool $removeUnsupported Whether or not to remove the
|
||||
* unsupported characters
|
||||
* @return Stringy Object whose $str contains only ASCII characters
|
||||
*/
|
||||
public function toAscii()
|
||||
public function toAscii($removeUnsupported = true)
|
||||
{
|
||||
$str = $this->str;
|
||||
$charsArray = array(
|
||||
'a' => array('à', 'á', 'â', 'ã', 'ā', 'ą', 'ă', 'å', 'α', 'ά', 'ἀ',
|
||||
'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ',
|
||||
'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ',
|
||||
'ᾶ', 'ᾷ', 'а'),
|
||||
'b' => array('б', 'β'),
|
||||
|
||||
foreach ($this->charsArray() as $key => $value) {
|
||||
$str = str_replace($value, $key, $str);
|
||||
}
|
||||
|
||||
if ($removeUnsupported) {
|
||||
$str = preg_replace('/[^\x20-\x7E]/u', '', $str);
|
||||
}
|
||||
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the replacements for the toAscii() method.
|
||||
*
|
||||
* @return array An array of replacements.
|
||||
*/
|
||||
protected function charsArray()
|
||||
{
|
||||
static $charsArray;
|
||||
if (isset($charsArray)) return $charsArray;
|
||||
|
||||
return $charsArray = array(
|
||||
'a' => array(
|
||||
'à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ',
|
||||
'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ä', 'ā', 'ą',
|
||||
'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ',
|
||||
'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ',
|
||||
'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ'),
|
||||
'b' => array('б', 'β', 'Ъ', 'Ь', 'ب'),
|
||||
'c' => array('ç', 'ć', 'č', 'ĉ', 'ċ'),
|
||||
'd' => array('ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д'),
|
||||
'e' => array('è', 'é', 'ê', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ',
|
||||
'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є'),
|
||||
'f' => array('ф'),
|
||||
'g' => array('ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ'),
|
||||
'h' => array('ĥ', 'ħ'),
|
||||
'i' => array('ì', 'í', 'î', 'ï', 'ī', 'ĩ', 'ĭ', 'į', 'ı', 'ι', 'ί',
|
||||
'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ',
|
||||
'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и'),
|
||||
'j' => array('ĵ'),
|
||||
'k' => array('ķ', 'ĸ', 'к'),
|
||||
'l' => array('ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л'),
|
||||
'm' => array('м'),
|
||||
'n' => array('ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н'),
|
||||
'o' => array('ò', 'ó', 'ô', 'õ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ό', 'ὀ',
|
||||
'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'ö', 'о'),
|
||||
'p' => array('п'),
|
||||
'r' => array('ŕ', 'ř', 'ŗ', 'р'),
|
||||
's' => array('ś', 'š', 'ş', 'с'),
|
||||
't' => array('ť', 'ţ', 'т'),
|
||||
'u' => array('ü', 'ù', 'ú', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ũ', 'ų', 'µ', 'у'),
|
||||
'd' => array('ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ',
|
||||
'д', 'δ', 'د', 'ض'),
|
||||
'e' => array('é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ',
|
||||
'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ',
|
||||
'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э',
|
||||
'є', 'ə'),
|
||||
'f' => array('ф', 'φ', 'ف'),
|
||||
'g' => array('ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ج'),
|
||||
'h' => array('ĥ', 'ħ', 'η', 'ή', 'ح', 'ه'),
|
||||
'i' => array('í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į',
|
||||
'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ',
|
||||
'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ',
|
||||
'ῗ', 'і', 'ї', 'и'),
|
||||
'j' => array('ĵ', 'ј', 'Ј'),
|
||||
'k' => array('ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك'),
|
||||
'l' => array('ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل'),
|
||||
'm' => array('м', 'μ', 'م'),
|
||||
'n' => array('ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن'),
|
||||
'o' => array('ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ',
|
||||
'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő',
|
||||
'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό',
|
||||
'ö', 'о', 'و', 'θ'),
|
||||
'p' => array('п', 'π'),
|
||||
'r' => array('ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر'),
|
||||
's' => array('ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص'),
|
||||
't' => array('ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط'),
|
||||
'u' => array('ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ',
|
||||
'ự', 'ü', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у'),
|
||||
'v' => array('в'),
|
||||
'w' => array('ŵ'),
|
||||
'y' => array('ÿ', 'ý', 'ŷ', 'й', 'ы'),
|
||||
'z' => array('ź', 'ž', 'ż', 'з'),
|
||||
'w' => array('ŵ', 'ω', 'ώ'),
|
||||
'x' => array('χ'),
|
||||
'y' => array('ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ',
|
||||
'ϋ', 'ύ', 'ΰ', 'ي'),
|
||||
'z' => array('ź', 'ž', 'ż', 'з', 'ζ', 'ز'),
|
||||
'aa' => array('ع'),
|
||||
'ae' => array('æ'),
|
||||
'ch' => array('ч'),
|
||||
'kh' => array('х'),
|
||||
'dj' => array('ђ', 'đ'),
|
||||
'dz' => array('џ'),
|
||||
'gh' => array('غ'),
|
||||
'kh' => array('х', 'خ'),
|
||||
'lj' => array('љ'),
|
||||
'nj' => array('њ'),
|
||||
'oe' => array('œ'),
|
||||
'ps' => array('ψ'),
|
||||
'sh' => array('ш'),
|
||||
'shch' => array('щ'),
|
||||
'ss' => array('ß'),
|
||||
'th' => array('þ', 'ث', 'ذ', 'ظ'),
|
||||
'ts' => array('ц'),
|
||||
'ya' => array('я'),
|
||||
'yu' => array('ю'),
|
||||
'zh' => array('ж'),
|
||||
'A' => array('Á', 'Â', 'Ã', 'Å', 'Ā', 'Ą', 'Ă', 'Α', 'Ά', 'Ἀ', 'Ἁ',
|
||||
'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ',
|
||||
'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А'),
|
||||
'B' => array('Б'),
|
||||
'C' => array('Ć', 'Č', 'Ĉ', 'Ċ'),
|
||||
'D' => array('Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д'),
|
||||
'E' => array('É', 'Ê', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ',
|
||||
'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', 'Є'),
|
||||
'F' => array('Ф'),
|
||||
'G' => array('Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ'),
|
||||
'I' => array('Í', 'Î', 'Ï', 'Ī', 'Ĩ', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ',
|
||||
'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί',
|
||||
'И', 'І', 'Ї'),
|
||||
'K' => array('К'),
|
||||
'L' => array('Ĺ', 'Ł', 'Л'),
|
||||
'M' => array('М'),
|
||||
'N' => array('Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н'),
|
||||
'O' => array('Ó', 'Ô', 'Õ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ',
|
||||
'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О'),
|
||||
'P' => array('П'),
|
||||
'R' => array('Ř', 'Ŕ', 'Р'),
|
||||
'S' => array('Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С'),
|
||||
'T' => array('Ť', 'Ţ', 'Ŧ', 'Ț', 'Т'),
|
||||
'U' => array('Ù', 'Ú', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ũ', 'Ų', 'У'),
|
||||
'(c)' => array('©'),
|
||||
'A' => array('Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ',
|
||||
'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Ä', 'Å', 'Ā',
|
||||
'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ',
|
||||
'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ',
|
||||
'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А'),
|
||||
'B' => array('Б', 'Β'),
|
||||
'C' => array('Ç','Ć', 'Č', 'Ĉ', 'Ċ'),
|
||||
'D' => array('Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'),
|
||||
'E' => array('É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ',
|
||||
'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ',
|
||||
'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э',
|
||||
'Є', 'Ə'),
|
||||
'F' => array('Ф', 'Φ'),
|
||||
'G' => array('Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ'),
|
||||
'H' => array('Η', 'Ή'),
|
||||
'I' => array('Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į',
|
||||
'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ',
|
||||
'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї'),
|
||||
'K' => array('К', 'Κ'),
|
||||
'L' => array('Ĺ', 'Ł', 'Л', 'Λ', 'Ļ'),
|
||||
'M' => array('М', 'Μ'),
|
||||
'N' => array('Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν'),
|
||||
'O' => array('Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ',
|
||||
'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ö', 'Ø', 'Ō',
|
||||
'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ',
|
||||
'Ὸ', 'Ό', 'О', 'Θ', 'Ө'),
|
||||
'P' => array('П', 'Π'),
|
||||
'R' => array('Ř', 'Ŕ', 'Р', 'Ρ'),
|
||||
'S' => array('Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ'),
|
||||
'T' => array('Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ'),
|
||||
'U' => array('Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ',
|
||||
'Ự', 'Û', 'Ü', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У'),
|
||||
'V' => array('В'),
|
||||
'Y' => array('Ý', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й'),
|
||||
'Z' => array('Ź', 'Ž', 'Ż', 'З'),
|
||||
'W' => array('Ω', 'Ώ'),
|
||||
'X' => array('Χ'),
|
||||
'Y' => array('Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ',
|
||||
'Ы', 'Й', 'Υ', 'Ϋ'),
|
||||
'Z' => array('Ź', 'Ž', 'Ż', 'З', 'Ζ'),
|
||||
'AE' => array('Æ'),
|
||||
'CH' => array('Ч'),
|
||||
'DJ' => array('Ђ'),
|
||||
'DZ' => array('Џ'),
|
||||
'KH' => array('Х'),
|
||||
'LJ' => array('Љ'),
|
||||
'NJ' => array('Њ'),
|
||||
'PS' => array('Ψ'),
|
||||
'SH' => array('Ш'),
|
||||
'SHCH' => array('Щ'),
|
||||
'SS' => array('ẞ'),
|
||||
'TH' => array('Þ'),
|
||||
'TS' => array('Ц'),
|
||||
'YA' => array('Я'),
|
||||
'YU' => array('Ю'),
|
||||
'ZH' => array('Ж')
|
||||
'ZH' => array('Ж'),
|
||||
' ' => array("\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81",
|
||||
"\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"),
|
||||
);
|
||||
|
||||
foreach ($charsArray as $key => $value) {
|
||||
$str = str_replace($value, $key, $str);
|
||||
}
|
||||
|
||||
$str = preg_replace('/[^\x20-\x7E]/u', '', $str);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -577,7 +663,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
private function applyPadding($left = 0, $right = 0, $padStr = ' ')
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
$length = mb_strlen($padStr, $stringy->encoding);
|
||||
|
||||
$strLength = $stringy->length();
|
||||
@@ -589,8 +675,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
|
||||
$leftPadding = mb_substr(str_repeat($padStr, ceil($left / $length)), 0,
|
||||
$left, $stringy->encoding);
|
||||
$rightPadding = mb_substr(str_repeat($padStr, ceil($right / $length)), 0,
|
||||
$right, $stringy->encoding);
|
||||
$rightPadding = mb_substr(str_repeat($padStr, ceil($right / $length)),
|
||||
0, $right, $stringy->encoding);
|
||||
|
||||
$stringy->str = $leftPadding . $stringy->str . $rightPadding;
|
||||
|
||||
@@ -617,7 +703,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
$startOfStr = mb_strtolower($startOfStr, $this->encoding);
|
||||
}
|
||||
|
||||
return $substring === $startOfStr;
|
||||
return (string) $substring === $startOfStr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -642,7 +728,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
$endOfStr = mb_strtolower($endOfStr, $this->encoding);
|
||||
}
|
||||
|
||||
return $substring === $endOfStr;
|
||||
return (string) $substring === $endOfStr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -657,7 +743,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
$spaces = str_repeat(' ', $tabLength);
|
||||
$str = str_replace("\t", $spaces, $this->str);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -673,7 +759,19 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
$spaces = str_repeat(' ', $tabLength);
|
||||
$str = str_replace($spaces, "\t", $this->str);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first character of each word in the string to uppercase.
|
||||
*
|
||||
* @return Stringy Object with all characters of $str being title-cased
|
||||
*/
|
||||
public function toTitleCase()
|
||||
{
|
||||
$str = mb_convert_case($this->str, MB_CASE_TITLE, $this->encoding);
|
||||
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -686,7 +784,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
{
|
||||
$str = mb_strtolower($this->str, $this->encoding);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -699,7 +797,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
{
|
||||
$str = mb_strtoupper($this->str, $this->encoding);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -714,13 +812,13 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function slugify($replacement = '-')
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = $this->toAscii();
|
||||
|
||||
$quotedReplacement = preg_quote($replacement);
|
||||
$pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u";
|
||||
$stringy->str = preg_replace($pattern, '', $stringy->toAscii());
|
||||
$stringy->str = preg_replace($pattern, '', $stringy);
|
||||
|
||||
return $stringy->toLowerCase()->applyDelimeter($replacement)
|
||||
return $stringy->toLowerCase()->delimit($replacement)
|
||||
->removeLeft($replacement)->removeRight($replacement);
|
||||
}
|
||||
|
||||
@@ -744,17 +842,96 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains any $needles, false otherwise. By
|
||||
* default the comparison is case-sensitive, but can be made insensitive by
|
||||
* setting $caseSensitive to false.
|
||||
*
|
||||
* @param array $needles Substrings to look for
|
||||
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||
* @return bool Whether or not $str contains $needle
|
||||
*/
|
||||
public function containsAny($needles, $caseSensitive = true)
|
||||
{
|
||||
if (empty($needles)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($needles as $needle) {
|
||||
if ($this->contains($needle, $caseSensitive)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains all $needles, false otherwise. By
|
||||
* default the comparison is case-sensitive, but can be made insensitive by
|
||||
* setting $caseSensitive to false.
|
||||
*
|
||||
* @param array $needles Substrings to look for
|
||||
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
|
||||
* @return bool Whether or not $str contains $needle
|
||||
*/
|
||||
public function containsAll($needles, $caseSensitive = true)
|
||||
{
|
||||
if (empty($needles)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($needles as $needle) {
|
||||
if (!$this->contains($needle, $caseSensitive)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first occurrence of $needle in the string,
|
||||
* and false if not found. Accepts an optional offset from which to begin
|
||||
* the search.
|
||||
*
|
||||
* @param string $needle Substring to look for
|
||||
* @param int $offset Offset from which to search
|
||||
* @return int|bool The occurrence's index if found, otherwise false
|
||||
*/
|
||||
public function indexOf($needle, $offset = 0)
|
||||
{
|
||||
return mb_strpos($this->str, (string) $needle,
|
||||
(int) $offset, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the last occurrence of $needle in the string,
|
||||
* and false if not found. Accepts an optional offset from which to begin
|
||||
* the search.
|
||||
*
|
||||
* @param string $needle Substring to look for
|
||||
* @param int $offset Offset from which to search
|
||||
* @return int|bool The last occurrence's index if found, otherwise false
|
||||
*/
|
||||
public function indexOfLast($needle, $offset = 0)
|
||||
{
|
||||
return mb_strrpos($this->str, (string) $needle,
|
||||
(int) $offset, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds $str with the given substring.
|
||||
*
|
||||
* @param string $substring The substring to add to both sides
|
||||
* @return Stringy Object whose $str had the substring prepended and appended
|
||||
* @return Stringy Object whose $str had the substring both prepended and
|
||||
* appended
|
||||
*/
|
||||
public function surround($substring)
|
||||
{
|
||||
$str = implode('', array($substring, $this->str, $substring));
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -766,7 +943,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function insert($substring, $index)
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
if ($index > $stringy->length()) {
|
||||
return $stringy;
|
||||
}
|
||||
@@ -791,7 +968,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function truncate($length, $substring = '')
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
if ($length >= $stringy->length()) {
|
||||
return $stringy;
|
||||
}
|
||||
@@ -818,7 +995,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function safeTruncate($length, $substring = '')
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
if ($length >= $stringy->length()) {
|
||||
return $stringy;
|
||||
}
|
||||
@@ -857,7 +1034,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
$reversed .= mb_substr($this->str, $i, 1, $this->encoding);
|
||||
}
|
||||
|
||||
return self::create($reversed, $this->encoding);
|
||||
return static::create($reversed, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -876,17 +1053,52 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
$shuffledStr .= mb_substr($this->str, $i, 1, $this->encoding);
|
||||
}
|
||||
|
||||
return self::create($shuffledStr, $this->encoding);
|
||||
return static::create($shuffledStr, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the trimmed string. An alias for PHP's trim() function.
|
||||
* Returns a string with whitespace removed from the start and end of the
|
||||
* string. Supports the removal of unicode whitespace. Accepts an optional
|
||||
* 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
|
||||
*/
|
||||
public function trim()
|
||||
public function trim($chars = null)
|
||||
{
|
||||
return self::create(trim($this->str), $this->encoding);
|
||||
$chars = ($chars) ? preg_quote($chars) : '[:space:]';
|
||||
|
||||
return $this->regexReplace("^[$chars]+|[$chars]+\$", '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string with whitespace removed from the start of the string.
|
||||
* Supports the removal of unicode whitespace. Accepts an optional
|
||||
* 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
|
||||
*/
|
||||
public function trimLeft($chars = null)
|
||||
{
|
||||
$chars = ($chars) ? preg_quote($chars) : '[:space:]';
|
||||
|
||||
return $this->regexReplace("^[$chars]+", '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string with whitespace removed from the end of the string.
|
||||
* Supports the removal of unicode whitespace. Accepts an optional
|
||||
* 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
|
||||
*/
|
||||
public function trimRight($chars = null)
|
||||
{
|
||||
$chars = ($chars) ? preg_quote($chars) : '[:space:]';
|
||||
|
||||
return $this->regexReplace("[$chars]+\$", '');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -911,7 +1123,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
}
|
||||
}
|
||||
|
||||
return self::create($longestCommonPrefix, $encoding);
|
||||
return static::create($longestCommonPrefix, $encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -936,7 +1148,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
}
|
||||
}
|
||||
|
||||
return self::create($longestCommonSuffix, $encoding);
|
||||
return static::create($longestCommonSuffix, $encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -951,7 +1163,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
// Uses dynamic programming to solve
|
||||
// http://en.wikipedia.org/wiki/Longest_common_substring_problem
|
||||
$encoding = $this->encoding;
|
||||
$stringy = self::create($this->str, $encoding);
|
||||
$stringy = static::create($this->str, $encoding);
|
||||
$strLength = $stringy->length();
|
||||
$otherLength = mb_strlen($otherStr, $encoding);
|
||||
|
||||
@@ -963,10 +1175,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
|
||||
$len = 0;
|
||||
$end = 0;
|
||||
$table = array_fill(0, $strLength + 1, array_fill(0, $otherLength + 1, 0));
|
||||
$table = array_fill(0, $strLength + 1,
|
||||
array_fill(0, $otherLength + 1, 0));
|
||||
|
||||
for ($i = 1; $i <= $strLength; $i++){
|
||||
for ($j = 1; $j <= $otherLength; $j++){
|
||||
for ($i = 1; $i <= $strLength; $i++) {
|
||||
for ($j = 1; $j <= $otherLength; $j++) {
|
||||
$strChar = mb_substr($stringy->str, $i - 1, 1, $encoding);
|
||||
$otherChar = mb_substr($otherStr, $j - 1, 1, $encoding);
|
||||
|
||||
@@ -1008,17 +1221,10 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function substr($start, $length = null)
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$length = $length === null ? $this->length() : $length;
|
||||
$str = mb_substr($this->str, $start, $length, $this->encoding);
|
||||
|
||||
if ($length === null) {
|
||||
$stringy->str = mb_substr($stringy->str, $start,
|
||||
$stringy->length() - $start, $this->encoding);
|
||||
} else {
|
||||
$stringy->str = mb_substr($stringy->str, $start, $length,
|
||||
$stringy->encoding);
|
||||
}
|
||||
|
||||
return $stringy;
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1040,7 +1246,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function first($n)
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
|
||||
if ($n < 0) {
|
||||
$stringy->str = '';
|
||||
@@ -1059,7 +1265,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function last($n)
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
|
||||
if ($n <= 0) {
|
||||
$stringy->str = '';
|
||||
@@ -1079,7 +1285,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function ensureLeft($substring)
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
|
||||
if (!$stringy->startsWith($substring)) {
|
||||
$stringy->str = $substring . $stringy->str;
|
||||
@@ -1097,7 +1303,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function ensureRight($substring)
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
|
||||
if (!$stringy->endsWith($substring)) {
|
||||
$stringy->str .= $substring;
|
||||
@@ -1114,7 +1320,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function removeLeft($substring)
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
|
||||
if ($stringy->startsWith($substring)) {
|
||||
$substringLength = mb_strlen($substring, $stringy->encoding);
|
||||
@@ -1132,7 +1338,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function removeRight($substring)
|
||||
{
|
||||
$stringy = self::create($this->str, $this->encoding);
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
|
||||
if ($stringy->endsWith($substring)) {
|
||||
$substringLength = mb_strlen($substring, $stringy->encoding);
|
||||
@@ -1159,6 +1365,28 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
return $match;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains a lower case char, false
|
||||
* otherwise.
|
||||
*
|
||||
* @return bool Whether or not the string contains a lower case character.
|
||||
*/
|
||||
public function hasLowerCase()
|
||||
{
|
||||
return $this->matchesPattern('.*[[:lower:]]');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains an upper case char, false
|
||||
* otherwise.
|
||||
*
|
||||
* @return bool Whether or not the string contains an upper case character.
|
||||
*/
|
||||
public function hasUpperCase()
|
||||
{
|
||||
return $this->matchesPattern('.*[[:upper:]]');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains only alphabetic chars, false
|
||||
* otherwise.
|
||||
@@ -1167,7 +1395,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function isAlpha()
|
||||
{
|
||||
return $this->matchesPattern('^([[:alpha:]])*$');
|
||||
return $this->matchesPattern('^[[:alpha:]]*$');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1178,7 +1406,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function isAlphanumeric()
|
||||
{
|
||||
return $this->matchesPattern('^([[:alnum:]])*$');
|
||||
return $this->matchesPattern('^[[:alnum:]]*$');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1189,7 +1417,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function isHexadecimal()
|
||||
{
|
||||
return $this->matchesPattern('^([[:xdigit:]])*$');
|
||||
return $this->matchesPattern('^[[:xdigit:]]*$');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1200,7 +1428,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function isBlank()
|
||||
{
|
||||
return $this->matchesPattern('^([[:space:]])*$');
|
||||
return $this->matchesPattern('^[[:space:]]*$');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1215,7 +1443,6 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
return (json_last_error() === JSON_ERROR_NONE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the string contains only lower case chars, false
|
||||
* otherwise.
|
||||
@@ -1224,7 +1451,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function isLowerCase()
|
||||
{
|
||||
return $this->matchesPattern('^([[:lower:]])*$');
|
||||
return $this->matchesPattern('^[[:lower:]]*$');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1235,7 +1462,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function isUpperCase()
|
||||
{
|
||||
return $this->matchesPattern('^([[:upper:]])*$');
|
||||
return $this->matchesPattern('^[[:upper:]]*$');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1300,6 +1527,32 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
$str = mb_ereg_replace($pattern, $replacement, $this->str, $options);
|
||||
mb_regex_encoding($regexEncoding);
|
||||
|
||||
return self::create($str, $this->encoding);
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all applicable characters to HTML entities.
|
||||
*
|
||||
* @param int|null $flags See http://php.net/manual/en/function.htmlentities.php
|
||||
* @return Stringy Object with the resulting $str after being html encoded.
|
||||
*/
|
||||
public function htmlEncode($flags = ENT_COMPAT)
|
||||
{
|
||||
$str = htmlentities($this->str, $flags, $this->encoding);
|
||||
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all HTML entities to their applicable characters.
|
||||
*
|
||||
* @param int|null $flags See http://php.net/manual/en/function.html-entity-decode.php
|
||||
* @return Stringy Object with the resulting $str after being html decoded.
|
||||
*/
|
||||
public function htmlDecode($flags = ENT_COMPAT)
|
||||
{
|
||||
$str = html_entity_decode($this->str, $flags, $this->encoding);
|
||||
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Stringy\Stringy;
|
||||
|
||||
abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Asserts that a variable is of a Stringy instance.
|
||||
*
|
||||
* @param mixed $actual
|
||||
*/
|
||||
public function assertStringy($actual)
|
||||
{
|
||||
$this->assertInstanceOf('Stringy\Stringy', $actual);
|
||||
}
|
||||
|
||||
public function indexOfProvider()
|
||||
{
|
||||
return array(
|
||||
array(2, 'This is the string', 'is'),
|
||||
array(2, 'This is the string', 'is', 0, 'UTF-8'),
|
||||
array(false, 'This is the string', 'not-found', 0, 'UTF-8'),
|
||||
array(32, 'This is the string... and there is another thing', 'is', 10, 'UTF-8'),
|
||||
);
|
||||
}
|
||||
|
||||
public function indexOfLastProvider()
|
||||
{
|
||||
return array(
|
||||
array(5, 'This is the string', 'is'),
|
||||
array(5, 'This is the string', 'is', 0, 'UTF-8'),
|
||||
array(false, 'This is the string', 'not-found', 0, 'UTF-8'),
|
||||
array(32, 'This is the string... and there is another thing', 'is', 0, 'UTF-8'),
|
||||
);
|
||||
}
|
||||
|
||||
public function charsProvider()
|
||||
{
|
||||
return array(
|
||||
@@ -113,6 +145,26 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function delimitProvider()
|
||||
{
|
||||
return array(
|
||||
array('test*case', 'testCase', '*'),
|
||||
array('test&case', 'Test-Case', '&'),
|
||||
array('test#case', 'test case', '#'),
|
||||
array('test**case', 'test -case', '**'),
|
||||
array('~!~test~!~case', '-test - case', '~!~'),
|
||||
array('test*case', 'test_case', '*'),
|
||||
array('test%c%test', ' test c test', '%'),
|
||||
array('test+u+case', 'TestUCase', '+'),
|
||||
array('test=c=c=test', 'TestCCTest', '='),
|
||||
array('string#>with1number', 'string_with1number', '#>'),
|
||||
array('1test2case', '1test2case', '*'),
|
||||
array('test ύα σase', 'test Σase', ' ύα ', 'UTF-8',),
|
||||
array('στανιλαcase', 'Στανιλ case', 'α', 'UTF-8',),
|
||||
array('σashΘcase', 'Σash Case', 'Θ', 'UTF-8')
|
||||
);
|
||||
}
|
||||
|
||||
public function swapCaseProvider()
|
||||
{
|
||||
return array(
|
||||
@@ -162,8 +214,12 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('test string', 'test string'),
|
||||
array('Ο συγγραφέας', ' Ο συγγραφέας '),
|
||||
array('123', ' 123 '),
|
||||
array('1 2 3', ' 1 2 3 ', 'UTF-8'), // ideographic spaces
|
||||
array('', ' ', 'UTF-8'), // thin space and space
|
||||
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('1 2 3', ' 1 2 3 ', 'UTF-8'),
|
||||
array('', ' '),
|
||||
array('', ''),
|
||||
);
|
||||
@@ -174,11 +230,21 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
return array(
|
||||
array('foo bar', 'fòô bàř'),
|
||||
array(' TEST ', ' ŤÉŚŢ '),
|
||||
array(' = z = 3', 'φ = ź = 3'),
|
||||
array('f = z = 3', 'φ = ź = 3'),
|
||||
array('perevirka', 'перевірка'),
|
||||
array('lysaya gora', 'лысая гора'),
|
||||
array('shchuka', 'щука'),
|
||||
array('', '漢字')
|
||||
array('', '漢字'),
|
||||
array('xin chao the gioi', 'xin chào thế giới'),
|
||||
array('XIN CHAO THE GIOI', 'XIN CHÀO THẾ GIỚI'),
|
||||
array('dam phat chet luon', 'đấm phát chết luôn'),
|
||||
array(' ', ' '), // no-break space (U+00A0)
|
||||
array(' ', ' '), // spaces U+2000 to U+200A
|
||||
array(' ', ' '), // narrow no-break space (U+202F)
|
||||
array(' ', ' '), // medium mathematical space (U+205F)
|
||||
array(' ', ' '), // ideographic space (U+3000)
|
||||
array('', '𐍉'), // some uncommon, unsupported character (U+10349)
|
||||
array('𐍉', '𐍉', false),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -318,6 +384,17 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function toTitleCaseProvider()
|
||||
{
|
||||
return array(
|
||||
array('Foo Bar', 'foo bar'),
|
||||
array(' Foo_Bar ', ' foo_bar '),
|
||||
array('Fòô Bàř', 'fòô bàř', 'UTF-8'),
|
||||
array(' Fòô_Bàř ', ' fòô_bàř ', 'UTF-8'),
|
||||
array('Αυτοκίνητο Αυτοκίνητο', 'αυτοκίνητο αυτοκίνητο', 'UTF-8'),
|
||||
);
|
||||
}
|
||||
|
||||
public function toUpperCaseProvider()
|
||||
{
|
||||
return array(
|
||||
@@ -338,7 +415,6 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('foo-dbar', " Foo d'Bar "),
|
||||
array('a-string-with-dashes', 'A string-with-dashes'),
|
||||
array('using-strings-like-foo-bar', 'Using strings like fòô bàř'),
|
||||
array('unrecognized-chars-like', 'unrecognized chars like συγγρ'),
|
||||
array('numbers-1234', 'numbers 1234'),
|
||||
array('perevirka-ryadka', 'перевірка рядка'),
|
||||
array('bukvar-s-bukvoy-y', 'букварь с буквой ы'),
|
||||
@@ -354,30 +430,106 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
public function containsProvider()
|
||||
{
|
||||
return array(
|
||||
array(true, 'This string contains foo bar', 'foo bar'),
|
||||
array(true, 'Str contains foo bar', 'foo bar'),
|
||||
array(true, '12398!@(*%!@# @!%#*&^%', ' @!%#*&^%'),
|
||||
array(true, 'Ο συγγραφέας είπε', 'συγγραφέας', 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å´¥©', true, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å˚ ∆', true, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'øœ¬', true, 'UTF-8'),
|
||||
array(false, 'This string contains foo bar', 'Foo bar'),
|
||||
array(false, 'This string contains foo bar', 'foobar'),
|
||||
array(false, 'This string contains foo bar', 'foo bar '),
|
||||
array(false, 'Str contains foo bar', 'Foo bar'),
|
||||
array(false, 'Str contains foo bar', 'foobar'),
|
||||
array(false, 'Str contains foo bar', 'foo bar '),
|
||||
array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', true, 'UTF-8'),
|
||||
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßå˚', true, 'UTF-8'),
|
||||
array(true, 'This string contains foo bar', 'Foo bar', false),
|
||||
array(true, 'Str contains foo bar', 'Foo bar', false),
|
||||
array(true, '12398!@(*%!@# @!%#*&^%', ' @!%#*&^%', false),
|
||||
array(true, 'Ο συγγραφέας είπε', 'ΣΥΓΓΡΑΦΈΑΣ', false, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'Å´¥©', false, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'Å˚ ∆', false, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'ØŒ¬', false, 'UTF-8'),
|
||||
array(false, 'This string contains foo bar', 'foobar', false),
|
||||
array(false, 'This string contains foo bar', 'foo bar ', false),
|
||||
array(false, 'Str contains foo bar', 'foobar', false),
|
||||
array(false, 'Str contains foo bar', 'foo bar ', false),
|
||||
array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', false, 'UTF-8'),
|
||||
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßÅ˚', false, 'UTF-8')
|
||||
);
|
||||
}
|
||||
|
||||
public function containsAnyProvider()
|
||||
{
|
||||
// One needle
|
||||
$singleNeedle = array_map(function ($array) {
|
||||
$array[2] = array($array[2]);
|
||||
return $array;
|
||||
}, $this->containsProvider());
|
||||
|
||||
$provider = array(
|
||||
// No needles
|
||||
array(false, 'Str contains foo bar', array()),
|
||||
// Multiple needles
|
||||
array(true, 'Str contains foo bar', array('foo', 'bar')),
|
||||
array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*', '&^%')),
|
||||
array(true, 'Ο συγγραφέας είπε', array('συγγρ', 'αφέας'), 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å´¥', '©'), true, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å˚ ', '∆'), true, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('øœ', '¬'), true, 'UTF-8'),
|
||||
array(false, 'Str contains foo bar', array('Foo', 'Bar')),
|
||||
array(false, 'Str contains foo bar', array('foobar', 'bar ')),
|
||||
array(false, 'Str contains foo bar', array('foo bar ', ' foo')),
|
||||
array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' συγγραφ '), true, 'UTF-8'),
|
||||
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßå˚', ' ß '), true, 'UTF-8'),
|
||||
array(true, 'Str contains foo bar', array('Foo bar', 'bar'), false),
|
||||
array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*&^%', '*&^%'), false),
|
||||
array(true, 'Ο συγγραφέας είπε', array('ΣΥΓΓΡΑΦΈΑΣ', 'ΑΦΈΑ'), false, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å´¥©', '¥©'), false, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å˚ ∆', ' ∆'), false, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('ØŒ¬', 'Œ'), false, 'UTF-8'),
|
||||
array(false, 'Str contains foo bar', array('foobar', 'none'), false),
|
||||
array(false, 'Str contains foo bar', array('foo bar ', ' ba '), false),
|
||||
array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' ραφέ '), false, 'UTF-8'),
|
||||
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßÅ˚', ' Å˚ '), false, 'UTF-8'),
|
||||
);
|
||||
|
||||
return array_merge($singleNeedle, $provider);
|
||||
}
|
||||
|
||||
public function containsAllProvider()
|
||||
{
|
||||
// One needle
|
||||
$singleNeedle = array_map(function ($array) {
|
||||
$array[2] = array($array[2]);
|
||||
return $array;
|
||||
}, $this->containsProvider());
|
||||
|
||||
$provider = array(
|
||||
// One needle
|
||||
array(false, 'Str contains foo bar', array()),
|
||||
// Multiple needles
|
||||
array(true, 'Str contains foo bar', array('foo', 'bar')),
|
||||
array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*', '&^%')),
|
||||
array(true, 'Ο συγγραφέας είπε', array('συγγρ', 'αφέας'), 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å´¥', '©'), true, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å˚ ', '∆'), true, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('øœ', '¬'), true, 'UTF-8'),
|
||||
array(false, 'Str contains foo bar', array('Foo', 'bar')),
|
||||
array(false, 'Str contains foo bar', array('foobar', 'bar')),
|
||||
array(false, 'Str contains foo bar', array('foo bar ', 'bar')),
|
||||
array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' συγγραφ '), true, 'UTF-8'),
|
||||
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßå˚', ' ß '), true, 'UTF-8'),
|
||||
array(true, 'Str contains foo bar', array('Foo bar', 'bar'), false),
|
||||
array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*&^%', '*&^%'), false),
|
||||
array(true, 'Ο συγγραφέας είπε', array('ΣΥΓΓΡΑΦΈΑΣ', 'ΑΦΈΑ'), false, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å´¥©', '¥©'), false, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å˚ ∆', ' ∆'), false, 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('ØŒ¬', 'Œ'), false, 'UTF-8'),
|
||||
array(false, 'Str contains foo bar', array('foobar', 'none'), false),
|
||||
array(false, 'Str contains foo bar', array('foo bar ', ' ba'), false),
|
||||
array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' ραφέ '), false, 'UTF-8'),
|
||||
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßÅ˚', ' Å˚ '), false, 'UTF-8'),
|
||||
);
|
||||
|
||||
return array_merge($singleNeedle, $provider);
|
||||
}
|
||||
|
||||
public function surroundProvider()
|
||||
{
|
||||
return array(
|
||||
@@ -488,7 +640,49 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('fòô bàř', ' fòô bàř '),
|
||||
array('fòô bàř', ' fòô bàř'),
|
||||
array('fòô bàř', 'fòô bàř '),
|
||||
array('fòô bàř', "\n\t fòô bàř \n\t")
|
||||
array(' foo bar ', "\n\t foo bar \n\t", "\n\t"),
|
||||
array('fòô bàř', "\n\t fòô bàř \n\t", null, 'UTF-8'),
|
||||
array('fòô', ' fòô ', null, 'UTF-8'), // narrow no-break space (U+202F)
|
||||
array('fòô', ' fòô ', null, 'UTF-8'), // medium mathematical space (U+205F)
|
||||
array('fòô', ' fòô', null, 'UTF-8') // spaces U+2000 to U+200A
|
||||
);
|
||||
}
|
||||
|
||||
public function trimLeftProvider()
|
||||
{
|
||||
return array(
|
||||
array('foo bar ', ' foo bar '),
|
||||
array('foo bar', ' foo bar'),
|
||||
array('foo bar ', 'foo bar '),
|
||||
array("foo bar \n\t", "\n\t foo bar \n\t"),
|
||||
array('fòô bàř ', ' fòô bàř '),
|
||||
array('fòô bàř', ' fòô bàř'),
|
||||
array('fòô bàř ', 'fòô bàř '),
|
||||
array('foo bar', '--foo bar', '-'),
|
||||
array('fòô bàř', 'òòfòô bàř', 'ò', 'UTF-8'),
|
||||
array("fòô bàř \n\t", "\n\t fòô bàř \n\t", null, 'UTF-8'),
|
||||
array('fòô ', ' fòô ', null, 'UTF-8'), // narrow no-break space (U+202F)
|
||||
array('fòô ', ' fòô ', null, 'UTF-8'), // medium mathematical space (U+205F)
|
||||
array('fòô', ' fòô', null, 'UTF-8') // spaces U+2000 to U+200A
|
||||
);
|
||||
}
|
||||
|
||||
public function trimRightProvider()
|
||||
{
|
||||
return array(
|
||||
array(' foo bar', ' foo bar '),
|
||||
array('foo bar', 'foo bar '),
|
||||
array(' foo bar', ' foo bar'),
|
||||
array("\n\t foo bar", "\n\t foo bar \n\t"),
|
||||
array(' fòô bàř', ' fòô bàř '),
|
||||
array('fòô bàř', 'fòô bàř '),
|
||||
array(' fòô bàř', ' fòô bàř'),
|
||||
array('foo bar', 'foo bar--', '-'),
|
||||
array('fòô bàř', 'fòô bàřòò', 'ò', 'UTF-8'),
|
||||
array("\n\t fòô bàř", "\n\t fòô bàř \n\t", null, 'UTF-8'),
|
||||
array(' fòô', ' fòô ', null, 'UTF-8'), // narrow no-break space (U+202F)
|
||||
array(' fòô', ' fòô ', null, 'UTF-8'), // medium mathematical space (U+205F)
|
||||
array('fòô', 'fòô ', null, 'UTF-8') // spaces U+2000 to U+200A
|
||||
);
|
||||
}
|
||||
|
||||
@@ -655,6 +849,8 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('bar', 'foo bar', 'foo '),
|
||||
array('foo bar', 'foo bar', 'oo'),
|
||||
array('foo bar', 'foo bar', 'oo bar'),
|
||||
array('oo bar', 'foo bar', Stringy::create('foo bar')->first(1), 'UTF-8'),
|
||||
array('oo bar', 'foo bar', Stringy::create('foo bar')->at(0), 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', '', 'UTF-8'),
|
||||
array('òô bàř', 'fòô bàř', 'f', 'UTF-8'),
|
||||
array('bàř', 'fòô bàř', 'fòô ', 'UTF-8'),
|
||||
@@ -671,6 +867,8 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('foo', 'foo bar', ' bar'),
|
||||
array('foo bar', 'foo bar', 'ba'),
|
||||
array('foo bar', 'foo bar', 'foo ba'),
|
||||
array('foo ba', 'foo bar', Stringy::create('foo bar')->last(1), 'UTF-8'),
|
||||
array('foo ba', 'foo bar', Stringy::create('foo bar')->at(6), 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', '', 'UTF-8'),
|
||||
array('fòô bà', 'fòô bàř', 'ř', 'UTF-8'),
|
||||
array('fòô', 'fòô bàř', ' bàř', 'UTF-8'),
|
||||
@@ -725,8 +923,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array(false, "\n\t ' \v\f"),
|
||||
array(false, "\n\t 2 \v\f"),
|
||||
array(true, '', 'UTF-8'),
|
||||
array(true, ' ', 'UTF-8'), // thin space
|
||||
array(true, ' ', 'UTF-8'), // ideographic spaces
|
||||
array(true, ' ', 'UTF-8'), // no-break space (U+00A0)
|
||||
array(true, ' ', 'UTF-8'), // spaces U+2000 to U+200A
|
||||
array(true, ' ', 'UTF-8'), // narrow no-break space (U+202F)
|
||||
array(true, ' ', 'UTF-8'), // medium mathematical space (U+205F)
|
||||
array(true, ' ', 'UTF-8'), // ideographic space (U+3000)
|
||||
array(false, ' z', 'UTF-8'),
|
||||
array(false, ' 1', 'UTF-8'),
|
||||
);
|
||||
@@ -766,6 +967,24 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function hasLowerCaseProvider()
|
||||
{
|
||||
return array(
|
||||
array(false, ''),
|
||||
array(true, 'foobar'),
|
||||
array(false, 'FOO BAR'),
|
||||
array(true, 'fOO BAR'),
|
||||
array(true, 'foO BAR'),
|
||||
array(true, 'FOO BAr'),
|
||||
array(true, 'Foobar'),
|
||||
array(false, 'FÒÔBÀŘ', 'UTF-8'),
|
||||
array(true, 'fòôbàř', 'UTF-8'),
|
||||
array(true, 'fòôbàř2', 'UTF-8'),
|
||||
array(true, 'Fòô bàř', 'UTF-8'),
|
||||
array(true, 'fòôbÀŘ', 'UTF-8'),
|
||||
);
|
||||
}
|
||||
|
||||
public function isSerializedProvider()
|
||||
{
|
||||
return array(
|
||||
@@ -793,6 +1012,24 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function hasUpperCaseProvider()
|
||||
{
|
||||
return array(
|
||||
array(false, ''),
|
||||
array(true, 'FOOBAR'),
|
||||
array(false, 'foo bar'),
|
||||
array(true, 'Foo bar'),
|
||||
array(true, 'FOo bar'),
|
||||
array(true, 'foo baR'),
|
||||
array(true, 'fOOBAR'),
|
||||
array(false, 'fòôbàř', 'UTF-8'),
|
||||
array(true, 'FÒÔBÀŘ', 'UTF-8'),
|
||||
array(true, 'FÒÔBÀŘ2', 'UTF-8'),
|
||||
array(true, 'fÒÔ BÀŘ', 'UTF-8'),
|
||||
array(true, 'FÒÔBàř', 'UTF-8'),
|
||||
);
|
||||
}
|
||||
|
||||
public function isHexadecimalProvider()
|
||||
{
|
||||
return array(
|
||||
@@ -868,4 +1105,26 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('fòô', 'bàř', '[[:alpha:]]{3}', 'fòô', 'msr', 'UTF-8')
|
||||
);
|
||||
}
|
||||
|
||||
public function htmlEncodeProvider()
|
||||
{
|
||||
return array(
|
||||
array('&', '&'),
|
||||
array('"', '"'),
|
||||
array(''', "'", ENT_QUOTES),
|
||||
array('<', '<'),
|
||||
array('>', '>'),
|
||||
);
|
||||
}
|
||||
|
||||
public function htmlDecodeProvider()
|
||||
{
|
||||
return array(
|
||||
array('&', '&'),
|
||||
array('"', '"'),
|
||||
array("'", ''', ENT_QUOTES),
|
||||
array('<', '<'),
|
||||
array('>', '>'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
16
tests/CreateTest.php
Normal file
16
tests/CreateTest.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/Create.php';
|
||||
|
||||
use function Stringy\create as s;
|
||||
|
||||
class CreateTestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$stringy = s('foo bar', 'UTF-8');
|
||||
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
||||
$this->assertEquals('foo bar', (string) $stringy);
|
||||
$this->assertEquals('UTF-8', $stringy->getEncoding());
|
||||
}
|
||||
}
|
@@ -6,6 +6,24 @@ use Stringy\StaticStringy as S;
|
||||
|
||||
class StaticStringyTestCase extends CommonTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider indexOfProvider()
|
||||
*/
|
||||
public function testIndexOf($expected, $str, $subStr, $offset = 0, $encoding = null)
|
||||
{
|
||||
$result = S::indexOf($str, $subStr, $offset, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider indexOfLastProvider()
|
||||
*/
|
||||
public function testIndexOfLast($expected, $str, $subStr, $offset = 0, $encoding = null)
|
||||
{
|
||||
$result = S::indexOfLast($str, $subStr, $offset, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider charsProvider()
|
||||
*/
|
||||
@@ -133,9 +151,9 @@ class StaticStringyTestCase extends CommonTest
|
||||
/**
|
||||
* @dataProvider toAsciiProvider()
|
||||
*/
|
||||
public function testToAscii($expected, $str)
|
||||
public function testToAscii($expected, $str, $removeUnsupported = true)
|
||||
{
|
||||
$result = S::toAscii($str);
|
||||
$result = S::toAscii($str, $removeUnsupported);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
@@ -244,6 +262,16 @@ class StaticStringyTestCase extends CommonTest
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider toTitleCaseProvider()
|
||||
*/
|
||||
public function testToTitleCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::toTitleCase($str, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider toUpperCaseProvider()
|
||||
*/
|
||||
@@ -275,6 +303,28 @@ class StaticStringyTestCase extends CommonTest
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider containsAnyProvider()
|
||||
*/
|
||||
public function testcontainsAny($expected, $haystack, $needles,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$result = S::containsAny($haystack, $needles, $caseSensitive, $encoding);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider containsAllProvider()
|
||||
*/
|
||||
public function testContainsAll($expected, $haystack, $needles,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$result = S::containsAll($haystack, $needles, $caseSensitive, $encoding);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider surroundProvider()
|
||||
*/
|
||||
@@ -352,9 +402,31 @@ class StaticStringyTestCase extends CommonTest
|
||||
/**
|
||||
* @dataProvider trimProvider()
|
||||
*/
|
||||
public function testTrim($expected, $str)
|
||||
public function testTrim($expected, $str, $chars = null, $encoding = null)
|
||||
{
|
||||
$result = S::trim($str);
|
||||
$result = S::trim($str, $chars, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider trimLeftProvider()
|
||||
*/
|
||||
public function testTrimLeft($expected, $str, $chars = null,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::trimLeft($str, $chars, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider trimRightProvider()
|
||||
*/
|
||||
public function testTrimRight($expected, $str, $chars = null,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::trimRight($str, $chars, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
@@ -533,6 +605,16 @@ class StaticStringyTestCase extends CommonTest
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider hasLowerCaseProvider()
|
||||
*/
|
||||
public function testHasLowerCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::hasLowerCase($str, $encoding);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider isSerializedProvider()
|
||||
*/
|
||||
@@ -553,6 +635,16 @@ class StaticStringyTestCase extends CommonTest
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider hasUpperCaseProvider()
|
||||
*/
|
||||
public function testHasUpperCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::hasUpperCase($str, $encoding);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider isHexadecimalProvider()
|
||||
*/
|
||||
@@ -595,4 +687,24 @@ class StaticStringyTestCase extends CommonTest
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider htmlEncodeProvider()
|
||||
*/
|
||||
public function testHtmlEncode($expected, $str, $flags = ENT_COMPAT, $encoding = null)
|
||||
{
|
||||
$result = S::htmlEncode($str, $flags, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider htmlDecodeProvider()
|
||||
*/
|
||||
public function testHtmlDecode($expected, $str, $flags = ENT_COMPAT, $encoding = null)
|
||||
{
|
||||
$result = S::htmlDecode($str, $flags, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ class StringyTestCase extends CommonTest
|
||||
public function testConstruct()
|
||||
{
|
||||
$stringy = new S('foo bar', 'UTF-8');
|
||||
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
||||
$this->assertStringy($stringy);
|
||||
$this->assertEquals('foo bar', (string) $stringy);
|
||||
$this->assertEquals('UTF-8', $stringy->getEncoding());
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class StringyTestCase extends CommonTest
|
||||
public function testCreate()
|
||||
{
|
||||
$stringy = S::create('foo bar', 'UTF-8');
|
||||
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
||||
$this->assertStringy($stringy);
|
||||
$this->assertEquals('foo bar', (string) $stringy);
|
||||
$this->assertEquals('UTF-8', $stringy->getEncoding());
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class StringyTestCase extends CommonTest
|
||||
public function testChaining()
|
||||
{
|
||||
$stringy = S::create("Fòô Bàř", 'UTF-8');
|
||||
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
||||
$this->assertStringy($stringy);
|
||||
$result = $stringy->collapseWhitespace()->swapCase()->upperCaseFirst();
|
||||
$this->assertEquals('FÒÔ bÀŘ', $result);
|
||||
}
|
||||
@@ -153,6 +153,24 @@ class StringyTestCase extends CommonTest
|
||||
unset($stringy[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider indexOfProvider()
|
||||
*/
|
||||
public function testIndexOf($expected, $str, $subStr, $offset = 0, $encoding = null)
|
||||
{
|
||||
$result = S::create($str, $encoding)->indexOf($subStr, $offset);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider indexOfLastProvider()
|
||||
*/
|
||||
public function testIndexOfLast($expected, $str, $subStr, $offset = 0, $encoding = null)
|
||||
{
|
||||
$result = S::create($str, $encoding)->indexOfLast($subStr, $offset);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider charsProvider()
|
||||
*/
|
||||
@@ -172,7 +190,7 @@ class StringyTestCase extends CommonTest
|
||||
public function testUpperCaseFirst($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::create($str, $encoding)->upperCaseFirst();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
@@ -183,7 +201,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->lowerCaseFirst();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -195,7 +213,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->camelize();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -207,7 +225,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->upperCamelize();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -219,7 +237,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->dasherize();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -231,7 +249,19 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->underscored();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider delimitProvider()
|
||||
*/
|
||||
public function testDelimit($expected, $str, $delimiter, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->delimit($delimiter);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -243,7 +273,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->swapCase();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -256,7 +286,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->titleize($ignore);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -268,7 +298,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->humanize();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -280,7 +310,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->tidy();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -292,7 +322,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->collapseWhitespace();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -300,11 +330,11 @@ class StringyTestCase extends CommonTest
|
||||
/**
|
||||
* @dataProvider toAsciiProvider()
|
||||
*/
|
||||
public function testToAscii($expected, $str)
|
||||
public function testToAscii($expected, $str, $removeUnsupported = true)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->toAscii();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$result = $stringy->toAscii($removeUnsupported);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -317,7 +347,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->pad($length, $padStr, $padType);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -339,7 +369,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->padLeft($length, $padStr);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -352,7 +382,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->padRight($length, $padStr);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -365,7 +395,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->padBoth($length, $padStr);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -403,7 +433,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->toSpaces($tabLength);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -415,7 +445,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->toTabs($tabLength);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -427,7 +457,19 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->toLowerCase();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider toTitleCaseProvider()
|
||||
*/
|
||||
public function testToTitleCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->toTitleCase();
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -439,7 +481,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->toUpperCase();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -451,7 +493,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->slugify($replacement);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -469,6 +511,32 @@ class StringyTestCase extends CommonTest
|
||||
$this->assertEquals($haystack, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider containsAnyProvider()
|
||||
*/
|
||||
public function testcontainsAny($expected, $haystack, $needles,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($haystack, $encoding);
|
||||
$result = $stringy->containsAny($needles, $caseSensitive);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($haystack, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider containsAllProvider()
|
||||
*/
|
||||
public function testContainsAll($expected, $haystack, $needles,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($haystack, $encoding);
|
||||
$result = $stringy->containsAll($needles, $caseSensitive);
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($haystack, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider surroundProvider()
|
||||
*/
|
||||
@@ -476,7 +544,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->surround($substring);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -489,7 +557,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->insert($substring, $index);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -502,7 +570,20 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->truncate($length, $substring);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider safeTruncateProvider()
|
||||
*/
|
||||
public function testSafeTruncate($expected, $str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->safeTruncate($length, $substring);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -514,7 +595,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->reverse();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -528,7 +609,7 @@ class StringyTestCase extends CommonTest
|
||||
$encoding = $encoding ?: mb_internal_encoding();
|
||||
$result = $stringy->shuffle();
|
||||
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
$this->assertEquals(mb_strlen($str, $encoding),
|
||||
mb_strlen($result, $encoding));
|
||||
@@ -545,11 +626,37 @@ class StringyTestCase extends CommonTest
|
||||
/**
|
||||
* @dataProvider trimProvider()
|
||||
*/
|
||||
public function testTrim($expected, $str)
|
||||
public function testTrim($expected, $str, $chars = null, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->trim();
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->trim($chars);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider trimLeftProvider()
|
||||
*/
|
||||
public function testTrimLeft($expected, $str, $chars = null,
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->trimLeft($chars);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider trimRightProvider()
|
||||
*/
|
||||
public function testTrimRight($expected, $str, $chars = null,
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->trimRight($chars);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -562,7 +669,20 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->longestCommonPrefix($otherStr);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider longestCommonSuffixProvider()
|
||||
*/
|
||||
public function testLongestCommonSuffix($expected, $str, $otherStr,
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->longestCommonSuffix($otherStr);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -575,7 +695,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->longestCommonSubstring($otherStr);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -600,7 +720,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->substr($start, $length);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -612,7 +732,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->at($index);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -624,7 +744,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->first($n);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -636,7 +756,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->last($n);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -648,7 +768,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->ensureLeft($substring);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -660,7 +780,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->ensureRight($substring);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -672,7 +792,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->removeLeft($substring);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -684,7 +804,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->removeRight($substring);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -749,6 +869,18 @@ class StringyTestCase extends CommonTest
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider hasLowerCaseProvider()
|
||||
*/
|
||||
public function testHasLowerCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->hasLowerCase();
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider isSerializedProvider()
|
||||
*/
|
||||
@@ -773,6 +905,18 @@ class StringyTestCase extends CommonTest
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider hasUpperCaseProvider()
|
||||
*/
|
||||
public function testHasUpperCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->hasUpperCase();
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider isHexadecimalProvider()
|
||||
*/
|
||||
@@ -806,7 +950,7 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->replace($search, $replacement);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
@@ -819,7 +963,31 @@ class StringyTestCase extends CommonTest
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->regexReplace($pattern, $replacement, $options);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider htmlEncodeProvider()
|
||||
*/
|
||||
public function testHtmlEncode($expected, $str, $flags = ENT_COMPAT, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->htmlEncode($flags);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider htmlDecodeProvider()
|
||||
*/
|
||||
public function testHtmlDecode($expected, $str, $flags = ENT_COMPAT, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->htmlDecode($flags);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
Reference in New Issue
Block a user