From 342c85242bced7dbfd83bf3d2621282751e996b8 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Mon, 11 Apr 2011 11:06:05 -0600 Subject: [PATCH] PATCH: final [perl #86972]: Allow /(?aia)/ This fixes "use re '/aia'", and completes the sequence of commits for this ticket. --- ext/re/re.pm | 27 +++++++++++++++++++-------- ext/re/t/reflags.t | 20 +++++++++++++++----- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/ext/re/re.pm b/ext/re/re.pm index 35d2e29..9d0921b 100644 --- a/ext/re/re.pm +++ b/ext/re/re.pm @@ -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 ' diff --git a/ext/re/t/reflags.t b/ext/re/t/reflags.t index 343a117..ab3a407 100644 --- a/ext/re/t/reflags.t +++ b/ext/re/t/reflags.t @@ -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\""; } -- 2.7.4