diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2017-10-18 16:49:22 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2017-10-18 16:49:22 +0000 |
commit | 77623cb511968bf5741f861b10a447f38ee843a6 (patch) | |
tree | 85ec3b0c80813a6a5679af2e7f9a60529d881157 /libcxx/include/regex | |
parent | f00509c3a58d3b929a0549d2f8c511e025d2a802 (diff) | |
download | bcm5719-llvm-77623cb511968bf5741f861b10a447f38ee843a6.tar.gz bcm5719-llvm-77623cb511968bf5741f861b10a447f38ee843a6.zip |
Fix regex bug with ^\W. Thanks to Tim Shen for the patch. Reviewed as https://reviews.llvm.org/D37955
llvm-svn: 316095
Diffstat (limited to 'libcxx/include/regex')
-rw-r--r-- | libcxx/include/regex | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/libcxx/include/regex b/libcxx/include/regex index dfc97c58a3f..bd72012040b 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -2409,17 +2409,28 @@ __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const goto __exit; } } - if (!__neg_chars_.empty()) + // set of "__found" chars = + // union(complement(union(__neg_chars_, __neg_mask_)), + // other cases...) + // + // __neg_chars_ and __neg_mask_'d better be handled together, as there + // are no short circuit opportunities. + // + // In addition, when __neg_mask_/__neg_chars_ is empty, they should be + // treated as all ones/all chars. { - for (size_t __i = 0; __i < __neg_chars_.size(); ++__i) - { - if (__ch == __neg_chars_[__i]) - goto __is_neg_char; - } + const bool __in_neg_mask = (__neg_mask_ == 0) || + __traits_.isctype(__ch, __neg_mask_); + const bool __in_neg_chars = + __neg_chars_.empty() || + std::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != + __neg_chars_.end(); + if (!(__in_neg_mask || __in_neg_chars)) + { __found = true; goto __exit; + } } -__is_neg_char: if (!__ranges_.empty()) { string_type __s2 = __collate_ ? @@ -2451,11 +2462,6 @@ __is_neg_char: __found = true; goto __exit; } - if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_)) - { - __found = true; - goto __exit; - } } else __found = __negate_; // force reject |