mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-11-30 04:39:48 +01:00
[Str] add after
and before
helpers (#102)
This commit is contained in:
parent
1f567ab2ed
commit
8ba16a607c
@ -215,6 +215,7 @@ final class Loader
|
||||
'Psl\Str\Byte\search',
|
||||
'Psl\Str\Byte\search_ci',
|
||||
'Psl\Str\Byte\search_last',
|
||||
'Psl\Str\Byte\search_last_ci',
|
||||
'Psl\Str\Byte\shuffle',
|
||||
'Psl\Str\Byte\slice',
|
||||
'Psl\Str\Byte\splice',
|
||||
@ -229,6 +230,14 @@ final class Loader
|
||||
'Psl\Str\Byte\uppercase',
|
||||
'Psl\Str\Byte\words',
|
||||
'Psl\Str\Byte\wrap',
|
||||
'Psl\Str\Byte\after',
|
||||
'Psl\Str\Byte\after_ci',
|
||||
'Psl\Str\Byte\after_last',
|
||||
'Psl\Str\Byte\after_last_ci',
|
||||
'Psl\Str\Byte\before',
|
||||
'Psl\Str\Byte\before_ci',
|
||||
'Psl\Str\Byte\before_last',
|
||||
'Psl\Str\Byte\before_last_ci',
|
||||
'Psl\Str\capitalize',
|
||||
'Psl\Str\capitalize_words',
|
||||
'Psl\Str\chr',
|
||||
@ -278,6 +287,14 @@ final class Loader
|
||||
'Psl\Str\uppercase',
|
||||
'Psl\Str\width',
|
||||
'Psl\Str\wrap',
|
||||
'Psl\Str\after',
|
||||
'Psl\Str\after_ci',
|
||||
'Psl\Str\after_last',
|
||||
'Psl\Str\after_last_ci',
|
||||
'Psl\Str\before',
|
||||
'Psl\Str\before_ci',
|
||||
'Psl\Str\before_last',
|
||||
'Psl\Str\before_last_ci',
|
||||
'Psl\invariant',
|
||||
'Psl\invariant_violation',
|
||||
'Psl\sequence',
|
||||
@ -353,6 +370,14 @@ final class Loader
|
||||
'Psl\Str\Grapheme\starts_with_ci',
|
||||
'Psl\Str\Grapheme\strip_prefix',
|
||||
'Psl\Str\Grapheme\strip_suffix',
|
||||
'Psl\Str\Grapheme\after',
|
||||
'Psl\Str\Grapheme\after_ci',
|
||||
'Psl\Str\Grapheme\after_last',
|
||||
'Psl\Str\Grapheme\after_last_ci',
|
||||
'Psl\Str\Grapheme\before',
|
||||
'Psl\Str\Grapheme\before_ci',
|
||||
'Psl\Str\Grapheme\before_last',
|
||||
'Psl\Str\Grapheme\before_last_ci',
|
||||
];
|
||||
|
||||
public const INTERFACES = [
|
||||
|
24
src/Psl/Str/Byte/after.php
Normal file
24
src/Psl/Str/Byte/after.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?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, int $offset = 0): ?string
|
||||
{
|
||||
$position = search($haystack, $needle, $offset);
|
||||
if (null === $position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position += length($needle);
|
||||
|
||||
return slice($haystack, $position);
|
||||
}
|
27
src/Psl/Str/Byte/after_ci.php
Normal file
27
src/Psl/Str/Byte/after_ci.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?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,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$position = search_ci($haystack, $needle, $offset);
|
||||
if (null === $position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position += length($needle);
|
||||
|
||||
return slice($haystack, $position);
|
||||
}
|
28
src/Psl/Str/Byte/after_last.php
Normal file
28
src/Psl/Str/Byte/after_last.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?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,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$position = search_last($haystack, $needle, $offset);
|
||||
if (null === $position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position += length($needle);
|
||||
|
||||
return slice($haystack, $position);
|
||||
}
|
27
src/Psl/Str/Byte/after_last_ci.php
Normal file
27
src/Psl/Str/Byte/after_last_ci.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?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,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$position = search_last_ci($haystack, $needle, $offset);
|
||||
if (null === $position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position += length($needle);
|
||||
|
||||
return slice($haystack, $position);
|
||||
}
|
25
src/Psl/Str/Byte/before.php
Normal file
25
src/Psl/Str/Byte/before.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?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,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$length = search($haystack, $needle, $offset);
|
||||
if (null === $length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return slice($haystack, 0, $length);
|
||||
}
|
25
src/Psl/Str/Byte/before_ci.php
Normal file
25
src/Psl/Str/Byte/before_ci.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?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,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$length = search_ci($haystack, $needle, $offset);
|
||||
if (null === $length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return slice($haystack, 0, $length);
|
||||
}
|
25
src/Psl/Str/Byte/before_last.php
Normal file
25
src/Psl/Str/Byte/before_last.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?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,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$length = search_last($haystack, $needle, $offset);
|
||||
if (null === $length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return slice($haystack, 0, $length);
|
||||
}
|
25
src/Psl/Str/Byte/before_last_ci.php
Normal file
25
src/Psl/Str/Byte/before_last_ci.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?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,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$length = search_last_ci($haystack, $needle, $offset);
|
||||
if (null === $length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return slice($haystack, 0, $length);
|
||||
}
|
@ -23,6 +23,10 @@ use function strrpos;
|
||||
*/
|
||||
function search_last(string $haystack, string $needle, int $offset = 0): ?int
|
||||
{
|
||||
if ('' === $needle) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$haystack_length = length($haystack);
|
||||
Psl\invariant($offset >= -$haystack_length && $offset <= $haystack_length, 'Offset is out-of-bounds.');
|
||||
|
||||
|
32
src/Psl/Str/Byte/search_last_ci.php
Normal file
32
src/Psl/Str/Byte/search_last_ci.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?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
|
||||
{
|
||||
if ('' === $needle) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
24
src/Psl/Str/Grapheme/after.php
Normal file
24
src/Psl/Str/Grapheme/after.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?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, int $offset = 0): ?string
|
||||
{
|
||||
$position = search($haystack, $needle, $offset);
|
||||
if (null === $position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position += length($needle);
|
||||
|
||||
return slice($haystack, $position);
|
||||
}
|
27
src/Psl/Str/Grapheme/after_ci.php
Normal file
27
src/Psl/Str/Grapheme/after_ci.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?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,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$position = search_ci($haystack, $needle, $offset);
|
||||
if (null === $position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position += length($needle);
|
||||
|
||||
return slice($haystack, $position);
|
||||
}
|
28
src/Psl/Str/Grapheme/after_last.php
Normal file
28
src/Psl/Str/Grapheme/after_last.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Str\Grapheme;
|
||||
|
||||
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,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$position = search_last($haystack, $needle, $offset);
|
||||
if (null === $position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position += length($needle);
|
||||
|
||||
return slice($haystack, $position);
|
||||
}
|
27
src/Psl/Str/Grapheme/after_last_ci.php
Normal file
27
src/Psl/Str/Grapheme/after_last_ci.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?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_last_ci(
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$position = search_last_ci($haystack, $needle, $offset);
|
||||
if (null === $position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position += length($needle);
|
||||
|
||||
return slice($haystack, $position);
|
||||
}
|
25
src/Psl/Str/Grapheme/before.php
Normal file
25
src/Psl/Str/Grapheme/before.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?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 before(
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$length = search($haystack, $needle, $offset);
|
||||
if (null === $length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return slice($haystack, 0, $length);
|
||||
}
|
25
src/Psl/Str/Grapheme/before_ci.php
Normal file
25
src/Psl/Str/Grapheme/before_ci.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?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 before_ci(
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$length = search_ci($haystack, $needle, $offset);
|
||||
if (null === $length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return slice($haystack, 0, $length);
|
||||
}
|
25
src/Psl/Str/Grapheme/before_last.php
Normal file
25
src/Psl/Str/Grapheme/before_last.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?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 before_last(
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$length = search_last($haystack, $needle, $offset);
|
||||
if (null === $length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return slice($haystack, 0, $length);
|
||||
}
|
25
src/Psl/Str/Grapheme/before_last_ci.php
Normal file
25
src/Psl/Str/Grapheme/before_last_ci.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?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 before_last_ci(
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset = 0
|
||||
): ?string {
|
||||
$length = search_last_ci($haystack, $needle, $offset);
|
||||
if (null === $length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return slice($haystack, 0, $length);
|
||||
}
|
29
src/Psl/Str/after.php
Normal file
29
src/Psl/Str/after.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Str;
|
||||
|
||||
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(
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset = 0,
|
||||
?string $encoding = null
|
||||
): ?string {
|
||||
$position = search($haystack, $needle, $offset, $encoding);
|
||||
if (null === $position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position += length($needle);
|
||||
|
||||
return slice($haystack, $position, null, $encoding);
|
||||
}
|
29
src/Psl/Str/after_ci.php
Normal file
29
src/Psl/Str/after_ci.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Str;
|
||||
|
||||
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_ci(
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset = 0,
|
||||
?string $encoding = null
|
||||
): ?string {
|
||||
$position = search_ci($haystack, $needle, $offset, $encoding);
|
||||
if (null === $position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position += length($needle);
|
||||
|
||||
return slice($haystack, $position, null, $encoding);
|
||||
}
|
29
src/Psl/Str/after_last.php
Normal file
29
src/Psl/Str/after_last.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Str;
|
||||
|
||||
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,
|
||||
int $offset = 0,
|
||||
?string $encoding = null
|
||||
): ?string {
|
||||
$position = search_last($haystack, $needle, $offset, $encoding);
|
||||
if (null === $position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position += length($needle);
|
||||
|
||||
return slice($haystack, $position, null, $encoding);
|
||||
}
|
29
src/Psl/Str/after_last_ci.php
Normal file
29
src/Psl/Str/after_last_ci.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Str;
|
||||
|
||||
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_ci(
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset = 0,
|
||||
?string $encoding = null
|
||||
): ?string {
|
||||
$position = search_last_ci($haystack, $needle, $offset, $encoding);
|
||||
if (null === $position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position += length($needle);
|
||||
|
||||
return slice($haystack, $position, null, $encoding);
|
||||
}
|
27
src/Psl/Str/before.php
Normal file
27
src/Psl/Str/before.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Str;
|
||||
|
||||
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 before(
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset = 0,
|
||||
?string $encoding = null
|
||||
): ?string {
|
||||
$length = search($haystack, $needle, $offset, $encoding);
|
||||
if (null === $length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return slice($haystack, 0, $length, $encoding);
|
||||
}
|
27
src/Psl/Str/before_ci.php
Normal file
27
src/Psl/Str/before_ci.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Str;
|
||||
|
||||
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 before_ci(
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset = 0,
|
||||
?string $encoding = null
|
||||
): ?string {
|
||||
$length = search_ci($haystack, $needle, $offset, $encoding);
|
||||
if (null === $length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return slice($haystack, 0, $length, $encoding);
|
||||
}
|
27
src/Psl/Str/before_last.php
Normal file
27
src/Psl/Str/before_last.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Str;
|
||||
|
||||
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 before_last(
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset = 0,
|
||||
?string $encoding = null
|
||||
): ?string {
|
||||
$length = search_last($haystack, $needle, $offset, $encoding);
|
||||
if (null === $length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return slice($haystack, 0, $length, $encoding);
|
||||
}
|
27
src/Psl/Str/before_last_ci.php
Normal file
27
src/Psl/Str/before_last_ci.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Str;
|
||||
|
||||
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 before_last_ci(
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset = 0,
|
||||
?string $encoding = null
|
||||
): ?string {
|
||||
$length = search_last_ci($haystack, $needle, $offset, $encoding);
|
||||
if (null === $length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return slice($haystack, 0, $length, $encoding);
|
||||
}
|
45
tests/Psl/Str/AfterCiTest.php
Normal file
45
tests/Psl/Str/AfterCiTest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str;
|
||||
|
||||
final class AfterCiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset,
|
||||
?string $encoding
|
||||
): void {
|
||||
static::assertSame($expected, Str\after_ci($haystack, $needle, $offset, $encoding));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0, null],
|
||||
['orld!', 'Hello, World!', 'W', 0, null],
|
||||
['!', '🤷!', '🤷', 0, null],
|
||||
[null, 'مرحبا بكم', '', 0, null],
|
||||
[null, 'مرحبا بكم', 'ß', 0, null],
|
||||
[', wôrld!', 'héllö, wôrld!', 'héllö', 0, null],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
['好', '你好', '你', 0, null],
|
||||
['にちは世界', 'こんにちは世界', 'こん', 0, null],
|
||||
['สดี', 'สวัสดี', 'วั', 0, null],
|
||||
[', world!', 'Hello, world!', 'o', 0, null],
|
||||
['rld!', 'Hello, world!', 'o', 7, null],
|
||||
];
|
||||
}
|
||||
}
|
45
tests/Psl/Str/AfterLastCiTest.php
Normal file
45
tests/Psl/Str/AfterLastCiTest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str;
|
||||
|
||||
final class AfterLastCiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset,
|
||||
?string $encoding
|
||||
): void {
|
||||
static::assertSame($expected, Str\after_last_ci($haystack, $needle, $offset, $encoding));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0, null],
|
||||
['orld!', 'Hello, World!', 'W', 0, null],
|
||||
['!', '🤷!', '🤷', 0, null],
|
||||
[null, 'مرحبا بكم', '', 0, null],
|
||||
[null, 'مرحبا بكم', 'ß', 0, null],
|
||||
[', wôrld!', 'héllö, wôrld!', 'héllö', 0, null],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
['好', '你好', '你', 0, null],
|
||||
['にちは世界', 'こんにちは世界', 'こん', 0, null],
|
||||
['สดี', 'สวัสดี', 'วั', 0, null],
|
||||
['rld!', 'Hello, world!', 'o', 0, null],
|
||||
['rld!', 'Hello, world!', 'o', 7, null],
|
||||
];
|
||||
}
|
||||
}
|
45
tests/Psl/Str/AfterLastTest.php
Normal file
45
tests/Psl/Str/AfterLastTest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str;
|
||||
|
||||
final class AfterLastTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset,
|
||||
?string $encoding
|
||||
): void {
|
||||
static::assertSame($expected, Str\after_last($haystack, $needle, $offset, $encoding));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0, null],
|
||||
['orld!', 'Hello, World!', 'W', 0, null],
|
||||
['!', '🤷!', '🤷', 0, null],
|
||||
[null, 'مرحبا بكم', '', 0, null],
|
||||
[null, 'مرحبا بكم', 'ß', 0, null],
|
||||
[', wôrld!', 'héllö, wôrld!', 'héllö', 0, null],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
['好', '你好', '你', 0, null],
|
||||
['にちは世界', 'こんにちは世界', 'こん', 0, null],
|
||||
['สดี', 'สวัสดี', 'วั', 0, null],
|
||||
['rld!', 'Hello, world!', 'o', 0, null],
|
||||
['rld!', 'Hello, world!', 'o', 7, null],
|
||||
];
|
||||
}
|
||||
}
|
46
tests/Psl/Str/AfterTest.php
Normal file
46
tests/Psl/Str/AfterTest.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str;
|
||||
|
||||
final class AfterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset,
|
||||
?string $encoding
|
||||
): void {
|
||||
static::assertSame($expected, Str\after($haystack, $needle, $offset, $encoding));
|
||||
}
|
||||
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0, null],
|
||||
['orld!', 'Hello, World!', 'W', 0, null],
|
||||
['!', '🤷!', '🤷', 0, null],
|
||||
[null, 'مرحبا بكم', '', 0, null],
|
||||
[null, 'مرحبا بكم', 'ß', 0, null],
|
||||
[', wôrld!', 'héllö, wôrld!', 'héllö', 0, null],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
['好', '你好', '你', 0, null],
|
||||
['にちは世界', 'こんにちは世界', 'こん', 0, null],
|
||||
['สดี', 'สวัสดี', 'วั', 0, null],
|
||||
[', world!', 'Hello, world!', 'o', 0, null],
|
||||
['rld!', 'Hello, world!', 'o', 7, null],
|
||||
];
|
||||
}
|
||||
}
|
52
tests/Psl/Str/BeforeCiTest.php
Normal file
52
tests/Psl/Str/BeforeCiTest.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str;
|
||||
|
||||
final class BeforeCiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset,
|
||||
?string $encoding
|
||||
): void {
|
||||
static::assertSame($expected, Str\before_ci($haystack, $needle, $offset, $encoding));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0, null],
|
||||
['Hello, ', 'Hello, World!', 'W', 0, null],
|
||||
['', '🤷!', '🤷', 0, null],
|
||||
[null, 'مرحبا بكم', '', 0, null],
|
||||
[null, 'مرحبا بكم', 'ß', 0, null],
|
||||
['', 'héllö, wôrld!', 'héllö', 0, null],
|
||||
['', 'ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
['', 'ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
['', 'Ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
['', 'Ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
['héllö, ', 'héllö, wôrld!', 'w', 0, null],
|
||||
['ḫéllö, ', 'ḫéllö, wôrld!', 'w', 0, null],
|
||||
['ḫéllö, ', 'ḫéllö, wôrld!', 'w', 0, null],
|
||||
['Ḫéllö, ', 'Ḫéllö, Wôrld!', 'w', 0, null],
|
||||
['Ḫéllö, ', 'Ḫéllö, wôrld!', 'w', 0, null],
|
||||
['你', '你好', '好', 0, null],
|
||||
['', '你好', '你', 0, null],
|
||||
['こんにちは世', 'こんにちは世界', '界', 0, null],
|
||||
['こんに', 'こんにちは世界', 'ち', 0, null],
|
||||
['ส ว ั ส ด', 'ส ว ั ส ด ี', ' ี', 0, null],
|
||||
['Hell', 'Hello, world!', 'o', 0, null],
|
||||
['Hello, w', 'Hello, world!', 'o', 7, null],
|
||||
];
|
||||
}
|
||||
}
|
50
tests/Psl/Str/BeforeLastCiTest.php
Normal file
50
tests/Psl/Str/BeforeLastCiTest.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str;
|
||||
|
||||
final class BeforeLastCiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset,
|
||||
?string $encoding
|
||||
): void {
|
||||
static::assertSame($expected, Str\before_last_ci($haystack, $needle, $offset, $encoding));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0, null],
|
||||
['Hello, ', 'Hello, World!', 'W', 0, null],
|
||||
['', '🤷!', '🤷', 0, null],
|
||||
[null, 'مرحبا بكم', '', 0, null],
|
||||
[null, 'مرحبا بكم', 'ß', 0, null],
|
||||
['', 'héllö, wôrld!', 'héllö', 0, null],
|
||||
['', 'ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
['', 'ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
['', 'Ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
['', 'Ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
['héllö, ', 'héllö, Wôrld!', 'wôrld', 0, null],
|
||||
['ḫéllö, ', 'ḫéllö, wôrld!', 'Wôrld', 0, null],
|
||||
['ḫéllö, ', 'ḫéllö, Wôrld!', 'wôrld', 0, null],
|
||||
['Ḫéllö, ', 'Ḫéllö, wôrld!', 'Wôrld', 0, null],
|
||||
['Ḫéllö, ', 'Ḫéllö, Wôrld!', 'wôrld', 0, null],
|
||||
['你', '你好', '好', 0, null],
|
||||
['こんにちは', 'こんにちは世界', '世界', 0, null],
|
||||
['สวัส', 'สวัสดี', 'ดี', 0, null],
|
||||
['Hello, w', 'Hello, world!', 'o', 0, null],
|
||||
['Hello, w', 'Hello, world!', 'o', 7, null],
|
||||
];
|
||||
}
|
||||
}
|
51
tests/Psl/Str/BeforeLastTest.php
Normal file
51
tests/Psl/Str/BeforeLastTest.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str;
|
||||
|
||||
final class BeforeLastTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset,
|
||||
?string $encoding
|
||||
): void {
|
||||
static::assertSame($expected, Str\before_last($haystack, $needle, $offset, $encoding));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0, null],
|
||||
['Hello, ', 'Hello, World!', 'W', 0, null],
|
||||
['', '🤷!', '🤷', 0, null],
|
||||
[null, 'مرحبا بكم', '', 0, null],
|
||||
[null, 'مرحبا بكم', 'ß', 0, null],
|
||||
['', 'héllö, wôrld!', 'héllö', 0, null],
|
||||
['', 'ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
['', 'Ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
[null, 'héllö, Wôrld!', 'wôrld', 0, null],
|
||||
[null, 'ḫéllö, wôrld!', 'Wôrld', 0, null],
|
||||
[null, 'ḫéllö, Wôrld!', 'wôrld', 0, null],
|
||||
[null, 'Ḫéllö, wôrld!', 'Wôrld', 0, null],
|
||||
[null, 'Ḫéllö, Wôrld!', 'wôrld', 0, null],
|
||||
['Ḫéllö, ', 'Ḫéllö, Wôrld!', 'Wôrld', 0, null],
|
||||
['你', '你好', '好', 0, null],
|
||||
['こんにちは', 'こんにちは世界', '世界', 0, null],
|
||||
['สวัส', 'สวัสดี', 'ดี', 0, null],
|
||||
['Hello, w', 'Hello, world!', 'o', 0, null],
|
||||
['Hello, w', 'Hello, world!', 'o', 7, null],
|
||||
];
|
||||
}
|
||||
}
|
52
tests/Psl/Str/BeforeTest.php
Normal file
52
tests/Psl/Str/BeforeTest.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str;
|
||||
|
||||
final class BeforeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset,
|
||||
?string $encoding
|
||||
): void {
|
||||
static::assertSame($expected, Str\before($haystack, $needle, $offset, $encoding));
|
||||
}
|
||||
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0, null],
|
||||
['Hello, ', 'Hello, World!', 'W', 0, null],
|
||||
['', '🤷!', '🤷', 0, null],
|
||||
[null, 'مرحبا بكم', '', 0, null],
|
||||
[null, 'مرحبا بكم', 'ß', 0, null],
|
||||
['', 'héllö, wôrld!', 'héllö', 0, null],
|
||||
['', 'ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
['', 'Ḫéllö, wôrld!', 'Ḫéllö', 0, null],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0, null],
|
||||
[null, 'héllö, Wôrld!', 'wôrld', 0, null],
|
||||
[null, 'ḫéllö, wôrld!', 'Wôrld', 0, null],
|
||||
[null, 'ḫéllö, Wôrld!', 'wôrld', 0, null],
|
||||
[null, 'Ḫéllö, wôrld!', 'Wôrld', 0, null],
|
||||
[null, 'Ḫéllö, Wôrld!', 'wôrld', 0, null],
|
||||
['Ḫéllö, ', 'Ḫéllö, Wôrld!', 'Wôrld', 0, null],
|
||||
['你', '你好', '好', 0, null],
|
||||
['こんにちは', 'こんにちは世界', '世界', 0, null],
|
||||
['สวัส', 'สวัสดี', 'ดี', 0, null],
|
||||
['Hell', 'Hello, world!', 'o', 0, null],
|
||||
['Hello, w', 'Hello, world!', 'o', 7, null],
|
||||
];
|
||||
}
|
||||
}
|
48
tests/Psl/Str/Byte/AfterCiTest.php
Normal file
48
tests/Psl/Str/Byte/AfterCiTest.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Byte;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Byte;
|
||||
|
||||
final class AfterCiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Byte\after_ci($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['orld!', 'Hello, World!', 'W', 0],
|
||||
['!', '🤷!', '🤷', 0],
|
||||
['', '🤷!', '!', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
[', wôrld!', 'héllö, wôrld!', 'héllö', 0],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[', world!', 'Hello, world!', 'Hello', 0],
|
||||
[', world!', 'Hello, world!', 'hello', 0],
|
||||
[', world!', 'hello, world!', 'Hello', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['好', '你好', '你', 0],
|
||||
['にちは世界', 'こんにちは世界', 'こん', 0],
|
||||
['สดี', 'สวัสดี', 'วั', 0],
|
||||
[', world!', 'Hello, world!', 'o', 0],
|
||||
['rld!', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
44
tests/Psl/Str/Byte/AfterLastCiTest.php
Normal file
44
tests/Psl/Str/Byte/AfterLastCiTest.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Byte;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Byte;
|
||||
|
||||
final class AfterLastCiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Byte\after_last_ci($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['orld!', 'Hello, World!', 'W', 0],
|
||||
['!', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
[', wôrld!', 'héllö, wôrld!', 'héllö', 0],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['好', '你好', '你', 0],
|
||||
['にちは世界', 'こんにちは世界', 'こん', 0],
|
||||
['สดี', 'สวัสดี', 'วั', 0],
|
||||
['rld!', 'Hello, world!', 'o', 0],
|
||||
['rld!', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
44
tests/Psl/Str/Byte/AfterLastTest.php
Normal file
44
tests/Psl/Str/Byte/AfterLastTest.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Byte;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Byte;
|
||||
|
||||
final class AfterLastTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Byte\after_last($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['orld!', 'Hello, World!', 'W', 0],
|
||||
['!', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
[', wôrld!', 'héllö, wôrld!', 'héllö', 0],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['好', '你好', '你', 0],
|
||||
['にちは世界', 'こんにちは世界', 'こん', 0],
|
||||
['สดี', 'สวัสดี', 'วั', 0],
|
||||
['rld!', 'Hello, world!', 'o', 0],
|
||||
['rld!', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
45
tests/Psl/Str/Byte/AfterTest.php
Normal file
45
tests/Psl/Str/Byte/AfterTest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Byte;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Byte;
|
||||
|
||||
final class AfterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Byte\after($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['orld!', 'Hello, World!', 'W', 0],
|
||||
['!', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
[', wôrld!', 'héllö, wôrld!', 'héllö', 0],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['好', '你好', '你', 0],
|
||||
['にちは世界', 'こんにちは世界', 'こん', 0],
|
||||
['สดี', 'สวัสดี', 'วั', 0],
|
||||
[', world!', 'Hello, world!', 'o', 0],
|
||||
['rld!', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
51
tests/Psl/Str/Byte/BeforeCiTest.php
Normal file
51
tests/Psl/Str/Byte/BeforeCiTest.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Byte;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Byte;
|
||||
|
||||
final class BeforeCiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Byte\before_ci($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['Hello, ', 'Hello, World!', 'W', 0],
|
||||
['', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
['', 'héllö, wôrld!', 'héllö', 0],
|
||||
['', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
['', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['héllö, ', 'héllö, wôrld!', 'w', 0],
|
||||
['ḫéllö, ', 'ḫéllö, wôrld!', 'w', 0],
|
||||
['ḫéllö, ', 'ḫéllö, wôrld!', 'w', 0],
|
||||
['Ḫéllö, ', 'Ḫéllö, Wôrld!', 'w', 0],
|
||||
['Ḫéllö, ', 'Ḫéllö, wôrld!', 'w', 0],
|
||||
['你', '你好', '好', 0],
|
||||
['', '你好', '你', 0],
|
||||
['こんにちは世', 'こんにちは世界', '界', 0],
|
||||
['こんに', 'こんにちは世界', 'ち', 0],
|
||||
['ส ว ั ส ด', 'ส ว ั ส ด ี', ' ี', 0],
|
||||
['Hell', 'Hello, world!', 'o', 0],
|
||||
['Hello, w', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
49
tests/Psl/Str/Byte/BeforeLastCiTest.php
Normal file
49
tests/Psl/Str/Byte/BeforeLastCiTest.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Byte;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Byte;
|
||||
|
||||
final class BeforeLastCiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Byte\before_last_ci($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['Hello, ', 'Hello, World!', 'W', 0],
|
||||
['', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
['', 'héllö, wôrld!', 'héllö', 0],
|
||||
['', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
['', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['héllö, ', 'héllö, Wôrld!', 'wôrld', 0],
|
||||
['ḫéllö, ', 'ḫéllö, wôrld!', 'Wôrld', 0],
|
||||
['ḫéllö, ', 'ḫéllö, Wôrld!', 'wôrld', 0],
|
||||
['Ḫéllö, ', 'Ḫéllö, wôrld!', 'Wôrld', 0],
|
||||
['Ḫéllö, ', 'Ḫéllö, Wôrld!', 'wôrld', 0],
|
||||
['你', '你好', '好', 0],
|
||||
['こんにちは', 'こんにちは世界', '世界', 0],
|
||||
['สวัส', 'สวัสดี', 'ดี', 0],
|
||||
['Hello, w', 'Hello, world!', 'o', 0],
|
||||
['Hello, w', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
50
tests/Psl/Str/Byte/BeforeLastTest.php
Normal file
50
tests/Psl/Str/Byte/BeforeLastTest.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Byte;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Byte;
|
||||
|
||||
final class BeforeLastTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Byte\before_last($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['Hello, ', 'Hello, World!', 'W', 0],
|
||||
['', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
['', 'héllö, wôrld!', 'héllö', 0],
|
||||
['', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
['', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'héllö, Wôrld!', 'wôrld', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Wôrld', 0],
|
||||
[null, 'ḫéllö, Wôrld!', 'wôrld', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'Wôrld', 0],
|
||||
[null, 'Ḫéllö, Wôrld!', 'wôrld', 0],
|
||||
['Ḫéllö, ', 'Ḫéllö, Wôrld!', 'Wôrld', 0],
|
||||
['你', '你好', '好', 0],
|
||||
['こんにちは', 'こんにちは世界', '世界', 0],
|
||||
['สวัส', 'สวัสดี', 'ดี', 0],
|
||||
['Hello, w', 'Hello, world!', 'o', 0],
|
||||
['Hello, w', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
51
tests/Psl/Str/Byte/BeforeTest.php
Normal file
51
tests/Psl/Str/Byte/BeforeTest.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Byte;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Byte;
|
||||
|
||||
final class BeforeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Byte\before($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['Hello, ', 'Hello, World!', 'W', 0],
|
||||
['', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
['', 'héllö, wôrld!', 'héllö', 0],
|
||||
['', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
['', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'héllö, Wôrld!', 'wôrld', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Wôrld', 0],
|
||||
[null, 'ḫéllö, Wôrld!', 'wôrld', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'Wôrld', 0],
|
||||
[null, 'Ḫéllö, Wôrld!', 'wôrld', 0],
|
||||
['Ḫéllö, ', 'Ḫéllö, Wôrld!', 'Wôrld', 0],
|
||||
['你', '你好', '好', 0],
|
||||
['こんにちは', 'こんにちは世界', '世界', 0],
|
||||
['สวัส', 'สวัสดี', 'ดี', 0],
|
||||
['Hell', 'Hello, world!', 'o', 0],
|
||||
['Hello, w', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
47
tests/Psl/Str/Grapheme/AfterCiTest.php
Normal file
47
tests/Psl/Str/Grapheme/AfterCiTest.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Grapheme;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Grapheme;
|
||||
|
||||
final class AfterCiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Grapheme\after_ci($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['orld!', 'Hello, World!', 'W', 0],
|
||||
['!', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
[', wôrld!', 'héllö, wôrld!', 'héllö', 0],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[', world!', 'Hello, world!', 'Hello', 0],
|
||||
[', world!', 'Hello, world!', 'hello', 0],
|
||||
[', world!', 'hello, world!', 'Hello', 0],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['好', '你好', '你', 0],
|
||||
['にちは世界', 'こんにちは世界', 'こん', 0],
|
||||
['สดี', 'สวัสดี', 'วั', 0],
|
||||
[', world!', 'Hello, world!', 'o', 0],
|
||||
['rld!', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
44
tests/Psl/Str/Grapheme/AfterLastCiTest.php
Normal file
44
tests/Psl/Str/Grapheme/AfterLastCiTest.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Grapheme;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Grapheme;
|
||||
|
||||
final class AfterLastCiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Grapheme\after_last_ci($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['orld!', 'Hello, World!', 'W', 0],
|
||||
['!', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
[', wôrld!', 'héllö, wôrld!', 'héllö', 0],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['好', '你好', '你', 0],
|
||||
['にちは世界', 'こんにちは世界', 'こん', 0],
|
||||
['สดี', 'สวัสดี', 'วั', 0],
|
||||
['rld!', 'Hello, world!', 'o', 0],
|
||||
['rld!', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
44
tests/Psl/Str/Grapheme/AfterLastTest.php
Normal file
44
tests/Psl/Str/Grapheme/AfterLastTest.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Grapheme;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Grapheme;
|
||||
|
||||
final class AfterLastTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Grapheme\after_last($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['orld!', 'Hello, World!', 'W', 0],
|
||||
['!', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
[', wôrld!', 'héllö, wôrld!', 'héllö', 0],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['好', '你好', '你', 0],
|
||||
['にちは世界', 'こんにちは世界', 'こん', 0],
|
||||
['สดี', 'สวัสดี', 'วั', 0],
|
||||
['rld!', 'Hello, world!', 'o', 0],
|
||||
['rld!', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
45
tests/Psl/Str/Grapheme/AfterTest.php
Normal file
45
tests/Psl/Str/Grapheme/AfterTest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Grapheme;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Grapheme;
|
||||
|
||||
final class AfterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Grapheme\after($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['orld!', 'Hello, World!', 'W', 0],
|
||||
['!', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
[', wôrld!', 'héllö, wôrld!', 'héllö', 0],
|
||||
[', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['好', '你好', '你', 0],
|
||||
['にちは世界', 'こんにちは世界', 'こん', 0],
|
||||
['สดี', 'สวัสดี', 'วั', 0],
|
||||
[', world!', 'Hello, world!', 'o', 0],
|
||||
['rld!', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
51
tests/Psl/Str/Grapheme/BeforeCiTest.php
Normal file
51
tests/Psl/Str/Grapheme/BeforeCiTest.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Grapheme;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Grapheme;
|
||||
|
||||
final class BeforeCiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Grapheme\before_ci($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['Hello, ', 'Hello, World!', 'W', 0],
|
||||
['', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
['', 'héllö, wôrld!', 'héllö', 0],
|
||||
['', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['', 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
['', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
['', 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['héllö, ', 'héllö, wôrld!', 'w', 0],
|
||||
['ḫéllö, ', 'ḫéllö, wôrld!', 'w', 0],
|
||||
['ḫéllö, ', 'ḫéllö, wôrld!', 'w', 0],
|
||||
['Ḫéllö, ', 'Ḫéllö, Wôrld!', 'w', 0],
|
||||
['Ḫéllö, ', 'Ḫéllö, wôrld!', 'w', 0],
|
||||
['你', '你好', '好', 0],
|
||||
['', '你好', '你', 0],
|
||||
['こんにちは世', 'こんにちは世界', '界', 0],
|
||||
['こんに', 'こんにちは世界', 'ち', 0],
|
||||
['ส ว ั ส ด', 'ส ว ั ส ด ี', ' ี', 0],
|
||||
['Hell', 'Hello, world!', 'o', 0],
|
||||
['Hello, w', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
49
tests/Psl/Str/Grapheme/BeforeLastCiTest.php
Normal file
49
tests/Psl/Str/Grapheme/BeforeLastCiTest.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Grapheme;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Grapheme;
|
||||
|
||||
final class BeforeLastCiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Grapheme\before_last_ci($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['Hello, ', 'Hello, World!', 'W', 0],
|
||||
['', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
['', 'héllö, wôrld!', 'héllö', 0],
|
||||
['', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['', 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
['', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
['', 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
['héllö, ', 'héllö, Wôrld!', 'wôrld', 0],
|
||||
['ḫéllö, ', 'ḫéllö, wôrld!', 'Wôrld', 0],
|
||||
['ḫéllö, ', 'ḫéllö, Wôrld!', 'wôrld', 0],
|
||||
['Ḫéllö, ', 'Ḫéllö, wôrld!', 'Wôrld', 0],
|
||||
['Ḫéllö, ', 'Ḫéllö, Wôrld!', 'wôrld', 0],
|
||||
['你', '你好', '好', 0],
|
||||
['こんにちは', 'こんにちは世界', '世界', 0],
|
||||
['สวัส', 'สวัสดี', 'ดี', 0],
|
||||
['Hello, w', 'Hello, world!', 'o', 0],
|
||||
['Hello, w', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
50
tests/Psl/Str/Grapheme/BeforeLastTest.php
Normal file
50
tests/Psl/Str/Grapheme/BeforeLastTest.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Grapheme;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Grapheme;
|
||||
|
||||
final class BeforeLastTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Grapheme\before_last($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['Hello, ', 'Hello, World!', 'W', 0],
|
||||
['', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
['', 'héllö, wôrld!', 'héllö', 0],
|
||||
['', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
['', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'héllö, Wôrld!', 'wôrld', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Wôrld', 0],
|
||||
[null, 'ḫéllö, Wôrld!', 'wôrld', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'Wôrld', 0],
|
||||
[null, 'Ḫéllö, Wôrld!', 'wôrld', 0],
|
||||
['Ḫéllö, ', 'Ḫéllö, Wôrld!', 'Wôrld', 0],
|
||||
['你', '你好', '好', 0],
|
||||
['こんにちは', 'こんにちは世界', '世界', 0],
|
||||
['สวัส', 'สวัสดี', 'ดี', 0],
|
||||
['Hello, w', 'Hello, world!', 'o', 0],
|
||||
['Hello, w', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
51
tests/Psl/Str/Grapheme/BeforeTest.php
Normal file
51
tests/Psl/Str/Grapheme/BeforeTest.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psl\Tests\Str\Grapheme;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psl\Str\Grapheme;
|
||||
|
||||
final class BeforeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testAfter(
|
||||
?string $expected,
|
||||
string $haystack,
|
||||
string $needle,
|
||||
int $offset
|
||||
): void {
|
||||
static::assertSame($expected, Grapheme\before($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
|
||||
public function provideData(): array
|
||||
{
|
||||
return [
|
||||
[null, '', '', 0],
|
||||
['Hello, ', 'Hello, World!', 'W', 0],
|
||||
['', '🤷!', '🤷', 0],
|
||||
[null, 'مرحبا بكم', '', 0],
|
||||
[null, 'مرحبا بكم', 'ß', 0],
|
||||
['', 'héllö, wôrld!', 'héllö', 0],
|
||||
['', 'ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
['', 'Ḫéllö, wôrld!', 'Ḫéllö', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'ḫéllö', 0],
|
||||
[null, 'héllö, Wôrld!', 'wôrld', 0],
|
||||
[null, 'ḫéllö, wôrld!', 'Wôrld', 0],
|
||||
[null, 'ḫéllö, Wôrld!', 'wôrld', 0],
|
||||
[null, 'Ḫéllö, wôrld!', 'Wôrld', 0],
|
||||
[null, 'Ḫéllö, Wôrld!', 'wôrld', 0],
|
||||
['Ḫéllö, ', 'Ḫéllö, Wôrld!', 'Wôrld', 0],
|
||||
['你', '你好', '好', 0],
|
||||
['こんにちは', 'こんにちは世界', '世界', 0],
|
||||
['สวัส', 'สวัสดี', 'ดี', 0],
|
||||
['Hell', 'Hello, world!', 'o', 0],
|
||||
['Hello, w', 'Hello, world!', 'o', 7],
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user