@@ -26,7 +26,7 @@ class Preg
2626 public static function match ($ pattern , $ subject , &$ matches = null , $ flags = 0 , $ offset = 0 )
2727 {
2828 if (($ flags & PREG_OFFSET_CAPTURE ) !== 0 ) {
29- throw new \InvalidArgumentException ('PREG_OFFSET_CAPTURE is not supported as it changes the type of $matches, use matchWithOffset () instead ' );
29+ throw new \InvalidArgumentException ('PREG_OFFSET_CAPTURE is not supported as it changes the type of $matches, use matchWithOffsets () instead ' );
3030 }
3131
3232 $ result = preg_match ($ pattern , $ subject , $ matches , $ flags , $ offset );
@@ -49,7 +49,7 @@ public static function match($pattern, $subject, &$matches = null, $flags = 0, $
4949 *
5050 * @phpstan-param array<int|string, array{string|null, int<-1, max>}> $matches
5151 */
52- public static function matchWithOffset ($ pattern , $ subject , &$ matches = null , $ flags = 0 , $ offset = 0 )
52+ public static function matchWithOffsets ($ pattern , $ subject , &$ matches , $ flags = 0 , $ offset = 0 )
5353 {
5454 $ result = preg_match ($ pattern , $ subject , $ matches , $ flags | PREG_OFFSET_CAPTURE , $ offset );
5555 if ($ result === false ) {
@@ -70,7 +70,7 @@ public static function matchWithOffset($pattern, $subject, &$matches = null, $fl
7070 public static function matchAll ($ pattern , $ subject , &$ matches = null , $ flags = 0 , $ offset = 0 )
7171 {
7272 if (($ flags & PREG_OFFSET_CAPTURE ) !== 0 ) {
73- throw new \InvalidArgumentException ('PREG_OFFSET_CAPTURE is not supported as it changes the type of $matches, use matchAllWithOffset () instead ' );
73+ throw new \InvalidArgumentException ('PREG_OFFSET_CAPTURE is not supported as it changes the type of $matches, use matchAllWithOffsets () instead ' );
7474 }
7575
7676 if (($ flags & PREG_SET_ORDER ) !== 0 ) {
@@ -97,7 +97,7 @@ public static function matchAll($pattern, $subject, &$matches = null, $flags = 0
9797 *
9898 * @phpstan-param array<int|string, list<array{string|null, int<-1, max>}>> $matches
9999 */
100- public static function matchAllWithOffset ($ pattern , $ subject , &$ matches = null , $ flags = 0 , $ offset = 0 )
100+ public static function matchAllWithOffsets ($ pattern , $ subject , &$ matches , $ flags = 0 , $ offset = 0 )
101101 {
102102 $ result = preg_match_all ($ pattern , $ subject , $ matches , $ flags | PREG_OFFSET_CAPTURE , $ offset );
103103 if ($ result === false || $ result === null ) {
@@ -195,7 +195,7 @@ public static function replaceCallbackArray(array $pattern, $subject, $limit = -
195195 public static function split ($ pattern , $ subject , $ limit = -1 , $ flags = 0 )
196196 {
197197 if (($ flags & PREG_SPLIT_OFFSET_CAPTURE ) !== 0 ) {
198- throw new \InvalidArgumentException ('PREG_SPLIT_OFFSET_CAPTURE is not supported as it changes the type of $matches, use splitWithOffset () instead ' );
198+ throw new \InvalidArgumentException ('PREG_SPLIT_OFFSET_CAPTURE is not supported as it changes the type of $matches, use splitWithOffsets () instead ' );
199199 }
200200
201201 $ result = preg_split ($ pattern , $ subject , $ limit , $ flags );
@@ -214,7 +214,7 @@ public static function split($pattern, $subject, $limit = -1, $flags = 0)
214214 * @return list<array{string, int}>
215215 * @phpstan-return list<array{string, int<0, max>}>
216216 */
217- public static function splitWithOffset ($ pattern , $ subject , $ limit = -1 , $ flags = 0 )
217+ public static function splitWithOffsets ($ pattern , $ subject , $ limit = -1 , $ flags = 0 )
218218 {
219219 $ result = preg_split ($ pattern , $ subject , $ limit , $ flags | PREG_SPLIT_OFFSET_CAPTURE );
220220 if ($ result === false ) {
@@ -267,4 +267,38 @@ public static function isMatchAll($pattern, $subject, &$matches = null, $flags =
267267 {
268268 return (bool ) static ::matchAll ($ pattern , $ subject , $ matches , $ flags , $ offset );
269269 }
270+
271+ /**
272+ * Runs preg_match_all with PREG_OFFSET_CAPTURE
273+ *
274+ * @param string $pattern
275+ * @param string $subject
276+ * @param array<int|string, array{string|null, int}> $matches Set by method
277+ * @param int $flags PREG_UNMATCHED_AS_NULL, only available on PHP 7.2+
278+ * @param int $offset
279+ * @return bool
280+ *
281+ * @phpstan-param array<int|string, array{string|null, int<-1, max>}> $matches
282+ */
283+ public static function isMatchWithOffsets ($ pattern , $ subject , &$ matches , $ flags = 0 , $ offset = 0 )
284+ {
285+ return (bool ) static ::matchWithOffsets ($ pattern , $ subject , $ matches , $ flags , $ offset );
286+ }
287+
288+ /**
289+ * Runs preg_match_all with PREG_OFFSET_CAPTURE
290+ *
291+ * @param string $pattern
292+ * @param string $subject
293+ * @param array<int|string, list<array{string|null, int}>> $matches Set by method
294+ * @param int $flags PREG_UNMATCHED_AS_NULL, only available on PHP 7.2+
295+ * @param int $offset
296+ * @return bool
297+ *
298+ * @phpstan-param array<int|string, list<array{string|null, int<-1, max>}>> $matches
299+ */
300+ public static function isMatchAllWithOffsets ($ pattern , $ subject , &$ matches , $ flags = 0 , $ offset = 0 )
301+ {
302+ return (bool ) static ::matchAllWithOffsets ($ pattern , $ subject , $ matches , $ flags , $ offset );
303+ }
270304}
0 commit comments