commit b5fc1a5a7866f232b38562db2c5c3c74b544ae56 Author: tim Date: Wed Oct 2 09:56:17 2013 -0400 2013-10-02 Tim Shen * include/bits/regex_compiler.h (_BracketMatcher<>::_M_add_equivalence_class): Implement it correctly. * include/bits/regex_compiler.tcc (_BracketMatcher<>::operator()): Add _M_equiv_set support. * testsuite/28_regex/algorithms/regex_match/extended/ cstring_bracket_01.cc: Add new "[[=a=]]" testcase. diff --git a/libstdc++-v3/include/bits/regex_compiler.h b/libstdc++-v3/include/bits/regex_compiler.h index 4e393e7..297fe3f 100644 --- a/libstdc++-v3/include/bits/regex_compiler.h +++ b/libstdc++-v3/include/bits/regex_compiler.h @@ -213,19 +213,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void _M_add_equivalence_class(const _StringT& __s) { - _M_add_character_class( - _M_traits.transform_primary(__s.data(), - __s.data() + __s.size())); + auto __st = _M_traits.lookup_collatename(__s.data(), + __s.data() + __s.size()); + if (__st.empty()) + __throw_regex_error(regex_constants::error_collate); + __st = _M_traits.transform_primary(__st.data(), + __st.data() + __st.size()); + _M_equiv_set.insert(__st); } void _M_add_character_class(const _StringT& __s) { - auto __st = _M_traits. - lookup_classname(__s.data(), __s.data() + __s.size(), _M_is_icase()); - if (__st == 0) + auto __mask = _M_traits.lookup_classname(__s.data(), + __s.data() + __s.size(), + _M_is_icase()); + if (__mask == 0) __throw_regex_error(regex_constants::error_ctype); - _M_class_set |= __st; + _M_class_set |= __mask; } void @@ -260,6 +265,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } std::set<_CharT> _M_char_set; + std::set<_StringT> _M_equiv_set; std::set> _M_range_set; const _TraitsT& _M_traits; _CharClassT _M_class_set; diff --git a/libstdc++-v3/include/bits/regex_compiler.tcc b/libstdc++-v3/include/bits/regex_compiler.tcc index 94f3d5e..5225bc1e 100644 --- a/libstdc++-v3/include/bits/regex_compiler.tcc +++ b/libstdc++-v3/include/bits/regex_compiler.tcc @@ -437,9 +437,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator()(_CharT __ch) const { bool __ret = false; - if (_M_traits.isctype(__ch, _M_class_set)) - __ret = true; - else if (_M_char_set.count(_M_translate(__ch))) + if (_M_traits.isctype(__ch, _M_class_set) + || _M_char_set.count(_M_translate(__ch)) + || _M_equiv_set.count(_M_traits.transform_primary(&__ch, &__ch+1))) __ret = true; else { diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_bracket_01.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_bracket_01.cc index 3a4ff31..5d83785 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_bracket_01.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_bracket_01.cc @@ -56,6 +56,11 @@ test01() VERIFY( std::regex_match("pre/a", re) ); VERIFY( std::regex_match("pre/0", re) ); } + { + std::regex re("pre/[[=a=]]", std::regex::extended); + VERIFY( std::regex_match("pre/a", re) ); + VERIFY( std::regex_match("pre/A", re) ); + } } int