X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2FStringUtils.php;h=7303d9beb7931018049d1b2dc52874673a29b5ba;hb=efbfa0a727a196e63a2b71f0a82f09150c2be354;hp=19dd8fe4d3f98d54921847402854838468d05c06;hpb=af80076034fb734d652eb043c523c1d8df974e51;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/StringUtils.php b/includes/libs/StringUtils.php index 19dd8fe4d3..7303d9beb7 100644 --- a/includes/libs/StringUtils.php +++ b/includes/libs/StringUtils.php @@ -316,6 +316,23 @@ class StringUtils { return $text; } + /** + * Utility function to check if the given string is a valid PCRE regex. Avoids + * manually calling suppressWarnings and restoreWarnings, and provides a + * one-line solution without the need to use @. + * + * @since 1.34 + * @param string $string The string you want to check being a valid regex + * @return bool + */ + public static function isValidPCRERegex( $string ) { + AtEase::suppressWarnings(); + // @phan-suppress-next-line PhanParamSuspiciousOrder False positive + $isValid = preg_match( $string, '' ); + AtEase::restoreWarnings(); + return $isValid !== false; + } + /** * Escape a string to make it suitable for inclusion in a preg_replace() * replacement parameter. @@ -343,21 +360,4 @@ class StringUtils { return new ArrayIterator( explode( $separator, $subject ) ); } } - - /** - * Utility function to check if the given string is a valid regex. Avoids - * manually calling suppressWarnings and restoreWarnings, and provides a - * one-line solution without the need to use @. - * - * @since 1.34 - * @param string $string The string you want to check being a valid regex - * @return bool - */ - public static function isValidRegex( $string ) { - AtEase::suppressWarnings(); - // @phan-suppress-next-line PhanParamSuspiciousOrder False positive - $isValid = preg_match( $string, '' ); - AtEase::restoreWarnings(); - return $isValid !== false; - } }