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