Test studied scalars with s///ge.
authorNicholas Clark <nick@ccl4.org>
Thu, 16 Jun 2011 20:31:07 +0000 (22:31 +0200)
committerNicholas Clark <nick@ccl4.org>
Thu, 23 Jun 2011 13:07:18 +0000 (15:07 +0200)
pp_ctl.c
t/op/study.t

index 0016484..8e53116 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -298,6 +298,13 @@ PP(pp_substcont)
        s -= RX_GOFS(rx);
 
        /* Are we done */
+       /* I believe that we can't set REXEC_SCREAM here if
+          SvSCREAM(cx->sb_targ) is true because SvPVX(cx->sb_targ) isn't always
+          equal to s.  [See the comment before Perl_re_intuit_start(), which is
+          called from Perl_regexec_flags(), which says that it should be when
+          SvSCREAM() is true.]  s, cx->sb_strend and orig will be consistent
+          with SvPVX(cx->sb_targ), as substconst doesn't modify cx->sb_targ
+          during the match.  */
        if (CxONCE(cx) || s < orig ||
                !CALLREGEXEC(rx, s, cx->sb_strend, orig,
                             (s == m) + RX_GOFS(rx), cx->sb_targ, NULL,
index adf5e2b..3733849 100644 (file)
@@ -7,7 +7,7 @@ BEGIN {
 }
 
 watchdog(10);
-plan(tests => 30);
+plan(tests => 36);
 use strict;
 use vars '$x';
 
@@ -92,3 +92,20 @@ TODO: {
     my @a = split /aab*/, $a;
     is("@a", 'Q Q Q Q', 'split with studied string passed to the regep engine');
 }
+
+{
+    $_ = "AABBAABB";
+    study;
+    is(s/AB+/1/ge, 2, 'studied scalar passed to pp_substconst');
+    is($_, 'A1A1');
+}
+
+{
+    $_ = "AABBAABB";
+    study;
+    is(s/(A)B+/1/ge, 2,
+       'studied scalar passed to pp_substconst with RX_MATCH_COPIED() true');
+    is($1, 'A');
+    is($2, undef);
+    is($_, 'A1A1');
+}