diff src/DLD-FUNCTIONS/regexp.cc @ 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 433e788a015b
children eb63fbe60fab
line wrap: on
line diff
--- 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);