[Pcre-svn] [915] code/trunk: Fix the value passed back for P…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [915] code/trunk: Fix the value passed back for POSIX unset groups when REG_STARTEND has a
Revision: 915
          http://www.exim.org/viewvc/pcre2?view=rev&revision=915
Author:   ph10
Date:     2018-02-19 14:49:42 +0000 (Mon, 19 Feb 2018)
Log Message:
-----------
Fix the value passed back for POSIX unset groups when REG_STARTEND has a 
non-zero starting offset, and make pcre2test show relevant POSIX unset groups.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/pcre2posix.c
    code/trunk/src/pcre2test.c
    code/trunk/testdata/testinput18
    code/trunk/testdata/testoutput18


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2018-02-12 11:34:42 UTC (rev 914)
+++ code/trunk/ChangeLog    2018-02-19 14:49:42 UTC (rev 915)
@@ -2,6 +2,19 @@
 --------------------



+Version 10.32-RC1 19-February-2018
+----------------------------------
+
+1. When matching using the the REG_STARTEND feature of the POSIX API with a
+non-zero starting offset, unset capturing groups with lower numbers than a
+group that did capture something were not being correctly returned as "unset"
+(that is, with offset values of -1).
+
+2. When matching using the POSIX API, pcre2test used to omit listing unset
+groups altogether. Now it shows those that come before any actual captures as
+"<unset>", as happens for non-POSIX matching.
+
+
Version 10.31 12-February-2018
------------------------------


Modified: code/trunk/src/pcre2posix.c
===================================================================
--- code/trunk/src/pcre2posix.c    2018-02-12 11:34:42 UTC (rev 914)
+++ code/trunk/src/pcre2posix.c    2018-02-19 14:49:42 UTC (rev 915)
@@ -7,7 +7,7 @@


                        Written by Philip Hazel
      Original API code Copyright (c) 1997-2012 University of Cambridge
-         New API code Copyright (c) 2016 University of Cambridge
+          New API code Copyright (c) 2016-2018 University of Cambridge


-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -93,7 +93,7 @@

void __cdecl function(....)

-might be needed. In order so make this easy, all the exported functions have
+might be needed. In order to make this easy, all the exported functions have
PCRE2_CALL_CONVENTION just before their names. It is rarely needed; if not
set, we ensure here that it has no effect. */

@@ -344,8 +344,10 @@
   if ((size_t)rc > nmatch) rc = (int)nmatch;
   for (i = 0; i < (size_t)rc; i++)
     {
-    pmatch[i].rm_so = ovector[i*2] + so;
-    pmatch[i].rm_eo = ovector[i*2+1] + so;
+    pmatch[i].rm_so = (ovector[i*2] == PCRE2_UNSET)? -1 : 
+      (int)(ovector[i*2] + so);
+    pmatch[i].rm_eo = (ovector[i*2+1] == PCRE2_UNSET)? -1 : 
+      (int)(ovector[i*2+1] + so);
     }
   for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;
   return 0;


Modified: code/trunk/src/pcre2test.c
===================================================================
--- code/trunk/src/pcre2test.c    2018-02-12 11:34:42 UTC (rev 914)
+++ code/trunk/src/pcre2test.c    2018-02-19 14:49:42 UTC (rev 915)
@@ -11,7 +11,7 @@


                        Written by Philip Hazel
      Original code Copyright (c) 1997-2012 University of Cambridge
-    Rewritten code Copyright (c) 2016-2017 University of Cambridge
+    Rewritten code Copyright (c) 2016-2018 University of Cambridge


 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -6761,7 +6761,8 @@
     fprintf(outfile, "Matched without capture\n");
   else
     {
-    size_t i;
+    size_t i, j;
+    size_t last_printed = (size_t)dat_datctl.oveccount;
     for (i = 0; i < (size_t)dat_datctl.oveccount; i++)
       {
       if (pmatch[i].rm_so >= 0)
@@ -6768,6 +6769,9 @@
         {
         PCRE2_SIZE start = pmatch[i].rm_so;
         PCRE2_SIZE end = pmatch[i].rm_eo;
+        for (j = last_printed + 1; j < i; j++)
+          fprintf(outfile, "%2d: <unset>\n", (int)j);
+        last_printed = i; 
         if (start > end)
           {
           start = pmatch[i].rm_eo;


Modified: code/trunk/testdata/testinput18
===================================================================
--- code/trunk/testdata/testinput18    2018-02-12 11:34:42 UTC (rev 914)
+++ code/trunk/testdata/testinput18    2018-02-19 14:49:42 UTC (rev 915)
@@ -134,4 +134,8 @@


/a\b(c/literal,posix,dotall

+/((a)(b)?(c))/posix
+    123ace
+    123ace\=posix_startend=2:6
+
 # End of testdata/testinput18


Modified: code/trunk/testdata/testoutput18
===================================================================
--- code/trunk/testdata/testoutput18    2018-02-12 11:34:42 UTC (rev 914)
+++ code/trunk/testdata/testoutput18    2018-02-19 14:49:42 UTC (rev 915)
@@ -46,6 +46,7 @@
     defabc\=noteol
  0: def
  1: def
+ 2: <unset>
  3: def


 /the quick brown fox/
@@ -206,4 +207,18 @@
 /a\b(c/literal,posix,dotall
 Failed: POSIX code 16: bad argument at offset 0     


+/((a)(b)?(c))/posix
+    123ace
+ 0: ac
+ 1: ac
+ 2: a
+ 3: <unset>
+ 4: c
+    123ace\=posix_startend=2:6
+ 0: ac
+ 1: ac
+ 2: a
+ 3: <unset>
+ 4: c
+
 # End of testdata/testinput18