mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-31 16:51:57 +02:00
Compare commits
290 Commits
1.0.0-rc.1
...
2.3.2
Author | SHA1 | Date | |
---|---|---|---|
|
4e214a5195 | ||
|
fcc2969210 | ||
|
30d1742082 | ||
|
bd90918858 | ||
|
a2d1ec535a | ||
|
b953a85d2c | ||
|
e07a07a076 | ||
|
c4d785d29f | ||
|
5554477962 | ||
|
87c1a47355 | ||
|
6d558974ba | ||
|
5a9b987f9a | ||
|
e3d397fa74 | ||
|
ffc3fa5ff9 | ||
|
c3f25577ed | ||
|
5a4629662c | ||
|
823e50a340 | ||
|
9d77c49fca | ||
|
a074d2a2ac | ||
|
b7cfa84219 | ||
|
e3be6a56ea | ||
|
bdbd4d7541 | ||
|
8419369f3b | ||
|
a3dde38a2f | ||
|
59ce593086 | ||
|
54cf92c89c | ||
|
d320bf8704 | ||
|
2de4c4aee3 | ||
|
fc39b70953 | ||
|
9b61dcc771 | ||
|
b85a84d0b9 | ||
|
e5c3043d75 | ||
|
49a7405a2a | ||
|
63109ce85c | ||
|
b223a2c320 | ||
|
264eed18dd | ||
|
d990a41a1a | ||
|
318db789b1 | ||
|
f086c67ac7 | ||
|
ee59d586f2 | ||
|
3c7bc662a6 | ||
|
2072e667e9 | ||
|
b65da66ae8 | ||
|
604ddc0528 | ||
|
abd5505e98 | ||
|
ee4b89c2f8 | ||
|
ac04be8416 | ||
|
41336996a1 | ||
|
a8793ff711 | ||
|
183e529e15 | ||
|
4673754054 | ||
|
83671e721a | ||
|
c5f370c46d | ||
|
436d269622 | ||
|
c09de057a1 | ||
|
efb10020f6 | ||
|
ae74e66369 | ||
|
f6475e1288 | ||
|
ff36c79892 | ||
|
8f40b3495d | ||
|
e237f30d94 | ||
|
ad6d32080f | ||
|
7377aabf61 | ||
|
01fb889a1a | ||
|
775d004629 | ||
|
fe266445f7 | ||
|
dd95144bf8 | ||
|
812f227f11 | ||
|
6667ca1aed | ||
|
cde0740118 | ||
|
fa22b94abf | ||
|
f12b40cc29 | ||
|
e1c562b7e8 | ||
|
a39ed63627 | ||
|
f34af92850 | ||
|
9165957971 | ||
|
b3f1bf5174 | ||
|
b9cf4b6ae3 | ||
|
cce314f4a5 | ||
|
4a971302f7 | ||
|
3dcc801483 | ||
|
fe7b54a4e7 | ||
|
5e3ac6231c | ||
|
342ef7c3dd | ||
|
9d5a06cf37 | ||
|
2d34e72cde | ||
|
bded15d683 | ||
|
6b74918cc9 | ||
|
804aa3e700 | ||
|
aef6f0c200 | ||
|
f77d9903fa | ||
|
c673cd3edf | ||
|
0d92d7e810 | ||
|
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 | ||
|
63ad4d238f | ||
|
ece219b609 | ||
|
e81dbaa6d9 | ||
|
2b2c03bd1f | ||
|
7600549abc | ||
|
8fe30d18b7 | ||
|
ae7527ad4a | ||
|
f74f535b78 | ||
|
5c5087db13 | ||
|
8d961e25d0 | ||
|
e46797a9f8 | ||
|
f0805f522d | ||
|
6103eca714 | ||
|
952ffd4c00 | ||
|
7832e22e09 | ||
|
bcd87c69b8 | ||
|
1d9001bcf0 | ||
|
ee88cd93e8 | ||
|
48f53e98fa | ||
|
6e7415a9f5 | ||
|
c62a5e8d4e | ||
|
cd41723b12 | ||
|
404909ffaa | ||
|
210c928b79 | ||
|
1965da2e39 | ||
|
25fa7340ed | ||
|
e5f66c6eca | ||
|
5d7e9a8d36 | ||
|
a7c5b8721c | ||
|
9399f7a694 | ||
|
b990df3c61 | ||
|
220d4f95c0 | ||
|
b3e922c517 | ||
|
edaf567a13 | ||
|
1d186ca79f | ||
|
ffe6c2575a | ||
|
3f5b6a2413 | ||
|
ebc58a51ef | ||
|
1c13f2ad7e | ||
|
7313dcc07e | ||
|
f14e8c16a4 | ||
|
9f930262af | ||
|
c230885a13 | ||
|
1f25d0c793 | ||
|
0e70d72352 | ||
|
d54628e6ae | ||
|
7335ee5c88 | ||
|
5e01d895db | ||
|
3458fd79fd | ||
|
6e5e5e055f | ||
|
88d5973701 | ||
|
75404a0338 | ||
|
bc96cdad0c | ||
|
6014ff52df | ||
|
6ba29637b2 | ||
|
2ada00ff62 | ||
|
2a197244a5 | ||
|
8b1a91fe0c | ||
|
906f217dc1 | ||
|
d4baab7583 | ||
|
0c8f0e9083 | ||
|
2155447ce8 | ||
|
77efce3a38 | ||
|
f6085ed2cb | ||
|
fa36291254 | ||
|
88145e83e8 | ||
|
9bd5a9c0c8 | ||
|
41ea0277b2 | ||
|
d862f9c24c | ||
|
61cd5f5f4d | ||
|
ea20aebc91 | ||
|
49e1c5ad2a | ||
|
90913d39bc | ||
|
02da00c433 | ||
|
07f23d6165 | ||
|
d27683b570 | ||
|
bc175f0e12 | ||
|
a6964e4561 | ||
|
5fff1a4124 | ||
|
545a5aec5f | ||
|
63298f36a8 | ||
|
a667c4aa6a | ||
|
cd5e897ac3 | ||
|
390671e131 | ||
|
0b76c56333 | ||
|
5f35226926 | ||
|
11f961cae6 | ||
|
660b1d6de8 | ||
|
3d81e2ef70 | ||
|
454e8e2f87 | ||
|
89c292c041 | ||
|
a1d9787309 | ||
|
f1abc38c17 | ||
|
7a64dad935 | ||
|
9d4ca96528 | ||
|
f0063f8bac |
16
.editorconfig
Normal file
16
.editorconfig
Normal file
@@ -0,0 +1,16 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.yml]
|
||||
indent_style = space
|
||||
indent_size = 2
|
8
.gitattributes
vendored
Normal file
8
.gitattributes
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
* text=auto
|
||||
|
||||
.editorconfig export-ignore
|
||||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
||||
.travis.yml export-ignore
|
||||
phpunit.xml.dist export-ignore
|
||||
tests export-ignore
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
||||
vendor/
|
||||
composer.lock
|
||||
.DS_Store
|
||||
|
44
.travis.yml
44
.travis.yml
@@ -1,5 +1,43 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.5
|
||||
- 5.4
|
||||
- 5.3
|
||||
- hhvm
|
||||
|
||||
# This triggers builds to run on the new TravisCI infrastructure.
|
||||
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
||||
sudo: false
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- php: 5.3
|
||||
env: polyfill='true'
|
||||
- php: 5.3
|
||||
env: polyfill='false'
|
||||
- php: 5.4
|
||||
env: polyfill='true'
|
||||
- php: 5.4
|
||||
env: polyfill='false'
|
||||
- php: 5.5
|
||||
env: polyfill='true'
|
||||
- php: 5.5
|
||||
env: polyfill='false'
|
||||
- php: 5.6
|
||||
env: polyfill='true'
|
||||
- php: 5.6
|
||||
env: polyfill='false'
|
||||
- php: 7.0
|
||||
env: polyfill='true'
|
||||
- php: 7.0
|
||||
env: polyfill='false'
|
||||
|
||||
install: travis_retry composer install --no-interaction --prefer-source
|
||||
|
||||
before_script:
|
||||
- travis_retry composer self-update
|
||||
- travis_retry composer install --no-interaction --prefer-source
|
||||
- if [[ $polyfill = 'false' ]]; then travis_retry composer remove symfony/polyfill-mbstring; fi
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit
|
||||
|
||||
|
149
CHANGELOG.md
149
CHANGELOG.md
@@ -1,3 +1,152 @@
|
||||
### 2.3.2 (2016-05-02)
|
||||
|
||||
* Improve support without mbstring
|
||||
|
||||
### 2.3.1 (2016-03-21)
|
||||
|
||||
* Always use root namespace for mbstring functions
|
||||
|
||||
### 2.3.0 (2016-03-19)
|
||||
|
||||
* Add Persian characters in Stringy::charsArray()
|
||||
* Use symfony/polyfill-mbstring to avoid dependency on ext-mbstring
|
||||
|
||||
### 2.2.0 (2015-12-20)
|
||||
|
||||
* isJSON now returns false for empty strings
|
||||
* Update for German umlaut transformation
|
||||
* Use reflection to generate method list for StaticStringy
|
||||
* Added isBase64 method
|
||||
* Improved toAscii char coverage
|
||||
|
||||
### 2.1.0 (2015-09-02)
|
||||
|
||||
* Added simplified StaticStringy class
|
||||
* str in Stringy::create and constructor is now optional
|
||||
|
||||
### 2.0.0 (2015-07-29)
|
||||
|
||||
* Removed StaticStringy class
|
||||
* Added append, prepend, toBoolean, repeat, between, slice, split, and lines
|
||||
* camelize/upperCamelize now strip leading dashes and underscores
|
||||
* titleize converts to lowercase, thus no longer preserving acronyms
|
||||
|
||||
### 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
|
||||
|
||||
### 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()
|
||||
* Renamed count() to countSubstr()
|
||||
* Updated count() to implement Countable interface
|
||||
* Implemented the ArrayAccess interface with positive and negative indices
|
||||
* Switched from PSR-0 to PSR-4 autoloading
|
||||
|
||||
### 1.3.0 (2013-12-16)
|
||||
|
||||
* Additional Bulgarian support for toAscii
|
||||
* str property made private
|
||||
* Constructor casts first argument to string
|
||||
* Constructor throws an InvalidArgumentException when given an array
|
||||
* Constructor throws an InvalidArgumentException when given an object without
|
||||
a __toString method
|
||||
|
||||
### 1.2.2 (2013-12-04)
|
||||
|
||||
* Updated create function to use late static binding
|
||||
* Added optional $replacement param to slugify
|
||||
|
||||
### 1.2.1 (2013-10-11)
|
||||
|
||||
* Cleaned up tests
|
||||
* Added homepage to composer.json
|
||||
|
||||
### 1.2.0 (2013-09-15)
|
||||
|
||||
* Fixed pad's use of InvalidArgumentException
|
||||
* Fixed replace(). It now correctly treats regex special chars as normal chars
|
||||
* Added additional Cyrillic letters to toAscii
|
||||
* Added $caseSensitive to contains() and count()
|
||||
* Added toLowerCase()
|
||||
* Added toUpperCase()
|
||||
* Added regexReplace()
|
||||
|
||||
### 1.1.0 (2013-08-31)
|
||||
|
||||
* Fix for collapseWhitespace()
|
||||
* Added isHexadecimal()
|
||||
* Added constructor to Stringy\Stringy
|
||||
* Added isSerialized()
|
||||
* Added isJson()
|
||||
|
||||
### 1.0.0 (2013-08-1)
|
||||
|
||||
* 1.0.0 release
|
||||
* Added test coverage for Stringy::create and method chaining
|
||||
* Added tests for returned type
|
||||
* Fixed StaticStringy::replace(). It was returning a Stringy object instead of string
|
||||
* Renamed standardize() to the more appropriate toAscii()
|
||||
* Cleaned up comments and README
|
||||
|
||||
### 1.0.0-rc.1 (2013-07-28)
|
||||
|
||||
* Release candidate
|
||||
|
@@ -5,6 +5,7 @@
|
||||
"multibyte", "string", "manipulation", "utility", "methods", "utf-8",
|
||||
"helpers", "utils", "utf"
|
||||
],
|
||||
"homepage": "https://github.com/danielstjules/Stringy",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
@@ -14,9 +15,21 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
"php": ">=5.3.0",
|
||||
"symfony/polyfill-mbstring": "~1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"support": {
|
||||
"issues": "https://github.com/danielstjules/Stringy/issues",
|
||||
"source": "https://github.com/danielstjules/Stringy"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Stringy": "src/" }
|
||||
"psr-4": { "Stringy\\": "src/" },
|
||||
"files": ["src/Create.php"]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"classmap": [ "tests" ]
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit processIsolation="false"
|
||||
<phpunit bootstrap="vendor/autoload.php"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
<testsuite name="Stringy">
|
||||
<directory>tests/Stringy</directory>
|
||||
<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);
|
||||
}
|
||||
}
|
148
src/StaticStringy.php
Normal file
148
src/StaticStringy.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace Stringy;
|
||||
|
||||
use BadMethodCallException;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Class StaticStringy
|
||||
*
|
||||
* @method static string append(string $str, string $stringAppend, string $encoding = null)
|
||||
* @method static string at(string $str, int $index, string $encoding = null)
|
||||
* @method static string between(string $str, string $start, string $end, int $offset = 0, string $encoding = null)
|
||||
* @method static string camelize(string $str, string $encoding = null)
|
||||
* @method static string chars(string $str, string $encoding = null)
|
||||
* @method static string collapseWhitespace(string $str, string $encoding = null)
|
||||
* @method static bool contains(string $str, string $needle, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static bool containsAll(string $str, string $needle, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static bool containsAny(string $str, string $needle, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static int count(string $str, string $encoding = null)
|
||||
* @method static int countSubstr(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static string dasherize(string $str, string $encoding = null)
|
||||
* @method static string delimit(string $str, string $delimiter, string $encoding = null)
|
||||
* @method static bool endsWith(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static string ensureLeft(string $str, string $substring, string $encoding = null)
|
||||
* @method static string ensureRight(string $str, string $substring, string $encoding = null)
|
||||
* @method static string first(string $str, int $n, string $encoding = null)
|
||||
* @method static bool hasLowerCase(string $str, string $encoding = null)
|
||||
* @method static bool hasUpperCase(string $str, string $encoding = null)
|
||||
* @method static string htmlDecode(string $str, int $flags = ENT_COMPAT, string $encoding = null)
|
||||
* @method static string htmlEncode(string $str, int $flags = ENT_COMPAT, string $encoding = null)
|
||||
* @method static string humanize(string $str, string $encoding = null)
|
||||
* @method static int indexOf(string $str, string $needle, int $offset = 0, string $encoding = null)
|
||||
* @method static int indexOfLast(string $str, string $needle, int $offset = 0, string $encoding = null)
|
||||
* @method static string insert(string $str, string $substring, int $index = 0, string $encoding = null)
|
||||
* @method static bool isAlpha(string $str, string $encoding = null)
|
||||
* @method static bool isAlphanumeric(string $str, string $encoding = null)
|
||||
* @method static bool isBase64(string $str, string $encoding = null)
|
||||
* @method static bool isBlank(string $str, string $encoding = null)
|
||||
* @method static bool isHexadecimal(string $str, string $encoding = null)
|
||||
* @method static bool isJson(string $str, string $encoding = null)
|
||||
* @method static bool isLowerCase(string $str, string $encoding = null)
|
||||
* @method static bool isSerialized(string $str, string $encoding = null)
|
||||
* @method static bool isUpperCase(string $str, string $encoding = null)
|
||||
* @method static string last(string $str, string $encoding = null)
|
||||
* @method static int length(string $str, string $encoding = null)
|
||||
* @method static Stringy[] lines(string $str, string $encoding = null)
|
||||
* @method static string longestCommonPrefix(string $str, string $otherStr, string $encoding = null)
|
||||
* @method static string longestCommonSuffix(string $str, string $otherStr, string $encoding = null)
|
||||
* @method static string longestCommonSubstring(string $str, string $otherStr, string $encoding = null)
|
||||
* @method static string lowerCaseFirst(string $str, string $encoding = null)
|
||||
* @method static string pad(string $str, int $length, string $padStr = ' ', string $padType = 'right', string $encoding = null)
|
||||
* @method static string padBoth(string $str, int $length, string $padStr = ' ', string $encoding = null)
|
||||
* @method static string padLeft(string $str, int $length, string $padStr = ' ', string $encoding = null)
|
||||
* @method static string padRight(string $str, int $length, string $padStr = ' ', string $encoding = null)
|
||||
* @method static string prepend(string $str, string $string, string $encoding = null)
|
||||
* @method static string regexReplace(string $str, string $pattern, string $replacement, string $options = 'msr', string $encoding = null)
|
||||
* @method static string removeLeft(string $str, string $substring, string $encoding = null)
|
||||
* @method static string removeRight(string $str, string $substring, string $encoding = null)
|
||||
* @method static string repeat(string $str, int $multiplier, string $encoding = null)
|
||||
* @method static string replace(string $str, string $search, string $replacement, string $encoding = null)
|
||||
* @method static string reverse(string $str, string $encoding = null)
|
||||
* @method static string safeTruncate(string $str, int $length, string $substring = '', string $encoding = null)
|
||||
* @method static string shuffle(string $str, string $encoding = null)
|
||||
* @method static string slugify(string $str, string $replacement = '-', string $encoding = null)
|
||||
* @method static bool startsWith(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static string slice(string $str, int $start, int $end = null, string $encoding = null)
|
||||
* @method static string split(string $str, string $pattern, int $limit = null, string $encoding = null)
|
||||
* @method static string substr(string $str, int $start, int $length = null, string $encoding = null)
|
||||
* @method static string surround(string $str, string $substring, string $encoding = null)
|
||||
* @method static string swapCase(string $str, string $encoding = null)
|
||||
* @method static string tidy(string $str, string $encoding = null)
|
||||
* @method static string titleize(string $str, string $encoding = null)
|
||||
* @method static string toAscii(string $str, bool $removeUnsupported = true, string $encoding = null)
|
||||
* @method static bool toBoolean(string $str, string $encoding = null)
|
||||
* @method static string toLowerCase(string $str, string $encoding = null)
|
||||
* @method static string toSpaces(string $str, int $tabLength = 4, string $encoding = null)
|
||||
* @method static string toTabs(string $str, int $tabLength = 4, string $encoding = null)
|
||||
* @method static string toTitleCase(string $str, string $encoding = null)
|
||||
* @method static string toUpperCase(string $str, string $encoding = null)
|
||||
* @method static string trim(string $str, string $chars = null, string $encoding = null)
|
||||
* @method static string trimLeft(string $str, string $chars = null, string $encoding = null)
|
||||
* @method static string trimRight(string $str, string $chars = null, string $encoding = null)
|
||||
* @method static string truncate(string $str, int $length, string $substring = '', string $encoding = null)
|
||||
* @method static string underscored(string $str, string $encoding = null)
|
||||
* @method static string upperCamelize(string $str, string $encoding = null)
|
||||
* @method static string upperCaseFirst(string $str, string $encoding = null)
|
||||
*/
|
||||
class StaticStringy
|
||||
{
|
||||
/**
|
||||
* A mapping of method names to the numbers of arguments it accepts. Each
|
||||
* should be two more than the equivalent Stringy method. Necessary as
|
||||
* static methods place the optional $encoding as the last parameter.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $methodArgs = null;
|
||||
|
||||
/**
|
||||
* Creates an instance of Stringy and invokes the given method with the
|
||||
* rest of the passed arguments. The optional encoding is expected to be
|
||||
* the last argument. For example, the following:
|
||||
* StaticStringy::slice('fòôbàř', 0, 3, 'UTF-8'); translates to
|
||||
* Stringy::create('fòôbàř', 'UTF-8')->slice(0, 3);
|
||||
* The result is not cast, so the return value may be of type Stringy,
|
||||
* integer, boolean, etc.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed[] $arguments
|
||||
*
|
||||
* @return Stringy
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public static function __callStatic($name, $arguments)
|
||||
{
|
||||
if (!static::$methodArgs) {
|
||||
$stringyClass = new ReflectionClass('Stringy\Stringy');
|
||||
$methods = $stringyClass->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||
|
||||
foreach ($methods as $method) {
|
||||
$params = $method->getNumberOfParameters() + 2;
|
||||
static::$methodArgs[$method->name] = $params;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset(static::$methodArgs[$name])) {
|
||||
throw new BadMethodCallException($name . ' is not a valid method');
|
||||
}
|
||||
|
||||
$numArgs = count($arguments);
|
||||
$str = ($numArgs) ? $arguments[0] : '';
|
||||
|
||||
if ($numArgs === static::$methodArgs[$name]) {
|
||||
$args = array_slice($arguments, 1, -1);
|
||||
$encoding = $arguments[$numArgs - 1];
|
||||
} else {
|
||||
$args = array_slice($arguments, 1);
|
||||
$encoding = null;
|
||||
}
|
||||
|
||||
$stringy = Stringy::create($str, $encoding);
|
||||
|
||||
return call_user_func_array(array($stringy, $name), $args);
|
||||
}
|
||||
}
|
1866
src/Stringy.php
Normal file
1866
src/Stringy.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,673 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Stringy;
|
||||
|
||||
class StaticStringy
|
||||
{
|
||||
/**
|
||||
* Converts the first character of the supplied string to upper case.
|
||||
*
|
||||
* @param string $str String to modify
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String with the first character being upper case
|
||||
*/
|
||||
public static function upperCaseFirst($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->upperCaseFirst()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first character of the supplied string to lower case.
|
||||
*
|
||||
* @param string $str String to modify
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String with the first character being lower case
|
||||
*/
|
||||
public static function lowerCaseFirst($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->lowerCaseFirst()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a camelCase version of a supplied string. Trims surrounding
|
||||
* spaces, capitalizes letters following digits, spaces, dashes and
|
||||
* underscores, and removes spaces, dashes, underscores.
|
||||
*
|
||||
* @param string $str String to convert to camelCase
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String in camelCase
|
||||
*/
|
||||
public static function camelize($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->camelize()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an UpperCamelCase version of a supplied string. Trims surrounding
|
||||
* spaces, capitalizes letters following digits, spaces, dashes and
|
||||
* underscores, and removes spaces, dashes, underscores.
|
||||
*
|
||||
* @param string $str String to convert to UpperCamelCase
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String in UpperCamelCase
|
||||
*/
|
||||
public static function upperCamelize($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->upperCamelize()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a lowercase and trimmed string seperated by dashes. Dashes are
|
||||
* inserted before uppercase characters (with the exception of the first
|
||||
* character of the string), and in place of spaces as well as underscores.
|
||||
*
|
||||
* @param string $str String to convert
|
||||
* @param string $encoding The character encoding
|
||||
* @return string Dasherized string
|
||||
*/
|
||||
public static function dasherize($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->dasherize()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a lowercase and trimmed string seperated by underscores.
|
||||
* Underscores are inserted before uppercase characters (with the exception
|
||||
* of the first character of the string), and in place of spaces as well as
|
||||
* dashes.
|
||||
*
|
||||
* @param string $str String to convert
|
||||
* @param string $encoding The character encoding
|
||||
* @return string Underscored string
|
||||
*/
|
||||
public static function underscored($str, $encoding = null)
|
||||
{
|
||||
return $result = Stringy::create($str, $encoding)->underscored()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a case swapped version of a string.
|
||||
*
|
||||
* @param string $str String to swap case
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String with each character's case swapped
|
||||
*/
|
||||
public static function swapCase($str, $encoding = null)
|
||||
{
|
||||
return $result = Stringy::create($str, $encoding)->swapCase()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Capitalizes the first letter of each word in a string, after trimming.
|
||||
* Ignores the case of other letters, allowing for the use of acronyms.
|
||||
* Also accepts an array, $ignore, allowing you to list words not to be
|
||||
* capitalized.
|
||||
*
|
||||
* @param string $str String to titleize
|
||||
* @param string $encoding The character encoding
|
||||
* @param array $ignore An array of words not to capitalize
|
||||
* @return string Titleized string
|
||||
*/
|
||||
public static function titleize($str, $ignore = null, $encoding = null)
|
||||
{
|
||||
return $result = Stringy::create($str, $encoding)->titleize($ignore)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Capitalizes the first word of a string, replaces underscores with spaces,
|
||||
* and strips '_id'.
|
||||
*
|
||||
* @param string $str String to humanize
|
||||
* @param string $encoding The character encoding
|
||||
* @return string A humanized string
|
||||
*/
|
||||
public static function humanize($str, $encoding = null)
|
||||
{
|
||||
return $result = Stringy::create($str, $encoding)->humanize()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces smart quotes, ellipsis characters, and dashes from Windows-1252
|
||||
* (and commonly used in Word documents) with their ASCII equivalents.
|
||||
*
|
||||
* @param string $str String to remove special chars
|
||||
* @param string $encoding The character encoding
|
||||
* @return string String with those characters removed
|
||||
*/
|
||||
public static function tidy($str)
|
||||
{
|
||||
return $result = Stringy::create($str)->tidy()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims the string and replaces consecutive whitespace characters with a
|
||||
* single space. This inclues tabs and newline characters.
|
||||
*
|
||||
* @param string $str The string to cleanup whitespace
|
||||
* @return string The trimmed string with condensed whitespace
|
||||
*/
|
||||
public static function collapseWhitespace($str)
|
||||
{
|
||||
return $result = Stringy::create($str)->collapseWhitespace()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts some non-ASCII characters to their closest ASCII counterparts.
|
||||
*
|
||||
* @param string $str A string with non-ASCII characters
|
||||
* @return string The string after the replacements
|
||||
*/
|
||||
public static function standardize($str)
|
||||
{
|
||||
return $result = Stringy::create($str)->standardize()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pads a string to a given length with another string. If length is less
|
||||
* than or equal to the length of $str, then no padding takes places. The
|
||||
* default string used for padding is a space, and the default type (one of
|
||||
* 'left', 'right', 'both') is 'right'. Throws an exception if $padType
|
||||
* isn't one of those 3 values.
|
||||
*
|
||||
* @param string $str String to pad
|
||||
* @param int $length Desired string length after padding
|
||||
* @param string $padStr String used to pad, defaults to space
|
||||
* @param string $padType One of 'left', 'right', 'both'
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The padded string
|
||||
* @throws InvalidArgumentException If $padType isn't one of 'right',
|
||||
* 'left' or 'both'
|
||||
*/
|
||||
public static function pad($str, $length, $padStr = ' ', $padType = 'right',
|
||||
$encoding = null)
|
||||
{
|
||||
return $result = Stringy::create($str, $encoding)
|
||||
->pad($length, $padStr, $padType)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new string of a given length such that the beginning of the
|
||||
* string is padded. Alias for pad($str, $length, $padStr, 'left', $encoding)
|
||||
*
|
||||
* @param string $str String to pad
|
||||
* @param int $length Desired string length after padding
|
||||
* @param string $padStr String used to pad, defaults to space
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The padded string
|
||||
*/
|
||||
public static function padLeft($str, $length, $padStr = ' ', $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->padLeft($length, $padStr)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new string of a given length such that the end of the string is
|
||||
* padded. Alias for pad($str, $length, $padStr, 'right', $encoding)
|
||||
*
|
||||
* @param string $str String to pad
|
||||
* @param int $length Desired string length after padding
|
||||
* @param string $padStr String used to pad, defaults to space
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The padded string
|
||||
*/
|
||||
public static function padRight($str, $length, $padStr = ' ', $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->padRight($length, $padStr)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new string of a given length such that both sides of the string
|
||||
* string are padded. Alias for pad($str, $length, $padStr, 'both', $encoding)
|
||||
*
|
||||
* @param string $str String to pad
|
||||
* @param int $length Desired string length after padding
|
||||
* @param string $padStr String used to pad, defaults to space
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The padded string
|
||||
*/
|
||||
public static function padBoth($str, $length, $padStr = ' ', $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->padBoth($length, $padStr)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string $str begins with $substring, false otherwise.
|
||||
* By default, the comparison is case-sensitive, but can be made insensitive
|
||||
* by setting $caseSensitive to false.
|
||||
*
|
||||
* @param string $str String to check the start of
|
||||
* @param string $substring The substring to look for
|
||||
* @param bool $caseSensitive Whether or not to enfore case-sensitivity
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $str starts with $substring
|
||||
*/
|
||||
public static function startsWith($str, $substring, $caseSensitive = true,
|
||||
$encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)
|
||||
->startsWith($substring, $caseSensitive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string $str ends with $substring, false otherwise.
|
||||
* By default, the comparison is case-sensitive, but can be made insensitive
|
||||
* by setting $caseSensitive to false.
|
||||
*
|
||||
* @param string $str String to check the end of
|
||||
* @param string $substring The substring to look for
|
||||
* @param bool $caseSensitive Whether or not to enfore case-sensitivity
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $str ends with $substring
|
||||
*/
|
||||
public static function endsWith($str, $substring, $caseSensitive = true,
|
||||
$encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)
|
||||
->endsWith($substring, $caseSensitive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts each tab in a string to some number of spaces, as defined by
|
||||
* $tabLength. By default, each tab is converted to 4 consecutive spaces.
|
||||
*
|
||||
* @param string $str String to convert tabs to spaces
|
||||
* @param int $tabLength Number of spaces to replace each tab with
|
||||
* @return string String with tabs switched to spaces
|
||||
*/
|
||||
public static function toSpaces($str, $tabLength = 4)
|
||||
{
|
||||
return Stringy::create($str)->toSpaces($tabLength)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts each occurence of some consecutive number of spaces, as defined
|
||||
* by $tabLength, to a tab. By default, each 4 consecutive spaces are
|
||||
* converted to a tab.
|
||||
*
|
||||
* @param string $str String to convert spaces to tabs
|
||||
* @param int $tabLength Number of spaces to replace with a tab
|
||||
* @return string String with spaces switched to tabs
|
||||
*/
|
||||
public static function toTabs($str, $tabLength = 4)
|
||||
{
|
||||
return Stringy::create($str)->toTabs($tabLength)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the supplied text into an URL slug. This includes replacing
|
||||
* non-ASCII characters with their closest ASCII equivalents, removing
|
||||
* non-alphanumeric and non-ASCII characters, and replacing whitespace with
|
||||
* dashes. The string is also converted to lowercase.
|
||||
*
|
||||
* @param string $str Text to transform into an URL slug
|
||||
* @return string The corresponding URL slug
|
||||
*/
|
||||
public static function slugify($str)
|
||||
{
|
||||
return Stringy::create($str)->slugify()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if $haystack contains $needle, false otherwise.
|
||||
*
|
||||
* @param string $haystack String being checked
|
||||
* @param string $needle Substring to look for
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $haystack contains $needle
|
||||
*/
|
||||
public static function contains($haystack, $needle, $encoding = null)
|
||||
{
|
||||
return Stringy::create($haystack, $encoding)->contains($needle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds a string with the given substring.
|
||||
*
|
||||
* @param string $str The string to surround
|
||||
* @param string $substring The substring to add to both sides
|
||||
* @return string The string with the substring prepended and appended
|
||||
*/
|
||||
public static function surround($str, $substring)
|
||||
{
|
||||
return Stringy::create($str)->surround($substring)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts $substring into $str at the $index provided.
|
||||
*
|
||||
* @param string $str String to insert into
|
||||
* @param string $substring String to be inserted
|
||||
* @param int $index The index at which to insert the substring
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The resulting string after the insertion
|
||||
*/
|
||||
public static function insert($str, $substring, $index, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->insert($substring, $index)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncates $str to a given length. If $substring is provided, and
|
||||
* truncating occurs, the string is further truncated so that the substring
|
||||
* may be appended without exceeding the desired length.
|
||||
*
|
||||
* @param string $str String to truncate
|
||||
* @param int $length Desired length of the truncated string
|
||||
* @param string $substring The substring to append if it can fit
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The resulting string after truncating
|
||||
*/
|
||||
public static function truncate($str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)
|
||||
->truncate($length, $substring)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncates the string to a given length, while ensuring that it does not
|
||||
* chop words. If $substring is provided, and truncating occurs, the string
|
||||
* is further truncated so that the substring may be appended without
|
||||
* exceeding the desired length.
|
||||
*
|
||||
* @param string $str String to truncate
|
||||
* @param int $length Desired length of the truncated string
|
||||
* @param string $substring The substring to append if it can fit
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The resulting string after truncating
|
||||
*/
|
||||
public static function safeTruncate($str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)
|
||||
->safeTruncate($length, $substring)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses a string. A multibyte version of strrev.
|
||||
*
|
||||
* @param string $str String to reverse
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The reversed string
|
||||
*/
|
||||
public static function reverse($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->reverse()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* A multibyte str_shuffle function. It randomizes the order of characters
|
||||
* in a string.
|
||||
*
|
||||
* @param string $str String to shuffle
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The shuffled string
|
||||
*/
|
||||
public static function shuffle($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->shuffle()->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims $str. An alias for PHP's trim() function.
|
||||
*
|
||||
* @param string $str String to trim
|
||||
* @return string Trimmed $str
|
||||
*/
|
||||
public static function trim($str)
|
||||
{
|
||||
return trim($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the longest common prefix between $str and $otherStr.
|
||||
*
|
||||
* @param string $str First string for comparison
|
||||
* @param string $otherStr Second string for comparison
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The longest common prefix
|
||||
*/
|
||||
public static function longestCommonPrefix($str, $otherStr, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)
|
||||
->longestCommonPrefix($otherStr)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the longest common suffix between $str and $otherStr.
|
||||
*
|
||||
* @param string $str First string for comparison
|
||||
* @param string $otherStr Second string for comparison
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The longest common suffix
|
||||
*/
|
||||
public static function longestCommonSuffix($str, $otherStr, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)
|
||||
->longestCommonSuffix($otherStr)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the longest common substring between $str and $otherStr. In the
|
||||
* case of ties, returns that which occurs first.
|
||||
*
|
||||
* @param string $str First string for comparison
|
||||
* @param string $otherStr Second string for comparison
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The longest common substring
|
||||
*/
|
||||
public static function longestCommonSubstring($str, $otherStr,
|
||||
$encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)
|
||||
->longestCommonSubstring($otherStr)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of $str. An alias for PHP's mb_strlen() function.
|
||||
*
|
||||
* @param string $str The string to get the length of
|
||||
* @param string $encoding The character encoding
|
||||
* @return int The number of characters in $str given the encoding
|
||||
*/
|
||||
public static function length($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the substring of $str beginning at $start with the specified $length.
|
||||
* It differs from the mb_substr() function in that providing a $length of
|
||||
* null will return the rest of the string, rather than an empty string.
|
||||
*
|
||||
* @param string $str The string to get the length of
|
||||
* @param int $start Position of the first character to use from str
|
||||
* @param int $length Maximum number of characters used
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The substring of $str
|
||||
*/
|
||||
public static function substr($str, $start, $length = null, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->substr($start, $length)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the character of $str at $index, with indexes starting at 0.
|
||||
*
|
||||
* @param string $str The string from which to get the char
|
||||
* @param int $index Position of the character
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The character at $index
|
||||
*/
|
||||
public static function at($str, $index, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->at($index)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first $n characters of $str.
|
||||
*
|
||||
* @param string $str The string from which to get the substring
|
||||
* @param int $n Number of chars to retrieve from the start
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The first $n characters
|
||||
*/
|
||||
public static function first($str, $n, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->first($n)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last $n characters of $str.
|
||||
*
|
||||
* @param string $str The string from which to get the substring
|
||||
* @param int $n Number of chars to retrieve from the end
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The last $n characters
|
||||
*/
|
||||
public static function last($str, $n, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->last($n)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that $str begins with $substring.
|
||||
*
|
||||
* @param string $str The string to modify
|
||||
* @param string $substring The substring to add if not present
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The string prefixed by the $substring
|
||||
*/
|
||||
public static function ensureLeft($str, $substring, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->ensureLeft($substring)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that $str ends with $substring.
|
||||
*
|
||||
* @param string $str The string to modify
|
||||
* @param string $substring The substring to add if not present
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The string suffixed by the $substring
|
||||
*/
|
||||
public static function ensureRight($str, $substring, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->ensureRight($substring)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the prefix $substring if present.
|
||||
*
|
||||
* @param string $str String from which to remove the prefix
|
||||
* @param string $substring The prefix to remove
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The string without the prefix $substring
|
||||
*/
|
||||
public static function removeLeft($str, $substring, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->removeLeft($substring)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the suffix $substring if present.
|
||||
*
|
||||
* @param string $str String from which to remove the suffix
|
||||
* @param string $substring The suffix to remove
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The string without the suffix $substring
|
||||
*/
|
||||
public static function removeRight($str, $substring, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->removeRight($substring)->str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if $str contains only alphabetic chars, false otherwise.
|
||||
*
|
||||
* @param string $str String to check
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $str contains only alphabetic chars
|
||||
*/
|
||||
public static function isAlpha($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->isAlpha();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if $str contains only alphabetic and numeric chars, false
|
||||
* otherwise.
|
||||
*
|
||||
* @param string $str String to check
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $str contains only alphanumeric chars
|
||||
*/
|
||||
public static function isAlphanumeric($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->isAlphanumeric();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if $str contains only whitespace chars, false otherwise.
|
||||
*
|
||||
* @param string $str String to check
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $str contains only whitespace characters
|
||||
*/
|
||||
public static function isBlank($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->isBlank();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if $str contains only lower case chars, false otherwise.
|
||||
*
|
||||
* @param string $str String to check
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $str contains only lower case characters
|
||||
*/
|
||||
public static function isLowerCase($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->isLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if $str contains only upper case chars, false otherwise.
|
||||
*
|
||||
* @param string $str String to check
|
||||
* @param string $encoding The character encoding
|
||||
* @return bool Whether or not $str contains only upper case characters
|
||||
*/
|
||||
public static function isUpperCase($str, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->isUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of occurences of $substring in $str. An alias for
|
||||
* mb_substr_count()
|
||||
*
|
||||
* @param string $str The haystack to search through
|
||||
* @param string $substring The substring to search for
|
||||
* @param string $encoding The character encoding
|
||||
* @return int The number of $substring occurences
|
||||
*/
|
||||
public static function count($str, $substring, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->count($substring);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all occurrences of $search with $replace in $str.
|
||||
*
|
||||
* @param string $str The haystack to search through
|
||||
* @param string $search The needle to search for
|
||||
* @param string $replace The string to replace with
|
||||
* @param string $encoding The character encoding
|
||||
* @return string The resulting string after the replacements
|
||||
*/
|
||||
public static function replace($str, $search, $replace, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->replace($search, $replace);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
14
tests/CreateTest.php
Normal file
14
tests/CreateTest.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
60
tests/StaticStringyTest.php
Normal file
60
tests/StaticStringyTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use Stringy\StaticStringy as S;
|
||||
|
||||
class StaticStringyTestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException BadMethodCallException
|
||||
*/
|
||||
public function testBadMethodCall()
|
||||
{
|
||||
$result = S::invalidMethod('foo');
|
||||
}
|
||||
|
||||
public function testEmptyArgsInvocation()
|
||||
{
|
||||
$result = S::toLowerCase();
|
||||
$this->assertEquals('', (string) $result);
|
||||
}
|
||||
|
||||
public function testInvocation()
|
||||
{
|
||||
$result = S::toLowerCase('FOOBAR');
|
||||
$this->assertEquals('foobar', (string) $result);
|
||||
}
|
||||
|
||||
public function testPartialArgsInvocation()
|
||||
{
|
||||
$result = S::slice('foobar', 0, 3);
|
||||
$this->assertEquals('foo', (string) $result);
|
||||
}
|
||||
|
||||
public function testFullArgsInvocation()
|
||||
{
|
||||
$result = S::slice('fòôbàř', 0, 3, 'UTF-8');
|
||||
$this->assertEquals('fòô', (string) $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use reflection to ensure that all argument numbers are correct. Each
|
||||
* static method should accept 2 more arguments than their Stringy
|
||||
* equivalent.
|
||||
*/
|
||||
public function testArgumentNumbers()
|
||||
{
|
||||
$staticStringyClass = new ReflectionClass('Stringy\StaticStringy');
|
||||
$stringyClass = new ReflectionClass('Stringy\Stringy');
|
||||
|
||||
// getStaticPropertyValue can't access protected properties
|
||||
$properties = $staticStringyClass->getStaticProperties();
|
||||
|
||||
foreach ($properties['methodArgs'] as $method => $expected) {
|
||||
$num = $stringyClass->getMethod($method)
|
||||
->getNumberOfParameters() + 2;
|
||||
|
||||
$this->assertEquals($expected, $num,
|
||||
'Invalid num args for ' . $method);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,840 +0,0 @@
|
||||
<?php
|
||||
|
||||
class CommonTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function stringsForUpperCaseFirst()
|
||||
{
|
||||
$testData = array(
|
||||
array('Test', 'Test'),
|
||||
array('Test', 'test'),
|
||||
array('1a', '1a'),
|
||||
array('Σ test', 'σ test', 'UTF-8'),
|
||||
array(' σ test', ' σ test', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLowerCaseFirst()
|
||||
{
|
||||
$testData = array(
|
||||
array('test', 'Test'),
|
||||
array('test', 'test'),
|
||||
array('1a', '1a'),
|
||||
array('σ test', 'Σ test', 'UTF-8'),
|
||||
array(' Σ test', ' Σ test', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForCamelize()
|
||||
{
|
||||
$testData = array(
|
||||
array('camelCase', 'CamelCase'),
|
||||
array('camelCase', 'Camel-Case'),
|
||||
array('camelCase', 'camel case'),
|
||||
array('camelCase', 'camel -case'),
|
||||
array('camelCase', 'camel - case'),
|
||||
array('camelCase', 'camel_case'),
|
||||
array('camelCTest', 'camel c test'),
|
||||
array('stringWith1Number', 'string_with1number'),
|
||||
array('stringWith22Numbers', 'string-with-2-2 numbers'),
|
||||
array('1Camel2Case', '1camel2case'),
|
||||
array('camelΣase', 'camel σase', 'UTF-8'),
|
||||
array('στανιλCase', 'Στανιλ case', 'UTF-8'),
|
||||
array('σamelCase', 'σamel Case', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForUpperCamelize()
|
||||
{
|
||||
$testData = array(
|
||||
array('CamelCase', 'camelCase'),
|
||||
array('CamelCase', 'Camel-Case'),
|
||||
array('CamelCase', 'camel case'),
|
||||
array('CamelCase', 'camel -case'),
|
||||
array('CamelCase', 'camel - case'),
|
||||
array('CamelCase', 'camel_case'),
|
||||
array('CamelCTest', 'camel c test'),
|
||||
array('StringWith1Number', 'string_with1number'),
|
||||
array('StringWith22Numbers', 'string-with-2-2 numbers'),
|
||||
array('1Camel2Case', '1camel2case'),
|
||||
array('CamelΣase', 'camel σase', 'UTF-8'),
|
||||
array('ΣτανιλCase', 'στανιλ case', 'UTF-8'),
|
||||
array('ΣamelCase', 'Σamel Case', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForDasherize()
|
||||
{
|
||||
$testData = 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-d-case', 'TestDCase'),
|
||||
array('test-c-c-test', 'TestCCTest'),
|
||||
array('string-with1number', 'string_with1number'),
|
||||
array('string-with-2-2-numbers', 'String-with_2_2 numbers'),
|
||||
array('1test2case', '1test2case'),
|
||||
array('dash-σase', 'dash Σase', 'UTF-8'),
|
||||
array('στανιλ-case', 'Στανιλ case', 'UTF-8'),
|
||||
array('σash-case', 'Σash Case', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForUnderscored()
|
||||
{
|
||||
$testData = 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('string_with_2_2_numbers', 'String-with_2_2 numbers'),
|
||||
array('1test2case', '1test2case'),
|
||||
array('test_σase', 'test Σase', 'UTF-8'),
|
||||
array('στανιλ_case', 'Στανιλ case', 'UTF-8'),
|
||||
array('σash_case', 'Σash Case', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForSwapCase()
|
||||
{
|
||||
$testData = array(
|
||||
array('TESTcASE', 'testCase'),
|
||||
array('tEST-cASE', 'Test-Case'),
|
||||
array(' - σASH cASE', ' - Σash Case', 'UTF-8'),
|
||||
array('νΤΑΝΙΛ', 'Ντανιλ', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForTitleize()
|
||||
{
|
||||
$ignore = array('at', 'by', 'for', 'in', 'of', 'on', 'out', 'to', 'the');
|
||||
|
||||
$testData = array(
|
||||
array('Testing The Method', 'testing the method'),
|
||||
array('Testing the Method', 'testing the method', $ignore, 'UTF-8'),
|
||||
array('I Like to Watch DVDs at Home', 'i like to watch DVDs at home',
|
||||
$ignore, 'UTF-8'),
|
||||
array('Θα Ήθελα Να Φύγει', ' Θα ήθελα να φύγει ', null, 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForHumanize()
|
||||
{
|
||||
$testData = array(
|
||||
array('Author', 'author_id'),
|
||||
array('Test user', ' _test_user_'),
|
||||
array('Συγγραφέας', ' συγγραφέας_id ', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForTidy()
|
||||
{
|
||||
$testData = array(
|
||||
array('"I see..."', '“I see…”'),
|
||||
array("'This too'", "‘This too’"),
|
||||
array('test-dash', 'test—dash'),
|
||||
array('Ο συγγραφέας είπε...', 'Ο συγγραφέας είπε…')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForCollapseWhitespace()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar', ' foo bar '),
|
||||
array('test string', 'test string'),
|
||||
array('Ο συγγραφέας', ' Ο συγγραφέας '),
|
||||
array('123', ' 123 '),
|
||||
array('', ' '),
|
||||
array('', ''),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForStandardize()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar', 'fòô bàř'),
|
||||
array(' TEST ', ' ŤÉŚŢ '),
|
||||
array('φ = z = 3', 'φ = ź = 3')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForPad()
|
||||
{
|
||||
$testData = array(
|
||||
// $length <= $str
|
||||
array('foo bar', 'foo bar', -1),
|
||||
array('foo bar', 'foo bar', 7),
|
||||
array('fòô bàř', 'fòô bàř', 7, ' ', 'right', 'UTF-8'),
|
||||
|
||||
// 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')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForPadLeft()
|
||||
{
|
||||
$testData = array(
|
||||
array(' foo bar', 'foo bar', 9),
|
||||
array('_*_foo bar', 'foo bar', 10, '_*'),
|
||||
array('¬ø¬øfòô bàř', 'fòô bàř', 11, '¬ø', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForPadRight()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar ', 'foo bar', 9),
|
||||
array('foo bar_*_', 'foo bar', 10, '_*'),
|
||||
array('fòô bàř¬ø¬ø', 'fòô bàř', 11, '¬ø', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForPadBoth()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar ', 'foo bar', 8),
|
||||
array(' foo bar ', 'foo bar', 9, ' '),
|
||||
array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬øÿ', 'UTF-8'),
|
||||
array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForStartsWith()
|
||||
{
|
||||
$testData = array(
|
||||
array(true, 'foo bars', 'foo bar'),
|
||||
array(true, 'FOO bars', 'foo bar', false),
|
||||
array(true, 'FOO bars', 'foo BAR', false),
|
||||
array(true, 'FÒÔ bàřs', 'fòô bàř', false, 'UTF-8'),
|
||||
array(true, 'fòô bàřs', 'fòô BÀŘ', false, 'UTF-8'),
|
||||
array(false, 'foo bar', 'bar'),
|
||||
array(false, 'foo bar', 'foo bars'),
|
||||
array(false, 'FOO bar', 'foo bars'),
|
||||
array(false, 'FOO bars', 'foo BAR'),
|
||||
array(false, 'FÒÔ bàřs', 'fòô bàř', true, 'UTF-8'),
|
||||
array(false, 'fòô bàřs', 'fòô BÀŘ', true, 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForEndsWith()
|
||||
{
|
||||
$testData = array(
|
||||
array(true, 'foo bars', 'o bars'),
|
||||
array(true, 'FOO bars', 'o bars', false),
|
||||
array(true, 'FOO bars', 'o BARs', false),
|
||||
array(true, 'FÒÔ bàřs', 'ô bàřs', false, 'UTF-8'),
|
||||
array(true, 'fòô bàřs', 'ô BÀŘs', false, 'UTF-8'),
|
||||
array(false, 'foo bar', 'foo'),
|
||||
array(false, 'foo bar', 'foo bars'),
|
||||
array(false, 'FOO bar', 'foo bars'),
|
||||
array(false, 'FOO bars', 'foo BARS'),
|
||||
array(false, 'FÒÔ bàřs', 'fòô bàřs', true, 'UTF-8'),
|
||||
array(false, 'fòô bàřs', 'fòô BÀŘS', true, 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForToSpaces()
|
||||
{
|
||||
$testData = array(
|
||||
array(' foo bar ', ' foo bar '),
|
||||
array(' foo bar ', ' foo bar ', 5),
|
||||
array(' foo bar ', ' foo bar ', 2),
|
||||
array('foobar', ' foo bar ', 0),
|
||||
array(" foo\n bar", " foo\n bar"),
|
||||
array(" fòô\n bàř", " fòô\n bàř")
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForToTabs()
|
||||
{
|
||||
$testData = array(
|
||||
array(' foo bar ', ' foo bar '),
|
||||
array(' foo bar ', ' foo bar ', 5),
|
||||
array(' foo bar ', ' foo bar ', 2),
|
||||
array(" foo\n bar", " foo\n bar"),
|
||||
array(" fòô\n bàř", " fòô\n bàř")
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForSlugify()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo-bar', ' 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àř'),
|
||||
array('unrecognized-chars-like', 'unrecognized chars like συγγρ'),
|
||||
array('numbers-1234', 'numbers 1234')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForContains()
|
||||
{
|
||||
$testData = array(
|
||||
array(true, 'This string contains foo bar', 'foo bar'),
|
||||
array(true, '12398!@(*%!@# @!%#*&^%', ' @!%#*&^%'),
|
||||
array(true, 'Ο συγγραφέας είπε', 'συγγραφέας', 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å´¥©', 'UTF-8'),
|
||||
array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å˚ ∆', 'UTF-8'),
|
||||
array(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, 'Ο συγγραφέας είπε', ' συγγραφέας ', 'UTF-8'),
|
||||
array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßå˚', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForSurround()
|
||||
{
|
||||
$testData = array(
|
||||
array('__foobar__', 'foobar', '__'),
|
||||
array('test', 'test', ''),
|
||||
array('**', '', '*'),
|
||||
array('¬fòô bàř¬', 'fòô bàř', '¬'),
|
||||
array('ßå∆˚ test ßå∆˚', ' test ', 'ßå∆˚')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForInsert()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar', 'oo bar', 'f', 0),
|
||||
array('foo bar', 'f bar', 'oo', 1),
|
||||
array('f bar', 'f bar', 'oo', 20),
|
||||
array('foo bar', 'foo ba', 'r', 6),
|
||||
array('fòô bàř', 'òô bàř', 'f', 0, 'UTF-8'),
|
||||
array('fòô bàř', 'f bàř', 'òô', 1, 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bà', 'ř', 6, 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForTruncate()
|
||||
{
|
||||
$testData = array(
|
||||
array('Test foo bar', 'Test foo bar', 12),
|
||||
array('Test foo ba', 'Test foo bar', 11),
|
||||
array('Test foo', 'Test foo bar', 8),
|
||||
array('Test fo', 'Test foo bar', 7),
|
||||
array('Test', 'Test foo bar', 4),
|
||||
array('Test foo bar', 'Test foo bar', 12, '...'),
|
||||
array('Test foo...', 'Test foo bar', 11, '...'),
|
||||
array('Test ...', 'Test foo bar', 8, '...'),
|
||||
array('Test...', 'Test foo bar', 7, '...'),
|
||||
array('T...', 'Test foo bar', 4, '...'),
|
||||
array('Test fo....', 'Test foo bar', 11, '....'),
|
||||
array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'),
|
||||
array('Test fòô bà', 'Test fòô bàř', 11, '', 'UTF-8'),
|
||||
array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'),
|
||||
array('Test fò', 'Test fòô bàř', 7, '', 'UTF-8'),
|
||||
array('Test', 'Test fòô bàř', 4, '', 'UTF-8'),
|
||||
array('Test fòô bàř', 'Test fòô bàř', 12, 'ϰϰ', 'UTF-8'),
|
||||
array('Test fòô ϰϰ', 'Test fòô bàř', 11, 'ϰϰ', 'UTF-8'),
|
||||
array('Test fϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'),
|
||||
array('Test ϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'),
|
||||
array('Teϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'),
|
||||
array('What are your pl...', 'What are your plans today?', 19, '...')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForSafeTruncate()
|
||||
{
|
||||
$testData = array(
|
||||
array('Test foo bar', 'Test foo bar', 12),
|
||||
array('Test foo', 'Test foo bar', 11),
|
||||
array('Test foo', 'Test foo bar', 8),
|
||||
array('Test', 'Test foo bar', 7),
|
||||
array('Test', 'Test foo bar', 4),
|
||||
array('Test foo bar', 'Test foo bar', 12, '...'),
|
||||
array('Test foo...', 'Test foo bar', 11, '...'),
|
||||
array('Test...', 'Test foo bar', 8, '...'),
|
||||
array('Test...', 'Test foo bar', 7, '...'),
|
||||
array('...', 'Test foo bar', 4, '...'),
|
||||
array('Test....', 'Test foo bar', 11, '....'),
|
||||
array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'),
|
||||
array('Test fòô', 'Test fòô bàř', 11, '', 'UTF-8'),
|
||||
array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'),
|
||||
array('Test', 'Test fòô bàř', 7, '', 'UTF-8'),
|
||||
array('Test', 'Test fòô bàř', 4, '', 'UTF-8'),
|
||||
array('Test fòô bàř', 'Test fòô bàř', 12, 'ϰϰ', 'UTF-8'),
|
||||
array('Test fòôϰϰ', 'Test fòô bàř', 11, 'ϰϰ', 'UTF-8'),
|
||||
array('Testϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'),
|
||||
array('Testϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'),
|
||||
array('ϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'),
|
||||
array('What are your plans...', 'What are your plans today?', 22, '...')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForReverse()
|
||||
{
|
||||
$testData = array(
|
||||
array('', ''),
|
||||
array('raboof', 'foobar'),
|
||||
array('řàbôòf', 'fòôbàř', 'UTF-8'),
|
||||
array('řàb ôòf', 'fòô bàř', 'UTF-8'),
|
||||
array('∂∆ ˚åß', 'ßå˚ ∆∂', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForShuffle()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar'),
|
||||
array('∂∆ ˚åß', 'UTF-8'),
|
||||
array('å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForTrim()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar', ' foo bar '),
|
||||
array('foo bar', ' foo bar'),
|
||||
array('foo bar', 'foo bar '),
|
||||
array('foo bar', "\n\t foo bar \n\t"),
|
||||
array('fòô bàř', ' fòô bàř '),
|
||||
array('fòô bàř', ' fòô bàř'),
|
||||
array('fòô bàř', 'fòô bàř '),
|
||||
array('fòô bàř', "\n\t fòô bàř \n\t")
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLongestCommonPrefix()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo', 'foobar', 'foo bar'),
|
||||
array('foo bar', 'foo bar', 'foo bar'),
|
||||
array('f', 'foo bar', 'far boo'),
|
||||
array('', 'toy car', 'foo bar'),
|
||||
array('', 'foo bar', ''),
|
||||
array('fòô', 'fòôbar', 'fòô bar', 'UTF-8'),
|
||||
array('fòô bar', 'fòô bar', 'fòô bar', 'UTF-8'),
|
||||
array('fò', 'fòô bar', 'fòr bar', 'UTF-8'),
|
||||
array('', 'toy car', 'fòô bar', 'UTF-8'),
|
||||
array('', 'fòô bar', '', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLongestCommonSuffix()
|
||||
{
|
||||
$testData = array(
|
||||
array('bar', 'foobar', 'foo bar'),
|
||||
array('foo bar', 'foo bar', 'foo bar'),
|
||||
array('ar', 'foo bar', 'boo far'),
|
||||
array('', 'foo bad', 'foo bar'),
|
||||
array('', 'foo bar', ''),
|
||||
array('bàř', 'fòôbàř', 'fòô bàř', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'fòô bàř', 'UTF-8'),
|
||||
array(' bàř', 'fòô bàř', 'fòr bàř', 'UTF-8'),
|
||||
array('', 'toy car', 'fòô bàř', 'UTF-8'),
|
||||
array('', 'fòô bàř', '', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLongestCommonSubstring()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo', 'foobar', 'foo bar'),
|
||||
array('foo bar', 'foo bar', 'foo bar'),
|
||||
array('oo ', 'foo bar', 'boo far'),
|
||||
array('foo ba', 'foo bad', 'foo bar'),
|
||||
array('', 'foo bar', ''),
|
||||
array('fòô', 'fòôbàř', 'fòô bàř', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'fòô bàř', 'UTF-8'),
|
||||
array(' bàř', 'fòô bàř', 'fòr bàř', 'UTF-8'),
|
||||
array(' ', 'toy car', 'fòô bàř', 'UTF-8'),
|
||||
array('', 'fòô bàř', '', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLength()
|
||||
{
|
||||
$testData = array(
|
||||
array(11, ' foo bar '),
|
||||
array(1, 'f'),
|
||||
array(0, ''),
|
||||
array(7, 'fòô bàř', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForSubstr()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar', 'foo bar', 0),
|
||||
array('bar', 'foo bar', 4),
|
||||
array('bar', 'foo bar', 4, null),
|
||||
array('o b', 'foo bar', 2, 3),
|
||||
array('', 'foo bar', 4, 0),
|
||||
array('fòô bàř', 'fòô bàř', 0, null, 'UTF-8'),
|
||||
array('bàř', 'fòô bàř', 4, null, 'UTF-8'),
|
||||
array('ô b', 'fòô bàř', 2, 3, 'UTF-8'),
|
||||
array('', 'fòô bàř', 4, 0, 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForAt()
|
||||
{
|
||||
$testData = array(
|
||||
array('f', 'foo bar', 0),
|
||||
array('o', 'foo bar', 1),
|
||||
array('r', 'foo bar', 6),
|
||||
array('', 'foo bar', 7),
|
||||
array('f', 'fòô bàř', 0, 'UTF-8'),
|
||||
array('ò', 'fòô bàř', 1, 'UTF-8'),
|
||||
array('ř', 'fòô bàř', 6, 'UTF-8'),
|
||||
array('', 'fòô bàř', 7, 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForFirst()
|
||||
{
|
||||
$testData = array(
|
||||
array('', 'foo bar', -5),
|
||||
array('', 'foo bar', 0),
|
||||
array('f', 'foo bar', 1),
|
||||
array('foo', 'foo bar', 3),
|
||||
array('foo bar', 'foo bar', 7),
|
||||
array('foo bar', 'foo bar', 8),
|
||||
array('', 'fòô bàř', -5, 'UTF-8'),
|
||||
array('', 'fòô bàř', 0, 'UTF-8'),
|
||||
array('f', 'fòô bàř', 1, 'UTF-8'),
|
||||
array('fòô', 'fòô bàř', 3, 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 7, 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 8, 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLast()
|
||||
{
|
||||
$testData = array(
|
||||
array('', 'foo bar', -5),
|
||||
array('', 'foo bar', 0),
|
||||
array('r', 'foo bar', 1),
|
||||
array('bar', 'foo bar', 3),
|
||||
array('foo bar', 'foo bar', 7),
|
||||
array('foo bar', 'foo bar', 8),
|
||||
array('', 'fòô bàř', -5, 'UTF-8'),
|
||||
array('', 'fòô bàř', 0, 'UTF-8'),
|
||||
array('ř', 'fòô bàř', 1, 'UTF-8'),
|
||||
array('bàř', 'fòô bàř', 3, 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 7, 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 8, 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForEnsureLeft()
|
||||
{
|
||||
$testData = array(
|
||||
array('foobar', 'foobar', 'f'),
|
||||
array('foobar', 'foobar', 'foo'),
|
||||
array('foo/foobar', 'foobar', 'foo/'),
|
||||
array('http://foobar', 'foobar', 'http://'),
|
||||
array('http://foobar', 'http://foobar', 'http://'),
|
||||
array('fòôbàř', 'fòôbàř', 'f', 'UTF-8'),
|
||||
array('fòôbàř', 'fòôbàř', 'fòô', 'UTF-8'),
|
||||
array('fòô/fòôbàř', 'fòôbàř', 'fòô/', 'UTF-8'),
|
||||
array('http://fòôbàř', 'fòôbàř', 'http://', 'UTF-8'),
|
||||
array('http://fòôbàř', 'http://fòôbàř', 'http://', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForEnsureRight()
|
||||
{
|
||||
$testData = array(
|
||||
array('foobar', 'foobar', 'r'),
|
||||
array('foobar', 'foobar', 'bar'),
|
||||
array('foobar/bar', 'foobar', '/bar'),
|
||||
array('foobar.com/', 'foobar', '.com/'),
|
||||
array('foobar.com/', 'foobar.com/', '.com/'),
|
||||
array('fòôbàř', 'fòôbàř', 'ř', 'UTF-8'),
|
||||
array('fòôbàř', 'fòôbàř', 'bàř', 'UTF-8'),
|
||||
array('fòôbàř/bàř', 'fòôbàř', '/bàř', 'UTF-8'),
|
||||
array('fòôbàř.com/', 'fòôbàř', '.com/', 'UTF-8'),
|
||||
array('fòôbàř.com/', 'fòôbàř.com/', '.com/', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForRemoveLeft()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar', 'foo bar', ''),
|
||||
array('oo bar', 'foo bar', 'f'),
|
||||
array('bar', 'foo bar', 'foo '),
|
||||
array('foo bar', 'foo bar', 'oo'),
|
||||
array('foo bar', 'foo bar', 'oo bar'),
|
||||
array('fòô bàř', 'fòô bàř', '', 'UTF-8'),
|
||||
array('òô bàř', 'fòô bàř', 'f', 'UTF-8'),
|
||||
array('bàř', 'fòô bàř', 'fòô ', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'òô', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'òô bàř', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForRemoveRight()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar', 'foo bar', ''),
|
||||
array('foo ba', 'foo bar', 'r'),
|
||||
array('foo', 'foo bar', ' bar'),
|
||||
array('foo bar', 'foo bar', 'ba'),
|
||||
array('foo bar', 'foo bar', 'foo ba'),
|
||||
array('fòô bàř', 'fòô bàř', '', 'UTF-8'),
|
||||
array('fòô bà', 'fòô bàř', 'ř', 'UTF-8'),
|
||||
array('fòô', 'fòô bàř', ' bàř', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'bà', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'fòô bà', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsAlpha()
|
||||
{
|
||||
$testData = array(
|
||||
array(true, ''),
|
||||
array(true, 'foobar'),
|
||||
array(false, 'foo bar'),
|
||||
array(false, 'foobar2'),
|
||||
array(true, 'fòôbàř', 'UTF-8'),
|
||||
array(false, 'fòô bàř', 'UTF-8'),
|
||||
array(false, 'fòôbàř2', 'UTF-8'),
|
||||
array(true, 'ҠѨњфгШ', 'UTF-8'),
|
||||
array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'),
|
||||
array(true, '丹尼爾', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsAlphanumeric()
|
||||
{
|
||||
$testData = array(
|
||||
array(true, ''),
|
||||
array(true, 'foobar1'),
|
||||
array(false, 'foo bar'),
|
||||
array(false, 'foobar2"'),
|
||||
array(false, "\nfoobar\n"),
|
||||
array(true, 'fòôbàř1', 'UTF-8'),
|
||||
array(false, 'fòô bàř', 'UTF-8'),
|
||||
array(false, 'fòôbàř2"', 'UTF-8'),
|
||||
array(true, 'ҠѨњфгШ', 'UTF-8'),
|
||||
array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'),
|
||||
array(true, '丹尼爾111', 'UTF-8'),
|
||||
array(true, 'دانيال1', 'UTF-8'),
|
||||
array(false, 'دانيال1 ', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsBlank()
|
||||
{
|
||||
$testData = array(
|
||||
array(true, ''),
|
||||
array(true, ' '),
|
||||
array(true, "\n\t "),
|
||||
array(true, "\n\t \v\f"),
|
||||
array(false, "\n\t a \v\f"),
|
||||
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(false, ' z', 'UTF-8'),
|
||||
array(false, ' 1', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsLowerCase()
|
||||
{
|
||||
$testData = array(
|
||||
array(true, ''),
|
||||
array(true, 'foobar'),
|
||||
array(false, 'foo bar'),
|
||||
array(false, 'Foobar'),
|
||||
array(true, 'fòôbàř', 'UTF-8'),
|
||||
array(false, 'fòôbàř2', 'UTF-8'),
|
||||
array(false, 'fòô bàř', 'UTF-8'),
|
||||
array(false, 'fòôbÀŘ', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForIsUpperCase()
|
||||
{
|
||||
$testData = array(
|
||||
array(true, ''),
|
||||
array(true, 'FOOBAR'),
|
||||
array(false, 'FOO BAR'),
|
||||
array(false, 'fOOBAR'),
|
||||
array(true, 'FÒÔBÀŘ', 'UTF-8'),
|
||||
array(false, 'FÒÔBÀŘ2', 'UTF-8'),
|
||||
array(false, 'FÒÔ BÀŘ', 'UTF-8'),
|
||||
array(false, 'FÒÔBàř', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForCount()
|
||||
{
|
||||
$testData = array(
|
||||
array(0, '', 'foo'),
|
||||
array(0, 'foo', 'bar'),
|
||||
array(1, 'foo bar', 'foo'),
|
||||
array(2, 'foo bar', 'o'),
|
||||
array(0, '', 'fòô', 'UTF-8'),
|
||||
array(0, 'fòô', 'bàř', 'UTF-8'),
|
||||
array(1, 'fòô bàř', 'fòô', 'UTF-8'),
|
||||
array(2, 'fôòô bàř', 'ô', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForReplace()
|
||||
{
|
||||
$testData = array(
|
||||
array('', '', '', ''),
|
||||
array('foo', '', '', 'foo'),
|
||||
array('foo bar', 'foo bar', '', ''),
|
||||
array('bar', 'foo bar', 'foo ', ''),
|
||||
array('far bar', 'foo bar', 'foo', 'far'),
|
||||
array('bar bar', 'foo bar foo bar', 'foo ', ''),
|
||||
array('', '', '', '', 'UTF-8'),
|
||||
array('fòô', '', '', 'fòô', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', '', '', 'UTF-8'),
|
||||
array('bàř', 'fòô bàř', 'fòô ', '', 'UTF-8'),
|
||||
array('far bàř', 'fòô bàř', 'fòô', 'far', 'UTF-8'),
|
||||
array('bàř bàř', 'fòô bàř fòô bàř', 'fòô ', '', 'UTF-8'),
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
// A test is required so as not to throw an error
|
||||
// This is a lot cleaner than using PHPUnit's mocks to spy
|
||||
public function test() {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
@@ -1,457 +0,0 @@
|
||||
<?php
|
||||
|
||||
$base = realpath(dirname(__FILE__) . '/../..');
|
||||
require("$base/src/Stringy/StaticStringy.php");
|
||||
|
||||
use Stringy\StaticStringy as S;
|
||||
|
||||
class StaticStringyTestCase extends CommonTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider stringsForUpperCaseFirst
|
||||
*/
|
||||
public function testUpperCaseFirst($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::upperCaseFirst($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLowerCaseFirst
|
||||
*/
|
||||
public function testLowerCaseFirst($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::lowerCaseFirst($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForCamelize
|
||||
*/
|
||||
public function testCamelize($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::camelize($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForUpperCamelize
|
||||
*/
|
||||
public function testUpperCamelize($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::upperCamelize($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForDasherize
|
||||
*/
|
||||
public function testDasherize($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::dasherize($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForUnderscored
|
||||
*/
|
||||
public function testUnderscored($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::underscored($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSwapCase
|
||||
*/
|
||||
public function testSwapCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::swapCase($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTitleize
|
||||
*/
|
||||
public function testTitleize($expected, $str, $ignore = null,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::titleize($str, $ignore, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForHumanize
|
||||
*/
|
||||
public function testHumanize($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::humanize($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTidy
|
||||
*/
|
||||
public function testTidy($expected, $str)
|
||||
{
|
||||
$result = S::tidy($str);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForCollapseWhitespace
|
||||
*/
|
||||
public function testCollapseWhitespace($expected, $str)
|
||||
{
|
||||
$result = S::collapseWhitespace($str);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForStandardize
|
||||
*/
|
||||
public function testStandardize($expected, $str)
|
||||
{
|
||||
$result = S::standardize($str);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPad
|
||||
*/
|
||||
public function testPad($expected, $str, $length, $padStr = ' ',
|
||||
$padType = 'right', $encoding = null)
|
||||
{
|
||||
$result = S::pad($str, $length, $padStr, $padType, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPadLeft
|
||||
*/
|
||||
public function testPadLeft($expected, $str, $length, $padStr = ' ',
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::padLeft($str, $length, $padStr, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPadRight
|
||||
*/
|
||||
public function testPadRight($expected, $str, $length, $padStr = ' ',
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::padRight($str, $length, $padStr, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPadBoth
|
||||
*/
|
||||
public function testPadBoth($expected, $str, $length, $padStr = ' ',
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::padBoth($str, $length, $padStr, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForStartsWith
|
||||
*/
|
||||
public function testStartsWith($expected, $str, $substring,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$result = S::startsWith($str, $substring, $caseSensitive, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForEndsWith
|
||||
*/
|
||||
public function testEndsWith($expected, $str, $substring,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$result = S::endsWith($str, $substring, $caseSensitive, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForToSpaces
|
||||
*/
|
||||
public function testToSpaces($expected, $str, $tabLength = 4)
|
||||
{
|
||||
$result = S::toSpaces($str, $tabLength);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForToTabs
|
||||
*/
|
||||
public function testToTabs($expected, $str, $tabLength = 4)
|
||||
{
|
||||
$result = S::toTabs($str, $tabLength);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSlugify
|
||||
*/
|
||||
public function testSlugify($expected, $str)
|
||||
{
|
||||
$result = S::slugify($str);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForContains
|
||||
*/
|
||||
public function testContains($expected, $haystack, $needle, $encoding = null)
|
||||
{
|
||||
$result = S::contains($haystack, $needle, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSurround
|
||||
*/
|
||||
public function testSurround($expected, $str, $substring)
|
||||
{
|
||||
$result = S::surround($str, $substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForInsert
|
||||
*/
|
||||
public function testInsert($expected, $str, $substring, $index,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::insert($str, $substring, $index, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTruncate
|
||||
*/
|
||||
public function testTruncate($expected, $str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::truncate($str, $length, $substring, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSafeTruncate
|
||||
*/
|
||||
public function testSafeTruncate($expected, $str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::safeTruncate($str, $length, $substring, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForReverse
|
||||
*/
|
||||
public function testReverse($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::reverse($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForShuffle
|
||||
*/
|
||||
public function testShuffle($str, $encoding = null)
|
||||
{
|
||||
// We'll just make sure that the chars are present before/after shuffle
|
||||
$result = S::shuffle($str, $encoding);
|
||||
$this->assertEquals(count_chars($str), count_chars($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTrim
|
||||
*/
|
||||
public function testTrim($expected, $str)
|
||||
{
|
||||
$result = S::trim($str);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLongestCommonPrefix
|
||||
*/
|
||||
public function testLongestCommonPrefix($expected, $str, $otherStr,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::longestCommonPrefix($str, $otherStr, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLongestCommonSuffix
|
||||
*/
|
||||
public function testLongestCommonSuffix($expected, $str, $otherStr,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::longestCommonSuffix($str, $otherStr, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLongestCommonSubstring
|
||||
*/
|
||||
public function testLongestCommonSubstring($expected, $str, $otherStr,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::longestCommonSubstring($str, $otherStr, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLength
|
||||
*/
|
||||
public function testLength($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::length($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSubstr
|
||||
*/
|
||||
public function testSubstr($expected, $str, $start, $length = null,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::substr($str, $start, $length, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForAt
|
||||
*/
|
||||
public function testAt($expected, $str, $index, $encoding = null)
|
||||
{
|
||||
$result = S::at($str, $index, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForFirst
|
||||
*/
|
||||
public function testFirst($expected, $str, $n, $encoding = null)
|
||||
{
|
||||
$result = S::first($str, $n, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLast
|
||||
*/
|
||||
public function testLast($expected, $str, $n, $encoding = null)
|
||||
{
|
||||
$result = S::last($str, $n, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForEnsureLeft
|
||||
*/
|
||||
public function testEnsureLeft($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$result = S::ensureLeft($str, $substring, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForEnsureRight
|
||||
*/
|
||||
public function testEnsureRight($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$result = S::ensureRight($str, $substring, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRemoveLeft
|
||||
*/
|
||||
public function testRemoveLeft($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$result = S::removeLeft($str, $substring, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRemoveRight
|
||||
*/
|
||||
public function testRemoveRight($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$result = S::removeRight($str, $substring, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsAlpha
|
||||
*/
|
||||
public function testIsAlpha($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::isAlpha($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsAlphanumeric
|
||||
*/
|
||||
public function testIsAlphanumeric($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::isAlphanumeric($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsBlank
|
||||
*/
|
||||
public function testIsBlank($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::isBlank($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsLowerCase
|
||||
*/
|
||||
public function testIsLowerCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::isLowerCase($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsUpperCase
|
||||
*/
|
||||
public function testIsUpperCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::isUpperCase($str, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForCount
|
||||
*/
|
||||
public function testCount($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$result = S::count($str, $substring, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForReplace
|
||||
*/
|
||||
public function testReplace($expected, $str, $search, $replace,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::replace($str, $search, $replace, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
@@ -1,527 +0,0 @@
|
||||
<?php
|
||||
|
||||
$base = realpath(dirname(__FILE__) . '/../..');
|
||||
require("$base/src/Stringy/Stringy.php");
|
||||
|
||||
use Stringy\Stringy as S;
|
||||
|
||||
class StringyTestCase extends CommonTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider stringsForUpperCaseFirst
|
||||
*/
|
||||
public function testUpperCaseFirst($expected, $str, $encoding = null)
|
||||
{
|
||||
$result = S::create($str, $encoding)->upperCaseFirst();
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLowerCaseFirst
|
||||
*/
|
||||
public function testLowerCaseFirst($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->lowerCaseFirst();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForCamelize
|
||||
*/
|
||||
public function testCamelize($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->camelize();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForUpperCamelize
|
||||
*/
|
||||
public function testUpperCamelize($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->upperCamelize();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForDasherize
|
||||
*/
|
||||
public function testDasherize($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->dasherize();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForUnderscored
|
||||
*/
|
||||
public function testUnderscored($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->underscored();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSwapCase
|
||||
*/
|
||||
public function testSwapCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->swapCase();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTitleize
|
||||
*/
|
||||
public function testTitleize($expected, $str, $ignore = null,
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->titleize($ignore);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForHumanize
|
||||
*/
|
||||
public function testHumanize($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->humanize();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTidy
|
||||
*/
|
||||
public function testTidy($expected, $str)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->tidy();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForCollapseWhitespace
|
||||
*/
|
||||
public function testCollapseWhitespace($expected, $str)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->collapseWhitespace();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForStandardize
|
||||
*/
|
||||
public function testStandardize($expected, $str)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->standardize();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPad
|
||||
*/
|
||||
public function testPad($expected, $str, $length, $padStr = ' ',
|
||||
$padType = 'right', $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->pad($length, $padStr, $padType);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPadLeft
|
||||
*/
|
||||
public function testPadLeft($expected, $str, $length, $padStr = ' ',
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->padLeft($length, $padStr);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPadRight
|
||||
*/
|
||||
public function testPadRight($expected, $str, $length, $padStr = ' ',
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->padRight($length, $padStr);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForPadBoth
|
||||
*/
|
||||
public function testPadBoth($expected, $str, $length, $padStr = ' ',
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->padBoth($length, $padStr);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForStartsWith
|
||||
*/
|
||||
public function testStartsWith($expected, $str, $substring,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->startsWith($substring, $caseSensitive);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForEndsWith
|
||||
*/
|
||||
public function testEndsWith($expected, $str, $substring,
|
||||
$caseSensitive = true, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->endsWith($substring, $caseSensitive);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForToSpaces
|
||||
*/
|
||||
public function testToSpaces($expected, $str, $tabLength = 4)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->toSpaces($tabLength);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForToTabs
|
||||
*/
|
||||
public function testToTabs($expected, $str, $tabLength = 4)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->toTabs($tabLength);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSlugify
|
||||
*/
|
||||
public function testSlugify($expected, $str)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->slugify();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForContains
|
||||
*/
|
||||
public function testContains($expected, $haystack, $needle, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($haystack, $encoding);
|
||||
$result = $stringy->contains($needle);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($haystack, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSurround
|
||||
*/
|
||||
public function testSurround($expected, $str, $substring)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->surround($substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForInsert
|
||||
*/
|
||||
public function testInsert($expected, $str, $substring, $index,
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->insert($substring, $index);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTruncate
|
||||
*/
|
||||
public function testTruncate($expected, $str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->truncate($length, $substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForReverse
|
||||
*/
|
||||
public function testReverse($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->reverse();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForShuffle
|
||||
*/
|
||||
public function testShuffle($str, $encoding = null)
|
||||
{
|
||||
// We'll just make sure that the chars are present before/after shuffle
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->shuffle();
|
||||
$this->assertEquals(count_chars($str), count_chars($result));
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTrim
|
||||
*/
|
||||
public function testTrim($expected, $str)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->trim();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLongestCommonPrefix
|
||||
*/
|
||||
public function testLongestCommonPrefix($expected, $str, $otherStr,
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->longestCommonPrefix($otherStr);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLongestCommonSubstring
|
||||
*/
|
||||
public function testLongestCommonSubstring($expected, $str, $otherStr,
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->longestCommonSubstring($otherStr);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLength
|
||||
*/
|
||||
public function testLength($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->length();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSubstr
|
||||
*/
|
||||
public function testSubstr($expected, $str, $start, $length = null,
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->substr($start, $length);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForAt
|
||||
*/
|
||||
public function testAt($expected, $str, $index, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->at($index);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForFirst
|
||||
*/
|
||||
public function testFirst($expected, $str, $n, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->first($n);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLast
|
||||
*/
|
||||
public function testLast($expected, $str, $n, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->last($n);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForEnsureLeft
|
||||
*/
|
||||
public function testEnsureLeft($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->ensureLeft($substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForEnsureRight
|
||||
*/
|
||||
public function testEnsureRight($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->ensureRight($substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRemoveLeft
|
||||
*/
|
||||
public function testRemoveLeft($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->removeLeft($substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRemoveRight
|
||||
*/
|
||||
public function testRemoveRight($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->removeRight($substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsAlpha
|
||||
*/
|
||||
public function testIsAlpha($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->isAlpha();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsAlphanumeric
|
||||
*/
|
||||
public function testIsAlphanumeric($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->isAlphanumeric();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsBlank
|
||||
*/
|
||||
public function testIsBlank($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->isBlank();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsLowerCase
|
||||
*/
|
||||
public function testIsLowerCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->isLowerCase();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForIsUpperCase
|
||||
*/
|
||||
public function testIsUpperCase($expected, $str, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->isUpperCase();
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForCount
|
||||
*/
|
||||
public function testCount($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->count($substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForReplace
|
||||
*/
|
||||
public function testReplace($expected, $str, $search, $replace,
|
||||
$encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->replace($search, $replace);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
}
|
2425
tests/StringyTest.php
Normal file
2425
tests/StringyTest.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user