1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-31 16:51:57 +02:00

47 Commits
1.8.0 ... 1.9.0

Author SHA1 Message Date
Daniel St. Jules
3cf18e9e42 1.9.0 2015-02-09 22:19:18 -08:00
Daniel St. Jules
04b12c9500 Document hasLowerCase and hasUpperCase 2015-02-09 22:10:46 -08:00
Daniel St. Jules
b2386b6c33 Sticking to the ruler where possible 2015-02-09 21:38:42 -08:00
Daniel St. Jules
1172a75d1e Improve coverage of charsArray() 2015-02-09 21:27:21 -08:00
Daniel St. Jules
4ebf9aee3d Merge pull request #79 from vlakoff/tweak
Just a little bit of tweaking
2015-02-03 02:21:24 -08:00
vlakoff
61b986a3e6 Code tweaking
Prettier, one less instanciation.
2015-02-03 11:13:58 +01:00
vlakoff
2bd4be60bb Uniformization in docblocks 2015-02-03 11:10:27 +01:00
Daniel St. Jules
0aa476d44c Merge pull request #68 from vlakoff/toAscii
[Proposal] Add $replaceUnsupported and $fallback parameters to toAscii()
2015-02-02 23:42:47 -08:00
Daniel St. Jules
f63646dcba Merge pull request #78 from vlakoff/readme
Clean up some commas in README
2015-02-02 23:41:43 -08:00
vlakoff
97e607dc5d Add $removeUnsupported parameter to toAscii() 2015-02-03 07:12:02 +01:00
vlakoff
a9a4ce461f Clean up some commas in README 2015-02-03 06:29:04 +01:00
Daniel St. Jules
9a0f0e16cb Merge pull request #77 from takobell/master
Add Stringy->hasUpperCase, Stringy->hasLowerCase along with StaticString counterparts & tests.
2015-02-01 22:09:48 -08:00
Brad Bell
e9cd229808 Add StaticStringy::hasUpperCase, StaticStringy::hasLowerCase, Stringy->hasUpperCase and Stringy->hasLowerCase along with tests. 2015-01-23 15:52:58 -08:00
Daniel St. Jules
4974407729 charsArray formatting 2015-01-18 20:14:57 -08:00
Daniel St. Jules
8a36b8d3f0 Merge pull request #74 from anhskohbo/master
Support Full Unicode For Vietnamese.
2015-01-18 20:11:40 -08:00
Daniel St. Jules
66c2a98e83 Merge pull request #75 from vlakoff/tweak
Minor improvements
2015-01-16 18:50:54 -08:00
vlakoff
36c3fd05d2 Use Stringy's trim() method in applyDelimiter()
This trim() method may be more powerful in the future.
2015-01-17 01:53:01 +01:00
vlakoff
f3bd5b6c62 Fix method name
applyDelimeter() --> applyDelimiter()

Thankfully, it is a protected method.
2015-01-17 01:52:55 +01:00
vlakoff
dd34bc6f85 Minor code adjustment 2015-01-17 01:52:46 +01:00
anhskohbo
f490aa2894 Support Full Unicode For Vietnamese.
Signed-off-by: anhskohbo <anhskohbo@gmail.com>
2015-01-14 03:43:59 +07:00
Daniel St. Jules
40974608d4 Merge pull request #70 from vlakoff/toAscii-2
Separate toAscii()'s charsArray to allow customization
2015-01-13 12:25:16 -08:00
vlakoff
8676bd9d9b Add cache in charsArray()
This is static but confined to this function block,
so this doesn't introduce any side effect.

The performance gain is really worth it.
2015-01-12 19:59:37 +01:00
Daniel St. Jules
f4327a2583 Merge pull request #73 from lucasmichot/missing-space
Style fix
2015-01-11 17:39:30 -08:00
Lucas Michot
571dc93d1e Add missing space 2015-01-12 02:38:52 +01:00
vlakoff
62f6fd7b3a Separate toAscii()'s charsArray to allow customization 2015-01-10 22:39:36 +01:00
Daniel St. Jules
8b834482df Merge pull request #72 from vlakoff/spaces
Add remaining Unicode spaces
2015-01-09 19:58:36 -08:00
vlakoff
08a72a72dd Add remaining Unicode spaces
* spaces U+2000 to U+200A (there already was thin space U+2009)
* medium mathematical space (U+205F)
2015-01-09 19:14:16 +01:00
Daniel St. Jules
6a7b0391b2 1.8.1 2015-01-08 07:21:43 -08:00
Daniel St. Jules
d6fa00bb1c Conditionally load Stringy\create 2015-01-07 09:09:07 -08:00
Daniel St. Jules
d1452263bd Merge pull request #59 from usernam3/master
Typecast comparison in startsWith/endsWith
2015-01-06 21:42:16 -08:00
Stanislav Dobrovolskiy
9da55d5d4f type cast in startsWith && endsWith, test cases for this behavior 2015-01-07 06:06:53 +02:00
Daniel St. Jules
b515598227 Merge pull request #67 from vlakoff/regex
Remove some useless (and erroneous) regex capturing groups
2015-01-06 16:42:30 -08:00
Daniel St. Jules
28b65615d7 Merge pull request #66 from vlakoff/nbsp
Support for various Unicode spaces in toAscii()
2015-01-06 16:38:55 -08:00
vlakoff
7b88b4f3da Support for various Unicode spaces in toAscii()
* no-break space (U+00A0)
* thin space (U+2009)
* narrow no-break space (U+202F)
* ideographic space (U+3000)
2015-01-07 01:28:49 +01:00
vlakoff
70e5b9c38b Remove some useless (and erroneous) regex capturing groups 2015-01-07 01:24:40 +01:00
vlakoff
e0d50f0b8f Unit tests for no-break space in collapseWhitespace() and isBlank() 2015-01-07 01:10:30 +01:00
Daniel St. Jules
c5365f256f Merge pull request #64 from vlakoff/tests
Add missing tests in StringyTest
2015-01-06 13:42:20 -08:00
Daniel St. Jules
401af084c7 Merge pull request #63 from vlakoff/docblock
Proper Stringy\create() description
2015-01-05 16:37:27 -08:00
vlakoff
773477cdd8 Add missing tests in StringyTest
For consistency with StaticStringyTest.
2015-01-06 00:39:31 +01:00
vlakoff
26444e4429 Proper Stringy\create() description 2015-01-06 00:10:39 +01:00
Daniel St. Jules
f3d32c79b0 Merge pull request #62 from vlakoff/static
Replace self::create() with static::create()
2015-01-05 14:06:06 -08:00
vlakoff
98c1013623 Replace self::create() with static::create()
In case someone wants to extend create().
2015-01-05 23:02:06 +01:00
Daniel St. Jules
91d8da4741 Cleanup toAscii array alignment 2015-01-05 13:55:08 -08:00
Daniel St. Jules
49cdd5b1e6 Merge pull request #61 from vlakoff/toAscii
Add « ä Ä Ö Ü » in toAscii()
2015-01-05 13:38:30 -08:00
vlakoff
2fe42b46a1 Add « ä Ä Ö Ü » in toAscii()
To complete diareses on vowels.
2015-01-05 22:20:22 +01:00
Daniel St. Jules
9baa545f23 Merge pull request #60 from vlakoff/optimize
Optimize chars() by not repeatedly call length()
2015-01-05 12:08:58 -05:00
vlakoff
640fc5b26b Optimize chars() by not repeatedly call length() 2015-01-05 13:49:48 +01:00
8 changed files with 453 additions and 159 deletions

View File

@@ -1,3 +1,22 @@
### 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

View File

@@ -26,6 +26,8 @@ PHP 5.3+ and HHVM. Inspired by underscore.string.js.
* [ensureRight](#ensureright)
* [first](#first)
* [getEncoding](#getencoding)
* [hasLowerCase](#haslowercase)
* [hasUpperCase](#hasuppercase)
* [humanize](#humanize)
* [insert](#insert)
* [isAlpha](#isalpha)
@@ -83,7 +85,7 @@ in your composer.json file:
```json
{
"require": {
"danielstjules/stringy": "~1.8"
"danielstjules/stringy": "~1.9"
}
}
```
@@ -314,7 +316,7 @@ S::countSubstr('Ο συγγραφέας είπε', 'α', 'UTF-8'); // 2
#### create
S::create(mixed $str, [, $encoding ])
S::create(mixed $str [, $encoding ])
Creates a Stringy object and assigns both str and encoding properties
the supplied values. $str is cast to a string prior to assignment, and if
@@ -405,6 +407,32 @@ Returns the encoding used by the Stringy object.
S::create('fòô bàř', 'UTF-8')->getEncoding(); // 'UTF-8'
```
#### hasLowerCase
$stringy->hasLowerCase()
S::hasLowerCase(string $str [, string $encoding ])
Returns true if the string contains a lower case char, false otherwise.
```php
S::create('fòô bàř', 'UTF-8')->hasLowerCase();
S::hasLowerCase('fòô bàř', 'UTF-8'); // true
```
#### hasUpperCase
$stringy->hasUpperCase()
S::hasUpperCase(string $str [, string $encoding ])
Returns true if the string contains an upper case char, false otherwise.
```php
S::create('fòô bàř', 'UTF-8')->hasUpperCase();
S::hasUpperCase('fòô bàř', 'UTF-8'); // false
```
#### humanize
$stringy->humanize()
@@ -734,7 +762,7 @@ S::replace('fòô bàř fòô bàř', 'fòô ', '', 'UTF-8'); // 'bàř bàř'
$stringy->reverse()
S::reverse(string $str, [, string $encoding ])
S::reverse(string $str [, string $encoding ])
Returns a reversed string. A multibyte version of strrev().
@@ -745,9 +773,9 @@ S::reverse('fòô bàř', 'UTF-8'); // 'řàb ôòf'
#### safeTruncate
$stringy->safeTruncate(int $length, [, string $substring = '' ])
$stringy->safeTruncate(int $length [, string $substring = '' ])
S::safeTruncate(string $str, int $length, [, string $substring = '' [, string $encoding ]])
S::safeTruncate(string $str, int $length [, string $substring = '' [, string $encoding ]])
Truncates the string to a given length, while ensuring that it does not
split words. If $substring is provided, and truncating occurs, the
@@ -881,10 +909,11 @@ S::titleize('i like to watch DVDs at home', $ignore, 'UTF-8');
$stringy->toAscii()
S::toAscii(string $str)
S::toAscii(string $str [, boolean $removeUnsupported = true])
Returns an ASCII version of the string. A set of non-ASCII characters are
replaced with their closest ASCII counterparts, and the rest are removed.
replaced with their closest ASCII counterparts, and the rest are removed
unless instructed otherwise.
```php
S::create('fòô bàř')->toAscii();
@@ -909,7 +938,7 @@ S::toLowerCase('FÒÔ BÀŘ', 'UTF-8'); // 'fòô bàř'
$stringy->toSpaces([ tabLength = 4 ])
S::toSpaces(string $str, [, int $tabLength = 4 ])
S::toSpaces(string $str [, int $tabLength = 4 ])
Converts each tab in the string to some number of spaces, as defined by
$tabLength. By default, each tab is converted to 4 consecutive spaces.
@@ -923,7 +952,7 @@ S::toSpaces(' String speech = "Hi"'); // ' String speech = "Hi"'
$stringy->toTabs([ tabLength = 4 ])
S::toTabs(string $str, [, int $tabLength = 4 ])
S::toTabs(string $str [, int $tabLength = 4 ])
Converts each occurrence of some consecutive number of spaces, as defined
by $tabLength, to a tab. By default, each 4 consecutive spaces are
@@ -976,9 +1005,9 @@ S::trim(' fòô bàř '); // 'fòô bàř'
#### truncate
$stringy->truncate(int $length, [, string $substring = '' ])
$stringy->truncate(int $length [, string $substring = '' ])
S::truncate(string $str, int $length, [, string $substring = '' [, string $encoding ]])
S::truncate(string $str, int $length [, string $substring = '' [, string $encoding ]])
Truncates the string to a given length. If $substring is provided, and
truncating occurs, the string is further truncated so that the substring

View File

@@ -2,16 +2,18 @@
namespace Stringy;
/**
* Invokes Stringy::create and returns the generated Stringy object 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);
if (!function_exists('Stringy\create')) {
/**
* Creates a Stringy object and returns it on success.
*
* @param mixed $str Value to modify, after being cast to string
* @param string $encoding The character encoding
* @return Stringy A Stringy object
* @throws \InvalidArgumentException if an array or object without a
* __toString method is passed as the first argument
*/
function create($str, $encoding = null)
{
return new Stringy($str, $encoding);
}
}

View File

@@ -166,14 +166,17 @@ class StaticStringy
/**
* Returns an ASCII version of the string. A set of non-ASCII characters are
* replaced with their closest ASCII counterparts, and the rest are removed.
* replaced with their closest ASCII counterparts, and the rest are removed
* unless instructed otherwise.
*
* @param string $str A string with non-ASCII characters
* @param string $str A string with non-ASCII characters
* @param bool $removeUnsupported Whether or not to remove the
* unsupported characters
* @return string A string containing only ASCII characters
*/
public static function toAscii($str)
public static function toAscii($str, $removeUnsupported = true)
{
return (string) Stringy::create($str)->toAscii();
return (string) Stringy::create($str)->toAscii($removeUnsupported);
}
/**
@@ -683,6 +686,32 @@ class StaticStringy
return (string) Stringy::create($str, $encoding)->removeRight($substring);
}
/**
* Returns true if the string contains a lower case char, false
* otherwise.
*
* @param string $str String to check
* @param string $encoding The character encoding
* @return bool Whether or not $str contains a lower case character.
*/
public static function hasLowerCase($str, $encoding = null)
{
return Stringy::create($str, $encoding)->hasLowerCase();
}
/**
* Returns true if the string contains an upper case char, false
* otherwise.
*
* @param string $str String to check
* @param string $encoding The character encoding
* @return bool Whether or not $str contains an upper case character.
*/
public static function hasUpperCase($str, $encoding = null)
{
return Stringy::create($str, $encoding)->hasUpperCase();
}
/**
* Returns true if the string contains only alphabetic chars, false
* otherwise.
@@ -815,7 +844,7 @@ class StaticStringy
public static function replace($str, $search, $replacement, $encoding = null)
{
return (string) Stringy::create($str, $encoding)
->replace($search,$replacement);
->replace($search, $replacement);
}
/**

View File

@@ -186,7 +186,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
public function chars()
{
$chars = array();
for ($i = 0; $i < $this->length(); $i++) {
for ($i = 0, $l = $this->length(); $i < $l; $i++) {
$chars[] = $this->at($i)->str;
}
@@ -206,7 +206,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$str = mb_strtoupper($first, $this->encoding) . $rest;
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -222,7 +222,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$str = mb_strtolower($first, $this->encoding) . $rest;
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -235,14 +235,14 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
public function camelize()
{
$encoding = $this->encoding;
$stringy = self::create($this->str, $this->encoding);
$stringy = $this->trim()->lowerCaseFirst();
$camelCase = preg_replace_callback(
'/[-_\s]+(.)?/u',
function ($match) use ($encoding) {
return $match[1] ? mb_strtoupper($match[1], $encoding) : '';
},
$stringy->trim()->lowerCaseFirst()->str
$stringy->str
);
$stringy->str = preg_replace_callback(
@@ -277,7 +277,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function dasherize()
{
return $this->applyDelimeter('-');
return $this->applyDelimiter('-');
}
/**
@@ -290,7 +290,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function underscored()
{
return $this->applyDelimeter('_');
return $this->applyDelimiter('_');
}
/**
@@ -299,19 +299,19 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
* @param string $delimiter Sequence used to separate parts of the string
* @return Stringy Object with a delimited $str
*/
protected function applyDelimeter($delimiter)
protected function applyDelimiter($delimiter)
{
// Save current regex encoding so we can reset it after
$regexEncoding = mb_regex_encoding();
mb_regex_encoding($this->encoding);
$str = mb_ereg_replace('\B([A-Z])', $delimiter .'\1', trim($this->str));
$str = mb_ereg_replace('\B([A-Z])', $delimiter .'\1', $this->trim());
$str = mb_ereg_replace('[-_\s]+', $delimiter, $str);
$str = mb_strtolower($str, $this->encoding);
mb_regex_encoding($regexEncoding);
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -321,7 +321,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function swapCase()
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
$encoding = $stringy->encoding;
$stringy->str = preg_replace_callback(
@@ -354,7 +354,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$buffer = preg_replace_callback(
'/([\S]+)/u',
function ($match) use (&$encoding, &$ignore) {
function ($match) use ($encoding, $ignore) {
if ($ignore && in_array($match[0], $ignore)) {
return $match[0];
} else {
@@ -378,7 +378,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{
$str = str_replace(array('_id', '_'), array('', ' '), $this->str);
return self::create($str, $this->encoding)->trim()->upperCaseFirst();
return static::create($str, $this->encoding)->trim()->upperCaseFirst();
}
/**
@@ -402,7 +402,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
'-',
), $this->str);
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -419,98 +419,161 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
/**
* Returns an ASCII version of the string. A set of non-ASCII characters are
* replaced with their closest ASCII counterparts, and the rest are removed.
* replaced with their closest ASCII counterparts, and the rest are removed
* unless instructed otherwise.
*
* @param bool $removeUnsupported Whether or not to remove the
* unsupported characters
* @return Stringy Object whose $str contains only ASCII characters
*/
public function toAscii()
public function toAscii($removeUnsupported = true)
{
$str = $this->str;
$charsArray = array(
'a' => array('à', 'á', 'â', 'ã', 'ā', 'ą', 'ă', 'å', 'α', 'ά', 'ἀ',
'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ',
'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ',
'ᾶ', 'ᾷ', 'а'),
'b' => array('б', 'β'),
foreach ($this->charsArray() as $key => $value) {
$str = str_replace($value, $key, $str);
}
if ($removeUnsupported) {
$str = preg_replace('/[^\x20-\x7E]/u', '', $str);
}
return static::create($str, $this->encoding);
}
/**
* Returns the replacements for the toAscii() method.
*
* @return array An array of replacements.
*/
protected function charsArray()
{
static $charsArray;
if (isset($charsArray)) return $charsArray;
return $charsArray = array(
'a' => array(
'à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ',
'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ä', 'ā', 'ą',
'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ',
'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ',
'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ'),
'b' => array('б', 'β', 'Ъ', 'Ь', 'ب'),
'c' => array('ç', 'ć', 'č', 'ĉ', 'ċ'),
'd' => array('ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д'),
'e' => array('è', 'é', 'ê', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ',
'ἐ', 'ἑ', '', '', '', '', '', 'έ', 'е', 'ё', 'э', 'є'),
'f' => array('ф'),
'g' => array('ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ'),
'h' => array('ĥ', 'ħ'),
'i' => array('ì', 'í', 'î', 'ï', 'ī', 'ĩ', 'ĭ', 'į', 'ı', 'ι', 'ί',
'ϊ', 'ΐ', 'ἰ', '', '', '', '', '', '', '', '',
'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', '', '', 'і', 'ї', 'и'),
'j' => array('ĵ'),
'k' => array('ķ', 'ĸ', 'к'),
'l' => array('ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л'),
'm' => array('м'),
'n' => array('ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', '),
'o' => array('ò', 'ó', 'ô', 'õ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ό', 'ὀ',
'ὁ', '', '', '', '', '', 'ό', 'ö', 'о'),
'p' => array('п'),
'r' => array('ŕ', 'ř', 'ŗ', 'р'),
's' => array('ś', 'š', 'ş', 'с'),
't' => array('ť', 'ţ', 'т'),
'u' => array('ü', 'ù', 'ú', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ũ', 'ų', 'µ', 'у'),
'd' => array('ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ',
'д', 'δ', 'د', 'ض'),
'e' => array('é', 'è', '', '', '', 'ê', 'ế', '', '', '',
'', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ',
'', 'ἒ', 'ἓ', 'ἔ', '', '', 'έ', 'е', 'ё', 'э',
'є', 'ə'),
'f' => array('ф', 'φ', 'ف'),
'g' => array('ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ج'),
'h' => array('ĥ', 'ħ', 'η', 'ή', 'ح', 'ه'),
'i' => array('í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į',
'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', '', '', '',
'', 'ἶ', 'ἷ', 'ὶ', 'ί', '', '', '', 'ΐ', '',
'', 'і', 'ї', 'и'),
'j' => array('ĵ', 'ј', 'Ј'),
'k' => array('ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك'),
'l' => array('ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل'),
'm' => array('м', 'μ', '),
'n' => array('ñ', 'ń', 'ň', 'ņ', 'ʼn', ', 'ν', 'н', 'ن'),
'o' => array('ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', '', '', 'ổ', 'ỗ',
'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő',
'ŏ', 'ο', '', '', '', '', '', '', '', 'ό',
'ö', 'о', 'و', 'θ'),
'p' => array('п', 'π'),
'r' => array('ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر'),
's' => array('ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص'),
't' => array('ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط'),
'u' => array('ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ',
'ự', 'ü', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у'),
'v' => array('в'),
'w' => array('ŵ'),
'y' => array('ÿ', 'ý', 'ŷ', 'й', '),
'z' => array('ź', 'ž', 'ż', 'з'),
'w' => array('ŵ', 'ω', 'ώ'),
'x' => array('χ'),
'y' => array('ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ',
'ϋ', 'ύ', 'ΰ', 'ي'),
'z' => array('ź', 'ž', 'ż', 'з', 'ζ', 'ز'),
'aa' => array('ع'),
'ae' => array('æ'),
'ch' => array('ч'),
'kh' => array('х'),
'dj' => array('ђ', '),
'dz' => array('џ'),
'gh' => array('غ'),
'kh' => array('х', 'خ'),
'lj' => array('љ'),
'nj' => array('њ'),
'oe' => array('œ'),
'ps' => array('ψ'),
'sh' => array('ш'),
'shch' => array('щ'),
'ss' => array('ß'),
'th' => array('þ', 'ث', 'ذ', 'ظ'),
'ts' => array('ц'),
'ya' => array('я'),
'yu' => array('ю'),
'zh' => array('ж'),
'A' => array('Á', 'Â', 'Ã', 'Å', 'Ā', 'Ą', 'Ă', 'Α', 'Ά', 'Ἀ', 'Ἁ',
'Ἂ', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', 'Ά', '', 'А'),
'B' => array('Б'),
'(c)' => array('©'),
'A' => array('Á', 'À', '', 'Ã', '', 'Ă', '', '', '', '',
'', 'Â', '', '', '', '', '', 'Ä', 'Å', 'Ā',
'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', '', 'Ἆ',
'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ',
'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А'),
'B' => array('Б', 'Β'),
'C' => array('Ć', 'Č', 'Ĉ', 'Ċ'),
'D' => array('Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д'),
'E' => array('É', 'Ê', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ',
'', '', 'Ἓ', 'Ἔ', '', 'Έ', '', 'Е', 'Ё', 'Э', 'Є'),
'F' => array('Ф'),
'G' => array('Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ'),
'I' => array('Í', 'Î', 'Ï', 'Ī', 'Ĩ', 'Ĭ', 'Į', 'İ', 'Ι', ', 'Ϊ',
'', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', '', 'Ἷ', '', '', '', 'Ί',
'И', 'І', 'Ї'),
'K' => array('К'),
'L' => array('Ĺ', 'Ł', 'Л'),
'M' => array('М'),
'N' => array('Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н'),
'O' => array('Ó', 'Ô', ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ',
'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О'),
'P' => array('П'),
'R' => array('Ř', 'Ŕ', 'Р'),
'S' => array('Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С'),
'T' => array('Ť', 'Ţ', 'Ŧ', 'Ț', 'Т'),
'U' => array('Ù', 'Ú', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ũ', 'Ų', 'У'),
'D' => array('Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'),
'E' => array('É', 'È', '', '', '', 'Ê', '', '', '', '',
'', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', '',
'', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э',
'Є', 'Ə'),
'F' => array('Ф', 'Φ'),
'G' => array('Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ'),
'H' => array('Η', 'Ή'),
'I' => array('Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į',
'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', '', '', '',
'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї'),
'K' => array('К', 'Κ'),
'L' => array('Ĺ', 'Ł', 'Л', 'Λ', 'Ļ'),
'M' => array('М', 'Μ'),
'N' => array('Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν'),
'O' => array('Ó', 'Ò', '', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ',
'', 'Ơ', 'Ớ', 'Ờ', '', '', '', 'Ö', 'Ø', 'Ō',
'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', '', '', '', '', '',
'', 'Ό', 'О', 'Θ', 'Ө'),
'P' => array('П', 'Π'),
'R' => array('Ř', 'Ŕ', 'Р', 'Ρ'),
'S' => array('Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ'),
'T' => array('Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ'),
'U' => array('Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ',
'Ự', 'Û', 'Ü', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У'),
'V' => array('В'),
'Y' => array('Ý', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', '),
'Z' => array('Ź', 'Ž', 'Ż', 'З'),
'W' => array('Ω', '),
'X' => array('Χ'),
'Y' => array('Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ',
'Ы', 'Й', 'Υ', 'Ϋ'),
'Z' => array('Ź', 'Ž', 'Ż', 'З', 'Ζ'),
'AE' => array('Æ'),
'CH' => array('Ч'),
'DJ' => array('Ђ'),
'DZ' => array('Џ'),
'KH' => array('Х'),
'LJ' => array('Љ'),
'NJ' => array('Њ'),
'PS' => array('Ψ'),
'SH' => array('Ш'),
'SHCH' => array('Щ'),
'SS' => array('ẞ'),
'TH' => array('Þ'),
'TS' => array('Ц'),
'YA' => array('Я'),
'YU' => array('Ю'),
'ZH' => array('Ж')
'ZH' => array('Ж'),
' ' => array("\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81",
"\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84",
"\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87",
"\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A",
"\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"),
);
foreach ($charsArray as $key => $value) {
$str = str_replace($value, $key, $str);
}
$str = preg_replace('/[^\x20-\x7E]/u', '', $str);
return self::create($str, $this->encoding);
}
/**
@@ -597,7 +660,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
private function applyPadding($left = 0, $right = 0, $padStr = ' ')
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
$length = mb_strlen($padStr, $stringy->encoding);
$strLength = $stringy->length();
@@ -609,8 +672,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$leftPadding = mb_substr(str_repeat($padStr, ceil($left / $length)), 0,
$left, $stringy->encoding);
$rightPadding = mb_substr(str_repeat($padStr, ceil($right / $length)), 0,
$right, $stringy->encoding);
$rightPadding = mb_substr(str_repeat($padStr, ceil($right / $length)),
0, $right, $stringy->encoding);
$stringy->str = $leftPadding . $stringy->str . $rightPadding;
@@ -637,7 +700,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$startOfStr = mb_strtolower($startOfStr, $this->encoding);
}
return $substring === $startOfStr;
return (string) $substring === $startOfStr;
}
/**
@@ -662,7 +725,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$endOfStr = mb_strtolower($endOfStr, $this->encoding);
}
return $substring === $endOfStr;
return (string) $substring === $endOfStr;
}
/**
@@ -677,7 +740,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$spaces = str_repeat(' ', $tabLength);
$str = str_replace("\t", $spaces, $this->str);
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -693,7 +756,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$spaces = str_repeat(' ', $tabLength);
$str = str_replace($spaces, "\t", $this->str);
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -705,7 +768,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{
$str = mb_convert_case($this->str, MB_CASE_TITLE, $this->encoding);
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -718,7 +781,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{
$str = mb_strtolower($this->str, $this->encoding);
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -731,7 +794,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{
$str = mb_strtoupper($this->str, $this->encoding);
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -746,13 +809,13 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function slugify($replacement = '-')
{
$stringy = self::create($this->str, $this->encoding);
$stringy = $this->toAscii();
$quotedReplacement = preg_quote($replacement);
$pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u";
$stringy->str = preg_replace($pattern, '', $stringy->toAscii());
$stringy->str = preg_replace($pattern, '', $stringy);
return $stringy->toLowerCase()->applyDelimeter($replacement)
return $stringy->toLowerCase()->applyDelimiter($replacement)
->removeLeft($replacement)->removeRight($replacement);
}
@@ -828,13 +891,14 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
* Surrounds $str with the given substring.
*
* @param string $substring The substring to add to both sides
* @return Stringy Object whose $str had the substring prepended and appended
* @return Stringy Object whose $str had the substring both prepended and
* appended
*/
public function surround($substring)
{
$str = implode('', array($substring, $this->str, $substring));
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -846,7 +910,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function insert($substring, $index)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($index > $stringy->length()) {
return $stringy;
}
@@ -871,7 +935,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function truncate($length, $substring = '')
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($length >= $stringy->length()) {
return $stringy;
}
@@ -898,7 +962,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function safeTruncate($length, $substring = '')
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($length >= $stringy->length()) {
return $stringy;
}
@@ -937,7 +1001,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$reversed .= mb_substr($this->str, $i, 1, $this->encoding);
}
return self::create($reversed, $this->encoding);
return static::create($reversed, $this->encoding);
}
/**
@@ -956,7 +1020,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$shuffledStr .= mb_substr($this->str, $i, 1, $this->encoding);
}
return self::create($shuffledStr, $this->encoding);
return static::create($shuffledStr, $this->encoding);
}
/**
@@ -966,7 +1030,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function trim()
{
return self::create(trim($this->str), $this->encoding);
return static::create(trim($this->str), $this->encoding);
}
/**
@@ -991,7 +1055,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
}
}
return self::create($longestCommonPrefix, $encoding);
return static::create($longestCommonPrefix, $encoding);
}
/**
@@ -1016,7 +1080,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
}
}
return self::create($longestCommonSuffix, $encoding);
return static::create($longestCommonSuffix, $encoding);
}
/**
@@ -1031,7 +1095,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
// Uses dynamic programming to solve
// http://en.wikipedia.org/wiki/Longest_common_substring_problem
$encoding = $this->encoding;
$stringy = self::create($this->str, $encoding);
$stringy = static::create($this->str, $encoding);
$strLength = $stringy->length();
$otherLength = mb_strlen($otherStr, $encoding);
@@ -1043,7 +1107,8 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$len = 0;
$end = 0;
$table = array_fill(0, $strLength + 1, array_fill(0, $otherLength + 1, 0));
$table = array_fill(0, $strLength + 1,
array_fill(0, $otherLength + 1, 0));
for ($i = 1; $i <= $strLength; $i++) {
for ($j = 1; $j <= $otherLength; $j++) {
@@ -1091,7 +1156,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$length = $length === null ? $this->length() : $length;
$str = mb_substr($this->str, $start, $length, $this->encoding);
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
/**
@@ -1113,7 +1178,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function first($n)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($n < 0) {
$stringy->str = '';
@@ -1132,7 +1197,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function last($n)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($n <= 0) {
$stringy->str = '';
@@ -1152,7 +1217,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function ensureLeft($substring)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if (!$stringy->startsWith($substring)) {
$stringy->str = $substring . $stringy->str;
@@ -1170,7 +1235,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function ensureRight($substring)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if (!$stringy->endsWith($substring)) {
$stringy->str .= $substring;
@@ -1187,7 +1252,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function removeLeft($substring)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($stringy->startsWith($substring)) {
$substringLength = mb_strlen($substring, $stringy->encoding);
@@ -1205,7 +1270,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function removeRight($substring)
{
$stringy = self::create($this->str, $this->encoding);
$stringy = static::create($this->str, $this->encoding);
if ($stringy->endsWith($substring)) {
$substringLength = mb_strlen($substring, $stringy->encoding);
@@ -1232,6 +1297,28 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
return $match;
}
/**
* Returns true if the string contains a lower case char, false
* otherwise.
*
* @return bool Whether or not the string contains a lower case character.
*/
public function hasLowerCase()
{
return $this->matchesPattern('.*[[:lower:]]');
}
/**
* Returns true if the string contains an upper case char, false
* otherwise.
*
* @return bool Whether or not the string contains an upper case character.
*/
public function hasUpperCase()
{
return $this->matchesPattern('.*[[:upper:]]');
}
/**
* Returns true if the string contains only alphabetic chars, false
* otherwise.
@@ -1240,7 +1327,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isAlpha()
{
return $this->matchesPattern('^([[:alpha:]])*$');
return $this->matchesPattern('^[[:alpha:]]*$');
}
/**
@@ -1251,7 +1338,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isAlphanumeric()
{
return $this->matchesPattern('^([[:alnum:]])*$');
return $this->matchesPattern('^[[:alnum:]]*$');
}
/**
@@ -1262,7 +1349,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isHexadecimal()
{
return $this->matchesPattern('^([[:xdigit:]])*$');
return $this->matchesPattern('^[[:xdigit:]]*$');
}
/**
@@ -1273,7 +1360,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isBlank()
{
return $this->matchesPattern('^([[:space:]])*$');
return $this->matchesPattern('^[[:space:]]*$');
}
/**
@@ -1296,7 +1383,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isLowerCase()
{
return $this->matchesPattern('^([[:lower:]])*$');
return $this->matchesPattern('^[[:lower:]]*$');
}
/**
@@ -1307,7 +1394,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/
public function isUpperCase()
{
return $this->matchesPattern('^([[:upper:]])*$');
return $this->matchesPattern('^[[:upper:]]*$');
}
/**
@@ -1372,6 +1459,6 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
$str = mb_ereg_replace($pattern, $replacement, $this->str, $options);
mb_regex_encoding($regexEncoding);
return self::create($str, $this->encoding);
return static::create($str, $this->encoding);
}
}

View File

@@ -1,5 +1,7 @@
<?php
use Stringy\Stringy;
abstract class CommonTest extends PHPUnit_Framework_TestCase
{
/**
@@ -172,8 +174,12 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
array('test string', 'test string'),
array('Ο συγγραφέας', ' Ο συγγραφέας '),
array('123', ' 123 '),
array('1 2 3', '  1  2  3  ', 'UTF-8'), // ideographic spaces
array('', ' ', 'UTF-8'), // thin space and space
array('', ' ', 'UTF-8'), // no-break space (U+00A0)
array('', ' ', 'UTF-8'), // spaces U+2000 to U+200A
array('', '', 'UTF-8'), // narrow no-break space (U+202F)
array('', '', 'UTF-8'), // medium mathematical space (U+205F)
array('', ' ', 'UTF-8'), // ideographic space (U+3000)
array('1 2 3', '  123  ', 'UTF-8'),
array('', ' '),
array('', ''),
);
@@ -184,11 +190,21 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
return array(
array('foo bar', 'fòô bàř'),
array(' TEST ', ' ŤÉŚŢ '),
array(' = z = 3', 'φ = ź = 3'),
array('f = z = 3', 'φ = ź = 3'),
array('perevirka', 'перевірка'),
array('lysaya gora', 'лысая гора'),
array('shchuka', 'щука'),
array('', '漢字')
array('', '漢字'),
array('xin chao the gioi', 'xin chào thế giới'),
array('XIN CHAO THE GIOI', 'XIN CHÀO THẾ GIỚI'),
array('dam phat chet luon', 'đấm phát chết luôn'),
array(' ', ' '), // no-break space (U+00A0)
array(' ', ' '), // spaces U+2000 to U+200A
array(' ', ''), // narrow no-break space (U+202F)
array(' ', ''), // medium mathematical space (U+205F)
array(' ', ' '), // ideographic space (U+3000)
array('', '𐍉'), // some uncommon, unsupported character (U+10349)
array('𐍉', '𐍉', false),
);
}
@@ -359,7 +375,6 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
array('foo-dbar', " Foo d'Bar "),
array('a-string-with-dashes', 'A string-with-dashes'),
array('using-strings-like-foo-bar', 'Using strings like fòô bàř'),
array('unrecognized-chars-like', 'unrecognized chars like συγγρ'),
array('numbers-1234', 'numbers 1234'),
array('perevirka-ryadka', 'перевірка рядка'),
array('bukvar-s-bukvoy-y', 'букварь с буквой ы'),
@@ -752,6 +767,8 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
array('bar', 'foo bar', 'foo '),
array('foo bar', 'foo bar', 'oo'),
array('foo bar', 'foo bar', 'oo bar'),
array('oo bar', 'foo bar', Stringy::create('foo bar')->first(1), 'UTF-8'),
array('oo bar', 'foo bar', Stringy::create('foo bar')->at(0), 'UTF-8'),
array('fòô bàř', 'fòô bàř', '', 'UTF-8'),
array('òô bàř', 'fòô bàř', 'f', 'UTF-8'),
array('bàř', 'fòô bàř', 'fòô ', 'UTF-8'),
@@ -768,6 +785,8 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
array('foo', 'foo bar', ' bar'),
array('foo bar', 'foo bar', 'ba'),
array('foo bar', 'foo bar', 'foo ba'),
array('foo ba', 'foo bar', Stringy::create('foo bar')->last(1), 'UTF-8'),
array('foo ba', 'foo bar', Stringy::create('foo bar')->at(6), 'UTF-8'),
array('fòô bàř', 'fòô bàř', '', 'UTF-8'),
array('fòô bà', 'fòô bàř', 'ř', 'UTF-8'),
array('fòô', 'fòô bàř', ' bàř', 'UTF-8'),
@@ -822,8 +841,11 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
array(false, "\n\t ' \v\f"),
array(false, "\n\t 2 \v\f"),
array(true, '', 'UTF-8'),
array(true, ' ', 'UTF-8'), // thin space
array(true, '  ', 'UTF-8'), // ideographic spaces
array(true, ' ', 'UTF-8'), // no-break space (U+00A0)
array(true, ' ', 'UTF-8'), // spaces U+2000 to U+200A
array(true, '', 'UTF-8'), // narrow no-break space (U+202F)
array(true, '', 'UTF-8'), // medium mathematical space (U+205F)
array(true, ' ', 'UTF-8'), // ideographic space (U+3000)
array(false, ' z', 'UTF-8'),
array(false, ' 1', 'UTF-8'),
);
@@ -863,6 +885,24 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
);
}
public function hasLowerCaseProvider()
{
return array(
array(false, ''),
array(true, 'foobar'),
array(false, 'FOO BAR'),
array(true, 'fOO BAR'),
array(true, 'foO BAR'),
array(true, 'FOO BAr'),
array(true, 'Foobar'),
array(false, 'FÒÔBÀŘ', 'UTF-8'),
array(true, 'fòôbàř', 'UTF-8'),
array(true, 'fòôbàř2', 'UTF-8'),
array(true, 'Fòô bàř', 'UTF-8'),
array(true, 'fòôbÀŘ', 'UTF-8'),
);
}
public function isSerializedProvider()
{
return array(
@@ -890,6 +930,24 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
);
}
public function hasUpperCaseProvider()
{
return array(
array(false, ''),
array(true, 'FOOBAR'),
array(false, 'foo bar'),
array(true, 'Foo bar'),
array(true, 'FOo bar'),
array(true, 'foo baR'),
array(true, 'fOOBAR'),
array(false, 'fòôbàř', 'UTF-8'),
array(true, 'FÒÔBÀŘ', 'UTF-8'),
array(true, 'FÒÔBÀŘ2', 'UTF-8'),
array(true, 'fÒÔ BÀŘ', 'UTF-8'),
array(true, 'FÒÔBàř', 'UTF-8'),
);
}
public function isHexadecimalProvider()
{
return array(

View File

@@ -133,9 +133,9 @@ class StaticStringyTestCase extends CommonTest
/**
* @dataProvider toAsciiProvider()
*/
public function testToAscii($expected, $str)
public function testToAscii($expected, $str, $removeUnsupported = true)
{
$result = S::toAscii($str);
$result = S::toAscii($str, $removeUnsupported);
$this->assertInternalType('string', $result);
$this->assertEquals($expected, $result);
}
@@ -565,6 +565,16 @@ class StaticStringyTestCase extends CommonTest
$this->assertEquals($expected, $result);
}
/**
* @dataProvider hasLowerCaseProvider()
*/
public function testHasLowerCase($expected, $str, $encoding = null)
{
$result = S::hasLowerCase($str, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider isSerializedProvider()
*/
@@ -585,6 +595,16 @@ class StaticStringyTestCase extends CommonTest
$this->assertEquals($expected, $result);
}
/**
* @dataProvider hasUpperCaseProvider()
*/
public function testHasUpperCase($expected, $str, $encoding = null)
{
$result = S::hasUpperCase($str, $encoding);
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider isHexadecimalProvider()
*/

View File

@@ -300,10 +300,10 @@ class StringyTestCase extends CommonTest
/**
* @dataProvider toAsciiProvider()
*/
public function testToAscii($expected, $str)
public function testToAscii($expected, $str, $removeUnsupported = true)
{
$stringy = S::create($str);
$result = $stringy->toAscii();
$result = $stringy->toAscii($removeUnsupported);
$this->assertStringy($result);
$this->assertEquals($expected, $result);
$this->assertEquals($str, $stringy);
@@ -545,6 +545,19 @@ class StringyTestCase extends CommonTest
$this->assertEquals($str, $stringy);
}
/**
* @dataProvider safeTruncateProvider()
*/
public function testSafeTruncate($expected, $str, $length, $substring = '',
$encoding = null)
{
$stringy = S::create($str, $encoding);
$result = $stringy->safeTruncate($length, $substring);
$this->assertStringy($result);
$this->assertEquals($expected, $result);
$this->assertEquals($str, $stringy);
}
/**
* @dataProvider reverseProvider()
*/
@@ -605,6 +618,19 @@ class StringyTestCase extends CommonTest
$this->assertEquals($str, $stringy);
}
/**
* @dataProvider longestCommonSuffixProvider()
*/
public function testLongestCommonSuffix($expected, $str, $otherStr,
$encoding = null)
{
$stringy = S::create($str, $encoding);
$result = $stringy->longestCommonSuffix($otherStr);
$this->assertStringy($result);
$this->assertEquals($expected, $result);
$this->assertEquals($str, $stringy);
}
/**
* @dataProvider longestCommonSubstringProvider()
*/
@@ -787,6 +813,18 @@ class StringyTestCase extends CommonTest
$this->assertEquals($str, $stringy);
}
/**
* @dataProvider hasLowerCaseProvider()
*/
public function testHasLowerCase($expected, $str, $encoding = null)
{
$stringy = S::create($str, $encoding);
$result = $stringy->hasLowerCase();
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
$this->assertEquals($str, $stringy);
}
/**
* @dataProvider isSerializedProvider()
*/
@@ -811,6 +849,18 @@ class StringyTestCase extends CommonTest
$this->assertEquals($str, $stringy);
}
/**
* @dataProvider hasUpperCaseProvider()
*/
public function testHasUpperCase($expected, $str, $encoding = null)
{
$stringy = S::create($str, $encoding);
$result = $stringy->hasUpperCase();
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
$this->assertEquals($str, $stringy);
}
/**
* @dataProvider isHexadecimalProvider()
*/