mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-09-01 09:03:03 +02:00
Compare commits
51 Commits
2.1.0
...
disable-mb
Author | SHA1 | Date | |
---|---|---|---|
|
ee1e4074a6 | ||
|
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 |
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
|
44
.travis.yml
44
.travis.yml
@@ -1,7 +1,43 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.6
|
||||
- 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 = 'true' ]]; then cat ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi
|
||||
- if [[ $polyfill = 'false' ]]; then travis_retry composer remove symfony/polyfill-mbstring; fi
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit
|
||||
|
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,3 +1,16 @@
|
||||
### 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
|
||||
|
36
README.md
36
README.md
@@ -1,7 +1,7 @@
|
||||

|
||||
|
||||
A PHP string manipulation library with multibyte support. Compatible with PHP
|
||||
5.3+ and HHVM. Refer to the [1.x branch](https://github.com/danielstjules/Stringy/tree/1.x)
|
||||
5.3+, PHP 7, and HHVM. Refer to the [1.x branch](https://github.com/danielstjules/Stringy/tree/1.x)
|
||||
for older documentation.
|
||||
|
||||
``` php
|
||||
@@ -9,6 +9,8 @@ s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
|
||||
```
|
||||
|
||||
[](https://travis-ci.org/danielstjules/Stringy)
|
||||
[](https://packagist.org/packages/danielstjules/stringy)
|
||||
[](https://packagist.org/packages/danielstjules/stringy)
|
||||
|
||||
* [Why?](#why)
|
||||
* [Installation](#installation)
|
||||
@@ -46,6 +48,7 @@ s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
|
||||
* [insert](#insertint-index-string-substring)
|
||||
* [isAlpha](#isalpha)
|
||||
* [isAlphanumeric](#isalphanumeric)
|
||||
* [isBase64](#isbase64)
|
||||
* [isBlank](#isblank)
|
||||
* [isHexadecimal](#ishexadecimal)
|
||||
* [isJson](#isjson)
|
||||
@@ -128,7 +131,7 @@ in your composer.json file:
|
||||
|
||||
```json
|
||||
"require": {
|
||||
"danielstjules/stringy": "~2.1"
|
||||
"danielstjules/stringy": "~2.3"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -151,11 +154,13 @@ And in either case, I'd suggest using an alias.
|
||||
use Stringy\Stringy as S;
|
||||
```
|
||||
|
||||
Please note that Stringy relies on the `mbstring` PHP module for its underlying
|
||||
multibyte support. This is a non-default, but very common module. For example,
|
||||
with debian and ubuntu, it's included in libapache2-mod-php5, php5-cli, and
|
||||
php5-fpm. For OSX users, it's a default for any version of PHP installed with
|
||||
homebrew. If compiling PHP from scratch, it can be included with the
|
||||
Please note that Stringy relies on the `mbstring` module for its underlying
|
||||
multibyte support. If the module is not found, Stringy will use
|
||||
[symfony/polyfill-mbstring](https://github.com/symfony/polyfill-mbstring).
|
||||
ex-mbstring is a non-default, but very common module. For example, with debian
|
||||
and ubuntu, it's included in libapache2-mod-php5, php5-cli, and php5-fpm. For
|
||||
OSX users, it's a default for any version of PHP installed with homebrew.
|
||||
If compiling PHP from scratch, it can be included with the
|
||||
`--enable-mbstring` flag.
|
||||
|
||||
## OO and Chaining
|
||||
@@ -396,7 +401,7 @@ s('foobar')->ensureLeft('http://'); // 'http://foobar'
|
||||
|
||||
##### ensureRight(string $substring)
|
||||
|
||||
Ensures that the string begins with $substring. If it doesn't, it's appended.
|
||||
Ensures that the string ends with $substring. If it doesn't, it's appended.
|
||||
|
||||
```php
|
||||
s('foobar')->ensureRight('.com'); // 'foobar.com'
|
||||
@@ -509,6 +514,14 @@ otherwise.
|
||||
s('دانيال1')->isAlphanumeric(); // true
|
||||
```
|
||||
|
||||
##### isBase64()
|
||||
|
||||
Returns true if the string is base64 encoded, false otherwise.
|
||||
|
||||
```php
|
||||
s('Zm9vYmFy')->isBase64(); // true
|
||||
```
|
||||
|
||||
##### isBlank()
|
||||
|
||||
Returns true if the string contains only whitespace chars, false otherwise.
|
||||
@@ -527,7 +540,9 @@ s('A102F')->isHexadecimal(); // true
|
||||
|
||||
##### isJson()
|
||||
|
||||
Returns true if the string is JSON, false otherwise.
|
||||
Returns true if the string is JSON, false otherwise. Unlike json_decode
|
||||
in PHP 5.x, this method is consistent with PHP 7 and other JSON parsers,
|
||||
in that an empty string is not considered valid JSON.
|
||||
|
||||
```php
|
||||
s('{"foo":"bar"}')->isJson(); // true
|
||||
@@ -671,7 +686,8 @@ to a lack of support in the bundled version of Oniguruma in PHP < 5.6,
|
||||
and current versions of HHVM (3.8 and below).
|
||||
|
||||
```php
|
||||
s('fòô ')->regexReplace('f[òô]+\s', 'bàř', 'msr'); // 'bàř'
|
||||
s('fòô ')->regexReplace('f[òô]+\s', 'bàř'); // 'bàř'
|
||||
s('fò')->regexReplace('(ò)', '\\1ô'); // 'fòô'
|
||||
```
|
||||
|
||||
##### removeLeft(string $substring)
|
||||
|
@@ -16,7 +16,7 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"ext-mbstring": "*"
|
||||
"symfony/polyfill-mbstring": "~1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit processIsolation="false"
|
||||
<phpunit bootstrap="vendor/autoload.php"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
|
@@ -2,6 +2,91 @@
|
||||
|
||||
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
|
||||
{
|
||||
/**
|
||||
@@ -11,85 +96,7 @@ class StaticStringy
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $methodArgs = array(
|
||||
'append' => 3,
|
||||
'at' => 3,
|
||||
'between' => 5,
|
||||
'camelize' => 2,
|
||||
'chars' => 2,
|
||||
'collapseWhitespace' => 2,
|
||||
'contains' => 4,
|
||||
'containsAll' => 4,
|
||||
'containsAny' => 4,
|
||||
'count' => 2,
|
||||
'countSubstr' => 4,
|
||||
'dasherize' => 2,
|
||||
'delimit' => 3,
|
||||
'endsWith' => 4,
|
||||
'ensureLeft' => 3,
|
||||
'ensureRight' => 3,
|
||||
'first' => 3,
|
||||
'getEncoding' => 2,
|
||||
'hasLowerCase' => 2,
|
||||
'hasUpperCase' => 2,
|
||||
'htmlDecode' => 3,
|
||||
'htmlEncode' => 3,
|
||||
'humanize' => 2,
|
||||
'indexOf' => 4,
|
||||
'indexOfLast' => 4,
|
||||
'insert' => 4,
|
||||
'isAlpha' => 2,
|
||||
'isAlphanumeric' => 2,
|
||||
'isBlank' => 2,
|
||||
'isHexadecimal' => 2,
|
||||
'isJson' => 2,
|
||||
'isLowerCase' => 2,
|
||||
'isSerialized' => 2,
|
||||
'isUpperCase' => 2,
|
||||
'last' => 3,
|
||||
'length' => 2,
|
||||
'lines' => 2,
|
||||
'longestCommonPrefix' => 3,
|
||||
'longestCommonSuffix' => 3,
|
||||
'longestCommonSubstring' => 3,
|
||||
'lowerCaseFirst' => 2,
|
||||
'pad' => 5,
|
||||
'padBoth' => 4,
|
||||
'padLeft' => 4,
|
||||
'padRight' => 4,
|
||||
'prepend' => 3,
|
||||
'regexReplace' => 5,
|
||||
'removeLeft' => 3,
|
||||
'removeRight' => 3,
|
||||
'repeat' => 3,
|
||||
'replace' => 4,
|
||||
'reverse' => 2,
|
||||
'safeTruncate' => 4,
|
||||
'shuffle' => 2,
|
||||
'slugify' => 3,
|
||||
'startsWith' => 4,
|
||||
'slice' => 4,
|
||||
'split' => 4,
|
||||
'substr' => 4,
|
||||
'surround' => 3,
|
||||
'swapCase' => 2,
|
||||
'tidy' => 2,
|
||||
'titleize' => 3,
|
||||
'toAscii' => 3,
|
||||
'toBoolean' => 2,
|
||||
'toLowerCase' => 2,
|
||||
'toSpaces' => 3,
|
||||
'toTabs' => 3,
|
||||
'toTitleCase' => 2,
|
||||
'toUpperCase' => 2,
|
||||
'trim' => 3,
|
||||
'trimLeft' => 3,
|
||||
'trimRight' => 3,
|
||||
'truncate' => 4,
|
||||
'underscored' => 2,
|
||||
'upperCamelize' => 2,
|
||||
'upperCaseFirst' => 2
|
||||
);
|
||||
protected static $methodArgs = null;
|
||||
|
||||
/**
|
||||
* Creates an instance of Stringy and invokes the given method with the
|
||||
@@ -102,11 +109,25 @@ class StaticStringy
|
||||
*
|
||||
* @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');
|
||||
throw new BadMethodCallException($name . ' is not a valid method');
|
||||
}
|
||||
|
||||
$numArgs = count($arguments);
|
||||
|
231
src/Stringy.php
231
src/Stringy.php
@@ -2,7 +2,15 @@
|
||||
|
||||
namespace Stringy;
|
||||
|
||||
class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
use ArrayAccess;
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use IteratorAggregate;
|
||||
use OutOfBoundsException;
|
||||
|
||||
class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||
{
|
||||
/**
|
||||
* An instance's string.
|
||||
@@ -34,11 +42,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
public function __construct($str = '', $encoding = null)
|
||||
{
|
||||
if (is_array($str)) {
|
||||
throw new \InvalidArgumentException(
|
||||
throw new InvalidArgumentException(
|
||||
'Passed value cannot be an array'
|
||||
);
|
||||
} elseif (is_object($str) && !method_exists($str, '__toString')) {
|
||||
throw new \InvalidArgumentException(
|
||||
throw new InvalidArgumentException(
|
||||
'Passed object must have a __toString method'
|
||||
);
|
||||
}
|
||||
@@ -104,7 +112,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*
|
||||
* @param string $start Delimiter marking the start of the substring
|
||||
* @param string $end Delimiter marketing the end of the substring
|
||||
* @param string $offset Index from which to begin the search
|
||||
* @param int $offset Index from which to begin the search
|
||||
* @return Stringy Object whose $str has been converted to an URL slug
|
||||
*/
|
||||
public function between($start, $end, $offset = 0)
|
||||
@@ -141,9 +149,9 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
function ($match) use ($encoding) {
|
||||
if (isset($match[1])) {
|
||||
return mb_strtoupper($match[1], $encoding);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
return '';
|
||||
},
|
||||
$stringy->str
|
||||
);
|
||||
@@ -201,9 +209,9 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
|
||||
if ($caseSensitive) {
|
||||
return (mb_strpos($this->str, $needle, 0, $encoding) !== false);
|
||||
} else {
|
||||
return (mb_stripos($this->str, $needle, 0, $encoding) !== false);
|
||||
}
|
||||
|
||||
return (mb_stripos($this->str, $needle, 0, $encoding) !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -365,7 +373,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the string begins with $substring. If it doesn't, it's
|
||||
* Ensures that the string ends with $substring. If it doesn't, it's
|
||||
* appended.
|
||||
*
|
||||
* @param string $substring The substring to add if not present
|
||||
@@ -394,11 +402,10 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
|
||||
if ($n < 0) {
|
||||
$stringy->str = '';
|
||||
} else {
|
||||
return $stringy->substr(0, $n);
|
||||
return $stringy;
|
||||
}
|
||||
|
||||
return $stringy;
|
||||
return $stringy->substr(0, $n);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -421,7 +428,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->chars());
|
||||
return new ArrayIterator($this->chars());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -589,12 +596,18 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string is JSON, false otherwise.
|
||||
* Returns true if the string is JSON, false otherwise. Unlike json_decode
|
||||
* in PHP 5.x, this method is consistent with PHP 7 and other JSON parsers,
|
||||
* in that an empty string is not considered valid JSON.
|
||||
*
|
||||
* @return bool Whether or not $str is JSON
|
||||
*/
|
||||
public function isJson()
|
||||
{
|
||||
if (!$this->length()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
json_decode($this->str);
|
||||
|
||||
return (json_last_error() === JSON_ERROR_NONE);
|
||||
@@ -621,6 +634,17 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
return $this->str === 'b:0;' || @unserialize($this->str) !== false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the string is base64 encoded, false otherwise.
|
||||
*
|
||||
* @return bool Whether or not $str is base64 encoded
|
||||
*/
|
||||
public function isBase64()
|
||||
{
|
||||
return (base64_encode(base64_decode($this->str, true)) === $this->str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains only lower case chars, false
|
||||
* otherwise.
|
||||
@@ -644,11 +668,10 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
|
||||
if ($n <= 0) {
|
||||
$stringy->str = '';
|
||||
} else {
|
||||
return $stringy->substr(-$n);
|
||||
return $stringy;
|
||||
}
|
||||
|
||||
return $stringy;
|
||||
return $stringy->substr(-$n);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -829,7 +852,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
$length = $this->length();
|
||||
|
||||
if (($offset >= 0 && $length <= $offset) || $length < abs($offset)) {
|
||||
throw new \OutOfBoundsException('No character exists at the index');
|
||||
throw new OutOfBoundsException('No character exists at the index');
|
||||
}
|
||||
|
||||
return mb_substr($this->str, $offset, 1, $this->encoding);
|
||||
@@ -846,7 +869,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
// Stringy is immutable, cannot directly set char
|
||||
throw new \Exception('Stringy object is immutable, cannot modify char');
|
||||
throw new Exception('Stringy object is immutable, cannot modify char');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -859,7 +882,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
// Don't allow directly modifying the string
|
||||
throw new \Exception('Stringy object is immutable, cannot unset char');
|
||||
throw new Exception('Stringy object is immutable, cannot unset char');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -873,13 +896,13 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
* @param string $padStr String used to pad, defaults to space
|
||||
* @param string $padType One of 'left', 'right', 'both'
|
||||
* @return Stringy Object with a padded $str
|
||||
* @throws InvalidArgumentException If $padType isn't one of 'right',
|
||||
* @throws /InvalidArgumentException If $padType isn't one of 'right',
|
||||
* 'left' or 'both'
|
||||
*/
|
||||
public function pad($length, $padStr = ' ', $padType = 'right')
|
||||
{
|
||||
if (!in_array($padType, array('left', 'right', 'both'))) {
|
||||
throw new \InvalidArgumentException('Pad expects $padType ' .
|
||||
throw new InvalidArgumentException('Pad expects $padType ' .
|
||||
"to be one of 'left', 'right' or 'both'");
|
||||
}
|
||||
|
||||
@@ -1262,9 +1285,9 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
function ($match) use ($encoding) {
|
||||
if ($match[0] == mb_strtoupper($match[0], $encoding)) {
|
||||
return mb_strtolower($match[0], $encoding);
|
||||
} else {
|
||||
return mb_strtoupper($match[0], $encoding);
|
||||
}
|
||||
|
||||
return mb_strtoupper($match[0], $encoding);
|
||||
},
|
||||
$stringy->str
|
||||
);
|
||||
@@ -1314,10 +1337,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
function ($match) use ($encoding, $ignore) {
|
||||
if ($ignore && in_array($match[0], $ignore)) {
|
||||
return $match[0];
|
||||
} else {
|
||||
$stringy = new Stringy($match[0], $encoding);
|
||||
return (string) $stringy->toLowerCase()->upperCaseFirst();
|
||||
}
|
||||
|
||||
$stringy = new Stringy($match[0], $encoding);
|
||||
|
||||
return (string) $stringy->toLowerCase()->upperCaseFirst();
|
||||
},
|
||||
$stringy->str
|
||||
);
|
||||
@@ -1377,10 +1401,10 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
if (array_key_exists($key, $map)) {
|
||||
return $map[$key];
|
||||
} elseif (is_numeric($this->str)) {
|
||||
return (intval($this->str) > 0);
|
||||
} else {
|
||||
return (bool) $this->regexReplace('[[:space:]]', '')->str;
|
||||
return (intval($this->str) > 0);
|
||||
}
|
||||
|
||||
return (bool) $this->regexReplace('[[:space:]]', '')->str;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1575,74 +1599,100 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
if (isset($charsArray)) return $charsArray;
|
||||
|
||||
return $charsArray = array(
|
||||
'a' => array(
|
||||
'à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ',
|
||||
'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ä', 'ā', 'ą',
|
||||
'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ',
|
||||
'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ',
|
||||
'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ'),
|
||||
'b' => array('б', 'β', 'Ъ', 'Ь', 'ب'),
|
||||
'0' => array('°', '₀', '۰'),
|
||||
'1' => array('¹', '₁', '۱'),
|
||||
'2' => array('²', '₂', '۲'),
|
||||
'3' => array('³', '₃', '۳'),
|
||||
'4' => array('⁴', '₄', '۴', '٤'),
|
||||
'5' => array('⁵', '₅', '۵', '٥'),
|
||||
'6' => array('⁶', '₆', '۶', '٦'),
|
||||
'7' => array('⁷', '₇', '۷'),
|
||||
'8' => array('⁸', '₈', '۸'),
|
||||
'9' => array('⁹', '₉', '۹'),
|
||||
'a' => array('à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ',
|
||||
'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å',
|
||||
'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ',
|
||||
'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά',
|
||||
'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ',
|
||||
'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا'),
|
||||
'b' => array('б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ'),
|
||||
'c' => array('ç', 'ć', 'č', 'ĉ', 'ċ'),
|
||||
'd' => array('ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ',
|
||||
'д', 'δ', 'د', 'ض'),
|
||||
'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ'),
|
||||
'e' => array('é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ',
|
||||
'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ',
|
||||
'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э',
|
||||
'є', 'ə'),
|
||||
'f' => array('ф', 'φ', 'ف'),
|
||||
'g' => array('ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ج'),
|
||||
'h' => array('ĥ', 'ħ', 'η', 'ή', 'ح', 'ه'),
|
||||
'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ'),
|
||||
'f' => array('ф', 'φ', 'ف', 'ƒ', 'ფ'),
|
||||
'g' => array('ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ'),
|
||||
'h' => array('ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ'),
|
||||
'i' => array('í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į',
|
||||
'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ',
|
||||
'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ',
|
||||
'ῗ', 'і', 'ї', 'и'),
|
||||
'j' => array('ĵ', 'ј', 'Ј'),
|
||||
'k' => array('ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك'),
|
||||
'l' => array('ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل'),
|
||||
'm' => array('м', 'μ', 'م'),
|
||||
'n' => array('ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن'),
|
||||
'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი',
|
||||
'इ', 'ی'),
|
||||
'j' => array('ĵ', 'ј', 'Ј', 'ჯ', 'ج'),
|
||||
'k' => array('ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک'),
|
||||
'l' => array('ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ'),
|
||||
'm' => array('м', 'μ', 'م', 'မ', 'მ'),
|
||||
'n' => array('ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န',
|
||||
'ნ'),
|
||||
'o' => array('ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ',
|
||||
'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő',
|
||||
'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό',
|
||||
'ö', 'о', 'و', 'θ'),
|
||||
'p' => array('п', 'π'),
|
||||
'r' => array('ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر'),
|
||||
's' => array('ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص'),
|
||||
't' => array('ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط'),
|
||||
'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ'),
|
||||
'p' => array('п', 'π', 'ပ', 'პ', 'پ'),
|
||||
'q' => array('ყ'),
|
||||
'r' => array('ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ'),
|
||||
's' => array('ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ',
|
||||
'ſ', 'ს'),
|
||||
't' => array('ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ',
|
||||
'თ', 'ტ'),
|
||||
'u' => array('ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ',
|
||||
'ự', 'ü', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у'),
|
||||
'v' => array('в'),
|
||||
'w' => array('ŵ', 'ω', 'ώ'),
|
||||
'x' => array('χ'),
|
||||
'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ',
|
||||
'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ'),
|
||||
'v' => array('в', 'ვ', 'ϐ'),
|
||||
'w' => array('ŵ', 'ω', 'ώ', 'ဝ', 'ွ'),
|
||||
'x' => array('χ', 'ξ'),
|
||||
'y' => array('ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ',
|
||||
'ϋ', 'ύ', 'ΰ', 'ي'),
|
||||
'z' => array('ź', 'ž', 'ż', 'з', 'ζ', 'ز'),
|
||||
'aa' => array('ع'),
|
||||
'ae' => array('æ'),
|
||||
'ch' => array('ч'),
|
||||
'ϋ', 'ύ', 'ΰ', 'ي', 'ယ'),
|
||||
'z' => array('ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ'),
|
||||
'aa' => array('ع', 'आ', 'آ'),
|
||||
'ae' => array('ä', 'æ', 'ǽ'),
|
||||
'ai' => array('ऐ'),
|
||||
'at' => array('@'),
|
||||
'ch' => array('ч', 'ჩ', 'ჭ', 'چ'),
|
||||
'dj' => array('ђ', 'đ'),
|
||||
'dz' => array('џ'),
|
||||
'gh' => array('غ'),
|
||||
'kh' => array('х', 'خ'),
|
||||
'dz' => array('џ', 'ძ'),
|
||||
'ei' => array('ऍ'),
|
||||
'gh' => array('غ', 'ღ'),
|
||||
'ii' => array('ई'),
|
||||
'ij' => array('ij'),
|
||||
'kh' => array('х', 'خ', 'ხ'),
|
||||
'lj' => array('љ'),
|
||||
'nj' => array('њ'),
|
||||
'oe' => array('œ'),
|
||||
'oe' => array('ö', 'œ', 'ؤ'),
|
||||
'oi' => array('ऑ'),
|
||||
'oii' => array('ऒ'),
|
||||
'ps' => array('ψ'),
|
||||
'sh' => array('ш'),
|
||||
'sh' => array('ш', 'შ', 'ش'),
|
||||
'shch' => array('щ'),
|
||||
'ss' => array('ß'),
|
||||
'th' => array('þ', 'ث', 'ذ', 'ظ'),
|
||||
'ts' => array('ц'),
|
||||
'sx' => array('ŝ'),
|
||||
'th' => array('þ', 'ϑ', 'ث', 'ذ', 'ظ'),
|
||||
'ts' => array('ц', 'ც', 'წ'),
|
||||
'ue' => array('ü'),
|
||||
'uu' => array('ऊ'),
|
||||
'ya' => array('я'),
|
||||
'yu' => array('ю'),
|
||||
'zh' => array('ж'),
|
||||
'zh' => array('ж', 'ჟ', 'ژ'),
|
||||
'(c)' => array('©'),
|
||||
'A' => array('Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ',
|
||||
'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Ä', 'Å', 'Ā',
|
||||
'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ',
|
||||
'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ',
|
||||
'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А'),
|
||||
'B' => array('Б', 'Β'),
|
||||
'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Å', 'Ā', 'Ą',
|
||||
'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ',
|
||||
'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ',
|
||||
'Ὰ', 'Ά', 'ᾼ', 'А', 'Ǻ', 'Ǎ'),
|
||||
'B' => array('Б', 'Β', 'ब'),
|
||||
'C' => array('Ç','Ć', 'Č', 'Ĉ', 'Ċ'),
|
||||
'D' => array('Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'),
|
||||
'E' => array('É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ',
|
||||
@@ -1651,43 +1701,50 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
'Є', 'Ə'),
|
||||
'F' => array('Ф', 'Φ'),
|
||||
'G' => array('Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ'),
|
||||
'H' => array('Η', 'Ή'),
|
||||
'H' => array('Η', 'Ή', 'Ħ'),
|
||||
'I' => array('Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į',
|
||||
'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ',
|
||||
'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї'),
|
||||
'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ'),
|
||||
'K' => array('К', 'Κ'),
|
||||
'L' => array('Ĺ', 'Ł', 'Л', 'Λ', 'Ļ'),
|
||||
'L' => array('Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', 'ल'),
|
||||
'M' => array('М', 'Μ'),
|
||||
'N' => array('Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν'),
|
||||
'O' => array('Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ',
|
||||
'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ö', 'Ø', 'Ō',
|
||||
'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ',
|
||||
'Ὸ', 'Ό', 'О', 'Θ', 'Ө'),
|
||||
'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ø', 'Ō', 'Ő',
|
||||
'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ',
|
||||
'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ'),
|
||||
'P' => array('П', 'Π'),
|
||||
'R' => array('Ř', 'Ŕ', 'Р', 'Ρ'),
|
||||
'R' => array('Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ'),
|
||||
'S' => array('Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ'),
|
||||
'T' => array('Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ'),
|
||||
'U' => array('Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ',
|
||||
'Ự', 'Û', 'Ü', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У'),
|
||||
'Ự', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У', 'Ǔ', 'Ǖ',
|
||||
'Ǘ', 'Ǚ', 'Ǜ'),
|
||||
'V' => array('В'),
|
||||
'W' => array('Ω', 'Ώ'),
|
||||
'X' => array('Χ'),
|
||||
'W' => array('Ω', 'Ώ', 'Ŵ'),
|
||||
'X' => array('Χ', 'Ξ'),
|
||||
'Y' => array('Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ',
|
||||
'Ы', 'Й', 'Υ', 'Ϋ'),
|
||||
'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ'),
|
||||
'Z' => array('Ź', 'Ž', 'Ż', 'З', 'Ζ'),
|
||||
'AE' => array('Æ'),
|
||||
'AE' => array('Ä', 'Æ', 'Ǽ'),
|
||||
'CH' => array('Ч'),
|
||||
'DJ' => array('Ђ'),
|
||||
'DZ' => array('Џ'),
|
||||
'GX' => array('Ĝ'),
|
||||
'HX' => array('Ĥ'),
|
||||
'IJ' => array('IJ'),
|
||||
'JX' => array('Ĵ'),
|
||||
'KH' => array('Х'),
|
||||
'LJ' => array('Љ'),
|
||||
'NJ' => array('Њ'),
|
||||
'OE' => array('Ö', 'Œ'),
|
||||
'PS' => array('Ψ'),
|
||||
'SH' => array('Ш'),
|
||||
'SHCH' => array('Щ'),
|
||||
'SS' => array('ẞ'),
|
||||
'TH' => array('Þ'),
|
||||
'TS' => array('Ц'),
|
||||
'UE' => array('Ü'),
|
||||
'YA' => array('Я'),
|
||||
'YU' => array('Ю'),
|
||||
'ZH' => array('Ж'),
|
||||
|
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/Create.php';
|
||||
|
||||
use function Stringy\create as s;
|
||||
|
||||
class CreateTestCase extends PHPUnit_Framework_TestCase
|
||||
|
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/StaticStringy.php';
|
||||
|
||||
use Stringy\StaticStringy as S;
|
||||
|
||||
class StaticStringyTestCase extends PHPUnit_Framework_TestCase
|
||||
|
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/Stringy.php';
|
||||
|
||||
use Stringy\Stringy as S;
|
||||
|
||||
class StringyTestCase extends PHPUnit_Framework_TestCase
|
||||
@@ -2066,7 +2064,13 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
|
||||
public function isJsonProvider()
|
||||
{
|
||||
return array(
|
||||
array(true, ''),
|
||||
array(false, ''),
|
||||
array(false, ' '),
|
||||
array(true, 'null'),
|
||||
array(true, 'true'),
|
||||
array(true, 'false'),
|
||||
array(true, '[]'),
|
||||
array(true, '{}'),
|
||||
array(true, '123'),
|
||||
array(true, '{"foo": "bar"}'),
|
||||
array(false, '{"foo":"bar",}'),
|
||||
@@ -2164,6 +2168,31 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider isBase64Provider()
|
||||
*/
|
||||
public function testIsBase64($expected, $str)
|
||||
{
|
||||
$stringy = S::create($str);
|
||||
$result = $stringy->isBase64();
|
||||
$this->assertInternalType('boolean', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
public function isBase64Provider()
|
||||
{
|
||||
return array(
|
||||
array(false, ' '),
|
||||
array(true, ''),
|
||||
array(true, base64_encode('FooBar') ),
|
||||
array(true, base64_encode(' ') ),
|
||||
array(true, base64_encode('FÒÔBÀŘ') ),
|
||||
array(true, base64_encode('συγγραφέας') ),
|
||||
array(false, 'Foobar'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider isUpperCaseProvider()
|
||||
*/
|
||||
@@ -2343,6 +2372,7 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
|
||||
array('foo', 'bar', '[[:alpha:]]{3}', 'foo'),
|
||||
array('', '', '', '', 'msr', 'UTF-8'),
|
||||
array('bàř', 'fòô ', 'f[òô]+\s', 'bàř', 'msr', 'UTF-8'),
|
||||
array('fòô', 'fò', '(ò)', '\\1ô', 'msr', 'UTF-8'),
|
||||
array('fòô', 'bàř', '[[:alpha:]]{3}', 'fòô', 'msr', 'UTF-8')
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user