Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4842 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40150 invoked by uid 1010); 14 Oct 2003 18:20:50 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 40126 invoked from network); 14 Oct 2003 18:20:50 -0000 Received: from unknown (HELO mail.sites-secure.com) (213.189.34.71) by pb1.pair.com with SMTP; 14 Oct 2003 18:20:50 -0000 Received: by mail.sites-secure.com (CommuniGate Pro PIPE 3.5.9) with PIPE id 31385622; Tue, 14 Oct 2003 20:17:29 +0200 Received: from [192.117.106.24] (account ilya@up.co.il HELO abox.co.il) by mail.sites-secure.com (CommuniGate Pro SMTP 3.5.9) with ESMTP id 31385657 for internals@lists.php.net; Tue, 14 Oct 2003 20:17:21 +0200 Message-ID: <3F8C3F72.1060100@abox.co.il> Date: Tue, 14 Oct 2003 20:24:50 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3; MultiZilla v1.3.1 (a)) Gecko/20031008 X-Accept-Language: en-us, en, he, ru MIME-Version: 1.0 To: internals@lists.php.net References: <3F8C1063.7040907@php.net> In-Reply-To: <3F8C1063.7040907@php.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-DoalSignature: rot-3 (smtp) Subject: Re: [PHP-DEV] regex operators From: netcat@abox.co.il (netcat) Hartmut Holzgraefe wrote: > David Sklar wrote: > >> I was thinking about adding one or two regex-related features to the >> engine: >> >> 1. "preg_case": this would behave just like case but instead of doing an >> equality comparison, would match against a regular expression, e.g. >> >> switch($data) { >> preg_case '/^\d{5}(-\d{4})?$/': >> print "US Postal Code"; >> break; >> preg_case '/^[a-z]\d[a-z] ?\d[a-z]\d$/i'; >> print "Canadian Postal Code"; >> break; >> default: >> print "something else!"; >> } >> > > i've started to play with a more general way to handle this: > > switch(mixed data [, callback compare_function]) seems the sanest thing up until now. slighly O.T.: would be and even better if lambda functions were available here > > { > ... > > "compare_function" would default to the functionality of the > "==" operator to show the current behavior > > "compare_function" will be called with two parameters: > the switch expression and the case value and should > return true if both match, false otherwise > > as a special case "compare_function" should also accept > "===" > > this way we do not have to add new keywords and are not > limited to preg expresions here, > possible uses not possible now would include: > > switch($foobar, "===") { > case false: ... > case 0: ... > case '': ... > > switch($foobar, "preg_match") { > case '/^\d{5}$/': ... > case '/(foo)?bar/': ... > > switch($foobar, "fnmatch") { > case '*.gif': ... > case '*.jpg': ... > > switch($foober, "my_custom_function") { > ... > > switch($foobar, array($this, "compare_function") { > ... > > > > -- NetCat -------------------------------------------------------- FREE 10MB email + Antivirus + AntiSpam + POP3 + more.... Get it at http://www.doal.co.il:81/free/?c=both