-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathPregLibrary.php
52 lines (45 loc) · 1.97 KB
/
PregLibrary.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* This file is part of the mo4-coding-standard (phpcs standard)
*
* @author Michael Moll <[email protected]>
*
* @license http://spdx.org/licenses/MIT MIT License
*
* @link https://github.com/mayflower/mo4-coding-standard
*/
declare(strict_types=1);
namespace MO4\Library;
use PHP_CodeSniffer\Exceptions\RuntimeException;
class PregLibrary
{
/**
* Split string by a regular expression
*
* @param string $pattern The pattern to search for, as a string.
* @param string $subject The input string.
* @param int $limit If specified, then only substrings up to limit are returned with the rest of the string
* being placed in the last substring. A limit of -1, 0 or NULL means "no limit" and, as is
* standard across PHP, you can use NULL to skip to the flags parameter.
* @param int $flags Can be any combination of the following flags (combined with the | bitwise operator):
* PREG_SPLIT_NO_EMPTY: If this flag is set, only non-empty pieces will be returned.
* PREG_SPLIT_DELIM_CAPTURE: If this flag is set, parenthesized expression in the delimiter
* pattern will be captured and returned as well.
* PREG_SPLIT_OFFSET_CAPTURE: If this flag is set, for every occurring match the appendant
* string offset will also be returned.
*
* @return array<string>|array<array>
*
* @throws RuntimeException
*
* @psalm-suppress ArgumentTypeCoercion
*/
public static function MO4PregSplit(string $pattern, string $subject, int $limit = -1, int $flags = 0): array
{
$pregSplitResult = \preg_split($pattern, $subject, $limit, $flags);
if (false === $pregSplitResult) {
throw new RuntimeException('Unexpected Error in MO4 Coding Standard.');
}
return $pregSplitResult;
}
}