Skip to content

Commit a40f1b0

Browse files
committed
changed split funcs in Strings
1 parent fd5d9ed commit a40f1b0

File tree

2 files changed

+23
-36
lines changed

2 files changed

+23
-36
lines changed

src/Arrays/ArrayValueFinder.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Strings.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,43 @@
22

33
namespace Utilitte\Php;
44

5-
use JetBrains\PhpStorm\ArrayShape;
6-
75
final class Strings
86
{
97

10-
#[ArrayShape('string', 'string')]
11-
public static function splitByPosition(string $haystack, int $pos): array
8+
/**
9+
* @return array{string|null, string}
10+
*/
11+
public static function splitByNeedle(string $haystack, string $needle): array
12+
{
13+
return self::splitByPositionFalseable($haystack, strpos($haystack, $needle), strlen($needle));
14+
}
15+
16+
public static function joinWith(string $join, string|null ... $arguments): string
17+
{
18+
return implode($join, array_filter($arguments));
19+
}
20+
21+
/**
22+
* @return array{string, string}
23+
*/
24+
public static function splitByPosition(string $haystack, int $pos, int $length = 1): array
1225
{
1326
return [
1427
substr($haystack, 0, $pos),
15-
substr($haystack, $pos + 1),
28+
substr($haystack, $pos + $length),
1629
];
1730
}
1831

19-
#[ArrayShape('string|null', 'string')]
20-
public static function splitByPositionFalseable(string $haystack, int|false $pos): array
32+
/**
33+
* @return array{string|null, string}
34+
*/
35+
public static function splitByPositionFalseable(string $haystack, int|false $pos, int $length = 1): array
2136
{
2237
if ($pos === false) {
2338
return [null, $haystack];
2439
}
2540

26-
return self::splitByPosition($haystack, $pos);
41+
return self::splitByPosition($haystack, $pos, $length);
2742
}
2843

2944
public static function append(?string $string, string $append): ?string

0 commit comments

Comments
 (0)