From: Vincent Pit Date: Tue, 19 Aug 2008 15:21:11 +0000 (+0200) Subject: This is 1.01 X-Git-Tag: v1.01^0 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FRegexp-Wildcards.git;a=commitdiff_plain;h=b89ade7968f3dfcf54d1c830f1ecdfd09731a412 This is 1.01 --- diff --git a/Changes b/Changes index be1f41b..1524d4f 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for Regexp-Wildcards +1.01 2008-08-19 15:20 UTC + + Fix : Now we can do both SQL and brackets. + + Tst : Add tests for embedded newlines. + 1.00 2008-08-18 17:20 UTC + Chg : Rewritten the module in an OO way. It's now easier to specify what you want to translate. diff --git a/META.yml b/META.yml index c0d2d4a..2050f11 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- #YAML:1.0 name: Regexp-Wildcards -version: 1.00 +version: 1.01 abstract: Converts wildcard expressions to Perl regular expressions. license: perl author: diff --git a/README b/README index 78cc7d9..7d0d9b9 100644 --- a/README +++ b/README @@ -3,7 +3,7 @@ NAME expressions. VERSION - Version 1.00 + Version 1.01 SYNOPSIS use Regexp::Wildcards; @@ -14,7 +14,7 @@ SYNOPSIS $re = $rw->convert('a{b?,c}*'); # Do it Unix shell style. $re = $rw->convert('a?,b*', 'win32'); # Do it Windows shell style. $re = $rw->convert('*{x,y}?', 'jokers'); # Process the jokers and escape the rest. - $re = $rw->convert('%a_c%', 'sql'); # Turn SQL wildcards into regexps. + $re = $rw->convert('%a_c%', 'sql'); # Turn SQL wildcards into regexps. $rw = Regexp::Wildcards->new( do => [ qw/jokers brackets/ ], # Do jokers and brackets. @@ -57,36 +57,44 @@ METHODS Specifies the list of metacharacters to convert. They are classified into five classes : - 'jokers' converts "?" to "." and "*" to ".*" ; + * 'jokers' converts "?" to "." and "*" to ".*" ; + 'a**\\*b??\\?c' ==> 'a.*\\*b..\\?c' - 'sql' converts "_" to "." and "%" to ".*" ; + * 'sql' converts "_" to "." and "%" to ".*" ; + 'a%%\\%b__\\_c' ==> 'a.*\\%b..\\_c' - 'commas' converts all "," to "|" and puts the complete resulting regular - expression inside "(?: ... )" ; + * 'commas' converts all "," to "|" and puts the complete resulting + regular expression inside "(?: ... )" ; + 'a,b{c,d},e' ==> '(?:a|b\\{c|d\\}|e)' - 'brackets' converts all matching "{ ... , ... }" brackets to "(?: ... | - ... )" alternations. If some brackets are unbalanced, it tries to - substitute as many of them as possible, and then escape the remaining - unmatched "{" and "}". Commas outside of any bracket-delimited block are - also escaped ; + * 'brackets' converts all matching "{ ... , ... }" brackets to "(?: + ... | ... )" alternations. If some brackets are unbalanced, it tries + to substitute as many of them as possible, and then escape the + remaining unmatched "{" and "}". Commas outside of any + bracket-delimited block are also escaped ; + 'a,b{c,d},e' ==> 'a\\,b(?:c|d)\\,e' '{a\\{b,c}d,e}' ==> '(?:a\\{b|c)d\\,e\\}' '{a{b,c\\}d,e}' ==> '\\{a\\{b\\,c\\}d\\,e\\}' - 'groups' keeps the parenthesis "( ... )" of the original string without - escaping them. Currently, no check is done to ensure that the - parenthesis are matching. + * 'groups' keeps the parenthesis "( ... )" of the original string + without escaping them. Currently, no check is done to ensure that + the parenthesis are matching. + 'a(b(c))d\\(\\)' ==> (no change) Each $c can be any of : - A hash reference, with wanted metacharacter group names (described - above) as keys and booleans as values ; - An array reference containing the list of wanted metacharacter classes ; - A plain scalar, when only one group is required. + * A hash reference, with wanted metacharacter group names (described + above) as keys and booleans as values ; + + * An array reference containing the list of wanted metacharacter + classes ; + + * A plain scalar, when only one group is required. When "set" is present, the classes given as its value replace the current object options. Then the "add" classes are added, and the "rem" @@ -116,22 +124,26 @@ METHODS Specifies the list of atoms to capture. This method works like "do", except that the classes are different : - 'single' will capture all unescaped *"exactly one"* metacharacters, i.e. - "?" for wildcards or "_" for SQL ; + * 'single' will capture all unescaped *"exactly one"* metacharacters, + i.e. "?" for wildcards or "_" for SQL ; + 'a???b\\??' ==> 'a(.)(.)(.)b\\?(.)' 'a___b\\__' ==> 'a(.)(.)(.)b\\_(.)' - 'any' will capture all unescaped *"any"* metacharacters, i.e. "*" for - wildcards or "%" for SQL ; + * 'any' will capture all unescaped *"any"* metacharacters, i.e. "*" + for wildcards or "%" for SQL ; + 'a***b\\**' ==> 'a(.*)b\\*(.*)' 'a%%%b\\%%' ==> 'a(.*)b\\%(.*)' - 'greedy', when used in conjunction with 'any', will make the 'any' - captures greedy (by default they are not) ; + * 'greedy', when used in conjunction with 'any', will make the 'any' + captures greedy (by default they are not) ; + 'a***b\\**' ==> 'a(.*?)b\\*(.*?)' 'a%%%b\\%%' ==> 'a(.*?)b\\%(.*?)' - 'brackets' will capture matching "{ ... , ... }" alternations. + * 'brackets' will capture matching "{ ... , ... }" alternations. + 'a{b\\},\\{c}' ==> 'a(b\\}|\\{c)' $rw->capture(set => 'single'); # Only capture "exactly one" metacharacters. diff --git a/lib/Regexp/Wildcards.pm b/lib/Regexp/Wildcards.pm index 5d7bf5b..e59e3ea 100644 --- a/lib/Regexp/Wildcards.pm +++ b/lib/Regexp/Wildcards.pm @@ -12,13 +12,13 @@ Regexp::Wildcards - Converts wildcard expressions to Perl regular expressions. =head1 VERSION -Version 1.00 +Version 1.01 =cut use vars qw/$VERSION/; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.01'; } =head1 SYNOPSIS