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

91 Commits
1.4.0 ... 1.8.1

Author SHA1 Message Date
Daniel St. Jules
6a7b0391b2 1.8.1 2015-01-08 07:21:43 -08:00
Daniel St. Jules
d6fa00bb1c Conditionally load Stringy\create 2015-01-07 09:09:07 -08:00
Daniel St. Jules
d1452263bd Merge pull request #59 from usernam3/master
Typecast comparison in startsWith/endsWith
2015-01-06 21:42:16 -08:00
Stanislav Dobrovolskiy
9da55d5d4f type cast in startsWith && endsWith, test cases for this behavior 2015-01-07 06:06:53 +02:00
Daniel St. Jules
b515598227 Merge pull request #67 from vlakoff/regex
Remove some useless (and erroneous) regex capturing groups
2015-01-06 16:42:30 -08:00
Daniel St. Jules
28b65615d7 Merge pull request #66 from vlakoff/nbsp
Support for various Unicode spaces in toAscii()
2015-01-06 16:38:55 -08:00
vlakoff
7b88b4f3da Support for various Unicode spaces in toAscii()
* no-break space (U+00A0)
* thin space (U+2009)
* narrow no-break space (U+202F)
* ideographic space (U+3000)
2015-01-07 01:28:49 +01:00
vlakoff
70e5b9c38b Remove some useless (and erroneous) regex capturing groups 2015-01-07 01:24:40 +01:00
vlakoff
e0d50f0b8f Unit tests for no-break space in collapseWhitespace() and isBlank() 2015-01-07 01:10:30 +01:00
Daniel St. Jules
c5365f256f Merge pull request #64 from vlakoff/tests
Add missing tests in StringyTest
2015-01-06 13:42:20 -08:00
Daniel St. Jules
401af084c7 Merge pull request #63 from vlakoff/docblock
Proper Stringy\create() description
2015-01-05 16:37:27 -08:00
vlakoff
773477cdd8 Add missing tests in StringyTest
For consistency with StaticStringyTest.
2015-01-06 00:39:31 +01:00
vlakoff
26444e4429 Proper Stringy\create() description 2015-01-06 00:10:39 +01:00
Daniel St. Jules
f3d32c79b0 Merge pull request #62 from vlakoff/static
Replace self::create() with static::create()
2015-01-05 14:06:06 -08:00
vlakoff
98c1013623 Replace self::create() with static::create()
In case someone wants to extend create().
2015-01-05 23:02:06 +01:00
Daniel St. Jules
91d8da4741 Cleanup toAscii array alignment 2015-01-05 13:55:08 -08:00
Daniel St. Jules
49cdd5b1e6 Merge pull request #61 from vlakoff/toAscii
Add « ä Ä Ö Ü » in toAscii()
2015-01-05 13:38:30 -08:00
vlakoff
2fe42b46a1 Add « ä Ä Ö Ü » in toAscii()
To complete diareses on vowels.
2015-01-05 22:20:22 +01:00
Daniel St. Jules
9baa545f23 Merge pull request #60 from vlakoff/optimize
Optimize chars() by not repeatedly call length()
2015-01-05 12:08:58 -05:00
vlakoff
640fc5b26b Optimize chars() by not repeatedly call length() 2015-01-05 13:49:48 +01:00
Daniel St. Jules
d661047fb3 1.8.0 2015-01-03 22:54:13 -08:00
Daniel St. Jules
26fe399396 Merge pull request #58 from GrahamCampbell/patch-1
Remove duplicate dependencies from autoload-dev
2015-01-03 19:26:38 -05:00
Daniel St. Jules
31c4ba145f Merge pull request #57 from vlakoff/dependency
Add ext-mbstring to composer.json
2015-01-03 19:25:41 -05:00
Graham Campbell
5a1be9bf20 autoload-dev behave the same as require-dev 2015-01-03 22:55:35 +00:00
vlakoff
28c3db01c5 Add ext-mbstring to composer.json 2015-01-03 23:20:21 +01:00
Daniel St. Jules
27ef5a8914 Add Stringy\create function for PHP 5.6 2015-01-01 21:40:48 -08:00
Daniel St. Jules
350d1e6f8e Merge pull request #56 from GrahamCampbell/patch-1
Tweaked the test config
2014-10-26 07:47:54 -07:00
Graham Campbell
ce58c93fc2 Tweaked the test config 2014-10-26 12:44:18 +00:00
Daniel St. Jules
d60422d197 1.7.0 2014-10-14 23:32:13 -07:00
Daniel St. Jules
3cc12c2ee7 Added containsAll and containsAny to readme 2014-10-14 23:25:43 -07:00
Daniel St. Jules
8e16ad472d Add docblocks for str and encoding 2014-10-14 23:14:02 -07:00
Daniel St. Jules
3f926c654a Merge pull request #49 from lucasmichot/factorize-substr
Factorize substr
2014-09-29 08:02:06 -07:00
Daniel St. Jules
f8fc711ae1 Merge pull request #51 from lucasmichot/remove-useless-variable
Remove useless variable
2014-09-29 07:58:45 -07:00
Daniel St. Jules
628c467a67 Merge pull request #48 from lucasmichot/factorize-tidy
Factorize tidy
2014-09-29 07:58:29 -07:00
Daniel St. Jules
24aa843639 Merge pull request #47 from lucasmichot/factorize-humanize
Factorize humanize
2014-09-29 07:43:43 -07:00
Lucas Michot
bb6ea99c52 Remove useless variable 2014-09-29 14:24:02 +02:00
Lucas Michot
d1df244678 Use $this 2014-09-29 14:05:35 +02:00
Lucas Michot
9a929d1860 Simplify substr 2014-09-29 13:48:30 +02:00
Lucas Michot
583789b9e3 Simplify tidy 2014-09-29 13:13:55 +02:00
Lucas Michot
f00e3d5d80 Simplify humanize 2014-09-29 13:08:57 +02:00
Daniel St. Jules
c31e41f57a Merge pull request #45 from GrahamCampbell/cs
CS Fixes
2014-09-27 09:25:57 -07:00
Graham Campbell
722f30d132 CS fixes 2014-09-27 17:23:34 +01:00
Daniel St. Jules
26a0fed52e Merge and fix containsAll 2014-09-27 09:07:37 -07:00
Daniel St. Jules
1c0026ca00 Cleanup containsAny 2014-09-27 08:42:51 -07:00
Lucas Michot
da5ee7057d Add containsAll 2014-09-23 23:51:27 +02:00
Lucas Michot
410ceac663 Add containsAny 2014-09-23 23:48:28 +02:00
Daniel St. Jules
857650f278 Merge pull request #42 from lucasmichot/assertStringy
Add assertStringy shortcut
2014-09-23 14:28:05 -07:00
Lucas Michot
bc11fce93e Add assertStringy shortcut 2014-09-23 22:48:14 +02:00
Daniel St. Jules
fc885d777d Merge pull request #38 from lucasmichot/psr2
Small PSR-2 fixes
2014-09-23 08:49:03 -07:00
Lucas Michot
9d2863b983 Go psr-2 2014-09-23 17:40:58 +02:00
Daniel St. Jules
037184e3d9 Updated intro in README 2014-09-14 23:01:46 -07:00
Daniel St. Jules
8ac1918386 Updated travis ci badge 2014-09-14 11:07:24 -07:00
Daniel St. Jules
7cb6709fd4 Merge pull request #33 from GrahamCampbell/patch-1
Improved the suggested version constraint
2014-09-14 11:05:17 -07:00
Graham Campbell
a663802c2c Improved the suggested version constraint 2014-09-14 19:02:49 +01:00
Daniel St. Jules
7e91d1ead2 1.6.0 2014-09-14 10:58:46 -07:00
Daniel St. Jules
abf3e38c1c Updated logo 2014-09-14 10:49:26 -07:00
Daniel St. Jules
5a5c39d02b Fix readme 2014-09-14 09:49:26 -07:00
Daniel St. Jules
c577684e0a Renamed toTitleCase 2014-09-14 09:27:46 -07:00
Lucas Michot
681463de87 Add casetitle function 2014-09-14 14:16:09 +02:00
Daniel St. Jules
90de5cca00 Merge pull request #29 from GrahamCampbell/patch-1
Update .travis.yml
2014-07-09 22:21:03 -04:00
Graham Campbell
a0b7615210 Update .travis.yml 2014-07-09 18:18:00 +01:00
Daniel St. Jules
63ad4d238f 1.5.2 release 2014-07-09 13:13:57 -04:00
Daniel St. Jules
ece219b609 Add note on HHVM support to readme 2014-07-09 13:11:48 -04:00
Daniel St. Jules
e81dbaa6d9 Disable allowing failures for 5.6 and hhvm 2014-05-18 21:02:29 -04:00
Daniel St. Jules
2b2c03bd1f Add 5.6 and hhvm to .travis.yml 2014-05-18 20:59:16 -04:00
Daniel St. Jules
7600549abc 1.5.1 release 2014-04-19 11:03:05 -04:00
Daniel St. Jules
8fe30d18b7 Fix toAscii failing to remove remaining non-ascii characters 2014-04-19 00:49:46 -04:00
Daniel St. Jules
ae7527ad4a Remove leading or trailing replacement from slugified string, if present 2014-04-19 00:33:59 -04:00
Yuri Druzhkov
f74f535b78 add preg_quote, add test on regex special symbols 2014-04-15 10:09:11 +04:00
Yuri Druzhkov
5c5087db13 dashes fixes 2014-04-01 18:03:48 +04:00
Daniel St. Jules
8d961e25d0 1.5.0 release 2014-03-19 19:25:00 -04:00
Daniel St. Jules
e46797a9f8 Updated pad methods 2014-03-19 00:40:36 -04:00
Daniel St. Jules
f0805f522d Merge branch 'pr/20' after cleanup 2014-03-18 23:36:52 -04:00
Bilge
6103eca714 Rewrote Stringy::pad to be DRY.
Fixed "Class 'CommonTest' not found" error when running specific tests in PHPUnit by including tests directory in Composer's autoloader.
2014-03-18 23:34:54 -04:00
Daniel St. Jules
952ffd4c00 Add tests classmap to composer
As suggested by Bilge in https://github.com/danielstjules/Stringy/pull/20
2014-03-09 20:52:18 -04:00
Daniel St. Jules
7832e22e09 Update require paths in tests 2014-03-09 20:12:53 -04:00
Daniel St. Jules
bcd87c69b8 Merge pull request #26 from lucasmichot/patch-1
Add PHPUnit 4.0.* to require-dev
2014-03-09 20:07:23 -04:00
Lucas
1d9001bcf0 Add PHPUnit 4.0.* to require-dev 2014-03-07 13:45:59 +01:00
Daniel St. Jules
ee88cd93e8 Rename protected method slug to applyDelimeter, fix typos in comments 2014-03-05 19:34:09 -05:00
Daniel St. Jules
48f53e98fa Merge pull request #25 from BastianHofmann/patch-1
DRY underscored and dasherize methods
2014-03-05 19:24:34 -05:00
Daniel St. Jules
6e7415a9f5 Merge pull request #24 from maximal/patch-1
Remove conflicting transliteration for Bulgarian
2014-03-05 19:23:16 -05:00
BastianHofmann
c62a5e8d4e DRY underscored and dasherize methods 2014-03-05 11:21:21 +01:00
MaximAL
cd41723b12 Update CommonTest.php 2014-02-19 10:43:06 +03:00
Daniel St. Jules
404909ffaa Fixes #19: Handle consecutive invalid chars in slugify 2014-02-17 11:22:59 -05:00
Daniel St. Jules
210c928b79 Added links to readme, included SliceableStringy 2014-02-17 10:41:38 -05:00
Daniel St. Jules
1965da2e39 Made str and encoding protected, added getEncoding
Neither should be private, so as to allow users to easily extend the
class
2014-02-16 21:22:32 -05:00
MaximAL
25fa7340ed Hard sign in Russian is not equivalent to a, it’s rather '
Apostrophe is also most common transliteration character for soft sign (ь).
2014-02-16 18:50:29 +03:00
Daniel St. Jules
e5f66c6eca Merge pull request #21 from Bilge/dry-regex-replace
Optimized replace() and collapseWhitespace() by reusing regexReplace().
2014-02-14 07:09:57 -05:00
Bilge
5d7e9a8d36 Optimized replace() and collapseWhitespace() by reusing regexReplace().
Fixed bug in replace() where replacement string was being escaped with preg_quote() and added matching tests.
2014-02-14 01:26:55 +00:00
Daniel St. Jules
a7c5b8721c Add composer.lock and .DS_Store to .gitignore 2014-02-13 13:29:57 -05:00
Daniel St. Jules
9399f7a694 Fix isJSON
Thanks to Drainedsoul
2014-02-13 06:32:54 -05:00
13 changed files with 781 additions and 265 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
vendor/
composer.lock
.DS_Store

View File

@@ -1,5 +1,7 @@
language: php
php:
- 5.6
- 5.5
- 5.4
- 5.3
- hhvm

View File

@@ -1,3 +1,46 @@
### 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
### 1.5.1 (2014-04-19)
* Fixed toAscii() failing to remove remaining non-ascii characters
* Updated slugify() to treat dash and underscore as delimiters by default
* Updated slugify() to remove leading and trailing delimiter, if present
### 1.5.0 (2014-03-19)
* Made both str and encoding protected, giving property access to subclasses
* Added getEncoding()
* Fixed isJSON() giving false negatives
* Cleaned up and simplified: replace(), collapseWhitespace(), underscored(),
dasherize(), pad(), padLeft(), padRight() and padBoth()
* Fixed handling consecutive invalid chars in slugify()
* Removed conflicting hard sign transliteration in toAscii()
### 1.4.0 (2014-02-12)
* Implemented the IteratorAggregate interface, added chars()

View File

@@ -1,20 +1,23 @@
![Stringy](http://danielstjules.com/stringy/logo.png)
![Stringy](http://danielstjules.com/github/stringy-logo.png)
A PHP library with a variety of string manipulation functions with multibyte
support. Offers both OO method chaining and a procedural-style static wrapper.
Compatible with PHP 5.3+. 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.
[![Build Status](https://travis-ci.org/danielstjules/Stringy.png)](https://travis-ci.org/danielstjules/Stringy)
[![Build Status](https://api.travis-ci.org/danielstjules/Stringy.svg?branch=master)](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)
@@ -22,6 +25,7 @@ Compatible with PHP 5.3+. Inspired by underscore.string.js.
* [ensureLeft](#ensureleft)
* [ensureRight](#ensureright)
* [first](#first)
* [getEncoding](#getencoding)
* [humanize](#humanize)
* [insert](#insert)
* [isAlpha](#isalpha)
@@ -60,12 +64,14 @@ Compatible with PHP 5.3+. Inspired by underscore.string.js.
* [toLowerCase](#tolowercase)
* [toSpaces](#tospaces)
* [toTabs](#totabs)
* [toTitleCase](#totitlecase)
* [toUpperCase](#touppercase)
* [trim](#trim)
* [truncate](#truncate)
* [underscored](#underscored)
* [upperCamelize](#uppercamelize)
* [upperCaseFirst](#uppercasefirst)
* [Links](#links)
* [Tests](#tests)
* [License](#license)
@@ -74,9 +80,13 @@ Compatible with PHP 5.3+. 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": "dev-master"
"danielstjules/stringy": "~1.8"
}
}
```
Then, after running `composer update` or `php composer.phar update`, you can
load the class using Composer's autoloading:
@@ -162,6 +172,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
@@ -242,6 +267,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 ])
@@ -340,6 +395,16 @@ S::create('fòô bàř', 'UTF-8')->first(3);
S::first('fòô bàř', 3, 'UTF-8'); // 'fòô'
```
#### getEncoding
$stringy->getEncoding()
Returns the encoding used by the Stringy object.
```php
S::create('fòô bàř', 'UTF-8')->getEncoding(); // 'UTF-8'
```
#### humanize
$stringy->humanize()
@@ -869,6 +934,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()
@@ -954,6 +1032,13 @@ S::create('σ test', 'UTF-8')->upperCaseFirst();
S::upperCaseFirst('σ test', 'UTF-8'); // 'Σ test'
```
## Links
The following is a list of libraries that extend Stringy:
* [SliceableStringy](https://github.com/danielstjules/SliceableStringy):
Python-like string slices in PHP
## Tests
From the project directory, tests can be ran using `phpunit`

View File

@@ -15,13 +15,21 @@
}
],
"require": {
"php": ">=5.3.0"
"php": ">=5.3.0",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"support": {
"issues": "https://github.com/danielstjules/Stringy/issues",
"source": "https://github.com/danielstjules/Stringy"
},
"autoload": {
"psr-4": { "Stringy\\": "src/" }
"psr-4": { "Stringy\\": "src/" },
"files": ["src/Create.php"]
},
"autoload-dev": {
"classmap": [ "tests" ]
}
}

View File

@@ -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
View 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);
}
}

View File

@@ -323,6 +323,18 @@ class StaticStringy
return (string) Stringy::create($str, $encoding)->toLowerCase();
}
/**
* Converts the first character of each word in the string to uppercase.
*
* @param string $str String to convert case
* @param string $encoding The character encoding
* @return string The title-cased string
*/
public static function toTitleCase($str, $encoding = null)
{
return (string) Stringy::create($str, $encoding)->toTitleCase();
}
/**
* Converts all characters in the string to uppercase. An alias for PHP's
* mb_strtoupper().
@@ -370,6 +382,42 @@ 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);
}
/**
* Surrounds a string with the given substring.
*
@@ -428,7 +476,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);

View File

@@ -4,9 +4,20 @@ namespace Stringy;
class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{
private $str;
/**
* An instance's string.
*
* @var string
*/
protected $str;
public $encoding;
/**
* The string's encoding, which should be one of the mbstring module's
* supported encodings.
*
* @var string
*/
protected $encoding;
/**
* Initializes a Stringy object and assigns both str and encoding properties
@@ -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'
);
@@ -64,6 +75,16 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
return $this->str;
}
/**
* Returns the encoding used by the Stringy object.
*
* @return string The current value of the $encoding property
*/
public function getEncoding()
{
return $this->encoding;
}
/**
* Returns the length of the string, implementing the countable interface.
*
@@ -95,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;
@@ -117,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();
@@ -136,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');
}
@@ -148,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');
}
@@ -161,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;
}
@@ -181,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);
}
/**
@@ -197,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);
}
/**
@@ -210,11 +235,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
public function camelize()
{
$encoding = $this->encoding;
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
$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
@@ -222,7 +247,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$stringy->str = preg_replace_callback(
'/[\d]+(.)?/u',
function($match) use ($encoding) {
function ($match) use ($encoding) {
return mb_strtoupper($match[0], $encoding);
},
$camelCase
@@ -252,17 +277,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function dasherize()
{
// 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])', '-\1', trim($this->str));
$str = mb_ereg_replace('[-_\s]+', '-', $str);
$str = mb_strtolower($str, $this->encoding);
mb_regex_encoding($regexEncoding);
return self::create($str, $this->encoding);
return $this->applyDelimeter('-');
}
/**
@@ -274,18 +289,29 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
* @return Stringy Object with an underscored $str
*/
public function underscored()
{
return $this->applyDelimeter('_');
}
/**
* Returns a lowercase and trimmed string separated by the given delimiter.
*
* @param string $delimiter Sequence used to separate parts of the string
* @return Stringy Object with a delimited $str
*/
protected function applyDelimeter($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])', '_\1', trim($this->str));
$str = mb_ereg_replace('[-_\s]+', '_', $str);
$str = mb_ereg_replace('\B([A-Z])', $delimiter .'\1', trim($this->str));
$str = mb_ereg_replace('[-_\s]+', $delimiter, $str);
$str = mb_strtolower($str, $this->encoding);
mb_regex_encoding($regexEncoding);
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -295,7 +321,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(
@@ -350,10 +376,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();
}
/**
@@ -365,13 +390,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);
}
/**
@@ -383,13 +414,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function collapseWhitespace()
{
$regexEncoding = mb_regex_encoding();
mb_regex_encoding($this->encoding);
$str = mb_ereg_replace('[[:space:]]+', ' ', $this->str);
mb_regex_encoding($regexEncoding);
return self::create($str, $this->encoding)->trim();
return $this->regexReplace('[[:space:]]+', ' ')->trim();
}
/**
@@ -402,33 +427,37 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{
$str = $this->str;
$charsArray = array(
'a' => array('à', 'á', 'â', 'ã', 'ā', 'ą', 'ă', 'å', 'α', 'ά', 'ἀ',
'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ',
'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ',
'ᾶ', 'ᾷ', 'а', 'ъ'),
'a' => array('à', 'á', 'â', 'ä', 'ã', 'ā', 'ą', 'ă', 'å', 'α',
'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ',
'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ',
'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а'),
'b' => array('б', 'β'),
'c' => array('ç', 'ć', 'č', 'ĉ', 'ċ'),
'd' => array('ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д'),
'e' => array('è', 'é', 'ê', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ',
'ἐ', 'ἑ', '', '', '', '', '', 'έ', 'е', 'ё', 'э', 'є'),
'd' => array('ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ',
'д'),
'e' => array('è', 'é', 'ê', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε',
'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е',
'ё', 'э', 'є'),
'f' => array('ф'),
'g' => array('ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ'),
'h' => array('ĥ', 'ħ'),
'i' => array('ì', 'í', 'î', 'ï', 'ī', 'ĩ', 'ĭ', 'į', 'ı', 'ι', 'ί',
'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ',
'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и'),
'i' => array('ì', 'í', 'î', 'ï', 'ī', 'ĩ', 'ĭ', 'į', 'ı', 'ι',
'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ',
'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і',
'ї', 'и'),
'j' => array('ĵ'),
'k' => array('ķ', 'ĸ', 'к'),
'l' => array('ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л'),
'm' => array('м'),
'n' => array('ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н'),
'o' => array('ò', 'ó', 'ô', 'õ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ό', 'ὀ',
'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'ö', 'о'),
'o' => array('ò', 'ó', 'ô', 'õ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ό',
'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'ö', 'о'),
'p' => array('п'),
'r' => array('ŕ', 'ř', 'ŗ', 'р'),
's' => array('ś', 'š', 'ş', 'с'),
't' => array('ť', 'ţ', 'т'),
'u' => array('ü', 'ù', 'ú', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ũ', 'ų', 'µ', 'у'),
'u' => array('ü', 'ù', 'ú', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ũ', 'ų',
'µ', 'у'),
'v' => array('в'),
'w' => array('ŵ'),
'y' => array('ÿ', 'ý', 'ŷ', 'й', 'ы'),
@@ -442,30 +471,33 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
'ya' => array('я'),
'yu' => array('ю'),
'zh' => array('ж'),
'A' => array('Á', 'Â', 'Ã', 'Å', 'Ā', 'Ą', 'Ă', 'Α', 'Ά', 'Ἀ', 'Ἁ',
'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ',
'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А', 'Ъ'),
'A' => array('Á', 'Â', 'Ä', 'Ã', 'Å', 'Ā', 'Ą', 'Ă', 'Α', 'Ά',
'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ',
'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά',
'ᾼ', 'А'),
'B' => array('Б'),
'C' => array('Ć', 'Č', 'Ĉ', 'Ċ'),
'D' => array('Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д'),
'E' => array('É', 'Ê', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ',
'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', 'Є'),
'E' => array('É', 'Ê', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ',
'Ἐ', 'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё',
'Э', 'Є'),
'F' => array('Ф'),
'G' => array('Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ'),
'I' => array('Í', 'Î', 'Ï', 'Ī', 'Ĩ', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ',
'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί',
'И', 'І', 'Ї'),
'I' => array('Í', 'Î', 'Ï', 'Ī', 'Ĩ', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί',
'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ',
'Ὶ', 'Ί', 'И', 'І', 'Ї'),
'K' => array('К'),
'L' => array('Ĺ', 'Ł', 'Л'),
'M' => array('М'),
'N' => array('Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н'),
'O' => array('Ó', 'Ô', 'Õ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ',
'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О'),
'O' => array('Ó', 'Ô', 'Ö', 'Õ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό',
'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О'),
'P' => array('П'),
'R' => array('Ř', 'Ŕ', 'Р'),
'S' => array('Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С'),
'T' => array('Ť', 'Ţ', 'Ŧ', 'Ț', 'Т'),
'U' => array('Ù', 'Ú', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ũ', 'Ų', 'У'),
'U' => array('Ù', 'Ú', 'Û', 'Ü', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ũ', 'Ų',
'У'),
'V' => array('В'),
'Y' => array('Ý', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й'),
'Z' => array('Ź', 'Ž', 'Ż', 'З'),
@@ -476,14 +508,18 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
'TS' => array('Ц'),
'YA' => array('Я'),
'YU' => array('Ю'),
'ZH' => array('Ж')
'ZH' => array('Ж'),
' ' => array("\xC2\xA0", "\xE2\x80\x89", "\xE2\x80\xAF",
"\xE3\x80\x80"),
);
foreach ($charsArray as $key => $value) {
$str = str_replace($value, $key, $str);
}
return self::create($str, $this->encoding);
$str = preg_replace('/[^\x20-\x7E]/u', '', $str);
return static::create($str, $this->encoding);
}
/**
@@ -507,44 +543,14 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
"to be one of 'left', 'right' or 'both'");
}
$stringy = self::create($this->str, $this->encoding);
$encoding = $stringy->encoding;
$strLength = $stringy->length();
$padStrLength = mb_strlen($padStr, $encoding);
if ($length <= $strLength || $padStrLength <= 0) {
return $stringy;
switch ($padType) {
case 'left':
return $this->padLeft($length, $padStr);
case 'right':
return $this->padRight($length, $padStr);
default:
return $this->padBoth($length, $padStr);
}
// Number of times to repeat the padStr if left or right
$times = ceil(($length - $strLength) / $padStrLength);
$paddedStr = '';
if ($padType == 'left') {
// Repeat the pad, cut it, and prepend
$leftPad = str_repeat($padStr, $times);
$leftPad = mb_substr($leftPad, 0, $length - $strLength, $encoding);
$stringy->str = $leftPad . $stringy->str;
} elseif ($padType == 'right') {
// Append the repeated pad and get a substring of the given length
$stringy->str = $stringy->str . str_repeat($padStr, $times);
$stringy->str = mb_substr($stringy->str, 0, $length, $encoding);
} else {
// Number of times to repeat the padStr on both sides
$paddingSize = ($length - $strLength) / 2;
$times = ceil($paddingSize / $padStrLength);
// Favour right padding over left, as with str_pad()
$rightPad = str_repeat($padStr, $times);
$rightPad = mb_substr($rightPad, 0, ceil($paddingSize), $encoding);
$leftPad = str_repeat($padStr, $times);
$leftPad = mb_substr($leftPad, 0, floor($paddingSize), $encoding);
$stringy->str = $leftPad . $stringy->str . $rightPad;
}
return $stringy;
}
/**
@@ -553,11 +559,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*
* @param int $length Desired string length after padding
* @param string $padStr String used to pad, defaults to space
* @return Stringy Object with a left padded $str
* @return Stringy String with left padding
*/
public function padLeft($length, $padStr = ' ')
{
return $this->pad($length, $padStr, 'left');
return $this->applyPadding($length - $this->length(), 0, $padStr);
}
/**
@@ -566,11 +572,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*
* @param int $length Desired string length after padding
* @param string $padStr String used to pad, defaults to space
* @return Stringy Object with a right padded $str
* @return Stringy String with right padding
*/
public function padRight($length, $padStr = ' ')
{
return $this->pad($length, $padStr, 'right');
return $this->applyPadding(0, $length - $this->length(), $padStr);
}
/**
@@ -579,11 +585,45 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*
* @param int $length Desired string length after padding
* @param string $padStr String used to pad, defaults to space
* @return Stringy The padded string
* @return Stringy String with padding applied
*/
public function padBoth($length, $padStr = ' ')
{
return $this->pad($length, $padStr, 'both');
$padding = $length - $this->length();
return $this->applyPadding(floor($padding / 2), ceil($padding / 2),
$padStr);
}
/**
* Adds the specified amount of left and right padding to the given string.
* The default character used is a space.
*
* @param int $left Length of left padding
* @param int $right Length of right padding
* @param string $padStr String used to pad
* @return Stringy String with padding applied
*/
private function applyPadding($left = 0, $right = 0, $padStr = ' ')
{
$stringy = static::create($this->str, $this->encoding);
$length = mb_strlen($padStr, $stringy->encoding);
$strLength = $stringy->length();
$paddedLength = $strLength + $left + $right;
if (!$length || $paddedLength <= $strLength) {
return $stringy;
}
$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);
$stringy->str = $leftPadding . $stringy->str . $rightPadding;
return $stringy;
}
/**
@@ -606,7 +646,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$startOfStr = mb_strtolower($startOfStr, $this->encoding);
}
return $substring === $startOfStr;
return (string) $substring === $startOfStr;
}
/**
@@ -631,7 +671,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$endOfStr = mb_strtolower($endOfStr, $this->encoding);
}
return $substring === $endOfStr;
return (string) $substring === $endOfStr;
}
/**
@@ -646,7 +686,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);
}
/**
@@ -662,7 +702,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);
}
/**
@@ -675,7 +727,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);
}
/**
@@ -688,7 +740,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);
}
/**
@@ -703,14 +755,14 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function slugify($replacement = '-')
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
$stringy->str = preg_replace("/[^a-zA-Z\d $replacement]/u", '',
$stringy->toAscii());
$stringy->str = $stringy->collapseWhitespace()->str;
$stringy->str = str_replace(' ', $replacement, strtolower($stringy));
$quotedReplacement = preg_quote($replacement);
$pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u";
$stringy->str = preg_replace($pattern, '', $stringy->toAscii());
return $stringy;
return $stringy->toLowerCase()->applyDelimeter($replacement)
->removeLeft($replacement)->removeRight($replacement);
}
/**
@@ -733,6 +785,54 @@ 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;
}
/**
* Surrounds $str with the given substring.
*
@@ -743,7 +843,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{
$str = implode('', array($substring, $this->str, $substring));
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -755,7 +855,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;
}
@@ -780,7 +880,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;
}
@@ -807,7 +907,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;
}
@@ -846,7 +946,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);
}
/**
@@ -865,7 +965,7 @@ 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);
}
/**
@@ -875,7 +975,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function trim()
{
return self::create(trim($this->str), $this->encoding);
return static::create(trim($this->str), $this->encoding);
}
/**
@@ -900,7 +1000,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
}
}
return self::create($longestCommonPrefix, $encoding);
return static::create($longestCommonPrefix, $encoding);
}
/**
@@ -925,7 +1025,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
}
}
return self::create($longestCommonSuffix, $encoding);
return static::create($longestCommonSuffix, $encoding);
}
/**
@@ -940,7 +1040,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);
@@ -954,8 +1054,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$end = 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);
@@ -997,17 +1097,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);
}
/**
@@ -1029,7 +1122,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 = '';
@@ -1048,7 +1141,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 = '';
@@ -1068,7 +1161,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;
@@ -1086,7 +1179,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;
@@ -1103,7 +1196,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);
@@ -1121,7 +1214,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);
@@ -1156,7 +1249,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isAlpha()
{
return $this->matchesPattern('^([[:alpha:]])*$');
return $this->matchesPattern('^[[:alpha:]]*$');
}
/**
@@ -1167,7 +1260,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isAlphanumeric()
{
return $this->matchesPattern('^([[:alnum:]])*$');
return $this->matchesPattern('^[[:alnum:]]*$');
}
/**
@@ -1178,7 +1271,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isHexadecimal()
{
return $this->matchesPattern('^([[:xdigit:]])*$');
return $this->matchesPattern('^[[:xdigit:]]*$');
}
/**
@@ -1189,7 +1282,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isBlank()
{
return $this->matchesPattern('^([[:space:]])*$');
return $this->matchesPattern('^[[:space:]]*$');
}
/**
@@ -1199,14 +1292,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isJson()
{
if (!$this->endsWith('}') && !$this->endsWith(']')) {
return false;
}
json_decode($this->str);
return !is_null(json_decode($this->str));
return (json_last_error() === JSON_ERROR_NONE);
}
/**
* Returns true if the string contains only lower case chars, false
* otherwise.
@@ -1215,7 +1305,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isLowerCase()
{
return $this->matchesPattern('^([[:lower:]])*$');
return $this->matchesPattern('^[[:lower:]]*$');
}
/**
@@ -1226,7 +1316,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isUpperCase()
{
return $this->matchesPattern('^([[:upper:]])*$');
return $this->matchesPattern('^[[:upper:]]*$');
}
/**
@@ -1269,17 +1359,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function replace($search, $replacement)
{
$regexEncoding = mb_regex_encoding();
mb_regex_encoding($this->encoding);
// Don't want the args being parsed as regex
$search = preg_quote($search);
$replacement = preg_quote($replacement);
$str = mb_ereg_replace($search, $replacement, $this->str);
mb_regex_encoding($regexEncoding);
return self::create($str, $this->encoding);
return $this->regexReplace(preg_quote($search), $replacement);
}
/**
@@ -1301,6 +1381,6 @@ 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);
}
}

View File

@@ -1,7 +1,19 @@
<?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 charsProvider()
{
return array(
@@ -162,6 +174,7 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
array('test string', 'test string'),
array('Ο συγγραφέας', ' Ο συγγραφέας '),
array('123', ' 123 '),
array('', ' ', 'UTF-8'), // no-break space
array('1 2 3', '  1  2  3  ', 'UTF-8'), // ideographic spaces
array('', ' ', 'UTF-8'), // thin space and space
array('', ' '),
@@ -174,17 +187,21 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
return array(
array('foo bar', 'fòô bàř'),
array(' TEST ', ' ŤÉŚŢ '),
array('φ = z = 3', 'φ = ź = 3'),
array(' = z = 3', 'φ = ź = 3'),
array('perevirka', 'перевірка'),
array('lysaya gora', 'лысая гора'),
array('shchuka', 'щука')
array('shchuka', 'щука'),
array('', '漢字'),
array(' ', ' '), // no-break space
array(' 1 2 3 ', '  1  2  3  '), // ideographic spaces
array(' ', ' '), // thin space and space
);
}
public function padProvider()
{
return array(
// $length <= $str
// length <= str
array('foo bar', 'foo bar', -1),
array('foo bar', 'foo bar', 7),
array('fòô bàř', 'fòô bàř', 7, ' ', 'right', 'UTF-8'),
@@ -192,32 +209,16 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
// right
array('foo bar ', 'foo bar', 9),
array('foo bar_*', 'foo bar', 9, '_*', 'right'),
array('foo bar_*_', 'foo bar', 10, '_*', 'right'),
array('fòô bàř ', 'fòô bàř', 9, ' ', 'right', 'UTF-8'),
array('fòô bàř¬ø', 'fòô bàř', 9, '¬ø', 'right', 'UTF-8'),
array('fòô bàř¬ø¬', 'fòô bàř', 10, '¬ø', 'right', 'UTF-8'),
array('fòô bàř¬ø¬ø', 'fòô bàř', 11, '¬ø', 'right', 'UTF-8'),
// left
array(' foo bar', 'foo bar', 9, ' ', 'left'),
array('_*foo bar', 'foo bar', 9, '_*', 'left'),
array('_*_foo bar', 'foo bar', 10, '_*', 'left'),
array(' fòô bàř', 'fòô bàř', 9, ' ', 'left', 'UTF-8'),
array('¬øfòô bàř', 'fòô bàř', 9, '¬ø', 'left', 'UTF-8'),
array('¬ø¬fòô bàř', 'fòô bàř', 10, '¬ø', 'left', 'UTF-8'),
array('¬ø¬øfòô bàř', 'fòô bàř', 11, '¬ø', 'left', 'UTF-8'),
// both
array('foo bar ', 'foo bar', 8, ' ', 'both'),
array(' foo bar ', 'foo bar', 9, ' ', 'both'),
array('fòô bàř ', 'fòô bàř', 8, ' ', 'both', 'UTF-8'),
array(' fòô bàř ', 'fòô bàř', 9, ' ', 'both', 'UTF-8'),
array('fòô bàř¬', 'fòô bàř', 8, '¬ø', 'both', 'UTF-8'),
array('¬fòô bàř¬', 'fòô bàř', 9, '¬ø', 'both', 'UTF-8'),
array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬ø', 'both', 'UTF-8'),
array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬ø', 'both', 'UTF-8'),
array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬øÿ', 'both', 'UTF-8'),
array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬øÿ', 'both', 'UTF-8'),
array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'both', 'UTF-8')
);
}
@@ -226,7 +227,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
{
return array(
array(' foo bar', 'foo bar', 9),
array('_*foo bar', 'foo bar', 9, '_*'),
array('_*_foo bar', 'foo bar', 10, '_*'),
array(' fòô bàř', 'fòô bàř', 9, ' ', 'UTF-8'),
array('¬øfòô bàř', 'fòô bàř', 9, '¬ø', 'UTF-8'),
array('¬ø¬fòô bàř', 'fòô bàř', 10, '¬ø', 'UTF-8'),
array('¬ø¬øfòô bàř', 'fòô bàř', 11, '¬ø', 'UTF-8'),
);
}
@@ -235,7 +240,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
{
return array(
array('foo bar ', 'foo bar', 9),
array('foo bar_*', 'foo bar', 9, '_*'),
array('foo bar_*_', 'foo bar', 10, '_*'),
array('fòô bàř ', 'fòô bàř', 9, ' ', 'UTF-8'),
array('fòô bàř¬ø', 'fòô bàř', 9, '¬ø', 'UTF-8'),
array('fòô bàř¬ø¬', 'fòô bàř', 10, '¬ø', 'UTF-8'),
array('fòô bàř¬ø¬ø', 'fòô bàř', 11, '¬ø', 'UTF-8'),
);
}
@@ -245,7 +254,14 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
return array(
array('foo bar ', 'foo bar', 8),
array(' foo bar ', 'foo bar', 9, ' '),
array('fòô bàř ', 'fòô bàř', 8, ' ', 'UTF-8'),
array(' fòô bàř ', 'fòô bàř', 9, ' ', 'UTF-8'),
array('fòô bàř¬', 'fòô bàř', 8, '¬ø', 'UTF-8'),
array('¬fòô bàř¬', 'fòô bàř', 9, '¬ø', 'UTF-8'),
array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬ø', 'UTF-8'),
array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬ø', 'UTF-8'),
array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬øÿ', 'UTF-8'),
array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬øÿ', 'UTF-8'),
array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'UTF-8')
);
}
@@ -318,6 +334,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(
@@ -333,6 +360,8 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
{
return array(
array('foo-bar', ' foo bar '),
array('foo-bar', 'foo -.-"-...bar'),
array('another-foo-bar', 'another..& foo -.-"-...bar'),
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àř'),
@@ -340,39 +369,118 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
array('numbers-1234', 'numbers 1234'),
array('perevirka-ryadka', 'перевірка рядка'),
array('bukvar-s-bukvoy-y', 'букварь с буквой ы'),
array('barzi-i-yarostni', 'бързи и яростни'),
array('podekhal-k-podezdu-moego-doma', 'подъехал к подъезду моего дома'),
array('foo:bar:baz', 'Foo bar baz', ':'),
array('a_string_with_underscores', 'A_string with_underscores', '_')
array('a_string_with_underscores', 'A_string with_underscores', '_'),
array('a_string_with_dashes', 'A string-with-dashes', '_'),
array('a\string\with\dashes', 'A string-with-dashes', '\\'),
array('an_odd_string', '-- An odd__ string-_', '_')
);
}
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(
@@ -650,6 +758,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'),
@@ -666,6 +776,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'),
@@ -720,6 +832,7 @@ 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'), // no-break space
array(true, ' ', 'UTF-8'), // thin space
array(true, '  ', 'UTF-8'), // ideographic spaces
array(false, ' z', 'UTF-8'),
@@ -730,14 +843,14 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
public function isJsonProvider()
{
return array(
array(false, ''),
array(false, '123'),
array(true, ''),
array(true, '123'),
array(true, '{"foo": "bar"}'),
array(false, '{"foo":"bar",}'),
array(false, '{"foo"}'),
array(true, '["foo"]'),
array(false, '{"foo": "bar"]'),
array(false, '123', 'UTF-8'),
array(true, '123', 'UTF-8'),
array(true, '{"fòô": "bàř"}', 'UTF-8'),
array(false, '{"fòô":"bàř",}', 'UTF-8'),
array(false, '{"fòô"}', 'UTF-8'),
@@ -835,6 +948,8 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
array('foo', '', '', 'foo'),
array('foo', '\s', '\s', 'foo'),
array('foo bar', 'foo bar', '', ''),
array('foo bar', 'foo bar', 'f(o)o', '\1'),
array('\1 bar', 'foo bar', 'foo', '\1'),
array('bar', 'foo bar', 'foo ', ''),
array('far bar', 'foo bar', 'foo', 'far'),
array('bar bar', 'foo bar foo bar', 'foo ', ''),
@@ -853,6 +968,7 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
return array(
array('', '', '', ''),
array('bar', 'foo', 'f[o]+', 'bar'),
array('o bar', 'foo bar', 'f(o)o', '\1'),
array('bar', 'foo bar', 'f[O]+\s', '', 'i'),
array('foo', 'bar', '[[:alpha:]]{3}', 'foo'),
array('', '', '', '', 'msr', 'UTF-8'),

16
tests/CreateTest.php Normal file
View 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());
}
}

View File

@@ -1,7 +1,6 @@
<?php
$base = realpath(dirname(__FILE__) . '/..');
require("$base/src/StaticStringy.php");
require __DIR__ . '/../src/StaticStringy.php';
use Stringy\StaticStringy as S;
@@ -245,6 +244,16 @@ class StaticStringyTestCase extends CommonTest
$this->assertEquals($expected, $result);
}
/**
* @dataProvider toTitleCaseProvider()
*/
public function testToTitleCase($expected, $str, $encoding = null)
{
$result = S::toTitleCase($str, $encoding);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider toUpperCaseProvider()
*/
@@ -276,6 +285,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()
*/

View File

@@ -1,7 +1,6 @@
<?php
$base = realpath(dirname(__FILE__) . '/..');
require("$base/src/Stringy.php");
require __DIR__ . '/../src/Stringy.php';
use Stringy\Stringy as S;
@@ -10,9 +9,9 @@ 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->encoding);
$this->assertEquals('UTF-8', $stringy->getEncoding());
}
/**
@@ -57,15 +56,15 @@ 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->encoding);
$this->assertEquals('UTF-8', $stringy->getEncoding());
}
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);
}
@@ -173,7 +172,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);
}
@@ -184,7 +183,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);
}
@@ -196,7 +195,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);
}
@@ -208,7 +207,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);
}
@@ -220,7 +219,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);
}
@@ -232,7 +231,7 @@ 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);
}
@@ -244,7 +243,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);
}
@@ -257,7 +256,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);
}
@@ -269,7 +268,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);
}
@@ -281,7 +280,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);
}
@@ -293,7 +292,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);
}
@@ -305,7 +304,7 @@ class StringyTestCase extends CommonTest
{
$stringy = S::create($str);
$result = $stringy->toAscii();
$this->assertInstanceOf('Stringy\Stringy', $result);
$this->assertStringy($result);
$this->assertEquals($expected, $result);
$this->assertEquals($str, $stringy);
}
@@ -318,7 +317,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);
}
@@ -340,7 +339,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);
}
@@ -353,7 +352,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);
}
@@ -366,7 +365,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);
}
@@ -404,7 +403,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);
}
@@ -416,7 +415,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);
}
@@ -428,7 +427,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);
}
@@ -440,7 +451,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);
}
@@ -452,7 +463,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);
}
@@ -470,6 +481,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()
*/
@@ -477,7 +514,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);
}
@@ -490,7 +527,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);
}
@@ -503,7 +540,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);
}
@@ -515,7 +565,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);
}
@@ -529,7 +579,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));
@@ -550,7 +600,7 @@ class StringyTestCase extends CommonTest
{
$stringy = S::create($str);
$result = $stringy->trim();
$this->assertInstanceOf('Stringy\Stringy', $result);
$this->assertStringy($result);
$this->assertEquals($expected, $result);
$this->assertEquals($str, $stringy);
}
@@ -563,7 +613,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);
}
@@ -576,7 +639,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);
}
@@ -601,7 +664,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);
}
@@ -613,7 +676,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);
}
@@ -625,7 +688,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);
}
@@ -637,7 +700,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);
}
@@ -649,7 +712,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);
}
@@ -661,7 +724,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);
}
@@ -673,7 +736,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);
}
@@ -685,7 +748,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);
}
@@ -807,7 +870,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);
}
@@ -820,7 +883,7 @@ 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);
}