Skip to content

Commit 63d8190

Browse files
Merge pull request #160 from danielstjules/3.x-dev
3.x
2 parents edbda41 + a2624d4 commit 63d8190

File tree

7 files changed

+1342
-1265
lines changed

7 files changed

+1342
-1265
lines changed

.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ sudo: false
1010
matrix:
1111
fast_finish: true
1212
include:
13-
- php: 5.3
14-
env: polyfill='true'
15-
- php: 5.3
16-
env: polyfill='false'
1713
- php: 5.4
1814
env: polyfill='true'
1915
- php: 5.4

README.md

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
![Stringy](http://danielstjules.com/github/stringy-logo.png)
22

33
A PHP string manipulation library with multibyte support. Compatible with PHP
4-
5.3+, PHP 7, and HHVM. Refer to the [1.x branch](https://github.com/danielstjules/Stringy/tree/1.x)
5-
for older documentation.
4+
5.4+, PHP 7, and HHVM.
65

76
``` php
87
s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
98
```
109

10+
Refer to the [1.x branch](https://github.com/danielstjules/Stringy/tree/1.x) or
11+
[2.x branch](https://github.com/danielstjules/Stringy/tree/2.x) for older
12+
documentation.
13+
1114
[![Build Status](https://api.travis-ci.org/danielstjules/Stringy.svg?branch=master)](https://travis-ci.org/danielstjules/Stringy)
1215
[![Total Downloads](https://poser.pugx.org/danielstjules/stringy/downloads)](https://packagist.org/packages/danielstjules/stringy)
1316
[![License](https://poser.pugx.org/danielstjules/stringy/license)](https://packagist.org/packages/danielstjules/stringy)
@@ -42,7 +45,7 @@ s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
4245
</tr>
4346
<tr>
4447
<td>[endsWith](#endswithstring-substring--boolean-casesensitive--true-)</td>
45-
<td>[endsWithAny](#endsWithAnystring-substrings--boolean-casesensitive--true-)</td>
48+
<td>[endsWithAny](#endswithanystring-substrings--boolean-casesensitive--true-)</td>
4649
<td>[ensureLeft](#ensureleftstring-substring)</td>
4750
<td>[ensureRight](#ensurerightstring-substring)</td>
4851
</tr>
@@ -74,7 +77,7 @@ s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
7477
<td>[isLowerCase](#islowercase)</td>
7578
<td>[isSerialized](#isserialized)</td>
7679
<td>[isUpperCase](#isuppercase)</td>
77-
<td>[last](#last)</td>
80+
<td>[last](#lastint-n)</td>
7881
</tr>
7982
<tr>
8083
<td>[length](#length)</td>
@@ -97,7 +100,7 @@ s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
97100
<tr>
98101
<td>[removeLeft](#removeleftstring-substring)</td>
99102
<td>[removeRight](#removerightstring-substring)</td>
100-
<td>[repeat](#repeatmultiplier)</td>
103+
<td>[repeat](#repeatint-multiplier)</td>
101104
<td>[replace](#replacestring-search-string-replacement)</td>
102105
</tr>
103106
<tr>
@@ -107,10 +110,10 @@ s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
107110
<td>[slugify](#slugify-string-replacement----)</td>
108111
</tr>
109112
<tr>
110-
<td>[startsWith](#startswithstring-substring--boolean-casesensitive--true-)</td>
111-
<td>[startsWithAny](#startswithanystring-substrings--boolean-casesensitive--true-)</td>
112113
<td>[slice](#sliceint-start--int-end-)</td>
113114
<td>[split](#splitstring-pattern--int-limit-)</td>
115+
<td>[startsWith](#startswithstring-substring--boolean-casesensitive--true-)</td>
116+
<td>[startsWithAny](#startswithanystring-substrings--boolean-casesensitive--true-)</td>
114117
</tr>
115118
<tr>
116119
<td>[stripWhitespace](#stripwhitespace)</td>
@@ -121,7 +124,7 @@ s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
121124
<tr>
122125
<td>[tidy](#tidy)</td>
123126
<td>[titleize](#titleize-array-ignore)</td>
124-
<td>[toAscii](#toascii)</td>
127+
<td>[toAscii](#toascii-string-locale--en--bool-removeunsupported--true-)</td>
125128
<td>[toBoolean](#toboolean)</td>
126129
</tr>
127130
<tr>
@@ -433,7 +436,7 @@ default, the comparison is case-sensitive, but can be made insensitive by
433436
setting $caseSensitive to false.
434437

435438
```php
436-
s('fòôbàř')->endsWith('bàř', true); // true
439+
s('fòôbàř')->endsWith('bàř'); // true
437440
```
438441

439442
##### endsWithAny(string[] $substrings [, boolean $caseSensitive = true ])
@@ -443,7 +446,7 @@ By default, the comparison is case-sensitive, but can be made insensitive
443446
by setting $caseSensitive to false.
444447

445448
```php
446-
s('fòôbàř')->endsWith(['bàř', 'baz'], true); // true
449+
s('fòôbàř')->endsWithAny(['bàř', 'baz']); // true
447450
```
448451

449452
##### ensureLeft(string $substring)
@@ -818,26 +821,6 @@ is also converted to lowercase.
818821
s('Using strings like fòô bàř')->slugify(); // 'using-strings-like-foo-bar'
819822
```
820823

821-
##### startsWith(string $substring [, boolean $caseSensitive = true ])
822-
823-
Returns true if the string begins with $substring, false otherwise.
824-
By default, the comparison is case-sensitive, but can be made insensitive
825-
by setting $caseSensitive to false.
826-
827-
```php
828-
s('FÒÔbàřbaz')->startsWith('fòôbàř', false); // true
829-
```
830-
831-
##### startsWithAny(string[] $substrings [, boolean $caseSensitive = true ])
832-
833-
Returns true if the string begins with any of $substrings, false
834-
otherwise. By default the comparison is case-sensitive, but can be made
835-
insensitive by setting $caseSensitive to false.
836-
837-
```php
838-
s('FÒÔbàřbaz')->startsWith(['fòô', 'bàř'], false); // true
839-
```
840-
841824
##### slice(int $start [, int $end ])
842825

843826
Returns the substring beginning at $start, and up to, but not including
@@ -859,6 +842,26 @@ results.
859842
s('foo,bar,baz')->split(',', 2); // ['foo', 'bar']
860843
```
861844

845+
##### startsWith(string $substring [, boolean $caseSensitive = true ])
846+
847+
Returns true if the string begins with $substring, false otherwise.
848+
By default, the comparison is case-sensitive, but can be made insensitive
849+
by setting $caseSensitive to false.
850+
851+
```php
852+
s('FÒÔbàřbaz')->startsWith('fòôbàř', false); // true
853+
```
854+
855+
##### startsWithAny(string[] $substrings [, boolean $caseSensitive = true ])
856+
857+
Returns true if the string begins with any of $substrings, false
858+
otherwise. By default the comparison is case-sensitive, but can be made
859+
insensitive by setting $caseSensitive to false.
860+
861+
```php
862+
s('FÒÔbàřbaz')->startsWithAny(['fòô', 'bàř'], false); // true
863+
```
864+
862865
##### stripWhitespace()
863866

864867
Strip all whitespace characters. This includes tabs and newline
@@ -916,14 +919,19 @@ s('i like to watch television')->titleize($ignore);
916919
// 'I Like to Watch Television'
917920
```
918921

919-
##### toAscii()
922+
##### toAscii([, string $locale = 'en' [, bool $removeUnsupported = true ]])
920923

921924
Returns an ASCII version of the string. A set of non-ASCII characters are
922925
replaced with their closest ASCII counterparts, and the rest are removed
923-
unless instructed otherwise.
926+
by default. The language or locale of the source string can be supplied
927+
for language-specific transliteration in any of the following formats:
928+
en, en_GB, or en-GB. For example, passing "de" results in "äöü" mapping
929+
to "aeoeue" rather than "aou" as in other languages.
924930

925931
```php
926932
s('fòôbàř')->toAscii(); // 'foobar'
933+
s('äöü')->toAscii(); // 'aou'
934+
s('äöü')->toAscii('de'); // 'aeoeue'
927935
```
928936

929937
##### toBoolean()

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=5.3.0",
18+
"php": ">=5.4.0",
1919
"symfony/polyfill-mbstring": "~1.1"
2020
},
2121
"require-dev": {

src/StaticStringy.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
* @method static string chars(string $str, string $encoding = null)
1717
* @method static string collapseWhitespace(string $str, string $encoding = null)
1818
* @method static bool contains(string $str, string $needle, bool $caseSensitive = true, string $encoding = null)
19-
* @method static bool containsAll(string $str, string $needle, bool $caseSensitive = true, string $encoding = null)
20-
* @method static bool containsAny(string $str, string $needle, bool $caseSensitive = true, string $encoding = null)
19+
* @method static bool containsAll(string $str, string[] $needle, bool $caseSensitive = true, string $encoding = null)
20+
* @method static bool containsAny(string $str, string[] $needle, bool $caseSensitive = true, string $encoding = null)
2121
* @method static int count(string $str, string $encoding = null)
2222
* @method static int countSubstr(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
2323
* @method static string dasherize(string $str, string $encoding = null)
2424
* @method static string delimit(string $str, string $delimiter, string $encoding = null)
2525
* @method static bool endsWith(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
26+
* @method static bool endsWithAny(string $str, string[] $substrings, bool $caseSensitive = true, string $encoding = null)
2627
* @method static string ensureLeft(string $str, string $substring, string $encoding = null)
2728
* @method static string ensureRight(string $str, string $substring, string $encoding = null)
2829
* @method static string first(string $str, int $n, string $encoding = null)
@@ -45,7 +46,7 @@
4546
* @method static bool isUpperCase(string $str, string $encoding = null)
4647
* @method static string last(string $str, string $encoding = null)
4748
* @method static int length(string $str, string $encoding = null)
48-
* @method static Stringy[] lines(string $str, string $encoding = null)
49+
* @method static string[] lines(string $str, string $encoding = null)
4950
* @method static string longestCommonPrefix(string $str, string $otherStr, string $encoding = null)
5051
* @method static string longestCommonSuffix(string $str, string $otherStr, string $encoding = null)
5152
* @method static string longestCommonSubstring(string $str, string $otherStr, string $encoding = null)
@@ -64,15 +65,17 @@
6465
* @method static string safeTruncate(string $str, int $length, string $substring = '', string $encoding = null)
6566
* @method static string shuffle(string $str, string $encoding = null)
6667
* @method static string slugify(string $str, string $replacement = '-', string $encoding = null)
67-
* @method static bool startsWith(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
6868
* @method static string slice(string $str, int $start, int $end = null, string $encoding = null)
6969
* @method static string split(string $str, string $pattern, int $limit = null, string $encoding = null)
70+
* @method static bool startsWith(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
71+
* @method static bool startsWithAny(string $str, string[] $substrings, bool $caseSensitive = true, string $encoding = null)
72+
* @method static string stripWhitespace(string $str, string $encoding = null)
7073
* @method static string substr(string $str, int $start, int $length = null, string $encoding = null)
7174
* @method static string surround(string $str, string $substring, string $encoding = null)
7275
* @method static string swapCase(string $str, string $encoding = null)
7376
* @method static string tidy(string $str, string $encoding = null)
7477
* @method static string titleize(string $str, string $encoding = null)
75-
* @method static string toAscii(string $str, bool $removeUnsupported = true, string $encoding = null)
78+
* @method static string toAscii(string $str, string $language = 'en', bool $removeUnsupported = true, string $encoding = null)
7679
* @method static bool toBoolean(string $str, string $encoding = null)
7780
* @method static string toLowerCase(string $str, string $encoding = null)
7881
* @method static string toSpaces(string $str, int $tabLength = 4, string $encoding = null)
@@ -143,6 +146,16 @@ public static function __callStatic($name, $arguments)
143146

144147
$stringy = Stringy::create($str, $encoding);
145148

146-
return call_user_func_array(array($stringy, $name), $args);
149+
$result = call_user_func_array([$stringy, $name], $args);
150+
151+
$cast = function($val) {
152+
if (is_object($val) && $val instanceof Stringy) {
153+
return (string) $val;
154+
} else {
155+
return $val;
156+
}
157+
};
158+
159+
return is_array($result) ? array_map($cast, $result) : $cast($result);
147160
}
148161
}

0 commit comments

Comments
 (0)