-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
893 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Str\Byte; | ||
|
||
use Psl; | ||
|
||
/** | ||
* @throws Psl\Exception\InvariantViolationException If the $offset is out-of-bounds. | ||
* | ||
* @psalm-pure | ||
*/ | ||
function after(string $haystack, string $needle, bool $include_needle = false, int $offset = 0): string | ||
{ | ||
$offset = search($haystack, $needle, $offset); | ||
if (null === $offset) { | ||
return $haystack; | ||
} | ||
|
||
if (!$include_needle) { | ||
$offset += length($needle); | ||
} | ||
|
||
return slice($haystack, $offset, null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Str\Byte; | ||
|
||
use Psl; | ||
|
||
/** | ||
* @throws Psl\Exception\InvariantViolationException If the $offset is out-of-bounds. | ||
* | ||
* @psalm-pure | ||
*/ | ||
function after_ci( | ||
string $haystack, | ||
string $needle, | ||
bool $include_needle = false, | ||
int $offset = 0 | ||
): string { | ||
$offset = search_ci($haystack, $needle, $offset); | ||
if (null === $offset) { | ||
return $haystack; | ||
} | ||
|
||
if (!$include_needle) { | ||
$offset += length($needle); | ||
} | ||
|
||
return slice($haystack, $offset, null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Str\Byte; | ||
|
||
use Psl; | ||
|
||
/** | ||
* @throws Psl\Exception\InvariantViolationException If the $offset is out-of-bounds. | ||
* @throws Psl\Exception\InvariantViolationException If an invalid $encoding is provided. | ||
* | ||
* @psalm-pure | ||
*/ | ||
function after_last( | ||
string $haystack, | ||
string $needle, | ||
bool $include_needle = false, | ||
int $offset = 0 | ||
): string { | ||
$offset = search_last($haystack, $needle, $offset); | ||
if (null === $offset) { | ||
return $haystack; | ||
} | ||
|
||
if (!$include_needle) { | ||
$offset += length($needle); | ||
} | ||
|
||
return slice($haystack, $offset, null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Str\Byte; | ||
|
||
use Psl; | ||
|
||
/** | ||
* @throws Psl\Exception\InvariantViolationException If the $offset is out-of-bounds. | ||
* | ||
* @psalm-pure | ||
*/ | ||
function after_last_ci( | ||
string $haystack, | ||
string $needle, | ||
bool $include_needle = false, | ||
int $offset = 0 | ||
): string { | ||
$offset = search_last_ci($haystack, $needle, $offset); | ||
if (null === $offset) { | ||
return $haystack; | ||
} | ||
|
||
if (!$include_needle) { | ||
$offset += length($needle); | ||
} | ||
|
||
return slice($haystack, $offset, null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Str\Byte; | ||
|
||
use Psl; | ||
|
||
/** | ||
* @throws Psl\Exception\InvariantViolationException If the $offset is out-of-bounds. | ||
* | ||
* @psalm-pure | ||
*/ | ||
function before( | ||
string $haystack, | ||
string $needle, | ||
bool $include_needle = false, | ||
int $offset = 0 | ||
): string { | ||
$length = search($haystack, $needle, $offset); | ||
if (null === $length) { | ||
return $haystack; | ||
} | ||
|
||
if (!$include_needle) { | ||
$length += length($needle); | ||
} | ||
|
||
return slice($haystack, 0, $length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Str\Byte; | ||
|
||
use Psl; | ||
|
||
/** | ||
* @throws Psl\Exception\InvariantViolationException If the $offset is out-of-bounds. | ||
* | ||
* @psalm-pure | ||
*/ | ||
function before_ci( | ||
string $haystack, | ||
string $needle, | ||
bool $include_needle = false, | ||
int $offset = 0 | ||
): string { | ||
$length = search_ci($haystack, $needle, $offset); | ||
if (null === $length) { | ||
return $haystack; | ||
} | ||
|
||
if (!$include_needle) { | ||
$length += length($needle); | ||
} | ||
|
||
return slice($haystack, 0, $length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Str\Byte; | ||
|
||
use Psl; | ||
|
||
/** | ||
* @throws Psl\Exception\InvariantViolationException If the $offset is out-of-bounds. | ||
* | ||
* @psalm-pure | ||
*/ | ||
function before_last( | ||
string $haystack, | ||
string $needle, | ||
bool $include_needle = false, | ||
int $offset = 0 | ||
): string { | ||
$length = search_last($haystack, $needle, $offset); | ||
if (null === $length) { | ||
return $haystack; | ||
} | ||
|
||
if (!$include_needle) { | ||
$length += length($needle); | ||
} | ||
|
||
return slice($haystack, 0, $length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Str\Byte; | ||
|
||
use Psl; | ||
|
||
/** | ||
* @throws Psl\Exception\InvariantViolationException If the $offset is out-of-bounds. | ||
* | ||
* @psalm-pure | ||
*/ | ||
function before_last_ci( | ||
string $haystack, | ||
string $needle, | ||
bool $include_needle = false, | ||
int $offset = 0 | ||
): string { | ||
$length = search_last_ci($haystack, $needle, $offset); | ||
if (null === $length) { | ||
return $haystack; | ||
} | ||
|
||
if (!$include_needle) { | ||
$length += length($needle); | ||
} | ||
|
||
return slice($haystack, 0, $length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Str\Byte; | ||
|
||
use Psl; | ||
|
||
/** | ||
* Returns the last position of the 'needle' string in the 'haystack' string, | ||
* or null if it isn't found (case-insensitive). | ||
* | ||
* An optional offset determines where in the haystack (from the beginning) the | ||
* search begins. If the offset is negative, the search will begin that many | ||
* characters from the end of the string and go backwards. If the offset is | ||
* out-of-bounds, an InvariantViolationException will be thrown. | ||
* | ||
* @psalm-pure | ||
* | ||
* @throws Psl\Exception\InvariantViolationException If $offset is out-of-bounds. | ||
*/ | ||
function search_last_ci(string $haystack, string $needle, int $offset = 0): ?int | ||
{ | ||
$haystack_length = length($haystack); | ||
Psl\invariant($offset >= -$haystack_length && $offset <= $haystack_length, 'Offset is out-of-bounds.'); | ||
|
||
return false === ($pos = strripos($haystack, $needle, $offset)) ? null : $pos; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Str\Grapheme; | ||
|
||
use Psl; | ||
|
||
/** | ||
* @throws Psl\Exception\InvariantViolationException If the $offset is out-of-bounds. | ||
* | ||
* @psalm-pure | ||
*/ | ||
function after(string $haystack, string $needle, bool $include_needle = false, int $offset = 0): string | ||
{ | ||
$offset = search($haystack, $needle, $offset); | ||
if (null === $offset) { | ||
return $haystack; | ||
} | ||
|
||
if (!$include_needle) { | ||
$offset += length($needle); | ||
} | ||
|
||
return slice($haystack, $offset, null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Str\Grapheme; | ||
|
||
use Psl; | ||
|
||
/** | ||
* @throws Psl\Exception\InvariantViolationException If the $offset is out-of-bounds. | ||
* | ||
* @psalm-pure | ||
*/ | ||
function after_ci( | ||
string $haystack, | ||
string $needle, | ||
bool $include_needle = false, | ||
int $offset = 0 | ||
): string { | ||
$offset = search_ci($haystack, $needle, $offset); | ||
if (null === $offset) { | ||
return $haystack; | ||
} | ||
|
||
if (!$include_needle) { | ||
$offset += length($needle); | ||
} | ||
|
||
return slice($haystack, $offset, null); | ||
} |
Oops, something went wrong.