summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
authorChristian Weber2012-02-29 10:12:11 +0000
committerChristian Weber2012-02-29 10:12:11 +0000
commitc0938f79a452c44e28fccc326775891ba6c743e3 (patch)
tree98db80457a9bb72f2c80621d3c36cbaa020b279a /it.class
parent4d945c4a8ced3835064592f35ce2d68083e51b09 (diff)
downloaditools-c0938f79a452c44e28fccc326775891ba6c743e3.tar.gz
itools-c0938f79a452c44e28fccc326775891ba6c743e3.tar.bz2
itools-c0938f79a452c44e28fccc326775891ba6c743e3.zip
it::convertregex() sets /u if default_charset is 'utf-8' (can be overridden)
Diffstat (limited to 'it.class')
-rw-r--r--it.class27
1 files changed, 8 insertions, 19 deletions
diff --git a/it.class b/it.class
index 818c9e0..292c154 100644
--- a/it.class
+++ b/it.class
@@ -310,35 +310,24 @@ static function toascii($text)
* @param $p['casesensitive'] Regex is case sensitive (omit modifier i)
* @param $p['multiline'] add modifier m: ^ and $ match \n
* @param $p['singleline'] add modifier s: . matches \n
- * @param $p['utf8'] add modifier u
+ * @param $p['utf8'] add modifier u. This is the default if default_charset is utf-8, override with $p['utf8'] = false
* @param $p['extended'] add modifier x (non signifcant whitespace)
* @return converted regex to use with preg
*/
static function convertregex($pattern, $p = array())
{
- $pattern = preg_replace('|/|', '\/', $pattern);
- $modifiers = '';
-
- if (!$p['casesensitive'])
- $modifiers .= 'i';
-
if ($p['exec'])
it::fatal("Option exec to it::replace has been removed for security reasons");
- foreach (array(
- 'multiline' => 'm',
- 'singleline' => 's',
- 'utf8' => 'u',
- 'extended' => 'x',
- ) as $key => $mod)
- {
- if ($p[$key])
- $modifiers .= $mod;
- }
-
- return "/$pattern/$modifiers";
+ return '/' . strtr($pattern, array('/' => '\/')) . '/' .
+ (!$p['casesensitive'] ? 'i' : '') .
+ ($p['multiline'] ? 'm' : '') .
+ ($p['singleline'] ? 's' : '') .
+ ($p['extended'] ? 'x' : '') .
+ ((!isset($p['utf8']) && ini_get('default_charset') == 'utf-8' || $p['utf8']) ? 'u' : '');
}
+
/**
* Try to match string against regex. Case insensitive by default.
* @param $pattern Regex to match against