From ff8fbaa3598ec6399bdb3f7e39d0889c1c891d94 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Thu, 4 Oct 2007 02:29:19 +0000 Subject: documenation, selectable it::match locale --- it.class | 21 ++++++++++++--------- 1 file 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']); -- cgit v1.2.3