Lines Matching refs:regex

143 void RE::Init(const char* regex) {  in Init()  argument
144 pattern_ = posix::StrDup(regex); in Init()
148 const size_t full_regex_len = strlen(regex) + 10; in Init()
151 snprintf(full_pattern, full_regex_len, "^(%s)$", regex); in Init()
162 const char* const partial_regex = (*regex == '\0') ? "()" : regex; in Init()
166 << "Regular expression \"" << regex in Init()
223 String FormatRegexSyntaxError(const char* regex, int index) { in FormatRegexSyntaxError() argument
225 << " in simple regular expression \"" << regex << "\": ").GetString(); in FormatRegexSyntaxError()
230 bool ValidateRegex(const char* regex) { in ValidateRegex() argument
231 if (regex == NULL) { in ValidateRegex()
243 for (int i = 0; regex[i]; i++) { in ValidateRegex()
244 if (regex[i] == '\\') { // An escape sequence in ValidateRegex()
246 if (regex[i] == '\0') { in ValidateRegex()
247 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1) in ValidateRegex()
252 if (!IsValidEscape(regex[i])) { in ValidateRegex()
253 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1) in ValidateRegex()
254 << "invalid escape sequence \"\\" << regex[i] << "\"."; in ValidateRegex()
259 const char ch = regex[i]; in ValidateRegex()
262 ADD_FAILURE() << FormatRegexSyntaxError(regex, i) in ValidateRegex()
265 } else if (ch == '$' && regex[i + 1] != '\0') { in ValidateRegex()
266 ADD_FAILURE() << FormatRegexSyntaxError(regex, i) in ValidateRegex()
270 ADD_FAILURE() << FormatRegexSyntaxError(regex, i) in ValidateRegex()
274 ADD_FAILURE() << FormatRegexSyntaxError(regex, i) in ValidateRegex()
294 bool escaped, char c, char repeat, const char* regex, in MatchRepetitionAndRegexAtHead() argument
304 if (i >= min_count && MatchRegexAtHead(regex, str + i)) { in MatchRepetitionAndRegexAtHead()
320 bool MatchRegexAtHead(const char* regex, const char* str) { in MatchRegexAtHead() argument
321 if (*regex == '\0') // An empty regex matches a prefix of anything. in MatchRegexAtHead()
326 if (*regex == '$') in MatchRegexAtHead()
330 const bool escaped = *regex == '\\'; in MatchRegexAtHead()
332 ++regex; in MatchRegexAtHead()
333 if (IsRepeat(regex[1])) { in MatchRegexAtHead()
338 escaped, regex[0], regex[1], regex + 2, str); in MatchRegexAtHead()
343 return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) && in MatchRegexAtHead()
344 MatchRegexAtHead(regex + 1, str + 1); in MatchRegexAtHead()
356 bool MatchRegexAnywhere(const char* regex, const char* str) { in MatchRegexAnywhere() argument
357 if (regex == NULL || str == NULL) in MatchRegexAnywhere()
360 if (*regex == '^') in MatchRegexAnywhere()
361 return MatchRegexAtHead(regex + 1, str); in MatchRegexAnywhere()
365 if (MatchRegexAtHead(regex, str)) in MatchRegexAnywhere()
390 void RE::Init(const char* regex) { in Init() argument
392 if (regex != NULL) { in Init()
393 pattern_ = posix::StrDup(regex); in Init()
396 is_valid_ = ValidateRegex(regex); in Init()
402 const size_t len = strlen(regex); in Init()
409 if (*regex != '^') in Init()
414 memcpy(buffer, regex, len); in Init()
417 if (len == 0 || regex[len - 1] != '$') in Init()