Matches a repeated regex atom followed by a valid simple regular expression. The regex atom is defined as c if escaped is false, or \c otherwise. repeat is the repetition meta character (?, *, or +). The behavior is undefined if str contains too many characters to be indexable by size_t, in which case the test will probably time out anyway. We are fine with this limitation as std::string has i
| 9359 | // probably time out anyway. We are fine with this limitation as |
| 9360 | // std::string has it too. |
| 9361 | bool MatchRepetitionAndRegexAtHead( |
| 9362 | bool escaped, char c, char repeat, const char* regex, |
| 9363 | const char* str) { |
| 9364 | const size_t min_count = (repeat == '+') ? 1 : 0; |
| 9365 | const size_t max_count = (repeat == '?') ? 1 : |
| 9366 | static_cast<size_t>(-1) - 1; |
| 9367 | // We cannot call numeric_limits::max() as it conflicts with the |
| 9368 | // max() macro on Windows. |
| 9369 | |
| 9370 | for (size_t i = 0; i <= max_count; ++i) { |
| 9371 | // We know that the atom matches each of the first i characters in str. |
| 9372 | if (i >= min_count && MatchRegexAtHead(regex, str + i)) { |
| 9373 | // We have enough matches at the head, and the tail matches too. |
| 9374 | // Since we only care about *whether* the pattern matches str |
| 9375 | // (as opposed to *how* it matches), there is no need to find a |
| 9376 | // greedy match. |
| 9377 | return true; |
| 9378 | } |
| 9379 | if (str[i] == '\0' || !AtomMatchesChar(escaped, c, str[i])) |
| 9380 | return false; |
| 9381 | } |
| 9382 | return false; |
| 9383 | } |
| 9384 | |
| 9385 | // Returns true iff regex matches a prefix of str. regex must be a |
| 9386 | // valid simple regular expression and not start with "^", or the |
no test coverage detected