Skip to content

Commit

Permalink
PATCH: final [perl #86972]: Allow /(?aia)/
Browse files Browse the repository at this point in the history
This fixes "use re '/aia'", and completes the sequence of commits
for this ticket.
  • Loading branch information
Karl Williamson committed Apr 11, 2011
1 parent efc5c7c commit 342c852
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
27 changes: 19 additions & 8 deletions ext/re/re.pm
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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 '
Expand Down
20 changes: 15 additions & 5 deletions ext/re/t/reflags.t
Expand Up @@ -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"';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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\"";


}

0 comments on commit 342c852

Please sign in to comment.