mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-09 23:06:41 +02:00
Added repeat
This commit is contained in:
13
README.md
13
README.md
@@ -26,7 +26,7 @@ S::create('string')->toTitleCase()->ensureRight('y') == 'Stringy'
|
|||||||
* [containsAny](#containsanyarray-needles--boolean-casesensitive--true-)
|
* [containsAny](#containsanyarray-needles--boolean-casesensitive--true-)
|
||||||
* [countSubstr](#countsubstrstring-substring--boolean-casesensitive--true-)
|
* [countSubstr](#countsubstrstring-substring--boolean-casesensitive--true-)
|
||||||
* [dasherize](#dasherize)
|
* [dasherize](#dasherize)
|
||||||
* [delimit](#delimitdelimiter)
|
* [delimit](#delimitint-delimiter)
|
||||||
* [endsWith](#endswithstring-substring--boolean-casesensitive--true-)
|
* [endsWith](#endswithstring-substring--boolean-casesensitive--true-)
|
||||||
* [ensureLeft](#ensureleftstring-substring)
|
* [ensureLeft](#ensureleftstring-substring)
|
||||||
* [ensureRight](#ensurerightstring-substring)
|
* [ensureRight](#ensurerightstring-substring)
|
||||||
@@ -62,6 +62,7 @@ S::create('string')->toTitleCase()->ensureRight('y') == 'Stringy'
|
|||||||
* [regexReplace](#regexreplacestring-pattern-string-replacement--string-options--msr)
|
* [regexReplace](#regexreplacestring-pattern-string-replacement--string-options--msr)
|
||||||
* [removeLeft](#removeleftstring-substring)
|
* [removeLeft](#removeleftstring-substring)
|
||||||
* [removeRight](#removerightstring-substring)
|
* [removeRight](#removerightstring-substring)
|
||||||
|
* [repeat](#repeatmultiplier)
|
||||||
* [replace](#replacestring-search-string-replacement)
|
* [replace](#replacestring-search-string-replacement)
|
||||||
* [reverse](#reverse)
|
* [reverse](#reverse)
|
||||||
* [safeTruncate](#safetruncateint-length--string-substring---)
|
* [safeTruncate](#safetruncateint-length--string-substring---)
|
||||||
@@ -307,7 +308,7 @@ character of the string), and in place of spaces as well as underscores.
|
|||||||
S::create('TestDCase')->dasherize(); // 'test-d-case'
|
S::create('TestDCase')->dasherize(); // 'test-d-case'
|
||||||
```
|
```
|
||||||
|
|
||||||
##### delimit($delimiter)
|
##### delimit(int $delimiter)
|
||||||
|
|
||||||
Returns a lowercase and trimmed string separated by the given delimiter.
|
Returns a lowercase and trimmed string separated by the given delimiter.
|
||||||
Delimiters are inserted before uppercase characters (with the exception
|
Delimiters are inserted before uppercase characters (with the exception
|
||||||
@@ -617,6 +618,14 @@ Returns a new string with the suffix $substring removed, if present.
|
|||||||
S::create('fòô bàř')->removeRight(' bàř'); // 'fòô'
|
S::create('fòô bàř')->removeRight(' bàř'); // 'fòô'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### repeat(int $multiplier)
|
||||||
|
|
||||||
|
Returns a repeated string given a multiplier. An alias for str_repeat.
|
||||||
|
|
||||||
|
```php
|
||||||
|
S::create('à')->repeat(3); // 'ààà'
|
||||||
|
```
|
||||||
|
|
||||||
##### replace(string $search, string $replacement)
|
##### replace(string $search, string $replacement)
|
||||||
|
|
||||||
Replaces all occurrences of $search in $str by $replacement.
|
Replaces all occurrences of $search in $str by $replacement.
|
||||||
|
@@ -1094,6 +1094,19 @@ 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
|
||||||
|
* @return Stringy Object with a repeated str
|
||||||
|
*/
|
||||||
|
public function repeat($multiplier)
|
||||||
|
{
|
||||||
|
$repeated = str_repeat($this->str, $multiplier);
|
||||||
|
|
||||||
|
return static::create($repeated, $this->encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
* A multibyte str_shuffle() function. It returns a string with its
|
* A multibyte str_shuffle() function. It returns a string with its
|
||||||
* characters in random order.
|
* characters in random order.
|
||||||
*
|
*
|
||||||
|
@@ -1298,6 +1298,31 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider repeatProvider()
|
||||||
|
*/
|
||||||
|
public function testRepeat($expected, $str, $multiplier, $encoding = null)
|
||||||
|
{
|
||||||
|
$stringy = S::create($str, $encoding);
|
||||||
|
$result = $stringy->repeat($multiplier);
|
||||||
|
$this->assertStringy($result);
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
$this->assertEquals($str, $stringy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function repeatProvider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('', 'foo', 0),
|
||||||
|
array('foo', 'foo', 1),
|
||||||
|
array('foofoo', 'foo', 2),
|
||||||
|
array('foofoofoo', 'foo', 3),
|
||||||
|
array('fòô', 'fòô', 1, 'UTF-8'),
|
||||||
|
array('fòôfòô', 'fòô', 2, 'UTF-8'),
|
||||||
|
array('fòôfòôfòô', 'fòô', 3, 'UTF-8')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider shuffleProvider()
|
* @dataProvider shuffleProvider()
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user