diff options
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 36 |
1 files changed, 15 insertions, 21 deletions
@@ -23,7 +23,6 @@ class it { - /** * Create config class with static members initialized (e.g. $home). * NOTE: PHP5 ONLY @@ -349,32 +348,28 @@ static function convertregex($pattern, $p = array()) * @param $p contains pattern modifiers, @see convertregex() * @return Matched string or false */ -static function match($pattern, $string, $p = array()) +static function match($pattern, $string, $p = null) { - $flags = 0; - $p += array('locale' => 'de_CH'); - - if($p['offset_capture']) - $flags |= PREG_OFFSET_CAPTURE; + if (!preg_match('/\\\\[wb]|[!\x80-\xff]/i', $pattern) && !$p) + $r = preg_match('!' . $pattern . '!i', $string, $m); # fast path for simple patterns + else + { + $flags = $p['offset_capture'] ? PREG_OFFSET_CAPTURE : 0; - $oldlocale = setlocale(LC_CTYPE, 0); - setlocale(LC_CTYPE, $p['locale']); + $oldlocale = setlocale(LC_CTYPE, 0); + setlocale(LC_CTYPE, $p['locale'] ? $p['locale'] : "de_CH"); - if ($p['all']) - $r = preg_match_all(it::convertregex($pattern, $p), $string, $m, $flags | PREG_PATTERN_ORDER, $p['offset']); - else - $r = preg_match(it::convertregex($pattern, $p), $string, $m, $flags, $p['offset']); + if ($p['all']) + $r = preg_match_all(it::convertregex($pattern, $p), $string, $m, $flags | PREG_PATTERN_ORDER, $p['offset']); + else + $r = preg_match(it::convertregex($pattern, $p), $string, $m, $flags, $p['offset']); - setlocale(LC_CTYPE, $oldlocale); + setlocale(LC_CTYPE, $oldlocale); + } if (!$r) # no match { - static $backtrackerror; - - if (!isset($backtrackerror)) - $backtrackerror = defined('PREG_BACKTRACK_LIMIT_ERROR') ? constant('PREG_BACKTRACK_LIMIT_ERROR') : 0; - - if ($backtrackerror && preg_last_error() == $backtrackerror) # Silence phpversionlint.php commit hook: function_exists('preg_last_error') + if (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR) # Silence phpversionlint.php commit hook: function_exists('preg_last_error') it::error("Exceeded pcre.backtrack_limit of " . ini_get('pcre.backtrack_limit') . " bytes"); $result = $p['all'] ? array() : null; @@ -846,5 +841,4 @@ function pipe($cmd, $args = array()) } } - ?> |