Home | History | Annotate | Download | only in src

Lines Matching full:regex

142     // regfree'ing an invalid regex might crash because the content
143 // of the regex is undefined. Since the regex's are essentially
170 void RE::Init(const char* regex) {
171 pattern_ = posix::StrDup(regex);
175 const size_t full_regex_len = strlen(regex) + 10;
178 snprintf(full_pattern, full_regex_len, "^(%s)$", regex);
185 // Some implementation of POSIX regex (e.g. on at least some
187 // regex. We change it to an equivalent form "()" to be safe.
189 const char* const partial_regex = (*regex == '\0') ? "()" : regex;
193 << "Regular expression \"" << regex
250 std::string FormatRegexSyntaxError(const char* regex, int index) {
252 << " in simple regular expression \"" << regex << "\": ").GetString();
255 // Generates non-fatal failures and returns false if regex is invalid;
257 bool ValidateRegex(const char* regex) {
258 if (regex == NULL) {
260 // assertion failures to match where the regex is used in user
270 for (int i = 0; regex[i]; i++) {
271 if (regex[i] == '\\') { // An escape sequence
273 if (regex[i] == '\0') {
274 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
279 if (!IsValidEscape(regex[i])) {
280 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
281 << "invalid escape sequence \"\\" << regex[i] << "\".";
286 const char ch = regex[i];
289 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
292 } else if (ch == '$' && regex[i + 1] != '\0') {
293 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
297 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
301 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
313 // Matches a repeated regex atom followed by a valid simple regular
314 // expression. The regex atom is defined as c if escaped is false,
321 bool escaped, char c, char repeat, const char* regex,
331 if (i >= min_count && MatchRegexAtHead(regex, str + i)) {
344 // Returns true iff regex matches a prefix of str. regex must be a
347 bool MatchRegexAtHead(const char* regex, const char* str) {
348 if (*regex == '\0') // An empty regex matches a prefix of anything.
351 // "$" only matches the end of a string. Note that regex being
353 if (*regex == '$')
356 // Is the first thing in regex an escape sequence?
357 const bool escaped = *regex == '\\';
359 ++regex;
360 if (IsRepeat(regex[1])) {
362 // here's an indirect recursion. It terminates as the regex gets
365 escaped, regex[0], regex[1], regex + 2, str);
367 // regex isn't empty, isn't "$", and doesn't start with a
368 // repetition. We match the first atom of regex with the first
370 return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) &&
371 MatchRegexAtHead(regex + 1, str + 1);
375 // Returns true iff regex matches any substring of str. regex must be
379 // the regex length, so we won't need to worry about running out of
381 // exponential with respect to the regex length + the string length,
383 bool MatchRegexAnywhere(const char* regex, const char* str) {
384 if (regex == NULL || str == NULL)
387 if (*regex == '^')
388 return MatchRegexAtHead(regex + 1, str);
392 if (MatchRegexAtHead(regex, str))
417 void RE::Init(const char* regex) {
419 if (regex != NULL) {
420 pattern_ = posix::StrDup(regex);
423 is_valid_ = ValidateRegex(regex);
425 // No need to calculate the full pattern when the regex is invalid.
429 const size_t len = strlen(regex);
436 if (*regex != '^')
441 memcpy(buffer, regex, len);
444 if (len == 0 || regex[len - 1] != '$')