15 #ifndef BENCHMARK_RE_H_
16 #define BENCHMARK_RE_H_
22 #if !defined(HAVE_STD_REGEX) && \
23 !defined(HAVE_GNU_POSIX_REGEX) && \
24 !defined(HAVE_POSIX_REGEX)
26 #if defined(BENCHMARK_OS_LINUX) || defined(BENCHMARK_OS_APPLE)
27 #define HAVE_POSIX_REGEX 1
28 #elif __cplusplus >= 199711L
29 #define HAVE_STD_REGEX 1
35 #if defined(BENCHMARK_HAS_NO_EXCEPTIONS) && \
36 defined(BENCHMARK_HAVE_STD_REGEX) && \
37 (defined(HAVE_GNU_POSIX_REGEX) || defined(HAVE_POSIX_REGEX))
41 #if defined(HAVE_STD_REGEX)
43 #elif defined(HAVE_GNU_POSIX_REGEX)
45 #elif defined(HAVE_POSIX_REGEX)
48 #error No regular expression backend was found!
79 #if defined(HAVE_STD_REGEX)
81 #elif defined(HAVE_POSIX_REGEX) || defined(HAVE_GNU_POSIX_REGEX)
84 #error No regular expression backend implementation available
88 #if defined(HAVE_STD_REGEX)
91 #ifdef BENCHMARK_HAS_NO_EXCEPTIONS
96 re_ = std::regex(
spec, std::regex_constants::extended);
98 #ifndef BENCHMARK_HAS_NO_EXCEPTIONS
100 catch (
const std::regex_error& e) {
115 return std::regex_search(
str, re_);
120 int ec = regcomp(&re_,
spec.c_str(), REG_EXTENDED | REG_NOSUB);
123 size_t needed = regerror(ec, &re_,
nullptr, 0);
124 char* errbuf =
new char[needed];
125 regerror(ec, &re_, errbuf, needed);
130 error->assign(errbuf, needed - 1);
152 return regexec(&re_,
str.c_str(), 0,
nullptr, 0) == 0;
158 #endif // BENCHMARK_RE_H_