Home | History | Annotate | Download | only in src

Lines Matching refs:regex

548     // regfree'ing an invalid regex might crash because the content
549 // of the regex is undefined. Since the regex's are essentially
576 void RE::Init(const char* regex) {
577 pattern_ = posix::StrDup(regex);
581 const size_t full_regex_len = strlen(regex) + 10;
584 snprintf(full_pattern, full_regex_len, "^(%s)$", regex);
591 // Some implementation of POSIX regex (e.g. on at least some
593 // regex. We change it to an equivalent form "()" to be safe.
595 const char* const partial_regex = (*regex == '\0') ? "()" : regex;
599 << "Regular expression \"" << regex
656 std::string FormatRegexSyntaxError(const char* regex, int index) {
658 << " in simple regular expression \"" << regex << "\": ").GetString();
661 // Generates non-fatal failures and returns false if regex is invalid;
663 bool ValidateRegex(const char* regex) {
664 if (regex == NULL) {
666 // assertion failures to match where the regex is used in user
676 for (int i = 0; regex[i]; i++) {
677 if (regex[i] == '\\') { // An escape sequence
679 if (regex[i] == '\0') {
680 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
685 if (!IsValidEscape(regex[i])) {
686 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
687 << "invalid escape sequence \"\\" << regex[i] << "\".";
692 const char ch = regex[i];
695 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
698 } else if (ch == '$' && regex[i + 1] != '\0') {
699 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
703 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
707 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
719 // Matches a repeated regex atom followed by a valid simple regular
720 // expression. The regex atom is defined as c if escaped is false,
727 bool escaped, char c, char repeat, const char* regex,
737 if (i >= min_count && MatchRegexAtHead(regex, str + i)) {
750 // Returns true iff regex matches a prefix of str. regex must be a
753 bool MatchRegexAtHead(const char* regex, const char* str) {
754 if (*regex == '\0') // An empty regex matches a prefix of anything.
757 // "$" only matches the end of a string. Note that regex being
759 if (*regex == '$')
762 // Is the first thing in regex an escape sequence?
763 const bool escaped = *regex == '\\';
765 ++regex;
766 if (IsRepeat(regex[1])) {
768 // here's an indirect recursion. It terminates as the regex gets
771 escaped, regex[0], regex[1], regex + 2, str);
773 // regex isn't empty, isn't "$", and doesn't start with a
774 // repetition. We match the first atom of regex with the first
776 return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) &&
777 MatchRegexAtHead(regex + 1, str + 1);
781 // Returns true iff regex matches any substring of str. regex must be
785 // the regex length, so we won't need to worry about running out of
787 // exponential with respect to the regex length + the string length,
789 bool MatchRegexAnywhere(const char* regex, const char* str) {
790 if (regex == NULL || str == NULL)
793 if (*regex == '^')
794 return MatchRegexAtHead(regex + 1, str);
798 if (MatchRegexAtHead(regex, str))
823 void RE::Init(const char* regex) {
825 if (regex != NULL) {
826 pattern_ = posix::StrDup(regex);
829 is_valid_ = ValidateRegex(regex);
831 // No need to calculate the full pattern when the regex is invalid.
835 const size_t len = strlen(regex);
842 if (*regex != '^')
847 memcpy(buffer, regex, len);
850 if (len == 0 || regex[len - 1] != '$')