commit 62121ad0480af3d9abe0b0ece9bc636dabd2b6c2 Author: tim Date: Thu Aug 22 17:28:51 2013 +0800 2013-08-23 Tim Shen * include/bits/regex.h: Fix callers. * include/bits/regex_compiler.h: Store _Traits reference. * include/bits/regex_executor.h: Add _Traits member for _DFSExecutor. * include/bits/regex_executor.tcc: Likewise. * testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc: New. diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h index 4838819..19d9bbd 100644 --- a/libstdc++-v3/include/bits/regex.h +++ b/libstdc++-v3/include/bits/regex.h @@ -880,8 +880,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION assign(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s, flag_type __flags = ECMAScript) { - basic_regex __tmp(__s, __flags); - this->swap(__tmp); + _M_automaton = + __detail::_Compiler + (__s.begin(), __s.end(), _M_traits, _M_flags)._M_get_nfa(); return *this; } diff --git a/libstdc++-v3/include/bits/regex_compiler.h b/libstdc++-v3/include/bits/regex_compiler.h index 1d588b9..a1107bb 100644 --- a/libstdc++-v3/include/bits/regex_compiler.h +++ b/libstdc++-v3/include/bits/regex_compiler.h @@ -214,7 +214,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _M_traits.transform(__s.begin(), __s.end()); } - _TraitsT _M_traits; + const _TraitsT& _M_traits; _FlagT _M_flags; bool _M_is_non_matching; std::vector<_CharT> _M_char_set; diff --git a/libstdc++-v3/include/bits/regex_executor.h b/libstdc++-v3/include/bits/regex_executor.h index 23998ed..6d66d88 100644 --- a/libstdc++-v3/include/bits/regex_executor.h +++ b/libstdc++-v3/include/bits/regex_executor.h @@ -120,13 +120,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef typename _BaseT::_ResultsVec _ResultsVec; typedef regex_constants::match_flag_type _FlagT; - _DFSExecutor(_BiIter __begin, - _BiIter __end, - _ResultsT& __results, - const _RegexT& __nfa, - _FlagT __flags) + _DFSExecutor(_BiIter __begin, + _BiIter __end, + _ResultsT& __results, + const _RegexT& __nfa, + const _TraitsT& __traits, + _FlagT __flags) : _BaseT(__begin, __end, __results, __flags, __nfa._M_sub_count()), - _M_traits(_TraitsT()), _M_nfa(__nfa), _M_results_ret(this->_M_results) + _M_traits(__traits), _M_nfa(__nfa), _M_results_ret(this->_M_results) { } void @@ -142,9 +143,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool _M_dfs(_StateIdT __i); - _ResultsVec _M_results_ret; - _TraitsT _M_traits; - const _RegexT& _M_nfa; + _ResultsVec _M_results_ret; + const _TraitsT& _M_traits; + const _RegexT& _M_nfa; }; // Like the DFS approach, it try every possible state transition; Unlike DFS, diff --git a/libstdc++-v3/include/bits/regex_executor.tcc b/libstdc++-v3/include/bits/regex_executor.tcc index edfd0b6..788d65e 100644 --- a/libstdc++-v3/include/bits/regex_executor.tcc +++ b/libstdc++-v3/include/bits/regex_executor.tcc @@ -320,7 +320,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION auto __p = std::static_pointer_cast<_NFA<_CharT, _TraitsT>> (__re._M_automaton); if (__p->_M_has_backref) - return _ExecutorPtr(new _DFSExecutorT(__b, __e, __m, *__p, __flags)); + return _ExecutorPtr(new _DFSExecutorT(__b, __e, __m, *__p, + __re._M_traits, __flags)); return _ExecutorPtr(new _BFSExecutorT(__b, __e, __m, *__p, __flags)); } diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc new file mode 100644 index 0000000..a7225cb --- /dev/null +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++11" } +// { dg-require-namedlocale "de_DE.UTF-8" } + +// +// 2013-08-23 Tim Shen +// +// Copyright (C) 2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 28.11.2 regex_match +// Tests Extended localization against a wide-string. + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::wstring str2 = L"ÜBER"; + std::wregex re2; + re2.imbue(std::locale("de_DE.UTF-8")); + re2.assign(L"[[:upper:]]*", std::regex::extended); + std::wsmatch m2; + VERIFY(std::regex_match(str2, m2, re2)); +} + +int +main() +{ + test01(); + return 0; +}