PATCH: final [perl #86972]: Allow /(?aia)/
authorKarl Williamson <public@khwilliamson.com>
Mon, 11 Apr 2011 17:06:05 +0000 (11:06 -0600)
committerKarl Williamson <public@khwilliamson.com>
Mon, 11 Apr 2011 17:31:57 +0000 (11:31 -0600)
This fixes "use re '/aia'", and completes the sequence of commits
for this ticket.

ext/re/re.pm
ext/re/t/reflags.t

index 35d2e29..9d0921b 100644 (file)
@@ -4,7 +4,7 @@ package re;
 use strict;
 use warnings;
 
-our $VERSION     = "0.17";
+our $VERSION     = "0.18";
 our @ISA         = qw(Exporter);
 our @EXPORT_OK   = ('regmust',
                     qw(is_regexp regexp_pattern
@@ -145,9 +145,26 @@ sub bits {
        } elsif ($s =~ s/^\///) {
            my $reflags = $^H{reflags} || 0;
            my $seen_charset;
-           while ($s =~ m/( aa | . )/gx) {
+           while ($s =~ m/( . )/gx) {
                 $_ = $1;
                if (/[adul]/) {
+                    # The 'a' may be repeated; hide this from the rest of the
+                    # code by counting and getting rid of all of them, then
+                    # changing to 'aa' if there is a repeat.
+                    if ($_ eq 'a') {
+                        my $sav_pos = pos $s;
+                        my $a_count = $s =~ s/a//g;
+                        pos $s = $sav_pos - 1;  # -1 because got rid of the 'a'
+                        if ($a_count > 2) {
+                           require Carp;
+                            Carp::carp(
+                            qq 'The "a" flag may only appear a maximum of twice'
+                            );
+                        }
+                        elsif ($a_count == 2) {
+                            $_ = 'aa';
+                        }
+                    }
                    if ($on) {
                        if ($seen_charset) {
                            require Carp;
@@ -157,12 +174,6 @@ sub bits {
                                 .qq 'are exclusive'
                                 );
                             }
-                            elsif ($seen_charset eq 'a') {
-                                Carp::carp(
-                                qq 'The "a" flag may only appear twice if '
-                                .qq 'adjacent, like "aa"'
-                                );
-                            }
                             else {
                                 Carp::carp(
                                 qq 'The "$seen_charset" flag may not appear '
index 343a117..ab3a407 100644 (file)
@@ -10,9 +10,9 @@ BEGIN {
 
 use strict;
 
-use Test::More tests => 58;
+use Test::More tests => 53;
 
-my @flags = qw( a d l u aa );
+my @flags = qw( a d l u );
 
 use re '/i';
 ok "Foo" =~ /foo/, 'use re "/i"';
@@ -118,6 +118,16 @@ ok "A\n\n" =~ / a.$/sm, 'use re "/xi" in combination with explicit /sm';
 }
 no re '/x';
 
+# Verify one and two a's work
+use re '/ia';
+is qr//, '(?^ai:)', 'use re "/ia"';
+no re '/ia';
+is qr//, '(?^:)', 'no re "/ia"';
+use re '/aai';
+is qr//, '(?^aai:)', 'use re "/aai"';
+no re '/aai';
+is qr//, '(?^:)', 'no re "/aai"';
+
 # use re "/adul" combinations
 {
   my $w;
@@ -150,9 +160,9 @@ no re '/x';
   }
 
   $w = "";
-  eval "use re '/axa'";
-  like $w, qr/The "a" flag may only appear twice if adjacent, like "aa"/,
-    "warning with eval \"use re \"/axa\"";
+  eval "use re '/axaa'";
+  like $w, qr/The "a" flag may only appear a maximum of twice/,
+    "warning with eval \"use re \"/axaa\"";
 
 
 }