Lines Matching refs:regex

697 void RE::Init(const char* regex) {  in Init()  argument
698 pattern_ = regex; in Init()
702 const size_t full_regex_len = strlen(regex) + 10; in Init()
705 snprintf(full_pattern, full_regex_len, "^(%s)$", regex); in Init()
716 const char* const partial_regex = (*regex == '\0') ? "()" : regex; in Init()
720 << "Regular expression \"" << regex in Init()
788 static std::string FormatRegexSyntaxError(const char* regex, int index) { in FormatRegexSyntaxError() argument
790 << " in simple regular expression \"" << regex << "\": ") in FormatRegexSyntaxError()
796 bool ValidateRegex(const char* regex) { in ValidateRegex() argument
797 if (regex == nullptr) { in ValidateRegex()
806 for (int i = 0; regex[i]; i++) { in ValidateRegex()
807 if (regex[i] == '\\') { // An escape sequence in ValidateRegex()
809 if (regex[i] == '\0') { in ValidateRegex()
810 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1) in ValidateRegex()
815 if (!IsValidEscape(regex[i])) { in ValidateRegex()
816 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1) in ValidateRegex()
817 << "invalid escape sequence \"\\" << regex[i] << "\"."; in ValidateRegex()
822 const char ch = regex[i]; in ValidateRegex()
825 ADD_FAILURE() << FormatRegexSyntaxError(regex, i) in ValidateRegex()
828 } else if (ch == '$' && regex[i + 1] != '\0') { in ValidateRegex()
829 ADD_FAILURE() << FormatRegexSyntaxError(regex, i) in ValidateRegex()
833 ADD_FAILURE() << FormatRegexSyntaxError(regex, i) << "'" << ch in ValidateRegex()
837 ADD_FAILURE() << FormatRegexSyntaxError(regex, i) << "'" << ch in ValidateRegex()
857 const char* regex, const char* str) { in MatchRepetitionAndRegexAtHead() argument
865 if (i >= min_count && MatchRegexAtHead(regex, str + i)) { in MatchRepetitionAndRegexAtHead()
880 bool MatchRegexAtHead(const char* regex, const char* str) { in MatchRegexAtHead() argument
881 if (*regex == '\0') // An empty regex matches a prefix of anything. in MatchRegexAtHead()
886 if (*regex == '$') return *str == '\0'; in MatchRegexAtHead()
889 const bool escaped = *regex == '\\'; in MatchRegexAtHead()
890 if (escaped) ++regex; in MatchRegexAtHead()
891 if (IsRepeat(regex[1])) { in MatchRegexAtHead()
895 return MatchRepetitionAndRegexAtHead(escaped, regex[0], regex[1], regex + 2, in MatchRegexAtHead()
901 return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) && in MatchRegexAtHead()
902 MatchRegexAtHead(regex + 1, str + 1); in MatchRegexAtHead()
914 bool MatchRegexAnywhere(const char* regex, const char* str) { in MatchRegexAnywhere() argument
915 if (regex == nullptr || str == nullptr) return false; in MatchRegexAnywhere()
917 if (*regex == '^') return MatchRegexAtHead(regex + 1, str); in MatchRegexAnywhere()
921 if (MatchRegexAtHead(regex, str)) return true; in MatchRegexAnywhere()
942 void RE::Init(const char* regex) { in Init() argument
946 if (regex != nullptr) { in Init()
947 pattern_ = regex; in Init()
950 is_valid_ = ValidateRegex(regex); in Init()