mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-11-30 04:39:48 +01:00
[Str][Byte] simplify reverse implementation (#160)
This commit is contained in:
parent
3830bc0d26
commit
5482786dac
@ -39,7 +39,7 @@
|
|||||||
- [replace_ci](./../../src/Psl/Str/Byte/replace_ci.php#L15)
|
- [replace_ci](./../../src/Psl/Str/Byte/replace_ci.php#L15)
|
||||||
- [replace_every](./../../src/Psl/Str/Byte/replace_every.php#L17)
|
- [replace_every](./../../src/Psl/Str/Byte/replace_every.php#L17)
|
||||||
- [replace_every_ci](./../../src/Psl/Str/Byte/replace_every_ci.php#L17)
|
- [replace_every_ci](./../../src/Psl/Str/Byte/replace_every_ci.php#L17)
|
||||||
- [reverse](./../../src/Psl/Str/Byte/reverse.php#L10)
|
- [reverse](./../../src/Psl/Str/Byte/reverse.php#L14)
|
||||||
- [rot13](./../../src/Psl/Str/Byte/rot13.php#L14)
|
- [rot13](./../../src/Psl/Str/Byte/rot13.php#L14)
|
||||||
- [search](./../../src/Psl/Str/Byte/search.php#L23)
|
- [search](./../../src/Psl/Str/Byte/search.php#L23)
|
||||||
- [search_ci](./../../src/Psl/Str/Byte/search_ci.php#L23)
|
- [search_ci](./../../src/Psl/Str/Byte/search_ci.php#L23)
|
||||||
|
@ -4,19 +4,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Psl\Str\Byte;
|
namespace Psl\Str\Byte;
|
||||||
|
|
||||||
|
use function strrev;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Reverses the string.
|
||||||
|
*
|
||||||
* @pure
|
* @pure
|
||||||
*/
|
*/
|
||||||
function reverse(string $string): string
|
function reverse(string $string): string
|
||||||
{
|
{
|
||||||
$lo = 0;
|
return strrev($string);
|
||||||
$hi = namespace\length($string) - 1;
|
|
||||||
|
|
||||||
for (; $lo < $hi; $lo++, $hi--) {
|
|
||||||
$temp = $string[$lo];
|
|
||||||
$string[$lo] = $string[$hi];
|
|
||||||
$string[$hi] = $temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $string;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user