1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-09-03 18:12:41 +02:00

7 Commits
3.0.0 ... 3.0.1

Author SHA1 Message Date
Daniel St. Jules
2288363663 3.0.1 2017-04-12 11:20:39 -04:00
Daniel St. Jules
f22117862b Use normal replacement for @ in slugify 2017-04-12 11:19:35 -04:00
Daniel St. Jules
eb13cc35d6 Don't replace @ in toAscii 2017-04-12 11:09:07 -04:00
Daniel St. Jules
9b6bddcb20 Fix list items 2017-04-09 21:57:32 -04:00
Daniel St. Jules
67f16c9423 Use HTML anchors in readme table 2017-04-09 21:56:46 -04:00
Daniel St. Jules
3708b6ba90 Update alignment in phpdocs 2017-03-13 23:10:57 -04:00
Daniel St. Jules
5c50a58bb8 Fix readme typo 2017-03-08 19:56:22 -05:00
4 changed files with 152 additions and 145 deletions

View File

@@ -1,3 +1,7 @@
### 3.0.1 (2017-04-12)
* Don't replace @ in toAscii
* Use normal replacement for @ in slugify, e.g. user@home => user-home
### 3.0.0 (2017-03-08)
* Breaking change: added $language parameter to toAscii, before

165
README.md
View File

@@ -26,126 +26,127 @@ documentation.
* [Instance methods](#instance-methods)
<table>
<tr>
<td>[append](#appendstring-string)</td>
<td>[at](#atint-index)</td>
<td>[between](#betweenstring-start-string-end--int-offset)</td>
<td>[camelize](#camelize)</td>
<td><a href="#appendstring-string">append</a></td>
<td><a href="#atint-index">at</a></td>
<td><a href="#betweenstring-start-string-end--int-offset">between</a></td>
<td><a href="#camelize">camelize</a></td>
</tr>
<tr>
<td>[chars](#chars)</td>
<td>[collapseWhitespace](#collapsewhitespace)</td>
<td>[contains](#containsstring-needle--boolean-casesensitive--true-)</td>
<td>[containsAll](#containsallarray-needles--boolean-casesensitive--true-)</td>
<td><a href="#chars">chars</a></td>
<td><a href="#collapsewhitespace">collapseWhitespace</a></td>
<td><a href="#containsstring-needle--boolean-casesensitive--true-">contains</a></td>
<td><a href="#containsallarray-needles--boolean-casesensitive--true-">containsAll</a></td>
</tr>
<tr>
<td>[containsAny](#containsanyarray-needles--boolean-casesensitive--true-)</td>
<td>[countSubstr](#countsubstrstring-substring--boolean-casesensitive--true-)</td>
<td>[dasherize](#dasherize)</td>
<td>[delimit](#delimitint-delimiter)</td>
<td><a href="#containsanyarray-needles--boolean-casesensitive--true-">containsAny</a></td>
<td><a href="#countsubstrstring-substring--boolean-casesensitive--true-">countSubstr</a></td>
<td><a href="#dasherize">dasherize</a></td>
<td><a href="#delimitint-delimiter">delimit</a></td>
</tr>
<tr>
<td>[endsWith](#endswithstring-substring--boolean-casesensitive--true-)</td>
<td>[endsWithAny](#endswithanystring-substrings--boolean-casesensitive--true-)</td>
<td>[ensureLeft](#ensureleftstring-substring)</td>
<td>[ensureRight](#ensurerightstring-substring)</td>
<td><a href="#endswithstring-substring--boolean-casesensitive--true-">endsWith</a></td>
<td><a href="#endswithanystring-substrings--boolean-casesensitive--true-">endsWithAny</a></td>
<td><a href="#ensureleftstring-substring">ensureLeft</a></td>
<td><a href="#ensurerightstring-substring">ensureRight</a></td>
</tr>
<tr>
<td>[first](#firstint-n)</td>
<td>[getEncoding](#getencoding)</td>
<td>[hasLowerCase](#haslowercase)</td>
<td>[hasUpperCase](#hasuppercase)</td>
<td><a href="#firstint-n">first</a></td>
<td><a href="#getencoding">getEncoding</a></td>
<td><a href="#haslowercase">hasLowerCase</a></td>
<td><a href="#hasuppercase">hasUpperCase</a></td>
</tr>
<tr>
<td>[htmlDecode](#htmldecode)</td>
<td>[htmlEncode](#htmlencode)</td>
<td>[humanize](#humanize)</td>
<td>[indexOf](#indexofstring-needle--offset--0-)</td>
<td><a href="#htmldecode">htmlDecode</a></td>
<td><a href="#htmlencode">htmlEncode</a></td>
<td><a href="#humanize">humanize</a></td>
<td><a href="#indexofstring-needle--offset--0-">indexOf</a></td>
</tr>
<tr>
<td>[indexOfLast](#indexoflaststring-needle--offset--0-)</td>
<td>[insert](#insertint-index-string-substring)</td>
<td>[isAlpha](#isalpha)</td>
<td>[isAlphanumeric](#isalphanumeric)</td>
<td><a href="#indexoflaststring-needle--offset--0-">indexOfLast</a></td>
<td><a href="#insertint-index-string-substring">insert</a></td>
<td><a href="#isalpha">isAlpha</a></td>
<td><a href="#isalphanumeric">isAlphanumeric</a></td>
</tr>
<tr>
<td>[isBase64](#isbase64)</td>
<td>[isBlank](#isblank)</td>
<td>[isHexadecimal](#ishexadecimal)</td>
<td>[isJson](#isjson)</td>
<td><a href="#isbase64">isBase64</a></td>
<td><a href="#isblank">isBlank</a></td>
<td><a href="#ishexadecimal">isHexadecimal</a></td>
<td><a href="#isjson">isJson</a></td>
</tr>
<tr>
<td>[isLowerCase](#islowercase)</td>
<td>[isSerialized](#isserialized)</td>
<td>[isUpperCase](#isuppercase)</td>
<td>[last](#lastint-n)</td>
<td><a href="#islowercase">isLowerCase</a></td>
<td><a href="#isserialized">isSerialized</a></td>
<td><a href="#isuppercase">isUpperCase</a></td>
<td><a href="#lastint-n">last</a></td>
</tr>
<tr>
<td>[length](#length)</td>
<td>[lines](#lines)</td>
<td>[longestCommonPrefix](#longestcommonprefixstring-otherstr)</td>
<td>[longestCommonSuffix](#longestcommonsuffixstring-otherstr)</td>
<td><a href="#length">length</a></td>
<td><a href="#lines">lines</a></td>
<td><a href="#longestcommonprefixstring-otherstr">longestCommonPrefix</a></td>
<td><a href="#longestcommonsuffixstring-otherstr">longestCommonSuffix</a></td>
</tr>
<tr>
<td>[longestCommonSubstring](#longestcommonsubstringstring-otherstr)</td>
<td>[lowerCaseFirst](#lowercasefirst)</td>
<td>[pad](#padint-length--string-padstr-----string-padtype--right-)</td>
<td>[padBoth](#padbothint-length--string-padstr----)</td>
<td><a href="#longestcommonsubstringstring-otherstr">longestCommonSubstring</a></td>
<td><a href="#lowercasefirst">lowerCaseFirst</a></td>
<td><a href="#padint-length--string-padstr-----string-padtype--right-">pad</a></td>
<td><a href="#padbothint-length--string-padstr----">padBoth</a></td>
</tr>
<tr>
<td>[padLeft](#padleftint-length--string-padstr----)</td>
<td>[padRight](#padrightint-length--string-padstr----)</td>
<td>[prepend](#prependstring-string)</td>
<td>[regexReplace](#regexreplacestring-pattern-string-replacement--string-options--msr)</td>
<td><a href="#padleftint-length--string-padstr----">padLeft</a></td>
<td><a href="#padrightint-length--string-padstr----">padRight</a></td>
<td><a href="#prependstring-string">prepend</a></td>
<td><a href="#regexreplacestring-pattern-string-replacement--string-options--msr">regexReplace</a></td>
</tr>
<tr>
<td>[removeLeft](#removeleftstring-substring)</td>
<td>[removeRight](#removerightstring-substring)</td>
<td>[repeat](#repeatint-multiplier)</td>
<td>[replace](#replacestring-search-string-replacement)</td>
<td><a href="#removeleftstring-substring">removeLeft</a></td>
<td><a href="#removerightstring-substring">removeRight</a></td>
<td><a href="#repeatint-multiplier">repeat</a></td>
<td><a href="#replacestring-search-string-replacement">replace</a></td>
</tr>
<tr>
<td>[reverse](#reverse)</td>
<td>[safeTruncate](#safetruncateint-length--string-substring---)</td>
<td>[shuffle](#shuffle)</td>
<td>[slugify](#slugify-string-replacement----)</td>
<td><a href="#reverse">reverse</a></td>
<td><a href="#safetruncateint-length--string-substring---">safeTruncate</a></td>
<td><a href="#shuffle">shuffle</a></td>
<td><a href="#slugify-string-replacement----">slugify</a></td>
</tr>
<tr>
<td>[slice](#sliceint-start--int-end-)</td>
<td>[split](#splitstring-pattern--int-limit-)</td>
<td>[startsWith](#startswithstring-substring--boolean-casesensitive--true-)</td>
<td>[startsWithAny](#startswithanystring-substrings--boolean-casesensitive--true-)</td>
<td><a href="#sliceint-start--int-end-">slice</a></td>
<td><a href="#splitstring-pattern--int-limit-">split</a></td>
<td><a href="#startswithstring-substring--boolean-casesensitive--true-">startsWith</a></td>
<td><a href="#startswithanystring-substrings--boolean-casesensitive--true-">startsWithAny</a></td>
</tr>
<tr>
<td>[stripWhitespace](#stripwhitespace)</td>
<td>[substr](#substrint-start--int-length-)</td>
<td>[surround](#surroundstring-substring)</td>
<td>[swapCase](#swapcase)</td>
<td><a href="#stripwhitespace">stripWhitespace</a></td>
<td><a href="#substrint-start--int-length-">substr</a></td>
<td><a href="#surroundstring-substring">surround</a></td>
<td><a href="#swapcase">swapCase</a></td>
</tr>
<tr>
<td>[tidy](#tidy)</td>
<td>[titleize](#titleize-array-ignore)</td>
<td>[toAscii](#toascii-string-locale--en--bool-removeunsupported--true-)</td>
<td>[toBoolean](#toboolean)</td>
<td><a href="#tidy">tidy</a></td>
<td><a href="#titleize-array-ignore">titleize</a></td>
<td><a href="#toascii-string-language--en--bool-removeunsupported--true-">toAscii</a></td>
<td><a href="#toboolean">toBoolean</a></td>
</tr>
<tr>
<td>[toLowerCase](#tolowercase)</td>
<td>[toSpaces](#tospaces-tablength--4-)</td>
<td>[toTabs](#totabs-tablength--4-)</td>
<td>[toTitleCase](#totitlecase)</td>
<td><a href="#tolowercase">toLowerCase</a></td>
<td><a href="#tospaces-tablength--4-">toSpaces</a></td>
<td><a href="#totabs-tablength--4-">toTabs</a></td>
<td><a href="#totitlecase">toTitleCase</a></td>
</tr>
<tr>
<td>[toUpperCase](#touppercase)</td>
<td>[trim](#trim-string-chars)</td>
<td>[trimLeft](#trimleft-string-chars)</td>
<td>[trimRight](#trimright-string-chars)</td>
<td><a href="#touppercase">toUpperCase</a></td>
<td><a href="#trim-string-chars">trim</a></td>
<td><a href="#trimleft-string-chars">trimLeft</a></td>
<td><a href="#trimright-string-chars">trimRight</a></td>
</tr>
<tr>
<td>[truncate](#truncateint-length--string-substring---)</td>
<td>[underscored](#underscored)</td>
<td>[upperCamelize](#uppercamelize)</td>
<td>[upperCaseFirst](#uppercasefirst)</td>
<td><a href="#truncateint-length--string-substring---">truncate</a></td>
<td><a href="#underscored">underscored</a></td>
<td><a href="#uppercamelize">upperCamelize</a></td>
<td><a href="#uppercasefirst">upperCaseFirst</a></td>
</tr>
</table>
* [Extensions](#extensions)
* [Tests](#tests)
* [License](#license)
@@ -179,7 +180,7 @@ in your composer.json file:
```json
"require": {
"danielstjules/stringy": "~3.0"
"danielstjules/stringy": "~3.0.1"
}
```
@@ -919,7 +920,7 @@ s('i like to watch television')->titleize($ignore);
// 'I Like to Watch Television'
```
##### toAscii([, string $locale = 'en' [, bool $removeUnsupported = true ]])
##### toAscii([, string $language = 'en' [, bool $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

View File

@@ -62,8 +62,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* then returns the initialized object. Throws an InvalidArgumentException
* if the first argument is an array or object without a __toString method.
*
* @param mixed $str Value to modify, after being cast to string
* @param string $encoding The character encoding
* @param mixed $str Value to modify, after being cast to string
* @param string $encoding The character encoding
* @return static A Stringy object
* @throws \InvalidArgumentException if an array or object without a
* __toString method is passed as the first argument
@@ -86,7 +86,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Returns a new string with $string appended.
*
* @param string $string The string to append
* @param string $string The string to append
* @return static Object with appended $string
*/
public function append($string)
@@ -97,7 +97,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Returns the character at $index, with indexes starting at 0.
*
* @param int $index Position of the character
* @param int $index Position of the character
* @return static The character at $index
*/
public function at($index)
@@ -219,9 +219,9 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* default the comparison is case-sensitive, but can be made insensitive by
* setting $caseSensitive to false.
*
* @param string[] $needles Substrings to look for
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
* @return bool Whether or not $str contains $needle
* @param string[] $needles Substrings to look for
* @param bool $caseSensitive Whether or not to enforce case-sensitivity
* @return bool Whether or not $str contains $needle
*/
public function containsAll($needles, $caseSensitive = true)
{
@@ -311,7 +311,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* of the first character of the string), and in place of spaces, dashes,
* and underscores. Alpha delimiters are not converted to lowercase.
*
* @param string $delimiter Sequence used to separate parts of the string
* @param string $delimiter Sequence used to separate parts of the string
* @return static Object with a delimited $str
*/
public function delimit($delimiter)
@@ -382,7 +382,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* Ensures that the string begins with $substring. If it doesn't, it's
* prepended.
*
* @param string $substring The substring to add if not present
* @param string $substring The substring to add if not present
* @return static Object with its $str prefixed by the $substring
*/
public function ensureLeft($substring)
@@ -400,7 +400,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* Ensures that the string ends with $substring. If it doesn't, it's
* appended.
*
* @param string $substring The substring to add if not present
* @param string $substring The substring to add if not present
* @return static Object with its $str suffixed by the $substring
*/
public function ensureRight($substring)
@@ -417,7 +417,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Returns the first $n characters of the string.
*
* @param int $n Number of characters to retrieve from the start
* @param int $n Number of characters to retrieve from the start
* @return static Object with its $str being the first $n chars
*/
public function first($n)
@@ -484,7 +484,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* http://php.net/manual/en/function.html-entity-decode.php
*
* @param int|null $flags Optional flags
* @return static Object with the resulting $str after being html decoded.
* @return static Object with the resulting $str after being html decoded.
*/
public function htmlDecode($flags = ENT_COMPAT)
{
@@ -499,7 +499,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* for a list of flags.
*
* @param int|null $flags Optional flags
* @return static Object with the resulting $str after being html encoded.
* @return static Object with the resulting $str after being html encoded.
*/
public function htmlEncode($flags = ENT_COMPAT)
{
@@ -555,8 +555,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Inserts $substring into the string at the $index provided.
*
* @param string $substring String to be inserted
* @param int $index The index at which to insert the substring
* @param string $substring String to be inserted
* @param int $index The index at which to insert the substring
* @return static Object with the resulting $str after the insertion
*/
public function insert($substring, $index)
@@ -683,7 +683,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Returns the last $n characters of the string.
*
* @param int $n Number of characters to retrieve from the end
* @param int $n Number of characters to retrieve from the end
* @return static Object with its $str being the last $n chars
*/
public function last($n)
@@ -727,7 +727,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Returns the longest common prefix between the string and $otherStr.
*
* @param string $otherStr Second string for comparison
* @param string $otherStr Second string for comparison
* @return static Object with its $str being the longest common prefix
*/
public function longestCommonPrefix($otherStr)
@@ -752,7 +752,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Returns the longest common suffix between the string and $otherStr.
*
* @param string $otherStr Second string for comparison
* @param string $otherStr Second string for comparison
* @return static Object with its $str being the longest common suffix
*/
public function longestCommonSuffix($otherStr)
@@ -778,7 +778,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* Returns the longest common substring between the string and $otherStr.
* In the case of ties, it returns that which occurs first.
*
* @param string $otherStr Second string for comparison
* @param string $otherStr Second string for comparison
* @return static Object with its $str being the longest common substring
*/
public function longestCommonSubstring($otherStr)
@@ -916,9 +916,9 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* 'left', 'right', 'both') is 'right'. Throws an InvalidArgumentException
* if $padType isn't one of those 3 values.
*
* @param int $length Desired string length after padding
* @param string $padStr String used to pad, defaults to space
* @param string $padType One of 'left', 'right', 'both'
* @param int $length Desired string length after padding
* @param string $padStr String used to pad, defaults to space
* @param string $padType One of 'left', 'right', 'both'
* @return static Object with a padded $str
* @throws /InvalidArgumentException If $padType isn't one of 'right',
* 'left' or 'both'
@@ -944,8 +944,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* Returns a new string of a given length such that both sides of the
* string are padded. Alias for pad() with a $padType of 'both'.
*
* @param int $length Desired string length after padding
* @param string $padStr String used to pad, defaults to space
* @param int $length Desired string length after padding
* @param string $padStr String used to pad, defaults to space
* @return static String with padding applied
*/
public function padBoth($length, $padStr = ' ')
@@ -960,8 +960,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* Returns a new string of a given length such that the beginning of the
* string is padded. Alias for pad() with a $padType of 'left'.
*
* @param int $length Desired string length after padding
* @param string $padStr String used to pad, defaults to space
* @param int $length Desired string length after padding
* @param string $padStr String used to pad, defaults to space
* @return static String with left padding
*/
public function padLeft($length, $padStr = ' ')
@@ -973,8 +973,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* Returns a new string of a given length such that the end of the string
* is padded. Alias for pad() with a $padType of 'right'.
*
* @param int $length Desired string length after padding
* @param string $padStr String used to pad, defaults to space
* @param int $length Desired string length after padding
* @param string $padStr String used to pad, defaults to space
* @return static String with right padding
*/
public function padRight($length, $padStr = ' ')
@@ -985,7 +985,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Returns a new string starting with $string.
*
* @param string $string The string to append
* @param string $string The string to append
* @return static Object with appended $string
*/
public function prepend($string)
@@ -1000,9 +1000,9 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* to a lack of support in the bundled version of Oniguruma in PHP < 5.6,
* and current versions of HHVM (3.8 and below).
*
* @param string $pattern The regular expression pattern
* @param string $replacement The string to replace with
* @param string $options Matching conditions to be used
* @param string $pattern The regular expression pattern
* @param string $replacement The string to replace with
* @param string $options Matching conditions to be used
* @return static Object with the resulting $str after the replacements
*/
public function regexReplace($pattern, $replacement, $options = 'msr')
@@ -1019,7 +1019,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Returns a new string with the prefix $substring removed, if present.
*
* @param string $substring The prefix to remove
* @param string $substring The prefix to remove
* @return static Object having a $str without the prefix $substring
*/
public function removeLeft($substring)
@@ -1037,7 +1037,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Returns a new string with the suffix $substring removed, if present.
*
* @param string $substring The suffix to remove
* @param string $substring The suffix to remove
* @return static Object having a $str without the suffix $substring
*/
public function removeRight($substring)
@@ -1055,7 +1055,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Returns a repeated string given a multiplier. An alias for str_repeat.
*
* @param int $multiplier The number of times to repeat the string
* @param int $multiplier The number of times to repeat the string
* @return static Object with a repeated str
*/
public function repeat($multiplier)
@@ -1068,8 +1068,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Replaces all occurrences of $search in $str by $replacement.
*
* @param string $search The needle to search for
* @param string $replacement The string to replace with
* @param string $search The needle to search for
* @param string $replacement The string to replace with
* @return static Object with the resulting $str after the replacements
*/
public function replace($search, $replacement)
@@ -1101,8 +1101,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* string is further truncated so that the substring may be appended without
* exceeding the desired length.
*
* @param int $length Desired length of the truncated string
* @param string $substring The substring to append if it can fit
* @param int $length Desired length of the truncated string
* @param string $substring The substring to append if it can fit
* @return static Object with the resulting $str after truncating
*/
public function safeTruncate($length, $substring = '')
@@ -1159,13 +1159,14 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* $replacement. The replacement defaults to a single dash, and the string
* is also converted to lowercase.
*
* @param string $replacement The string used to replace whitespace
* @param string $replacement The string used to replace whitespace
* @return static Object whose $str has been converted to an URL slug
*/
public function slugify($replacement = '-')
{
$stringy = $this->toAscii();
$stringy->str = str_replace('@', $replacement, $stringy);
$quotedReplacement = preg_quote($replacement);
$pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u";
$stringy->str = preg_replace($pattern, '', $stringy);
@@ -1229,8 +1230,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* the remaining string. If $end is negative, it is computed from the end
* of the string.
*
* @param int $start Initial index from which to begin extraction
* @param int $end Optional index at which to end extraction
* @param int $start Initial index from which to begin extraction
* @param int $end Optional index at which to end extraction
* @return static Object with its $str being the extracted substring
*/
public function slice($start, $end = null)
@@ -1253,8 +1254,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* array of Stringy objects. An optional integer $limit will truncate the
* results.
*
* @param string $pattern The regex with which to split the string
* @param int $limit Optional maximum number of results to return
* @param string $pattern The regex with which to split the string
* @param int $limit Optional maximum number of results to return
* @return static[] An array of Stringy objects
*/
public function split($pattern, $limit = null)
@@ -1317,8 +1318,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* It differs from the mb_substr() function in that providing a $length of
* null will return the rest of the string, rather than an empty string.
*
* @param int $start Position of the first character to use
* @param int $length Maximum number of characters used
* @param int $start Position of the first character to use
* @param int $length Maximum number of characters used
* @return static Object with its $str being the substring
*/
public function substr($start, $length = null)
@@ -1332,7 +1333,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
/**
* Surrounds $str with the given substring.
*
* @param string $substring The substring to add to both sides
* @param string $substring The substring to add to both sides
* @return static Object whose $str had the substring both prepended and
* appended
*/
@@ -1397,7 +1398,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* Also accepts an array, $ignore, allowing you to list words not to be
* capitalized.
*
* @param array $ignore An array of words not to capitalize
* @param array $ignore An array of words not to capitalize
* @return static Object with a titleized $str
*/
public function titleize($ignore = null)
@@ -1430,8 +1431,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* en, en_GB, or en-GB. For example, passing "de" results in "äöü" mapping
* to "aeoeue" rather than "aou" as in other languages.
*
* @param string $language Language of the source string
* @param bool $removeUnsupported Whether or not to remove the
* @param string $language Language of the source string
* @param bool $removeUnsupported Whether or not to remove the
* unsupported characters
* @return static Object whose $str contains only ASCII characters
*/
@@ -1506,7 +1507,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* 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.
*
* @param int $tabLength Number of spaces to replace each tab with
* @param int $tabLength Number of spaces to replace each tab with
* @return static Object whose $str has had tabs switched to spaces
*/
public function toSpaces($tabLength = 4)
@@ -1522,7 +1523,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* defined by $tabLength, to a tab. By default, each 4 consecutive spaces
* are converted to a tab.
*
* @param int $tabLength Number of spaces to replace with a tab
* @param int $tabLength Number of spaces to replace with a tab
* @return static Object whose $str has had spaces switched to tabs
*/
public function toTabs($tabLength = 4)
@@ -1563,7 +1564,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* string. Supports the removal of unicode whitespace. Accepts an optional
* string of characters to strip instead of the defaults.
*
* @param string $chars Optional string of characters to strip
* @param string $chars Optional string of characters to strip
* @return static Object with a trimmed $str
*/
public function trim($chars = null)
@@ -1578,7 +1579,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* Supports the removal of unicode whitespace. Accepts an optional
* string of characters to strip instead of the defaults.
*
* @param string $chars Optional string of characters to strip
* @param string $chars Optional string of characters to strip
* @return static Object with a trimmed $str
*/
public function trimLeft($chars = null)
@@ -1593,7 +1594,7 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* Supports the removal of unicode whitespace. Accepts an optional
* string of characters to strip instead of the defaults.
*
* @param string $chars Optional string of characters to strip
* @param string $chars Optional string of characters to strip
* @return static Object with a trimmed $str
*/
public function trimRight($chars = null)
@@ -1608,8 +1609,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* truncating occurs, the string is further truncated so that the substring
* may be appended without exceeding the desired length.
*
* @param int $length Desired length of the truncated string
* @param string $substring The substring to append if it can fit
* @param int $length Desired length of the truncated string
* @param string $substring The substring to append if it can fit
* @return static Object with the resulting $str after truncating
*/
public function truncate($length, $substring = '')
@@ -1747,7 +1748,6 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
'aa' => ['ع', 'आ', 'آ'],
'ae' => ['æ', 'ǽ'],
'ai' => ['ऐ'],
'at' => ['@'],
'ch' => ['ч', 'ჩ', 'ჭ', 'چ'],
'dj' => ['ђ', 'đ'],
'dz' => ['џ', 'ძ'],
@@ -1851,8 +1851,8 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* For example, German will map 'ä' to 'ae', while other languages
* will simply return 'a'.
*
* param string $language Language of the source string
* @return array An array of replacements.
* @param string $language Language of the source string
* @return array An array of replacements.
*/
protected static function langSpecificCharsArray($language = 'en')
{
@@ -1884,9 +1884,9 @@ class Stringy implements Countable, IteratorAggregate, ArrayAccess
* Adds the specified amount of left and right padding to the given string.
* The default character used is a space.
*
* @param int $left Length of left padding
* @param int $right Length of right padding
* @param string $padStr String used to pad
* @param int $left Length of left padding
* @param int $right Length of right padding
* @param string $padStr String used to pad
* @return static String with padding applied
*/
protected function applyPadding($left = 0, $right = 0, $padStr = ' ')

View File

@@ -671,6 +671,7 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
['f = z = 3', 'φ = ź = 3'],
['perevirka', 'перевірка'],
['lysaya gora', 'лысая гора'],
['user@host', 'user@host'],
['shchuka', 'щука'],
['', '漢字'],
['xin chao the gioi', 'xin chào thế giới'],
@@ -1107,6 +1108,7 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
['another-foo-bar', 'another..& foo -.-"-...bar'],
['foo-dbar', " Foo d'Bar "],
['a-string-with-dashes', 'A string-with-dashes'],
['user-host', 'user@host'],
['using-strings-like-foo-bar', 'Using strings like fòô bàř'],
['numbers-1234', 'numbers 1234'],
['perevirka-ryadka', 'перевірка рядка'],