aboutsummaryrefslogtreecommitdiff
path: root/googletest/src/gtest-port.cc
diff options
context:
space:
mode:
Diffstat (limited to 'googletest/src/gtest-port.cc')
-rw-r--r--googletest/src/gtest-port.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc
index e9d12d92..3bb7dd45 100644
--- a/googletest/src/gtest-port.cc
+++ b/googletest/src/gtest-port.cc
@@ -697,13 +697,24 @@ bool RE::PartialMatch(const char* str, const RE& re) {
void RE::Init(const char* regex) {
pattern_ = regex;
+ // NetBSD (and Android, which takes its regex implemntation from NetBSD) does
+ // not include the GNU regex extensions (such as Perl style character classes
+ // like \w) in REG_EXTENDED. REG_EXTENDED is only specified to include the
+ // [[:alpha:]] style character classes. Enable REG_GNU wherever it is defined
+ // so users can use those extensions.
+#if defined(REG_GNU)
+ constexpr int reg_flags = REG_EXTENDED | REG_GNU;
+#else
+ constexpr int reg_flags = REG_EXTENDED;
+#endif
+
// Reserves enough bytes to hold the regular expression used for a
// full match.
const size_t full_regex_len = strlen(regex) + 10;
char* const full_pattern = new char[full_regex_len];
snprintf(full_pattern, full_regex_len, "^(%s)$", regex);
- is_valid_ = regcomp(&full_regex_, full_pattern, REG_EXTENDED) == 0;
+ is_valid_ = regcomp(&full_regex_, full_pattern, reg_flags) == 0;
// We want to call regcomp(&partial_regex_, ...) even if the
// previous expression returns false. Otherwise partial_regex_ may
// not be properly initialized can may cause trouble when it's
@@ -714,7 +725,7 @@ void RE::Init(const char* regex) {
// regex. We change it to an equivalent form "()" to be safe.
if (is_valid_) {
const char* const partial_regex = (*regex == '\0') ? "()" : regex;
- is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0;
+ is_valid_ = regcomp(&partial_regex_, partial_regex, reg_flags) == 0;
}
EXPECT_TRUE(is_valid_)
<< "Regular expression \"" << regex