[Pcre-svn] [619] code/trunk: Fix capturing not happening in …

トップ ページ
このメッセージを削除
著者: Subversion repository
日付:  
To: pcre-svn
題目: [Pcre-svn] [619] code/trunk: Fix capturing not happening in assertion conditions.
Revision: 619
          http://vcs.pcre.org/viewvc?view=rev&revision=619
Author:   ph10
Date:     2011-07-17 14:23:14 +0100 (Sun, 17 Jul 2011)


Log Message:
-----------
Fix capturing not happening in assertion conditions.

Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/pcre_exec.c
    code/trunk/testdata/testinput1
    code/trunk/testdata/testinput11
    code/trunk/testdata/testoutput1
    code/trunk/testdata/testoutput11


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2011-07-16 17:24:16 UTC (rev 618)
+++ code/trunk/ChangeLog    2011-07-17 13:23:14 UTC (rev 619)
@@ -133,6 +133,10 @@
     "aaaabaaabaabab" the value of captured group 2 is now correctly recorded as 
     "aaa". Previously, it would have been "a". As part of this code 
     refactoring, the way recursive calls are handled has also been changed.
+    
+24. If an assertion condition captured any substrings, they were not passed 
+    back unless some other capturing happened later. For example, if
+    (?(?=(a))a) was matched against "a", no capturing was returned.



Version 8.12 15-Jan-2011

Modified: code/trunk/pcre_exec.c
===================================================================
--- code/trunk/pcre_exec.c    2011-07-16 17:24:16 UTC (rev 618)
+++ code/trunk/pcre_exec.c    2011-07-17 13:23:14 UTC (rev 619)
@@ -1253,6 +1253,8 @@
       RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM3);
       if (rrc == MATCH_MATCH)
         {
+        if (md->end_offset_top > offset_top)
+          offset_top = md->end_offset_top;  /* Captures may have happened */
         condition = TRUE;
         ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
         while (*ecode == OP_ALT) ecode += GET(ecode, 1);
@@ -1316,43 +1318,22 @@
     break;



-    /* End of the pattern, either real or forced. If we are in a recursion, we
-    should restore the offsets appropriately, and if it's a top-level
-    recursion, continue from after the call. */
+    /* End of the pattern, either real or forced. */


+    case OP_END:
     case OP_ACCEPT:
     case OP_ASSERT_ACCEPT: 
-    case OP_END:
-    
-/* 
-    if (md->recursive != NULL)
-      {
-      recursion_info *rec = md->recursive;
-
-      md->recursive = rec->prevrec;
-
-      memmove(md->offset_vector, rec->offset_save, 
-        rec->saved_max * sizeof(int));
-      offset_top = rec->save_offset_top;
-      if (rec->group_num == 0)
-        {
-        ecode = rec->after_call;
-        break;
-        } 
-      }
-*/
-    /* Otherwise, if we have matched an empty string, fail if not in an 
-    assertion and if either PCRE_NOTEMPTY is set, or if PCRE_NOTEMPTY_ATSTART
+     
+    /* If we have matched an empty string, fail if not in an assertion and not
+    in a recursion if either PCRE_NOTEMPTY is set, or if PCRE_NOTEMPTY_ATSTART
     is set and we have matched at the start of the subject. In both cases,
     backtracking will then try other alternatives, if any. */


-/*    else */ if (eptr == mstart && op != OP_ASSERT_ACCEPT &&
-
+    if (eptr == mstart && op != OP_ASSERT_ACCEPT &&
          md->recursive == NULL &&
-
-        (md->notempty ||
-          (md->notempty_atstart &&
-            mstart == md->start_subject + md->start_offset)))
+         (md->notempty ||
+           (md->notempty_atstart &&
+             mstart == md->start_subject + md->start_offset)))
       MRRETURN(MATCH_NOMATCH);


     /* Otherwise, we have a match. */


Modified: code/trunk/testdata/testinput1
===================================================================
--- code/trunk/testdata/testinput1    2011-07-16 17:24:16 UTC (rev 618)
+++ code/trunk/testdata/testinput1    2011-07-17 13:23:14 UTC (rev 619)
@@ -4175,4 +4175,10 @@
 /(?:a+|ab)+c/
     aabc


+/(?(?=(a))a)/
+    a
+
+/(?(?=(a))a)(b)/
+    ab
+
 /-- End of testinput1 --/


Modified: code/trunk/testdata/testinput11
===================================================================
--- code/trunk/testdata/testinput11    2011-07-16 17:24:16 UTC (rev 618)
+++ code/trunk/testdata/testinput11    2011-07-17 13:23:14 UTC (rev 619)
@@ -630,4 +630,7 @@
 /(?:(b))++/
     beetle


+/(?(?=(a(*ACCEPT)z))a)/
+    a
+
 /-- End of testinput11 --/


Modified: code/trunk/testdata/testoutput1
===================================================================
--- code/trunk/testdata/testoutput1    2011-07-16 17:24:16 UTC (rev 618)
+++ code/trunk/testdata/testoutput1    2011-07-17 13:23:14 UTC (rev 619)
@@ -6832,4 +6832,15 @@
     aabc
  0: aabc


+/(?(?=(a))a)/
+    a
+ 0: a
+ 1: a
+
+/(?(?=(a))a)(b)/
+    ab
+ 0: ab
+ 1: a
+ 2: b
+
 /-- End of testinput1 --/


Modified: code/trunk/testdata/testoutput11
===================================================================
--- code/trunk/testdata/testoutput11    2011-07-16 17:24:16 UTC (rev 618)
+++ code/trunk/testdata/testoutput11    2011-07-17 13:23:14 UTC (rev 619)
@@ -1198,4 +1198,9 @@
  0: b
  1: b


+/(?(?=(a(*ACCEPT)z))a)/
+    a
+ 0: a
+ 1: a
+
 /-- End of testinput11 --/