Lines Matching full:regex
525 // regfree'ing an invalid regex might crash because the content
526 // of the regex is undefined. Since the regex's are essentially
553 void RE::Init(const char* regex) {
554 pattern_ = posix::StrDup(regex);
558 const size_t full_regex_len = strlen(regex) + 10;
561 snprintf(full_pattern, full_regex_len, "^(%s)$", regex);
568 // Some implementation of POSIX regex (e.g. on at least some
570 // regex. We change it to an equivalent form "()" to be safe.
572 const char* const partial_regex = (*regex == '\0') ? "()" : regex;
576 << "Regular expression \"" << regex
633 std::string FormatRegexSyntaxError(const char* regex, int index) {
635 << " in simple regular expression \"" << regex << "\": ").GetString();
638 // Generates non-fatal failures and returns false if regex is invalid;
640 bool ValidateRegex(const char* regex) {
641 if (regex == NULL) {
643 // assertion failures to match where the regex is used in user
653 for (int i = 0; regex[i]; i++) {
654 if (regex[i] == '\\') { // An escape sequence
656 if (regex[i] == '\0') {
657 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
662 if (!IsValidEscape(regex[i])) {
663 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
664 << "invalid escape sequence \"\\" << regex[i] << "\".";
669 const char ch = regex[i];
672 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
675 } else if (ch == '$' && regex[i + 1] != '\0') {
676 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
680 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
684 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
696 // Matches a repeated regex atom followed by a valid simple regular
697 // expression. The regex atom is defined as c if escaped is false,
704 bool escaped, char c, char repeat, const char* regex,
714 if (i >= min_count && MatchRegexAtHead(regex, str + i)) {
727 // Returns true iff regex matches a prefix of str. regex must be a
730 bool MatchRegexAtHead(const char* regex, const char* str) {
731 if (*regex == '\0') // An empty regex matches a prefix of anything.
734 // "$" only matches the end of a string. Note that regex being
736 if (*regex == '$')
739 // Is the first thing in regex an escape sequence?
740 const bool escaped = *regex == '\\';
742 ++regex;
743 if (IsRepeat(regex[1])) {
745 // here's an indirect recursion. It terminates as the regex gets
748 escaped, regex[0], regex[1], regex + 2, str);
750 // regex isn't empty, isn't "$", and doesn't start with a
751 // repetition. We match the first atom of regex with the first
753 return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) &&
754 MatchRegexAtHead(regex + 1, str + 1);
758 // Returns true iff regex matches any substring of str. regex must be
762 // the regex length, so we won't need to worry about running out of
764 // exponential with respect to the regex length + the string length,
766 bool MatchRegexAnywhere(const char* regex, const char* str) {
767 if (regex == NULL || str == NULL)
770 if (*regex == '^')
771 return MatchRegexAtHead(regex + 1, str);
775 if (MatchRegexAtHead(regex, str))
800 void RE::Init(const char* regex) {
802 if (regex != NULL) {
803 pattern_ = posix::StrDup(regex);
806 is_valid_ = ValidateRegex(regex);
808 // No need to calculate the full pattern when the regex is invalid.
812 const size_t len = strlen(regex);
819 if (*regex != '^')
824 memcpy(buffer, regex, len);
827 if (len == 0 || regex[len - 1] != '$')