summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider2007-01-24 12:36:24 +0000
committerChristian Schneider2007-01-24 12:36:24 +0000
commit23c257265ab9c3d88408b1c58f82df22e06e17bd (patch)
treec42d76e72212c83e7ed17c69194d4a259947ce0f
parent70a8d4b8041833696ab8c8fdc57429782ba2485f (diff)
downloaditools-23c257265ab9c3d88408b1c58f82df22e06e17bd.tar.gz
itools-23c257265ab9c3d88408b1c58f82df22e06e17bd.tar.bz2
itools-23c257265ab9c3d88408b1c58f82df22e06e17bd.zip
Minor style cleanup and simplified setlocale logic
-rw-r--r--it.class20
1 files changed, 6 insertions, 14 deletions
diff --git a/it.class b/it.class
index 2b61fda..e79f228 100644
--- a/it.class
+++ b/it.class
@@ -212,17 +212,14 @@ function match($pattern, $string, $p = array())
$flags |= PREG_OFFSET_CAPTURE;
$oldlocale = setlocale( LC_CTYPE, 0 );
-
- if ($oldlocale != 'de_CH')
- setlocale(LC_CTYPE, 'de_CH');
+ setlocale(LC_CTYPE, '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 ($oldlocale != 'de_CH')
- setlocale(LC_CTYPE, $oldlocale);
+ setlocale(LC_CTYPE, $oldlocale);
if (!$r) # no match
$result = $p['all'] ? array() : false;
@@ -248,18 +245,13 @@ function replace($replacements, $string, $p = array())
{
$patterns = array();
- foreach (array_keys( $replacements ) as $pat)
- $patterns[] = it::convertregex($pat, $p);
+ foreach (array_keys($replacements) as $pattern)
+ $patterns[] = it::convertregex($pattern, $p);
$oldlocale = setlocale(LC_CTYPE, 0);
-
- if ($oldlocale != 'de_CH')
- setlocale(LC_CTYPE, 'de_CH');
-
+ setlocale(LC_CTYPE, 'de_CH');
$result = preg_replace($patterns, array_values($replacements), $string, isset($p['limit']) ? $p['limit'] : -1);
-
- if ($oldlocale != 'de_CH')
- setlocale(LC_CTYPE, $oldlocale);
+ setlocale(LC_CTYPE, $oldlocale);
return $result;
}