Lines Matching full:regex
1353 GTEST_API_ bool ValidateRegex(const char* regex);
1354 GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
1356 bool escaped, char ch, char repeat, const char* regex, const char* str);
1357 GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
1700 "A colon-separated list of glob (not regex) patterns "
6839 bool DeathTest::Create(const char* statement, const RE* regex,
6842 statement, regex, file, line, test);
6874 const RE* regex() const { return regex_; }
7013 // regex: A regular expression object to be applied to
7049 const bool matched = RE::PartialMatch(error_message.c_str(), *regex());
7054 << " Expected: " << regex()->pattern() << "\n"
7272 ForkingDeathTest(const char* statement, const RE* regex);
7647 bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,
7676 *test = new WindowsDeathTest(statement, regex, file, line);
7682 *test = new ExecDeathTest(statement, regex, file, line);
7684 *test = new NoExecDeathTest(statement, regex);
8352 // regfree'ing an invalid regex might crash because the content
8353 // of the regex is undefined. Since the regex's are essentially
8380 void RE::Init(const char* regex) {
8381 pattern_ = posix::StrDup(regex);
8385 const size_t full_regex_len = strlen(regex) + 10;
8388 snprintf(full_pattern, full_regex_len, "^(%s)$", regex);
8395 // Some implementation of POSIX regex (e.g. on at least some
8397 // regex. We change it to an equivalent form "()" to be safe.
8399 const char* const partial_regex = (*regex == '\0') ? "()" : regex;
8403 << "Regular expression \"" << regex
8460 std::string FormatRegexSyntaxError(const char* regex, int index) {
8462 << " in simple regular expression \"" << regex << "\": ").GetString();
8465 // Generates non-fatal failures and returns false if regex is invalid;
8467 bool ValidateRegex(const char* regex) {
8468 if (regex == NULL) {
8470 // assertion failures to match where the regex is used in user
8480 for (int i = 0; regex[i]; i++) {
8481 if (regex[i] == '\\') { // An escape sequence
8483 if (regex[i] == '\0') {
8484 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
8489 if (!IsValidEscape(regex[i])) {
8490 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
8491 << "invalid escape sequence \"\\" << regex[i] << "\".";
8496 const char ch = regex[i];
8499 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
8502 } else if (ch == '$' && regex[i + 1] != '\0') {
8503 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
8507 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
8511 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
8523 // Matches a repeated regex atom followed by a valid simple regular
8524 // expression. The regex atom is defined as c if escaped is false,
8531 bool escaped, char c, char repeat, const char* regex,
8541 if (i >= min_count && MatchRegexAtHead(regex, str + i)) {
8554 // Returns true iff regex matches a prefix of str. regex must be a
8557 bool MatchRegexAtHead(const char* regex, const char* str) {
8558 if (*regex == '\0') // An empty regex matches a prefix of anything.
8561 // "$" only matches the end of a string. Note that regex being
8563 if (*regex == '$')
8566 // Is the first thing in regex an escape sequence?
8567 const bool escaped = *regex == '\\';
8569 ++regex;
8570 if (IsRepeat(regex[1])) {
8572 // here's an indirect recursion. It terminates as the regex gets
8575 escaped, regex[0], regex[1], regex + 2, str);
8577 // regex isn't empty, isn't "$", and doesn't start with a
8578 // repetition. We match the first atom of regex with the first
8580 return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) &&
8581 MatchRegexAtHead(regex + 1, str + 1);
8585 // Returns true iff regex matches any substring of str. regex must be
8589 // the regex length, so we won't need to worry about running out of
8591 // exponential with respect to the regex length + the string length,
8593 bool MatchRegexAnywhere(const char* regex, const char* str) {
8594 if (regex == NULL || str == NULL)
8597 if (*regex == '^')
8598 return MatchRegexAtHead(regex + 1, str);
8602 if (MatchRegexAtHead(regex, str))
8627 void RE::Init(const char* regex) {
8629 if (regex != NULL) {
8630 pattern_ = posix::StrDup(regex);
8633 is_valid_ = ValidateRegex(regex);
8635 // No need to calculate the full pattern when the regex is invalid.
8639 const size_t len = strlen(regex);
8646 if (*regex != '^')
8651 memcpy(buffer, regex, len);
8654 if (len == 0 || regex[len - 1] != '$')