changeset 8619:930a8114197b

For zero length matches in regexp, advance index by one and try again
author David Bateman <dbateman@free.fr>
date Wed, 28 Jan 2009 23:43:27 +0100
parents f8b3ece45bda
children a2dd2ffc504d
files src/ChangeLog src/DLD-FUNCTIONS/regexp.cc
diffstat 2 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Jan 28 17:42:18 2009 -0500
+++ b/src/ChangeLog	Wed Jan 28 23:43:27 2009 +0100
@@ -3,6 +3,12 @@
 	* Makefile.in (install, uninstall): Handle SHLLIBPRE and SHLBINPRE
 	library prefixes.  From Marco Atzeri <marco_atzeri@yahoo.it>.
 
+2008-01-28  David Bateman  <dbateman@free.fr>
+
+	* DLD-FUNCTIONS/regexp.cc (octregexp_list): Don't break for zero
+	length match, but rather advance the index by one character and
+	try again.
+
 2009-01-28  Jaroslav Hajek  <highegg@gmail.com>
 
 	* DLD-FUNCTIONS/lookup.cc (Flookup): Fix doc string.
--- a/src/DLD-FUNCTIONS/regexp.cc	Wed Jan 28 17:42:18 2009 -0500
+++ b/src/DLD-FUNCTIONS/regexp.cc	Wed Jan 28 23:43:27 2009 +0100
@@ -314,7 +314,7 @@
 
 		      for (; i < max_length + 1; i++)
 			{
-			  buf <<pattern.substr(new_pos, tmp_pos3 - new_pos)
+			  buf << pattern.substr(new_pos, tmp_pos3 - new_pos)
 			      << "{" << i << "}";
 			  buf << pattern.substr(tmp_pos3 + 1, 
 						tmp_pos1 - tmp_pos3 - 1);
@@ -421,7 +421,11 @@
 	  else if (matches == PCRE_ERROR_NOMATCH)
 	    break;
 	  else if (ovector[1] <= ovector[0])
-	    break;
+	    {
+	      // FIXME: Zero sized match!! Is this the right thing to do?
+	      idx = ovector[0] + 1;
+	      continue;
+	    }
 	  else
 	    {
 	      int pos_match = 0;
@@ -516,6 +520,9 @@
 	      while (matches < subexpr && match[matches].rm_so >= 0) 
 		matches++;
 
+	      if (matches == 0 || match[0].rm_eo == 0)
+		break;
+
 	      s = double (match[0].rm_so+1+idx);
 	      e = double (match[0].rm_eo+idx);
 	      Matrix te(matches-1,2);