comparison 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
comparison
equal deleted inserted replaced
8618:f8b3ece45bda 8619:930a8114197b
312 else 312 else
313 i = 1; 313 i = 1;
314 314
315 for (; i < max_length + 1; i++) 315 for (; i < max_length + 1; i++)
316 { 316 {
317 buf <<pattern.substr(new_pos, tmp_pos3 - new_pos) 317 buf << pattern.substr(new_pos, tmp_pos3 - new_pos)
318 << "{" << i << "}"; 318 << "{" << i << "}";
319 buf << pattern.substr(tmp_pos3 + 1, 319 buf << pattern.substr(tmp_pos3 + 1,
320 tmp_pos1 - tmp_pos3 - 1); 320 tmp_pos1 - tmp_pos3 - 1);
321 if (i != max_length) 321 if (i != max_length)
322 buf << "|"; 322 buf << "|";
419 return 0; 419 return 0;
420 } 420 }
421 else if (matches == PCRE_ERROR_NOMATCH) 421 else if (matches == PCRE_ERROR_NOMATCH)
422 break; 422 break;
423 else if (ovector[1] <= ovector[0]) 423 else if (ovector[1] <= ovector[0])
424 break; 424 {
425 // FIXME: Zero sized match!! Is this the right thing to do?
426 idx = ovector[0] + 1;
427 continue;
428 }
425 else 429 else
426 { 430 {
427 int pos_match = 0; 431 int pos_match = 0;
428 Matrix te(matches-1,2); 432 Matrix te(matches-1,2);
429 for (int i = 1; i < matches; i++) 433 for (int i = 1; i < matches; i++)
513 { 517 {
514 // Count actual matches 518 // Count actual matches
515 int matches = 0; 519 int matches = 0;
516 while (matches < subexpr && match[matches].rm_so >= 0) 520 while (matches < subexpr && match[matches].rm_so >= 0)
517 matches++; 521 matches++;
522
523 if (matches == 0 || match[0].rm_eo == 0)
524 break;
518 525
519 s = double (match[0].rm_so+1+idx); 526 s = double (match[0].rm_so+1+idx);
520 e = double (match[0].rm_eo+idx); 527 e = double (match[0].rm_eo+idx);
521 Matrix te(matches-1,2); 528 Matrix te(matches-1,2);
522 for (int i = 1; i < matches; i++) 529 for (int i = 1; i < matches; i++)