summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
authorUrban Müller2011-11-14 18:52:12 +0000
committerUrban Müller2011-11-14 18:52:12 +0000
commit88321feeb17e271cbaa582dd2507f3591f65f5f7 (patch)
tree644948c7f10273fd0e708e327b36fba9566c2f4b /it.class
parenta1d1496cce437afe3ceb2f84fd3baac806ab6659 (diff)
downloaditools-88321feeb17e271cbaa582dd2507f3591f65f5f7.tar.gz
itools-88321feeb17e271cbaa582dd2507f3591f65f5f7.tar.bz2
itools-88321feeb17e271cbaa582dd2507f3591f65f5f7.zip
faster it::replace, tests
Diffstat (limited to 'it.class')
-rw-r--r--it.class15
1 files changed, 10 insertions, 5 deletions
diff --git a/it.class b/it.class
index 772364a..3055cb0 100644
--- a/it.class
+++ b/it.class
@@ -397,12 +397,17 @@ static function replace($replacements, $string, $p = array())
$patterns = array();
foreach (array_keys($replacements) as $pattern)
- $patterns[] = it::convertregex($pattern, $p);
+ $patterns[] = !preg_match('/\\\\[wb]|[!\x80-\xff]|\[\[:/i', $pattern) && !$p ? "!$pattern!i" : it::convertregex($complex = $pattern, $p);
- $oldlocale = setlocale(LC_CTYPE, 0);
- setlocale(LC_CTYPE, 'de_CH');
- $result = preg_replace($patterns, array_values($replacements), $string, isset($p['limit']) ? $p['limit'] : -1);
- setlocale(LC_CTYPE, $oldlocale);
+ if (!$complex)
+ $result = preg_replace($patterns, array_values($replacements), $string);
+ else
+ {
+ $oldlocale = setlocale(LC_CTYPE, 0);
+ setlocale(LC_CTYPE, 'de_CH');
+ $result = preg_replace($patterns, array_values($replacements), $string, isset($p['limit']) ? $p['limit'] : -1);
+ setlocale(LC_CTYPE, $oldlocale);
+ }
return $result;
}