| 554 | } |
| 555 | |
| 556 | bool RE2::PossibleMatchRange(std::string* min, std::string* max, |
| 557 | int maxlen) const { |
| 558 | if (prog_ == NULL) |
| 559 | return false; |
| 560 | |
| 561 | int n = static_cast<int>(prefix_.size()); |
| 562 | if (n > maxlen) |
| 563 | n = maxlen; |
| 564 | |
| 565 | // Determine initial min max from prefix_ literal. |
| 566 | *min = prefix_.substr(0, n); |
| 567 | *max = prefix_.substr(0, n); |
| 568 | if (prefix_foldcase_) { |
| 569 | // prefix is ASCII lowercase; change *min to uppercase. |
| 570 | for (int i = 0; i < n; i++) { |
| 571 | char& c = (*min)[i]; |
| 572 | if ('a' <= c && c <= 'z') |
| 573 | c += 'A' - 'a'; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | // Add to prefix min max using PossibleMatchRange on regexp. |
| 578 | std::string dmin, dmax; |
| 579 | maxlen -= n; |
| 580 | if (maxlen > 0 && prog_->PossibleMatchRange(&dmin, &dmax, maxlen)) { |
| 581 | min->append(dmin); |
| 582 | max->append(dmax); |
| 583 | } else if (!max->empty()) { |
| 584 | // prog_->PossibleMatchRange has failed us, |
| 585 | // but we still have useful information from prefix_. |
| 586 | // Round up *max to allow any possible suffix. |
| 587 | PrefixSuccessor(max); |
| 588 | } else { |
| 589 | // Nothing useful. |
| 590 | *min = ""; |
| 591 | *max = ""; |
| 592 | return false; |
| 593 | } |
| 594 | |
| 595 | return true; |
| 596 | } |
| 597 | |
| 598 | // Avoid possible locale nonsense in standard strcasecmp. |
| 599 | // The string a is known to be all lowercase. |