From 0655fae0cb567203bb0bf2a46b0089089acb4bef Mon Sep 17 00:00:00 2001 From: irhen Date: Fri, 2 Mar 2018 17:22:02 +0300 Subject: [PATCH 1/6] move implemented --- src/Lib/StrMB.php | 24 ++++++++++++++++++++++++ src/Str.php | 16 ++++++++++++++++ tests/FS/Lib/StrMBTest.php | 22 ++++++++++++++++++++++ tests/FS/StrTest.php | 1 + 4 files changed, 63 insertions(+) diff --git a/src/Lib/StrMB.php b/src/Lib/StrMB.php index 0448c10..1e26c29 100644 --- a/src/Lib/StrMB.php +++ b/src/Lib/StrMB.php @@ -1836,3 +1836,27 @@ function libstr_underscored(string $str): string return libstr_delimit($innerStr, '_'); } + +/** @noinspection MoreThanThreeArgumentsInspection */ +/** + * Move substring of desired $length to $destination index of the original $str. + * In case $destination is less than $length returns $str untouched. + * + * @param string $str + * @param int $start + * @param int $length + * @param int $destination + * @return string + */ +function libstr_move(string $str, int $start, int $length, int $destination): string +{ + $innerStr = $str; + + if ($destination <= $length) { return $innerStr; } + + $substr = libstr_substr($innerStr, $start, $length); + $result = libstr_insert($innerStr, $substr, $destination); + $result = libstr_replace($result, $substr, '', 1); + + return $result; +} diff --git a/src/Str.php b/src/Str.php index 9f495d5..2839dd9 100644 --- a/src/Str.php +++ b/src/Str.php @@ -42,6 +42,7 @@ use function Str\Lib\libstr_isUUIDv4; use function Str\Lib\libstr_langSpecificCharsArray; use function Str\Lib\libstr_last; +use function Str\Lib\libstr_move; use function Str\Lib\libstr_split; use function Str\Lib\libstr_length; use function Str\Lib\libstr_lines; @@ -1219,4 +1220,19 @@ public function underscored(): Str $this->str = libstr_underscored($this->str); return $this; } + + /** + * Move substring of desired $length to $destination index of the original $str. + * In case $destination is less than $length returns $str untouched. + * + * @param int $start + * @param int $length + * @param int $destination + * @return Str + */ + public function move(int $start, int $length, int $destination): Str + { + $this->str = libstr_move($this->str, $start, $length, $destination); + return $this; + } } diff --git a/tests/FS/Lib/StrMBTest.php b/tests/FS/Lib/StrMBTest.php index 42ae03f..22f988d 100644 --- a/tests/FS/Lib/StrMBTest.php +++ b/tests/FS/Lib/StrMBTest.php @@ -9,6 +9,7 @@ use function Str\Lib\libstr_hasPrefix; use function Str\Lib\libstr_hasSuffix; use function Str\Lib\libstr_contains; +use function Str\Lib\libstr_move; use function Str\Lib\libstr_replace; use function Str\Lib\libstr_toLowerCase; use function Str\Lib\libstr_toUpperCase; @@ -2516,4 +2517,25 @@ public function underscoredProvider() ['σash_case', 'Σash Case'] ]; } + + /** + * @dataProvider moveProvider() + * @param $expected + * @param $str + * @param $start + * @param $length + * @param $destination + */ + public function testMove($expected, $str, $start, $length, $destination) + { + $this->assertEquals($expected, libstr_move($str, $start, $length, $destination), $str); + } + public function moveProvider() + { + return [ + ['stte_case', 'test_case', 0, 2, 4], + ['Στανιλ case', 'Στανιλ case', 0, 4, 1], + ['ιλΣταν case', 'Στανιλ case', 0, 4, 6], + ]; + } } diff --git a/tests/FS/StrTest.php b/tests/FS/StrTest.php index b48bb2b..a406411 100644 --- a/tests/FS/StrTest.php +++ b/tests/FS/StrTest.php @@ -127,6 +127,7 @@ public function testModifiers() $s = new Str('str with whitespace '); $this->assertEquals('strwithwhitespace', $s->stripWhitespace()); $this->assertEquals('Strwithwhitespace', $s->upperCamelize()); + $this->assertEquals('rwStithwhitespace', $s->move(0, 2, 4)); $s = new Str('I see…'); $this->assertEquals('I see...', $s->tidy()); From 4c263173423481db3588bbb7dce329329ded7012 Mon Sep 17 00:00:00 2001 From: irhen Date: Fri, 2 Mar 2018 17:54:19 +0300 Subject: [PATCH 2/6] overwrite implemented, readme updated --- README.md | 27 ++++++++++++++++++++++++++- src/Lib/StrMB.php | 24 ++++++++++++++++++++++-- src/Str.php | 15 +++++++++++++++ tests/FS/Lib/StrMBTest.php | 22 ++++++++++++++++++++++ tests/FS/StrTest.php | 1 + 5 files changed, 86 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 87a4cfc..359738e 100644 --- a/README.md +++ b/README.md @@ -124,9 +124,34 @@ composer require str/str - [x] toTabs - [x] toTitleCase - [x] underscored +- [x] move +- [x] overwrite ### Todo New - +- [ ] snakeize +- [ ] appendUniqueIdentifier +- [ ] afterFirst +- [ ] beforeFirst +- [ ] afterLast +- [ ] beforeLast +- [ ] ord +- [ ] quote +- [ ] unquote +- [ ] words +- [ ] formatNumber +- [ ] toNumber +- [ ] toInt +- [ ] toFloat +- [ ] join +- [ ] chop +- [ ] random +- [ ] pop +- [ ] shift +- [ ] shiftReversed +- [ ] popReversed +- [ ] isEmail +- [ ] isUrl +- [ ] isIp ## Optimization diff --git a/src/Lib/StrMB.php b/src/Lib/StrMB.php index 1e26c29..873532a 100644 --- a/src/Lib/StrMB.php +++ b/src/Lib/StrMB.php @@ -1856,7 +1856,27 @@ function libstr_move(string $str, int $start, int $length, int $destination): st $substr = libstr_substr($innerStr, $start, $length); $result = libstr_insert($innerStr, $substr, $destination); - $result = libstr_replace($result, $substr, '', 1); - return $result; + return libstr_replace($result, $substr, '', 1); +} + +/** @noinspection MoreThanThreeArgumentsInspection */ +/** + * Replaces substring in the original $str of $length with given $substr. + * + * @param string $str + * @param int $start + * @param int $length + * @param string $substr + * @return string + */ +function libstr_overwrite(string $str, int $start, int $length, string $substr): string +{ + $innerStr = $str; + + if ($length <= 0) { return $innerStr; } + + $sub = libstr_substr($innerStr, $start, $length); + + return libstr_replace($innerStr, $sub, $substr, 1); } diff --git a/src/Str.php b/src/Str.php index 2839dd9..bf5e20c 100644 --- a/src/Str.php +++ b/src/Str.php @@ -43,6 +43,7 @@ use function Str\Lib\libstr_langSpecificCharsArray; use function Str\Lib\libstr_last; use function Str\Lib\libstr_move; +use function Str\Lib\libstr_overwrite; use function Str\Lib\libstr_split; use function Str\Lib\libstr_length; use function Str\Lib\libstr_lines; @@ -1235,4 +1236,18 @@ public function move(int $start, int $length, int $destination): Str $this->str = libstr_move($this->str, $start, $length, $destination); return $this; } + + /** + * Replaces substring in the original $str of $length with given $substr. + * + * @param int $start + * @param int $length + * @param string $substr + * @return Str + */ + public function overwrite(int $start, int $length, string $substr): Str + { + $this->str = libstr_overwrite($this->str, $start, $length, $substr); + return $this; + } } diff --git a/tests/FS/Lib/StrMBTest.php b/tests/FS/Lib/StrMBTest.php index 22f988d..c1da397 100644 --- a/tests/FS/Lib/StrMBTest.php +++ b/tests/FS/Lib/StrMBTest.php @@ -10,6 +10,7 @@ use function Str\Lib\libstr_hasSuffix; use function Str\Lib\libstr_contains; use function Str\Lib\libstr_move; +use function Str\Lib\libstr_overwrite; use function Str\Lib\libstr_replace; use function Str\Lib\libstr_toLowerCase; use function Str\Lib\libstr_toUpperCase; @@ -2538,4 +2539,25 @@ public function moveProvider() ['ιλΣταν case', 'Στανιλ case', 0, 4, 6], ]; } + + /** + * @dataProvider overwriteProvider() + * @param $expected + * @param $str + * @param $start + * @param $length + * @param $substr + */ + public function testOverwrite($expected, $str, $start, $length, $substr) + { + $this->assertEquals($expected, libstr_overwrite($str, $start, $length, $substr), $str); + } + public function overwriteProvider() + { + return [ + ['overwrittenst_case', 'test_case', 0, 2, 'overwritten'], + ['oh ιλ case', 'Στανιλ case', 0, 4, 'oh '], + ['Στανλ case', 'Στανιλ case', 4, 1, ''], + ]; + } } diff --git a/tests/FS/StrTest.php b/tests/FS/StrTest.php index a406411..f2fc653 100644 --- a/tests/FS/StrTest.php +++ b/tests/FS/StrTest.php @@ -137,6 +137,7 @@ public function testModifiers() $this->assertEquals('strwith tabs', $s->toSpaces(0)); $this->assertEquals("strwith\ttabs", $s->toTabs(1)); $this->assertEquals("Strwith\tTabs", $s->toTitleCase()); + $this->assertEquals("hello with\tTabs", $s->overwrite(0, 3, 'hello ')); } public function testTrim() From 1ed209727a188c66c4d55ea4a33b8bef4155361f Mon Sep 17 00:00:00 2001 From: irhen Date: Fri, 2 Mar 2018 19:03:14 +0300 Subject: [PATCH 3/6] snakeize implemented --- README.md | 2 +- src/Lib/StrMB.php | 35 +++++++++++++++++++++++++++++++++++ src/Str.php | 12 ++++++++++++ tests/FS/Lib/StrMBTest.php | 34 ++++++++++++++++++++++++++++++++++ tests/FS/StrTest.php | 1 + 5 files changed, 83 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 359738e..4b1fa27 100644 --- a/README.md +++ b/README.md @@ -126,9 +126,9 @@ composer require str/str - [x] underscored - [x] move - [x] overwrite +- [x] snakeize ### Todo New -- [ ] snakeize - [ ] appendUniqueIdentifier - [ ] afterFirst - [ ] beforeFirst diff --git a/src/Lib/StrMB.php b/src/Lib/StrMB.php index 873532a..416fbb9 100644 --- a/src/Lib/StrMB.php +++ b/src/Lib/StrMB.php @@ -1880,3 +1880,38 @@ function libstr_overwrite(string $str, int $start, int $length, string $substr): return libstr_replace($innerStr, $sub, $substr, 1); } + +/** + * Returns a snake_case version of the string. + * + * @param string $str + * @return string + */ +function libstr_snakeize(string $str): string +{ + $innerStr = $str; + + $innerStr = \mb_ereg_replace('-', '_', $innerStr); + $innerStr = \mb_ereg_replace_callback( + '([\d|A-Z])', + function ($matches) { + $match = $matches[1]; + $matchInt = (int)$match; + if ("$matchInt" === $match) { + return '_' . $match . '_'; + } + return '_' . libstr_toLowerCase($match); + }, + $innerStr + ); + + $innerStr = \mb_ereg_replace('\s+', '_', $innerStr); + $innerStr = \mb_ereg_replace('^\s+|\s+$', '', $innerStr); + $innerStr = \mb_ereg_replace('_+', '_', $innerStr); + + $innerStr = libstr_trim($innerStr, '_'); + $innerStr = libstr_trim($innerStr); + $innerStr = libstr_toLowerCase($innerStr); + + return $innerStr; +} diff --git a/src/Str.php b/src/Str.php index bf5e20c..8f488ff 100644 --- a/src/Str.php +++ b/src/Str.php @@ -44,6 +44,7 @@ use function Str\Lib\libstr_last; use function Str\Lib\libstr_move; use function Str\Lib\libstr_overwrite; +use function Str\Lib\libstr_snakeize; use function Str\Lib\libstr_split; use function Str\Lib\libstr_length; use function Str\Lib\libstr_lines; @@ -1250,4 +1251,15 @@ public function overwrite(int $start, int $length, string $substr): Str $this->str = libstr_overwrite($this->str, $start, $length, $substr); return $this; } + + /** + * Returns a snake_case version of the string. + * + * @return Str + */ + public function snakeize(): Str + { + $this->str = libstr_snakeize($this->str); + return $this; + } } diff --git a/tests/FS/Lib/StrMBTest.php b/tests/FS/Lib/StrMBTest.php index c1da397..ee85e31 100644 --- a/tests/FS/Lib/StrMBTest.php +++ b/tests/FS/Lib/StrMBTest.php @@ -12,6 +12,7 @@ use function Str\Lib\libstr_move; use function Str\Lib\libstr_overwrite; use function Str\Lib\libstr_replace; +use function Str\Lib\libstr_snakeize; use function Str\Lib\libstr_toLowerCase; use function Str\Lib\libstr_toUpperCase; use function Str\Lib\libstr_trim; @@ -2560,4 +2561,37 @@ public function overwriteProvider() ['Στανλ case', 'Στανιλ case', 4, 1, ''], ]; } + + /** + * @dataProvider snakeizeProvider() + * @param $expected + * @param $str + */ + public function testSnakeize($expected, $str) + { + $this->assertEquals($expected, libstr_snakeize($str), $str); + } + public function snakeizeProvider() + { + return [ + ['camel_case', 'CamelCase'], + ['camel_case', 'Camel-Case'], + ['camel_case', 'camel case'], + ['camel_case', 'camel -case'], + ['camel_case', 'camel - case'], + ['camel_case', 'camel_case'], + ['camel_c_test', 'camel c test'], + ['string_with_1_number', 'string_with1number'], + ['string_with_2_2_numbers', 'string-with-2-2 numbers'], + ['data_rate', 'data_rate'], + ['background_color', 'background-color'], + ['yes_we_can', 'yes_we_can'], + ['moz_something', '-moz-something'], + ['car_speed', '_car_speed_'], + ['1_camel_2_case', '1camel2case'], + ['camel_σase', 'camel σase'], + ['στανιλ_case', 'Στανιλ case'], + ['σamel_case', 'σamel Case'] + ]; + } } diff --git a/tests/FS/StrTest.php b/tests/FS/StrTest.php index f2fc653..cf4bf75 100644 --- a/tests/FS/StrTest.php +++ b/tests/FS/StrTest.php @@ -128,6 +128,7 @@ public function testModifiers() $this->assertEquals('strwithwhitespace', $s->stripWhitespace()); $this->assertEquals('Strwithwhitespace', $s->upperCamelize()); $this->assertEquals('rwStithwhitespace', $s->move(0, 2, 4)); + $this->assertEquals('rw_stithwhitespace', $s->snakeize()); $s = new Str('I see…'); $this->assertEquals('I see...', $s->tidy()); From c8685ed394e52bf5d7768167d5db0eeffd5fc982 Mon Sep 17 00:00:00 2001 From: irhen Date: Fri, 2 Mar 2018 19:35:45 +0300 Subject: [PATCH 4/6] afterFirst, beforeFirst, afterLast, beforeLast implemented --- src/Lib/StrMB.php | 86 ++++++++++++++++++++++++++++++++++++- src/Str.php | 64 +++++++++++++++++++++++++++ tests/FS/Lib/StrMBTest.php | 88 ++++++++++++++++++++++++++++++++++++++ tests/FS/StrTest.php | 4 ++ 4 files changed, 241 insertions(+), 1 deletion(-) diff --git a/src/Lib/StrMB.php b/src/Lib/StrMB.php index 416fbb9..14e6175 100644 --- a/src/Lib/StrMB.php +++ b/src/Lib/StrMB.php @@ -1884,6 +1884,7 @@ function libstr_overwrite(string $str, int $start, int $length, string $substr): /** * Returns a snake_case version of the string. * + * @todo refactoring + abbreviations support * @param string $str * @return string */ @@ -1910,8 +1911,91 @@ function ($matches) { $innerStr = \mb_ereg_replace('_+', '_', $innerStr); $innerStr = libstr_trim($innerStr, '_'); - $innerStr = libstr_trim($innerStr); $innerStr = libstr_toLowerCase($innerStr); return $innerStr; } + +/** @noinspection MoreThanThreeArgumentsInspection */ +/** + * Inserts given $substr $times times into the original $str after + * the first occurrence of $needle. + * + * @param string $str + * @param string $needle + * @param string $substr + * @param int $times + * @return string + */ +function libstr_afterFirst(string $str, string $needle, string $substr, int $times = 1): string +{ + $innerStr = $str; + $idx = libstr_indexOf($innerStr, $needle); + $needleLen = \mb_strlen($needle); + $idxEnd = $idx + $needleLen; + $innerSubstr = libstr_repeat($substr, $times); + + return libstr_insert($innerStr, $innerSubstr, $idxEnd); +} + +/** @noinspection MoreThanThreeArgumentsInspection */ +/** + * Inserts given $substr $times times into the original $str before + * the first occurrence of $needle. + * + * @param string $str + * @param string $needle + * @param string $substr + * @param int $times + * @return string + */ +function libstr_beforeFirst(string $str, string $needle, string $substr, int $times = 1): string +{ + $innerStr = $str; + $idx = libstr_indexOf($innerStr, $needle); + $innerSubstr = libstr_repeat($substr, $times); + + return libstr_insert($innerStr, $innerSubstr, $idx); +} + +/** @noinspection MoreThanThreeArgumentsInspection */ +/** + * Inserts given $substr $times times into the original $str after + * the last occurrence of $needle. + * + * @param string $str + * @param string $needle + * @param string $substr + * @param int $times + * @return string + */ +function libstr_afterLast(string $str, string $needle, string $substr, int $times = 1): string +{ + $innerStr = $str; + $idx = libstr_indexOfLast($innerStr, $needle); + $needleLen = \mb_strlen($needle); + $idxEnd = $idx + $needleLen; + $innerSubstr = libstr_repeat($substr, $times); + + return libstr_insert($innerStr, $innerSubstr, $idxEnd); +} + +/** @noinspection MoreThanThreeArgumentsInspection */ +/** + * Inserts given $substr $times times into the original $str before + * the last occurrence of $needle. + * + * @param string $str + * @param string $needle + * @param string $substr + * @param int $times + * @return string + */ +function libstr_beforeLast(string $str, string $needle, string $substr, int $times = 1): string +{ + $innerStr = $str; + $idx = libstr_indexOfLast($innerStr, $needle); + $innerSubstr = libstr_repeat($substr, $times); + + return libstr_insert($innerStr, $innerSubstr, $idx); +} diff --git a/src/Str.php b/src/Str.php index 8f488ff..b7e1dec 100644 --- a/src/Str.php +++ b/src/Str.php @@ -4,9 +4,13 @@ namespace Str; +use function Str\Lib\libstr_afterFirst; +use function Str\Lib\libstr_afterLast; use function Str\Lib\libstr_at; use function Str\Lib\libstr_append; use function Str\Lib\libstr_applyPadding; +use function Str\Lib\libstr_beforeFirst; +use function Str\Lib\libstr_beforeLast; use function Str\Lib\libstr_between; use function Str\Lib\libstr_camelize; use function Str\Lib\libstr_chars; @@ -1262,4 +1266,64 @@ public function snakeize(): Str $this->str = libstr_snakeize($this->str); return $this; } + + /** + * Inserts given $substr $times times into the original $str after + * the first occurrence of $needle. + * + * @param string $needle + * @param string $substr + * @param int $times + * @return Str + */ + public function afterFirst(string $needle, string $substr, int $times = 1): Str + { + $this->str = libstr_afterFirst($this->str, $needle, $substr, $times); + return $this; + } + + /** + * Inserts given $substr $times times into the original $str before + * the first occurrence of $needle. + * + * @param string $needle + * @param string $substr + * @param int $times + * @return Str + */ + public function beforeFirst(string $needle, string $substr, int $times = 1): Str + { + $this->str = libstr_beforeFirst($this->str, $needle, $substr, $times); + return $this; + } + + /** + * Inserts given $substr $times times into the original $str after + * the last occurrence of $needle. + * + * @param string $needle + * @param string $substr + * @param int $times + * @return Str + */ + public function afterLast(string $needle, string $substr, int $times = 1): Str + { + $this->str = libstr_afterLast($this->str, $needle, $substr, $times); + return $this; + } + + /** + * Inserts given $substr $times times into the original $str before + * the last occurrence of $needle. + * + * @param string $needle + * @param string $substr + * @param int $times + * @return Str + */ + public function beforeLast(string $needle, string $substr, int $times = 1): Str + { + $this->str = libstr_beforeLast($this->str, $needle, $substr, $times); + return $this; + } } diff --git a/tests/FS/Lib/StrMBTest.php b/tests/FS/Lib/StrMBTest.php index ee85e31..1522d21 100644 --- a/tests/FS/Lib/StrMBTest.php +++ b/tests/FS/Lib/StrMBTest.php @@ -3,6 +3,10 @@ declare(strict_types=1); use PHPUnit\Framework\TestCase; +use function Str\Lib\libstr_afterFirst; +use function Str\Lib\libstr_afterLast; +use function Str\Lib\libstr_beforeFirst; +use function Str\Lib\libstr_beforeLast; use function Str\Lib\libstr_matchesPattern; use function Str\Lib\libstr_ensureLeft; use function Str\Lib\libstr_ensureRight; @@ -2594,4 +2598,88 @@ public function snakeizeProvider() ['σamel_case', 'σamel Case'] ]; } + + /** + * @dataProvider afterFirstProvider() + * @param $expected + * @param $str + * @param $needle + * @param $substr + * @param int $times + */ + public function testAfterFirst($expected, $str, $needle, $substr, $times = 1) + { + $this->assertEquals($expected, libstr_afterFirst($str, $needle, $substr, $times), $str); + } + public function afterFirstProvider() + { + return [ + ['CameHERE!HERE!lCase', 'CamelCase', 'me', 'HERE!', 2], + ['Camel-Case', 'Camel-Case', 'e', 'not gonna happen', 0], + ['Στανν_νιλ case', 'Στανιλ case', 'ν', 'ν_ν'] + ]; + } + + /** + * @dataProvider beforeFirstProvider() + * @param $expected + * @param $str + * @param $needle + * @param $substr + * @param int $times + */ + public function testBeforeFirst($expected, $str, $needle, $substr, $times = 1) + { + $this->assertEquals($expected, libstr_beforeFirst($str, $needle, $substr, $times), $str); + } + public function beforeFirstProvider() + { + return [ + ['CaHERE!HERE!melCase', 'CamelCase', 'me', 'HERE!', 2], + ['Camel-Case', 'Camel-Case', 'e', 'not gonna happen', 0], + ['Σταν_ννιλ case', 'Στανιλ case', 'ν', 'ν_ν'] + ]; + } + + /** + * @dataProvider afterLastProvider() + * @param $expected + * @param $str + * @param $needle + * @param $substr + * @param int $times + */ + public function testAfterLast($expected, $str, $needle, $substr, $times = 1) + { + $this->assertEquals($expected, libstr_afterLast($str, $needle, $substr, $times), $str); + } + public function afterLastProvider() + { + return [ + ['CamelCaHERE!HERE!se', 'CamelCase', 'a', 'HERE!', 2], + ['Camel-Case', 'Camel-Case', 'e', 'not gonna happen', 0], + ['Στανιλν_ν case', 'Στανιλ case', 'λ', 'ν_ν'] + ]; + } + + /** + * @dataProvider beforeLastProvider() + * @param $expected + * @param $str + * @param $needle + * @param $substr + * @param int $times + */ + public function testBeforeLastFirst($expected, $str, $needle, $substr, $times = 1) + { + $this->assertEquals($expected, libstr_beforeLast($str, $needle, $substr, $times), $str); + } + public function beforeLastProvider() + { + return [ + ['CamelCHERE!HERE!ase', 'CamelCase', 'a', 'HERE!', 2], + ['Camel-Case', 'Camel-Case', 'e', 'not gonna happen', 0], + ['Στανιν_νλ case', 'Στανιλ case', 'λ', 'ν_ν'] + ]; + } } diff --git a/tests/FS/StrTest.php b/tests/FS/StrTest.php index cf4bf75..96ba190 100644 --- a/tests/FS/StrTest.php +++ b/tests/FS/StrTest.php @@ -129,6 +129,10 @@ public function testModifiers() $this->assertEquals('Strwithwhitespace', $s->upperCamelize()); $this->assertEquals('rwStithwhitespace', $s->move(0, 2, 4)); $this->assertEquals('rw_stithwhitespace', $s->snakeize()); + $this->assertEquals('rw_stit_here!_hwhitespace', $s->afterFirst('it', '_here!_')); + $this->assertEquals('rw_stit_h_here!_ere!_hwhitespace', $s->beforeFirst('e', '_here!_')); + $this->assertEquals('rw_stit_h_here!_ere!_hwhit_ttt!_espace', $s->afterLast('t', '_ttt!_')); + $this->assertEquals('rw_stit_h_here!_ere!_hwhit_tt_morett!_t!_espace', $s->beforeLast('t', '_morett!_')); $s = new Str('I see…'); $this->assertEquals('I see...', $s->tidy()); From 9d453e8448bc8b77fbc83eaa98a11a4f4552e03d Mon Sep 17 00:00:00 2001 From: irhen Date: Fri, 2 Mar 2018 19:50:16 +0300 Subject: [PATCH 5/6] readme updated --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4b1fa27..b1c2888 100644 --- a/README.md +++ b/README.md @@ -127,13 +127,13 @@ composer require str/str - [x] move - [x] overwrite - [x] snakeize +- [x] afterFirst +- [x] beforeFirst +- [x] afterLast +- [x] beforeLast ### Todo New - [ ] appendUniqueIdentifier -- [ ] afterFirst -- [ ] beforeFirst -- [ ] afterLast -- [ ] beforeLast - [ ] ord - [ ] quote - [ ] unquote From 159bceb20ba66d1e6cb0ed46c721b1636a2af548 Mon Sep 17 00:00:00 2001 From: irhen Date: Fri, 2 Mar 2018 20:02:57 +0300 Subject: [PATCH 6/6] readme updated again --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b1c2888..bb3c669 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ $send($s->getString()); // same ``` A fast string manipulation library with multi-byte support. -Based on "Stringy" library, with focus on speed. +Inspired by the ["Stringy"](https://github.com/danielstjules/Stringy) library, with focus on speed. Lib uses php7 features and does not throw any exceptions (because all input parameters are @@ -124,6 +124,8 @@ composer require str/str - [x] toTabs - [x] toTitleCase - [x] underscored + +### New Features - [x] move - [x] overwrite - [x] snakeize