summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2007-10-04 02:29:19 +0000
committerUrban Müller2007-10-04 02:29:19 +0000
commitff8fbaa3598ec6399bdb3f7e39d0889c1c891d94 (patch)
tree85f77b992ecaf1d9bd2f38400e8dd0490b413d50
parentfe5c9e378aee5c205fe77e29bc179af1d0410a0f (diff)
downloaditools-ff8fbaa3598ec6399bdb3f7e39d0889c1c891d94.tar.gz
itools-ff8fbaa3598ec6399bdb3f7e39d0889c1c891d94.tar.bz2
itools-ff8fbaa3598ec6399bdb3f7e39d0889c1c891d94.zip
documenation, selectable it::match locale
-rw-r--r--it.class21
1 files changed, 12 insertions, 9 deletions
diff --git a/it.class b/it.class
index 9b5056e..281853a 100644
--- a/it.class
+++ b/it.class
@@ -240,11 +240,11 @@ function toascii($text)
/**
* Convert regex for preg (adds and escapes delimiter, adds modifiers)
* @param $pattern Regex to convert
- * @param named parameter casesensitive Regex is case sensitive (omit modifier i)
- * @param named parameter multiline add modifier m
- * @param named parameter singleline add modifier s
- * @param named parameter utf8 add modifier u
- * @param named parameter extended add modifier x
+ * @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['extended'] add modifier x
* @return converted regex to use with preg
*/
function convertregex($pattern, $p = array())
@@ -270,22 +270,25 @@ function convertregex($pattern, $p = array())
}
/**
- * Try to match string against regex. See convertregex for additional named parameters.
+ * Try to match string against regex. Case insensitive by default.
* @param $pattern Regex to match against
* @param $string String to match
- * @param named parameter offset_capture Set flag preg_offset_capture (returns offsets with the matches).
- * @param named parameter all Return every match as array instead of first 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
*/
function match($pattern, $string, $p = array())
{
$flags = 0;
+ $p += array('locale' => 'de_CH');
if($p['offset_capture'])
$flags |= PREG_OFFSET_CAPTURE;
$oldlocale = setlocale( LC_CTYPE, 0 );
- setlocale(LC_CTYPE, 'de_CH');
+ setlocale(LC_CTYPE, $p['locale']);
if ($p['all'])
$r = preg_match_all(it::convertregex($pattern, $p), $string, $m, $flags | PREG_PATTERN_ORDER, $p['offset']);