• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/llvmCore-3425.0.34/utils/unittest/googletest/

Lines Matching defs:regex

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