Lines Matching refs:regex
135 void RE::Init(const char* regex) {
136 pattern_ = posix::StrDup(regex);
140 const size_t full_regex_len = strlen(regex) + 10;
143 snprintf(full_pattern, full_regex_len, "^(%s)$", regex);
150 // Some implementation of POSIX regex (e.g. on at least some
152 // regex. We change it to an equivalent form "()" to be safe.
153 const char* const partial_regex = (*regex == '\0') ? "()" : regex;
157 << "Regular expression \"" << regex
214 String FormatRegexSyntaxError(const char* regex, int index) {
216 << " in simple regular expression \"" << regex << "\": ").GetString();
219 // Generates non-fatal failures and returns false if regex is invalid;
221 bool ValidateRegex(const char* regex) {
222 if (regex == NULL) {
224 // assertion failures to match where the regex is used in user
234 for (int i = 0; regex[i]; i++) {
235 if (regex[i] == '\\') { // An escape sequence
237 if (regex[i] == '\0') {
238 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
243 if (!IsValidEscape(regex[i])) {
244 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
245 << "invalid escape sequence \"\\" << regex[i] << "\".";
250 const char ch = regex[i];
253 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
256 } else if (ch == '$' && regex[i + 1] != '\0') {
257 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
261 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
265 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
277 // Matches a repeated regex atom followed by a valid simple regular
278 // expression. The regex atom is defined as c if escaped is false,
285 bool escaped, char c, char repeat, const char* regex,
295 if (i >= min_count && MatchRegexAtHead(regex, str + i)) {
308 // Returns true iff regex matches a prefix of str. regex must be a
311 bool MatchRegexAtHead(const char* regex, const char* str) {
312 if (*regex == '\0') // An empty regex matches a prefix of anything.
315 // "$" only matches the end of a string. Note that regex being
317 if (*regex == '$')
320 // Is the first thing in regex an escape sequence?
321 const bool escaped = *regex == '\\';
323 ++regex;
324 if (IsRepeat(regex[1])) {
326 // here's an indirect recursion. It terminates as the regex gets
329 escaped, regex[0], regex[1], regex + 2, str);
331 // regex isn't empty, isn't "$", and doesn't start with a
332 // repetition. We match the first atom of regex with the first
334 return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) &&
335 MatchRegexAtHead(regex + 1, str + 1);
339 // Returns true iff regex matches any substring of str. regex must be
343 // the regex length, so we won't need to worry about running out of
345 // exponential with respect to the regex length + the string length,
347 bool MatchRegexAnywhere(const char* regex, const char* str) {
348 if (regex == NULL || str == NULL)
351 if (*regex == '^')
352 return MatchRegexAtHead(regex + 1, str);
356 if (MatchRegexAtHead(regex, str))
381 void RE::Init(const char* regex) {
383 if (regex != NULL) {
384 pattern_ = posix::StrDup(regex);
387 is_valid_ = ValidateRegex(regex);
389 // No need to calculate the full pattern when the regex is invalid.
393 const size_t len = strlen(regex);
400 if (*regex != '^')
405 memcpy(buffer, regex, len);
408 if (len == 0 || regex[len - 1] != '$')