Lines Matching full:regex
117 // regfree'ing an invalid regex might crash because the content in ~RE()
118 // of the regex is undefined. Since the regex's are essentially in ~RE()
145 void RE::Init(const char* regex) { in Init() argument
146 pattern_ = posix::StrDup(regex); in Init()
150 const size_t full_regex_len = strlen(regex) + 10; in Init()
153 snprintf(full_pattern, full_regex_len, "^(%s)$", regex); in Init()
160 // Some implementation of POSIX regex (e.g. on at least some in Init()
162 // regex. We change it to an equivalent form "()" to be safe. in Init()
164 const char* const partial_regex = (*regex == '\0') ? "()" : regex; in Init()
168 << "Regular expression \"" << regex in Init()
225 String FormatRegexSyntaxError(const char* regex, int index) { in FormatRegexSyntaxError() argument
227 << " in simple regular expression \"" << regex << "\": ").GetString(); in FormatRegexSyntaxError()
230 // Generates non-fatal failures and returns false if regex is invalid;
232 bool ValidateRegex(const char* regex) { in ValidateRegex() argument
233 if (regex == NULL) { in ValidateRegex()
235 // assertion failures to match where the regex is used in user in ValidateRegex()
245 for (int i = 0; regex[i]; i++) { in ValidateRegex()
246 if (regex[i] == '\\') { // An escape sequence in ValidateRegex()
248 if (regex[i] == '\0') { in ValidateRegex()
249 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1) in ValidateRegex()
254 if (!IsValidEscape(regex[i])) { in ValidateRegex()
255 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1) in ValidateRegex()
256 << "invalid escape sequence \"\\" << regex[i] << "\"."; in ValidateRegex()
261 const char ch = regex[i]; in ValidateRegex()
264 ADD_FAILURE() << FormatRegexSyntaxError(regex, i) in ValidateRegex()
267 } else if (ch == '$' && regex[i + 1] != '\0') { in ValidateRegex()
268 ADD_FAILURE() << FormatRegexSyntaxError(regex, i) in ValidateRegex()
272 ADD_FAILURE() << FormatRegexSyntaxError(regex, i) in ValidateRegex()
276 ADD_FAILURE() << FormatRegexSyntaxError(regex, i) in ValidateRegex()
288 // Matches a repeated regex atom followed by a valid simple regular
289 // expression. The regex atom is defined as c if escaped is false,
296 bool escaped, char c, char repeat, const char* regex, in MatchRepetitionAndRegexAtHead() argument
306 if (i >= min_count && MatchRegexAtHead(regex, str + i)) { in MatchRepetitionAndRegexAtHead()
319 // Returns true iff regex matches a prefix of str. regex must be a
322 bool MatchRegexAtHead(const char* regex, const char* str) { in MatchRegexAtHead() argument
323 if (*regex == '\0') // An empty regex matches a prefix of anything. in MatchRegexAtHead()
326 // "$" only matches the end of a string. Note that regex being in MatchRegexAtHead()
328 if (*regex == '$') in MatchRegexAtHead()
331 // Is the first thing in regex an escape sequence? in MatchRegexAtHead()
332 const bool escaped = *regex == '\\'; in MatchRegexAtHead()
334 ++regex; in MatchRegexAtHead()
335 if (IsRepeat(regex[1])) { in MatchRegexAtHead()
337 // here's an indirect recursion. It terminates as the regex gets in MatchRegexAtHead()
340 escaped, regex[0], regex[1], regex + 2, str); in MatchRegexAtHead()
342 // regex isn't empty, isn't "$", and doesn't start with a in MatchRegexAtHead()
343 // repetition. We match the first atom of regex with the first in MatchRegexAtHead()
345 return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) && in MatchRegexAtHead()
346 MatchRegexAtHead(regex + 1, str + 1); in MatchRegexAtHead()
350 // Returns true iff regex matches any substring of str. regex must be
354 // the regex length, so we won't need to worry about running out of
356 // exponential with respect to the regex length + the string length,
358 bool MatchRegexAnywhere(const char* regex, const char* str) { in MatchRegexAnywhere() argument
359 if (regex == NULL || str == NULL) in MatchRegexAnywhere()
362 if (*regex == '^') in MatchRegexAnywhere()
363 return MatchRegexAtHead(regex + 1, str); in MatchRegexAnywhere()
367 if (MatchRegexAtHead(regex, str)) in MatchRegexAnywhere()
392 void RE::Init(const char* regex) { in Init() argument
394 if (regex != NULL) { in Init()
395 pattern_ = posix::StrDup(regex); in Init()
398 is_valid_ = ValidateRegex(regex); in Init()
400 // No need to calculate the full pattern when the regex is invalid. in Init()
404 const size_t len = strlen(regex); in Init()
411 if (*regex != '^') in Init()
416 memcpy(buffer, regex, len); in Init()
419 if (len == 0 || regex[len - 1] != '$') in Init()