diff options
author | Nathan Gass | 2012-03-22 18:36:01 +0000 |
---|---|---|
committer | Nathan Gass | 2012-03-22 18:36:01 +0000 |
commit | 8d9bcc5de7ebf6d44fea96bfea920a77c7fcbd00 (patch) | |
tree | d9ccaa550f5329059470665171e6af5bac9ba5b8 /it.class | |
parent | 37f1f926bebf1d181dda083a593d5845ab5f4551 (diff) | |
download | itools-8d9bcc5de7ebf6d44fea96bfea920a77c7fcbd00.tar.gz itools-8d9bcc5de7ebf6d44fea96bfea920a77c7fcbd00.tar.bz2 itools-8d9bcc5de7ebf6d44fea96bfea920a77c7fcbd00.zip |
remove locale switching from it::match and it::replace
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 18 |
1 files changed, 2 insertions, 16 deletions
@@ -335,7 +335,6 @@ static function convertregex($pattern, $p = null) * @param $string String to match * @param $p['offset_capture'] Set flag preg_offset_capture (returns offsets with the matches). * @param $p['all'] Return every match as array instead of first match. - * @param $p['locale'] Use given locale (default: de_CH), mainly affects handling of iso-latin chars * @param $p contains pattern modifiers, @see convertregex() * @return Matched string or false */ @@ -347,15 +346,10 @@ static function match($pattern, $string, $p = null) { $flags = $p['offset_capture'] ? PREG_OFFSET_CAPTURE : 0; - $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']); - - setlocale(LC_CTYPE, $oldlocale); } if (!$r) # no match @@ -386,17 +380,9 @@ static function match($pattern, $string, $p = null) static function replace($replacements, $string, $p = array()) { foreach ($replacements as $pattern => $dummy) - $patterns[] = !preg_match('/\\\\[wb]|[!\x80-\xff]|\[\[:/i', $pattern) && !$p ? "!$pattern!i" : it::convertregex($complex = $pattern, $p); + $patterns[] = !preg_match('/\\\\[wb]|[!\x80-\xff]|\[\[:/i', $pattern) && !$p ? "!$pattern!i" : it::convertregex($pattern, $p); - if (!$complex && !$p) - $result = preg_replace($patterns, $replacements, $string); - else - { - $oldlocale = setlocale(LC_CTYPE, 0); - setlocale(LC_CTYPE, 'de_CH'); - $result = preg_replace($patterns, $replacements, $string, isset($p['limit']) ? $p['limit'] : -1); - setlocale(LC_CTYPE, $oldlocale); - } + $result = preg_replace($patterns, $replacements, $string, isset($p['limit']) ? $p['limit'] : -1); return $result; } |