Commit 6cb43087 by Tim Shen Committed by Tim Shen

regex.h: (regex_token_iterator<>::regex_token_iterator): Fix compile error.

2013-10-06  Tim Shen  <timshen91@gmail.com>

	* include/bits/regex.h: (regex_token_iterator<>::regex_token_iterator):
	Fix compile error.
	* include/bits/regex.tcc: (regex_replace<>): Remove default parameter.

2013-10-06  Tim Shen  <timshen91@gmail.com>

	* include/bits/regex.h (__regex_algo_impl<>, regex_match<>,
	regex_search<>): New abstract function for regex_match and regex_search.
	* include/bits/regex.tcc (__regex_algo_impl<>): Implement.
	* include/bits/regex_executor.h
	(_Executor<>::_M_lookahead,
	 _DFSExecutor<>::_M_clone,
	 _BFSExecutor<>::_M_clone): Let _M_clone to choose which executor to
	use.
	* include/bits/regex_executor.tcc (__get_executor<>): Update the
	definition to support __policy.
	* testsuite/28_regex/algorithms/regex_match/awk/cstring_01.cc: Use
	*_debug.
	* testsuite/28_regex/algorithms/regex_match/basic/empty_range.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/basic/string_01.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/basic/string_range_00_03.cc:
	Same.
	* testsuite/28_regex/algorithms/regex_match/basic/string_range_01_03.cc:
	Same.
	* testsuite/28_regex/algorithms/regex_match/basic/string_range_02_03.cc:
	Same.
	* testsuite/28_regex/algorithms/regex_match/ecma/char/53622.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/ecma/char/57173.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/ecma/char/58576.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/ecma/char/anymatcher.cc:
	Same.
	* testsuite/28_regex/algorithms/regex_match/ecma/char/backref.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/ecma/char/empty_range.cc:
	Same.
	* testsuite/28_regex/algorithms/regex_match/ecma/char/emptygroup.cc:
	Same.
	* testsuite/28_regex/algorithms/regex_match/ecma/char/hex.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/ecma/char/quoted_char.cc:
	Same.
	* testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/anymatcher.cc:
	Same.
	* testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/hex.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/extended/
	string_bracket_01.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/extended/cstring_plus.cc:
	Same.
	* testsuite/28_regex/algorithms/regex_match/extended/
	string_questionmark.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/extended/cstring_range.cc:
	Same.
	* testsuite/28_regex/algorithms/regex_match/extended/string_any.cc:
	Same.
	* testsuite/28_regex/algorithms/regex_match/extended/
	string_dispatch_01.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/extended/
	string_range_00_03.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/extended/
	string_range_01_03.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/extended/
	string_range_02_03.cc: Same.
	* testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc:
	Same.
	* testsuite/28_regex/algorithms/regex_search/basic/string_01.cc: Same.
	* testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc: Same.
	* testsuite/28_regex/algorithms/regex_search/ecma/flags.cc: Same.
	* testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc: Same.
	* testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc: Same.
	* testsuite/28_regex/match_results/format.cc: Same.
	* testsuite/util/testsuite_regex.h
	(regex_match_debug<>, regex_search_debug<>): Implement.

From-SVN: r203231
parent fef7e16b
2013-10-06 Tim Shen <timshen91@gmail.com>
* include/bits/regex.h: (regex_token_iterator<>::regex_token_iterator):
Fix compile error.
* include/bits/regex.tcc: (regex_replace<>): Remove default parameter.
2013-10-06 Tim Shen <timshen91@gmail.com>
* include/bits/regex.h (__regex_algo_impl<>, regex_match<>,
regex_search<>): New abstract function for regex_match and regex_search.
* include/bits/regex.tcc (__regex_algo_impl<>): Implement.
* include/bits/regex_executor.h
(_Executor<>::_M_lookahead,
_DFSExecutor<>::_M_clone,
_BFSExecutor<>::_M_clone): Let _M_clone to choose which executor to
use.
* include/bits/regex_executor.tcc (__get_executor<>): Update the
definition to support __policy.
* testsuite/28_regex/algorithms/regex_match/awk/cstring_01.cc: Use
*_debug.
* testsuite/28_regex/algorithms/regex_match/basic/empty_range.cc: Same.
* testsuite/28_regex/algorithms/regex_match/basic/string_01.cc: Same.
* testsuite/28_regex/algorithms/regex_match/basic/string_range_00_03.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/basic/string_range_01_03.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/basic/string_range_02_03.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/53622.cc: Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/57173.cc: Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/58576.cc: Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/anymatcher.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/backref.cc: Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/empty_range.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/emptygroup.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/hex.cc: Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/quoted_char.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/anymatcher.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/hex.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/
string_bracket_01.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/cstring_plus.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/extended/
string_questionmark.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/cstring_range.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/extended/string_any.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/extended/
string_dispatch_01.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/
string_range_00_03.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/
string_range_01_03.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/
string_range_02_03.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc:
Same.
* testsuite/28_regex/algorithms/regex_search/basic/string_01.cc: Same.
* testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc: Same.
* testsuite/28_regex/algorithms/regex_search/ecma/flags.cc: Same.
* testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc: Same.
* testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc: Same.
* testsuite/28_regex/match_results/format.cc: Same.
* testsuite/util/testsuite_regex.h
(regex_match_debug<>, regex_search_debug<>): Implement.
2013-10-06 Oleg Endo <olegendo@gcc.gnu.org> 2013-10-06 Oleg Endo <olegendo@gcc.gnu.org>
Paolo Carlini <paolo.carlini@oracle.com> Paolo Carlini <paolo.carlini@oracle.com>
......
...@@ -32,6 +32,24 @@ namespace std _GLIBCXX_VISIBILITY(default) ...@@ -32,6 +32,24 @@ namespace std _GLIBCXX_VISIBILITY(default)
{ {
_GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_BEGIN_NAMESPACE_VERSION
namespace __detail
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _BiIter, typename _Alloc,
typename _CharT, typename _TraitsT,
_RegexExecutorPolicy __policy,
bool __match_mode>
bool
__regex_algo_impl(_BiIter __s,
_BiIter __e,
match_results<_BiIter, _Alloc>& __m,
const basic_regex<_CharT, _TraitsT>& __re,
regex_constants::match_flag_type __flags);
_GLIBCXX_END_NAMESPACE_VERSION
}
/** /**
* @addtogroup regex * @addtogroup regex
* @{ * @{
...@@ -713,7 +731,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -713,7 +731,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_AutomatonPtr; _AutomatonPtr;
template<typename _BiIter, typename _Alloc, template<typename _BiIter, typename _Alloc,
typename _CharT, typename _TraitsT> typename _CharT, typename _TraitsT,
__detail::_RegexExecutorPolicy __policy>
friend std::unique_ptr< friend std::unique_ptr<
__detail::_Executor<_BiIter, _Alloc, _CharT, _TraitsT>> __detail::_Executor<_BiIter, _Alloc, _CharT, _TraitsT>>
__detail::__get_executor(_BiIter, __detail::__get_executor(_BiIter,
...@@ -722,19 +741,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -722,19 +741,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const basic_regex<_CharT, _TraitsT>&, const basic_regex<_CharT, _TraitsT>&,
regex_constants::match_flag_type); regex_constants::match_flag_type);
template<typename _Bp, typename _Ap, typename _Cp, typename _Rp> template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
friend bool __detail::_RegexExecutorPolicy, bool>
regex_match(_Bp, _Bp,
match_results<_Bp, _Ap>&,
const basic_regex<_Cp, _Rp>&,
regex_constants::match_flag_type);
template<typename _Bp, typename _Ap, typename _Cp, typename _Rp>
friend bool friend bool
regex_search(_Bp, _Bp, __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Rp>&,
const basic_regex<_Cp, _Rp>&, regex_constants::match_flag_type);
regex_constants::match_flag_type);
template<typename, typename, typename, typename> template<typename, typename, typename, typename>
friend class __detail::_Executor; friend class __detail::_Executor;
...@@ -1851,21 +1863,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1851,21 +1863,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename, typename, typename> template<typename, typename, typename>
friend class regex_iterator; friend class regex_iterator;
template<typename _Bp, typename _Ap, template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
typename _Ch_type, typename _Rx_traits> __detail::_RegexExecutorPolicy, bool>
friend bool
regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&,
const basic_regex<_Ch_type,
_Rx_traits>&,
regex_constants::match_flag_type);
template<typename _Bp, typename _Ap,
typename _Ch_type, typename _Rx_traits>
friend bool friend bool
regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
const basic_regex<_Ch_type, const basic_regex<_Cp, _Rp>&,
_Rx_traits>&, regex_constants::match_flag_type);
regex_constants::match_flag_type);
_Bi_iter _M_begin; _Bi_iter _M_begin;
bool _M_in_iterator; bool _M_in_iterator;
...@@ -1951,13 +1954,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1951,13 +1954,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*/ */
template<typename _Bi_iter, typename _Alloc, template<typename _Bi_iter, typename _Alloc,
typename _Ch_type, typename _Rx_traits> typename _Ch_type, typename _Rx_traits>
bool inline bool
regex_match(_Bi_iter __s, regex_match(_Bi_iter __s,
_Bi_iter __e, _Bi_iter __e,
match_results<_Bi_iter, _Alloc>& __m, match_results<_Bi_iter, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __re, const basic_regex<_Ch_type, _Rx_traits>& __re,
regex_constants::match_flag_type __flags regex_constants::match_flag_type __flags
= regex_constants::match_default); = regex_constants::match_default)
{
return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
__detail::_RegexExecutorPolicy::_S_auto, true>
(__s, __e, __m, __re, __flags);
}
/** /**
* @brief Indicates if there is a match between the regular expression @p e * @brief Indicates if there is a match between the regular expression @p e
...@@ -2091,12 +2099,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -2091,12 +2099,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*/ */
template<typename _Bi_iter, typename _Alloc, template<typename _Bi_iter, typename _Alloc,
typename _Ch_type, typename _Rx_traits> typename _Ch_type, typename _Rx_traits>
bool inline bool
regex_search(_Bi_iter __first, _Bi_iter __last, regex_search(_Bi_iter __s, _Bi_iter __e,
match_results<_Bi_iter, _Alloc>& __m, match_results<_Bi_iter, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __re, const basic_regex<_Ch_type, _Rx_traits>& __re,
regex_constants::match_flag_type __flags regex_constants::match_flag_type __flags
= regex_constants::match_default); = regex_constants::match_default)
{
return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
__detail::_RegexExecutorPolicy::_S_auto, false>
(__s, __e, __m, __re, __flags);
}
/** /**
* Searches for a regular expression within a range. * Searches for a regular expression within a range.
...@@ -2586,8 +2599,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -2586,8 +2599,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __rhs [IN] A %regex_token_iterator to copy. * @param __rhs [IN] A %regex_token_iterator to copy.
*/ */
regex_token_iterator(const regex_token_iterator& __rhs) regex_token_iterator(const regex_token_iterator& __rhs)
: _M_position(__rhs.position), _M_subs(__rhs.subs), _M_n(__rhs.N), : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs),
_M_result(__rhs.result), _M_suffix(__rhs.suffix), _M_n(__rhs._M_n), _M_result(__rhs._M_result), _M_suffix(__rhs._M_suffix),
_M_has_m1(__rhs._M_has_m1) _M_has_m1(__rhs._M_has_m1)
{ {
if (__rhs._M_result == &__rhs._M_suffix) if (__rhs._M_result == &__rhs._M_suffix)
......
...@@ -32,6 +32,83 @@ namespace std _GLIBCXX_VISIBILITY(default) ...@@ -32,6 +32,83 @@ namespace std _GLIBCXX_VISIBILITY(default)
{ {
_GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_BEGIN_NAMESPACE_VERSION
namespace __detail
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
// Result of merging regex_match and regex_search.
//
// __policy now can be _S_auto(auto dispatch by checking back-references)
// and _S_force_dfs(just use _DFSExecutor).
//
// That __match_mode is true means regex_match, else regex_search.
template<typename _BiIter, typename _Alloc,
typename _CharT, typename _TraitsT,
_RegexExecutorPolicy __policy,
bool __match_mode>
bool
__regex_algo_impl(_BiIter __s,
_BiIter __e,
match_results<_BiIter, _Alloc>& __m,
const basic_regex<_CharT, _TraitsT>& __re,
regex_constants::match_flag_type __flags)
{
if (__re._M_automaton == nullptr)
return false;
typename match_results<_BiIter, _Alloc>::_Base_type& __res = __m;
__res.resize(__re._M_automaton->_M_sub_count() + 2);
for (auto& __it : __res)
__it.matched = false;
typedef std::unique_ptr<_Executor<_BiIter, _Alloc, _CharT, _TraitsT>>
_ExecutorPtr;
typedef _DFSExecutor<_BiIter, _Alloc, _CharT, _TraitsT> _DFSExecutorT;
typedef _BFSExecutor<_BiIter, _Alloc, _CharT, _TraitsT> _BFSExecutorT;
_ExecutorPtr __executor =
__get_executor<_BiIter, _Alloc, _CharT, _TraitsT,
__policy>(__s, __e, __res, __re, __flags);
bool __ret;
if (__match_mode)
__ret = __executor->_M_match();
else
__ret = __executor->_M_search();
if (__ret)
{
for (auto __it : __res)
if (!__it.matched)
__it.first = __it.second = __e;
auto& __pre = __res[__res.size()-2];
auto& __suf = __res[__res.size()-1];
if (__match_mode)
{
__pre.matched = false;
__pre.first = __s;
__pre.second = __s;
__suf.matched = false;
__suf.first = __e;
__suf.second = __e;
}
else
{
__pre.first = __s;
__pre.second = __res[0].first;
__pre.matched = (__pre.first != __pre.second);
__suf.first = __res[0].second;
__suf.second = __e;
__suf.matched = (__suf.first != __suf.second);
}
if (__re.flags() & regex_constants::nosubs)
__res.resize(3);
}
return __ret;
}
_GLIBCXX_END_NAMESPACE_VERSION
}
template<typename _Ch_type> template<typename _Ch_type>
template<typename _Fwd_iter> template<typename _Fwd_iter>
typename regex_traits<_Ch_type>::string_type typename regex_traits<_Ch_type>::string_type
...@@ -295,7 +372,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -295,7 +372,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
value(_Ch_type __ch, int __radix) const value(_Ch_type __ch, int __radix) const
{ {
std::basic_istringstream<char_type> __is(string_type(1, __ch)); std::basic_istringstream<char_type> __is(string_type(1, __ch));
int __v; long __v;
if (__radix == 8) if (__radix == 8)
__is >> std::oct; __is >> std::oct;
else if (__radix == 16) else if (__radix == 16)
...@@ -318,7 +395,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -318,7 +395,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const __ctype_type& const __ctype_type&
__fctyp(use_facet<__ctype_type>(__traits.getloc())); __fctyp(use_facet<__ctype_type>(__traits.getloc()));
auto __output = [&](int __idx) auto __output = [&](size_t __idx)
{ {
auto& __sub = _Base_type::operator[](__idx); auto& __sub = _Base_type::operator[](__idx);
if (__sub.matched) if (__sub.matched)
...@@ -376,7 +453,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -376,7 +453,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__output(_Base_type::size()-1); __output(_Base_type::size()-1);
else if (__fctyp.is(__ctype_type::digit, *__next)) else if (__fctyp.is(__ctype_type::digit, *__next))
{ {
int __num = __traits.value(*__next, 10); long __num = __traits.value(*__next, 10);
if (++__next != __fmt_last if (++__next != __fmt_last
&& __fctyp.is(__ctype_type::digit, *__next)) && __fctyp.is(__ctype_type::digit, *__next))
{ {
...@@ -395,90 +472,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -395,90 +472,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __out; return __out;
} }
template<typename _Bi_iter, typename _Alloc,
typename _Ch_type, typename _Rx_traits>
bool
regex_match(_Bi_iter __s,
_Bi_iter __e,
match_results<_Bi_iter, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __re,
regex_constants::match_flag_type __flags
= regex_constants::match_default)
{
if (__re._M_automaton == nullptr)
return false;
typename match_results<_Bi_iter, _Alloc>::_Base_type& __res = __m;
auto __size = __re._M_automaton->_M_sub_count();
__size += 2;
__res.resize(__size);
for (decltype(__size) __i = 0; __i < __size; ++__i)
__res[__i].matched = false;
if (__detail::__get_executor(__s, __e, __res, __re, __flags)->_M_match())
{
for (auto __it : __res)
if (!__it.matched)
__it.first = __it.second = __e;
auto& __pre = __res[__res.size()-2];
auto& __suf = __res[__res.size()-1];
__pre.matched = false;
__pre.first = __s;
__pre.second = __s;
__suf.matched = false;
__suf.first = __e;
__suf.second = __e;
return true;
}
return false;
}
template<typename _Bi_iter, typename _Alloc,
typename _Ch_type, typename _Rx_traits>
bool
regex_search(_Bi_iter __first, _Bi_iter __last,
match_results<_Bi_iter, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __re,
regex_constants::match_flag_type __flags
= regex_constants::match_default)
{
if (__re._M_automaton == nullptr)
return false;
typename match_results<_Bi_iter, _Alloc>::_Base_type& __res = __m;
auto __size = __re._M_automaton->_M_sub_count();
__size += 2;
__res.resize(__size);
for (decltype(__size) __i = 0; __i < __size; ++__i)
__res[__i].matched = false;
if (__detail::__get_executor(__first, __last, __res, __re, __flags)
->_M_search())
{
for (auto __it : __res)
if (!__it.matched)
__it.first = __it.second = __last;
auto& __pre = __res[__res.size()-2];
auto& __suf = __res[__res.size()-1];
__pre.first = __first;
__pre.second = __res[0].first;
__pre.matched = (__pre.first != __pre.second);
__suf.first = __res[0].second;
__suf.second = __last;
__suf.matched = (__suf.first != __suf.second);
return true;
}
return false;
}
template<typename _Out_iter, typename _Bi_iter, template<typename _Out_iter, typename _Bi_iter,
typename _Rx_traits, typename _Ch_type> typename _Rx_traits, typename _Ch_type>
_Out_iter _Out_iter
regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last, regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
const basic_regex<_Ch_type, _Rx_traits>& __e, const basic_regex<_Ch_type, _Rx_traits>& __e,
const _Ch_type* __fmt, const _Ch_type* __fmt,
regex_constants::match_flag_type __flags regex_constants::match_flag_type __flags)
= regex_constants::match_default)
{ {
typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> _IterT; typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> _IterT;
_IterT __i(__first, __last, __e, __flags); _IterT __i(__first, __last, __e, __flags);
......
...@@ -40,7 +40,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -40,7 +40,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @{ * @{
*/ */
typedef int _StateIdT; typedef long _StateIdT;
typedef std::set<_StateIdT> _StateSet; typedef std::set<_StateIdT> _StateSet;
static const _StateIdT _S_invalid_state_id = -1; static const _StateIdT _S_invalid_state_id = -1;
...@@ -49,7 +49,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -49,7 +49,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// Operation codes that define the type of transitions within the base NFA /// Operation codes that define the type of transitions within the base NFA
/// that represents the regular expression. /// that represents the regular expression.
enum _Opcode enum _Opcode : int
{ {
_S_opcode_unknown, _S_opcode_unknown,
_S_opcode_alternative, _S_opcode_alternative,
...@@ -69,15 +69,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -69,15 +69,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
class _State class _State
{ {
public: public:
typedef int _OpcodeT;
typedef _Matcher<_CharT> _MatcherT; typedef _Matcher<_CharT> _MatcherT;
_OpcodeT _M_opcode; // type of outgoing transition _Opcode _M_opcode; // type of outgoing transition
_StateIdT _M_next; // outgoing transition _StateIdT _M_next; // outgoing transition
union // Since they are mutually exclusive. union // Since they are mutually exclusive.
{ {
unsigned int _M_subexpr; // for _S_opcode_subexpr_* size_t _M_subexpr; // for _S_opcode_subexpr_*
unsigned int _M_backref_index; // for _S_opcode_backref size_t _M_backref_index; // for _S_opcode_backref
struct struct
{ {
// for _S_opcode_alternative. // for _S_opcode_alternative.
...@@ -91,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -91,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}; };
_MatcherT _M_matches; // for _S_opcode_match _MatcherT _M_matches; // for _S_opcode_match
explicit _State(_OpcodeT __opcode) explicit _State(_Opcode __opcode)
: _M_opcode(__opcode), _M_next(_S_invalid_state_id) : _M_opcode(__opcode), _M_next(_S_invalid_state_id)
{ } { }
...@@ -110,7 +109,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -110,7 +109,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
class _Automaton class _Automaton
{ {
public: public:
typedef unsigned int _SizeT; typedef size_t _SizeT;
public: public:
virtual _SizeT virtual _SizeT
...@@ -130,7 +129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -130,7 +129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
public: public:
typedef _State<_CharT, _TraitsT> _StateT; typedef _State<_CharT, _TraitsT> _StateT;
typedef const _Matcher<_CharT>& _MatcherT; typedef const _Matcher<_CharT>& _MatcherT;
typedef unsigned int _SizeT; typedef size_t _SizeT;
typedef regex_constants::syntax_option_type _FlagT; typedef regex_constants::syntax_option_type _FlagT;
_NFA(_FlagT __f) _NFA(_FlagT __f)
...@@ -203,7 +202,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -203,7 +202,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
_StateIdT _StateIdT
_M_insert_backref(unsigned int __index); _M_insert_backref(size_t __index);
_StateIdT _StateIdT
_M_insert_line_begin() _M_insert_line_begin()
...@@ -250,7 +249,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -250,7 +249,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_dot(std::ostream& __ostr) const; _M_dot(std::ostream& __ostr) const;
#endif #endif
std::vector<unsigned int> _M_paren_stack; std::vector<size_t> _M_paren_stack;
_StateSet _M_accepting_states; _StateSet _M_accepting_states;
_FlagT _M_flags; _FlagT _M_flags;
_StateIdT _M_start_state; _StateIdT _M_start_state;
......
...@@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ {
__ostr << "digraph _Nfa {\n" __ostr << "digraph _Nfa {\n"
<< " rankdir=LR;\n"; << " rankdir=LR;\n";
for (unsigned int __i = 0; __i < this->size(); ++__i) for (size_t __i = 0; __i < this->size(); ++__i)
{ this->at(__i)._M_dot(__ostr, __i); } { this->at(__i)._M_dot(__ostr, __i); }
__ostr << "}\n"; __ostr << "}\n";
return __ostr; return __ostr;
...@@ -146,7 +146,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -146,7 +146,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _CharT, typename _TraitsT> template<typename _CharT, typename _TraitsT>
_StateIdT _NFA<_CharT, _TraitsT>:: _StateIdT _NFA<_CharT, _TraitsT>::
_M_insert_backref(unsigned int __index) _M_insert_backref(size_t __index)
{ {
// To figure out whether a backref is valid, a stack is used to store // To figure out whether a backref is valid, a stack is used to store
// unfinished sub-expressions. For example, when parsing // unfinished sub-expressions. For example, when parsing
......
...@@ -222,9 +222,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -222,9 +222,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__throw_regex_error(regex_constants::error_badbrace); __throw_regex_error(regex_constants::error_badbrace);
_StateSeqT __r(_M_pop()); _StateSeqT __r(_M_pop());
_StateSeqT __e(_M_nfa, _M_nfa._M_insert_dummy()); _StateSeqT __e(_M_nfa, _M_nfa._M_insert_dummy());
int __min_rep = _M_cur_int_value(10); long __min_rep = _M_cur_int_value(10);
bool __infi = false; bool __infi = false;
int __n; long __n;
// {3 // {3
if (_M_match_token(_ScannerT::_S_token_comma)) if (_M_match_token(_ScannerT::_S_token_comma))
...@@ -239,7 +239,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -239,7 +239,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__neg = __neg && _M_match_token(_ScannerT::_S_token_opt); __neg = __neg && _M_match_token(_ScannerT::_S_token_opt);
for (int __i = 0; __i < __min_rep; ++__i) for (long __i = 0; __i < __min_rep; ++__i)
__e._M_append(__r._M_clone()); __e._M_append(__r._M_clone());
if (__infi) if (__infi)
...@@ -260,7 +260,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -260,7 +260,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// "match less" one. Switch _M_alt and _M_next of all created // "match less" one. Switch _M_alt and _M_next of all created
// nodes. This is a hacking but IMO works well. // nodes. This is a hacking but IMO works well.
std::stack<_StateIdT> __stack; std::stack<_StateIdT> __stack;
for (int __i = 0; __i < __n; ++__i) for (long __i = 0; __i < __n; ++__i)
{ {
auto __tmp = __r._M_clone(); auto __tmp = __r._M_clone();
auto __alt = _M_nfa._M_insert_alt(__tmp._M_start, auto __alt = _M_nfa._M_insert_alt(__tmp._M_start,
...@@ -318,7 +318,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -318,7 +318,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
else if (_M_match_token(_ScannerT::_S_token_subexpr_begin)) else if (_M_match_token(_ScannerT::_S_token_subexpr_begin))
{ {
int __mark = _M_nfa._M_sub_count(); auto __mark = _M_nfa._M_sub_count();
_StateSeqT __r(_M_nfa, _M_nfa._M_insert_subexpr_begin()); _StateSeqT __r(_M_nfa, _M_nfa._M_insert_subexpr_begin());
this->_M_disjunction(); this->_M_disjunction();
if (!_M_match_token(_ScannerT::_S_token_subexpr_end)) if (!_M_match_token(_ScannerT::_S_token_subexpr_end))
...@@ -425,7 +425,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -425,7 +425,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Compiler<_FwdIter, _CharT, _TraitsT>:: _Compiler<_FwdIter, _CharT, _TraitsT>::
_M_cur_int_value(int __radix) _M_cur_int_value(int __radix)
{ {
int __v = 0; long __v = 0;
for (typename _StringT::size_type __i = 0; for (typename _StringT::size_type __i = 0;
__i < _M_value.length(); ++__i) __i < _M_value.length(); ++__i)
__v =__v * __radix + _M_traits.value(_M_value[__i], __radix); __v =__v * __radix + _M_traits.value(_M_value[__i], __radix);
......
...@@ -145,8 +145,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -145,8 +145,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool bool
_M_word_boundry(_State<_CharT, _TraitsT> __state) const; _M_word_boundry(_State<_CharT, _TraitsT> __state) const;
virtual std::unique_ptr<_Executor>
_M_clone() const = 0;
// Return whether now match the given sub-NFA.
bool bool
_M_lookahead(_State<_CharT, _TraitsT> __state) const; _M_lookahead(_State<_CharT, _TraitsT> __state) const
{
auto __sub = this->_M_clone();
__sub->_M_set_start(__state._M_alt);
return __sub->_M_search_from_first();
}
void void
_M_set_results(_ResultsVec& __cur_results); _M_set_results(_ResultsVec& __cur_results);
...@@ -226,6 +235,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -226,6 +235,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool bool
_M_dfs(_StateIdT __start); _M_dfs(_StateIdT __start);
std::unique_ptr<_BaseT>
_M_clone() const
{
return std::unique_ptr<_BaseT>(new _DFSExecutor(this->_M_current,
this->_M_end,
this->_M_results,
this->_M_re,
this->_M_flags));
}
// To record current solution. // To record current solution.
_ResultsVec _M_cur_results; _ResultsVec _M_cur_results;
const _NFAT& _M_nfa; const _NFAT& _M_nfa;
...@@ -268,8 +287,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -268,8 +287,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// greedy policy. // greedy policy.
// //
// The definition of `greedy`: // The definition of `greedy`:
// For the sequence of quantifiers in NFA sorted by there start position, // For the sequence of quantifiers in NFA sorted by their start positions,
// now maintain a vector in every matching state, with equal length to // now maintain a vector in every matching state, with length equal to
// quantifier seq, recording repeating times of every quantifier. Now to // quantifier seq, recording repeating times of every quantifier. Now to
// compare two matching states, we just lexically compare these two // compare two matching states, we just lexically compare these two
// vectors. To win the compare(to survive), one matching state needs to // vectors. To win the compare(to survive), one matching state needs to
...@@ -281,26 +300,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -281,26 +300,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// operator<() for lexicographical_compare will emit the answer. // operator<() for lexicographical_compare will emit the answer.
// //
// When two vectors equal, it means the `where`, `when` and quantifier // When two vectors equal, it means the `where`, `when` and quantifier
// counts are identical, and indicates the same solution; so just return // counts are identical, and indicates the same solution; so
// false. // _ResultsEntry::operator<() just return false.
struct _ResultsEntry struct _ResultsEntry
: private _ResultsVec : private _ResultsVec
{ {
public: public:
_ResultsEntry(unsigned int __res_sz, unsigned int __sz) _ResultsEntry(size_t __res_sz, size_t __sz)
: _ResultsVec(__res_sz), _M_quant_keys(__sz) : _ResultsVec(__res_sz), _M_quant_keys(__sz)
{ } { }
void void
resize(unsigned int __n) resize(size_t __n)
{ _ResultsVec::resize(__n); } { _ResultsVec::resize(__n); }
unsigned int size_t
size() size()
{ return _ResultsVec::size(); } { return _ResultsVec::size(); }
sub_match<_BiIter>& sub_match<_BiIter>&
operator[](unsigned int __idx) operator[](size_t __idx)
{ return _ResultsVec::operator[](__idx); } { return _ResultsVec::operator[](__idx); }
bool bool
...@@ -315,7 +334,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -315,7 +334,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
void void
_M_inc(unsigned int __idx, bool __neg) _M_inc(size_t __idx, bool __neg)
{ _M_quant_keys[__idx] += __neg ? 1 : -1; } { _M_quant_keys[__idx] += __neg ? 1 : -1; }
_ResultsVec& _ResultsVec&
...@@ -369,6 +388,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -369,6 +388,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool bool
_M_includes_some(); _M_includes_some();
std::unique_ptr<_BaseT>
_M_clone() const
{
return std::unique_ptr<_BaseT>(new _BFSExecutor(this->_M_current,
this->_M_end,
this->_M_results,
this->_M_re,
this->_M_flags));
}
std::map<_StateIdT, _ResultsPtr> _M_covered; std::map<_StateIdT, _ResultsPtr> _M_covered;
// To record global optimal solution. // To record global optimal solution.
_ResultsPtr _M_cur_results; _ResultsPtr _M_cur_results;
...@@ -376,15 +405,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -376,15 +405,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_StateIdT _M_start_state; _StateIdT _M_start_state;
}; };
template<typename _BiIter, typename _Alloc,
typename _CharT, typename _TraitsT>
std::unique_ptr<_Executor<_BiIter, _Alloc, _CharT, _TraitsT>>
__get_executor(_BiIter __b,
_BiIter __e,
std::vector<sub_match<_BiIter>, _Alloc>& __m,
const basic_regex<_CharT, _TraitsT>& __re,
regex_constants::match_flag_type __flags);
//@} regex-detail //@} regex-detail
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
} // namespace __detail } // namespace __detail
......
...@@ -365,39 +365,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -365,39 +365,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __ans; return __ans;
} }
// Return whether now match the given sub-NFA.
template<typename _BiIter, typename _Alloc,
typename _CharT, typename _TraitsT>
bool _Executor<_BiIter, _Alloc, _CharT, _TraitsT>::
_M_lookahead(_State<_CharT, _TraitsT> __state) const
{
auto __sub = __get_executor(this->_M_current,
this->_M_end,
this->_M_results,
this->_M_re,
this->_M_flags);
__sub->_M_set_start(__state._M_alt);
return __sub->_M_search_from_first();
}
template<typename _BiIter, typename _Alloc, template<typename _BiIter, typename _Alloc,
typename _CharT, typename _TraitsT> typename _CharT, typename _TraitsT>
void _Executor<_BiIter, _Alloc, _CharT, _TraitsT>:: void _Executor<_BiIter, _Alloc, _CharT, _TraitsT>::
_M_set_results(_ResultsVec& __cur_results) _M_set_results(_ResultsVec& __cur_results)
{ {
if (_M_re.flags() & regex_constants::nosubs) for (size_t __i = 0; __i < __cur_results.size(); ++__i)
{
// truncate
__cur_results.resize(3);
_M_results.resize(3);
}
for (unsigned int __i = 0; __i < __cur_results.size(); ++__i)
if (__cur_results[__i].matched) if (__cur_results[__i].matched)
_M_results[__i] = __cur_results[__i]; _M_results[__i] = __cur_results[__i];
} }
enum class _RegexExecutorPolicy : int
{ _S_auto, _S_force_dfs };
template<typename _BiIter, typename _Alloc, template<typename _BiIter, typename _Alloc,
typename _CharT, typename _TraitsT> typename _CharT, typename _TraitsT,
_RegexExecutorPolicy __policy>
std::unique_ptr<_Executor<_BiIter, _Alloc, _CharT, _TraitsT>> std::unique_ptr<_Executor<_BiIter, _Alloc, _CharT, _TraitsT>>
__get_executor(_BiIter __b, __get_executor(_BiIter __b,
_BiIter __e, _BiIter __e,
...@@ -411,7 +394,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -411,7 +394,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef _BFSExecutor<_BiIter, _Alloc, _CharT, _TraitsT> _BFSExecutorT; typedef _BFSExecutor<_BiIter, _Alloc, _CharT, _TraitsT> _BFSExecutorT;
auto __p = std::static_pointer_cast<_NFA<_CharT, _TraitsT>> auto __p = std::static_pointer_cast<_NFA<_CharT, _TraitsT>>
(__re._M_automaton); (__re._M_automaton);
if (__p->_M_has_backref) if (__policy == _RegexExecutorPolicy::_S_force_dfs
|| (__policy == _RegexExecutorPolicy::_S_auto && __p->_M_has_backref))
return _ExecutorPtr(new _DFSExecutorT(__b, __e, __m, __re, __flags)); return _ExecutorPtr(new _DFSExecutorT(__b, __e, __m, __re, __flags));
return _ExecutorPtr(new _BFSExecutorT(__b, __e, __m, __re, __flags)); return _ExecutorPtr(new _BFSExecutorT(__b, __e, __m, __re, __flags));
} }
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -34,12 +36,12 @@ test01() ...@@ -34,12 +36,12 @@ test01()
bool test __attribute__((unused)) = true; bool test __attribute__((unused)) = true;
regex("\\[", regex_constants::awk); regex("\\[", regex_constants::awk);
VERIFY(regex_match("\"", regex("[\\\"]", regex_constants::awk))); VERIFY(regex_match_debug("\"", regex("[\\\"]", regex_constants::awk)));
VERIFY(regex_match("/", regex("/", regex_constants::awk))); VERIFY(regex_match_debug("/", regex("/", regex_constants::awk)));
VERIFY(regex_match("\a", regex("\\a", regex_constants::awk))); VERIFY(regex_match_debug("\a", regex("\\a", regex_constants::awk)));
VERIFY(regex_match("\"", regex("\\\"", regex_constants::awk))); VERIFY(regex_match_debug("\"", regex("\\\"", regex_constants::awk)));
VERIFY(regex_match("5", regex("\\65", regex_constants::awk))); VERIFY(regex_match_debug("5", regex("\\65", regex_constants::awk)));
VERIFY(regex_match("53", regex("\\0653", regex_constants::awk))); VERIFY(regex_match_debug("53", regex("\\0653", regex_constants::awk)));
} }
int int
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -45,8 +47,8 @@ test01() ...@@ -45,8 +47,8 @@ test01()
} }
FAIL("[]"); FAIL("[]");
FAIL("[^]"); FAIL("[^]");
VERIFY(regex_match("]", regex("[]]", regex_constants::basic))); VERIFY(regex_match_debug ("]", regex("[]]", regex_constants::basic)));
VERIFY(!regex_match("]", regex("[^]]", regex_constants::basic))); VERIFY(!regex_match_debug ("]", regex("[^]]", regex_constants::basic)));
} }
int int
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
...@@ -35,7 +39,7 @@ test01() ...@@ -35,7 +39,7 @@ test01()
std::string target("aaba"); std::string target("aaba");
std::smatch m; std::smatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.size() == re.mark_count()+1 );
VERIFY( m.empty() == false ); VERIFY( m.empty() == false );
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
...@@ -35,7 +39,7 @@ test01() ...@@ -35,7 +39,7 @@ test01()
std::string target("aa"); std::string target("aa");
std::smatch m; std::smatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.size() == re.mark_count()+1 );
VERIFY( m.empty() == false ); VERIFY( m.empty() == false );
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
...@@ -35,7 +39,7 @@ test01() ...@@ -35,7 +39,7 @@ test01()
std::string target("aa"); std::string target("aa");
std::smatch m; std::smatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.size() == re.mark_count()+1 );
VERIFY( m.empty() == false ); VERIFY( m.empty() == false );
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
...@@ -35,7 +39,7 @@ test01() ...@@ -35,7 +39,7 @@ test01()
std::string target("aa"); std::string target("aa");
std::smatch m; std::smatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.size() == re.mark_count()+1 );
VERIFY( m.empty() == false ); VERIFY( m.empty() == false );
......
...@@ -24,6 +24,10 @@ ...@@ -24,6 +24,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
// libstdc++/53622 // libstdc++/53622
void void
...@@ -36,7 +40,7 @@ test01() ...@@ -36,7 +40,7 @@ test01()
std::string target("zxcv/onetwoabc"); std::string target("zxcv/onetwoabc");
std::smatch m; std::smatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( m.size() == 2 ); VERIFY( m.size() == 2 );
VERIFY( m[0].matched == true ); VERIFY( m[0].matched == true );
VERIFY( std::string(m[0].first, m[0].second) == "zxcv/onetwoabc" ); VERIFY( std::string(m[0].first, m[0].second) == "zxcv/onetwoabc" );
...@@ -49,7 +53,7 @@ test01() ...@@ -49,7 +53,7 @@ test01()
std::string target("zxcv/onetwoabc"); std::string target("zxcv/onetwoabc");
std::smatch m; std::smatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( m.size() == 3 ); VERIFY( m.size() == 3 );
VERIFY( m[0].matched == true ); VERIFY( m[0].matched == true );
VERIFY( std::string(m[0].first, m[0].second) == "zxcv/onetwoabc" ); VERIFY( std::string(m[0].first, m[0].second) == "zxcv/onetwoabc" );
......
...@@ -24,6 +24,10 @@ ...@@ -24,6 +24,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
#include <iostream> #include <iostream>
// libstdc++/57173 // libstdc++/57173
...@@ -37,7 +41,7 @@ test01() ...@@ -37,7 +41,7 @@ test01()
std::string target("/asdf/qwerty"); std::string target("/asdf/qwerty");
std::smatch m; std::smatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( m.size() == 2 ); VERIFY( m.size() == 2 );
VERIFY( std::string(m[1].first, m[1].second) == "/qwerty"); VERIFY( std::string(m[1].first, m[1].second) == "/qwerty");
} }
...@@ -46,7 +50,7 @@ test01() ...@@ -46,7 +50,7 @@ test01()
std::string target("/asdf/qwerty"); std::string target("/asdf/qwerty");
std::smatch m; std::smatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( m.size() == 3 ); VERIFY( m.size() == 3 );
VERIFY( std::string(m[1].first, m[1].second) == "/qwerty"); VERIFY( std::string(m[1].first, m[1].second) == "/qwerty");
} }
......
...@@ -24,13 +24,15 @@ ...@@ -24,13 +24,15 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
// libstdc++/58576 // libstdc++/58576
void void
test01() test01()
{ {
using namespace std;
bool test __attribute__((unused)) = true; bool test __attribute__((unused)) = true;
string domain_name = "valid.hostname.org"; string domain_name = "valid.hostname.org";
...@@ -74,9 +76,9 @@ test01() ...@@ -74,9 +76,9 @@ test01()
}; };
try try
{ {
VERIFY(regex_match( domain_name, m, fqdn_regex )); VERIFY(regex_match_debug( domain_name, m, fqdn_regex ));
VERIFY(m.size() == sizeof(sol) / sizeof(*sol)); VERIFY(m.size() == sizeof(sol) / sizeof(*sol));
for (int i = 0; i < (int)m.size(); i++) { for (size_t i = 0; i < m.size(); i++) {
string s(m[i].first, m[i].second); string s(m[i].first, m[i].second);
VERIFY(s == sol[i]); VERIFY(s == sol[i]);
} }
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -37,7 +39,7 @@ test01() ...@@ -37,7 +39,7 @@ test01()
{\ {\
regex re(res);\ regex re(res);\
string st(s);\ string st(s);\
VERIFY(!regex_match(st, re));\ VERIFY(!regex_match_debug(st, re));\
} }
TEST(".", "\0"); TEST(".", "\0");
TEST(".", "\n"); TEST(".", "\n");
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -33,10 +35,10 @@ test01() ...@@ -33,10 +35,10 @@ test01()
{ {
bool test __attribute__((unused)) = true; bool test __attribute__((unused)) = true;
VERIFY(!regex_match("x", regex("[]"))); VERIFY(!regex_match_debug("x", regex("[]")));
VERIFY(regex_match("x", regex("[^]"))); VERIFY(regex_match_debug("x", regex("[^]")));
VERIFY(!regex_match("]", regex("[]]"))); VERIFY(!regex_match_debug("]", regex("[]]")));
VERIFY(!regex_match("]", regex("[^]]"))); VERIFY(!regex_match_debug("]", regex("[^]]")));
} }
int int
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -37,7 +39,7 @@ test01() ...@@ -37,7 +39,7 @@ test01()
regex re("()*\\1"); regex re("()*\\1");
cmatch m; cmatch m;
const char s[] = ""; const char s[] = "";
VERIFY( regex_match(s, m, re) ); VERIFY( regex_match_debug(s, m, re) );
VERIFY( m.size() == 2 ); VERIFY( m.size() == 2 );
VERIFY( m[0].matched ); VERIFY( m[0].matched );
VERIFY( m[1].matched ); VERIFY( m[1].matched );
...@@ -46,7 +48,7 @@ test01() ...@@ -46,7 +48,7 @@ test01()
regex re("()*"); regex re("()*");
cmatch m; cmatch m;
const char s[] = ""; const char s[] = "";
VERIFY( regex_match(s, m, re) ); VERIFY( regex_match_debug(s, m, re) );
} }
} }
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -33,7 +35,7 @@ test01() ...@@ -33,7 +35,7 @@ test01()
{ {
bool test __attribute__((unused)) = true; bool test __attribute__((unused)) = true;
VERIFY(regex_match(":", regex("\\x3a"))); VERIFY(regex_match_debug(":", regex("\\x3a")));
try try
{ {
regex("\\u400x"); regex("\\u400x");
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -33,15 +35,15 @@ test01() ...@@ -33,15 +35,15 @@ test01()
{ {
bool test __attribute__((unused)) = true; bool test __attribute__((unused)) = true;
VERIFY(regex_match("01", regex("\\d*"))); VERIFY(regex_match_debug("01", regex("\\d*")));
VERIFY(regex_match("asdfjkl", regex("\\D*"))); VERIFY(regex_match_debug("asdfjkl", regex("\\D*")));
VERIFY(!regex_match("asdfjkl0", regex("\\D*"))); VERIFY(!regex_match_debug("asdfjkl0", regex("\\D*")));
VERIFY(regex_match("\r\t\v\f ", regex("\\s*"))); VERIFY(regex_match_debug("\r\t\v\f ", regex("\\s*")));
VERIFY(regex_match("asdfjkl", regex("\\S*"))); VERIFY(regex_match_debug("asdfjkl", regex("\\S*")));
VERIFY(!regex_match("asdfjkl\r", regex("\\S*"))); VERIFY(!regex_match_debug("asdfjkl\r", regex("\\S*")));
VERIFY(regex_match("_az", regex("\\w*"))); VERIFY(regex_match_debug("_az", regex("\\w*")));
VERIFY(regex_match("!@#$%", regex("\\W*"))); VERIFY(regex_match_debug("!@#$%", regex("\\W*")));
VERIFY(!regex_match("_01234", regex("\\W*"))); VERIFY(!regex_match_debug("_01234", regex("\\W*")));
} }
int int
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -37,7 +39,7 @@ test01() ...@@ -37,7 +39,7 @@ test01()
{\ {\
wregex re(res);\ wregex re(res);\
wstring st(s);\ wstring st(s);\
VERIFY(!regex_match(st, re));\ VERIFY(!regex_match_debug(st, re));\
} }
TESTL(L".", L"\u2028"); TESTL(L".", L"\u2028");
TESTL(L".", L"\u2029"); TESTL(L".", L"\u2029");
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -33,7 +35,7 @@ test01() ...@@ -33,7 +35,7 @@ test01()
{ {
bool test __attribute__((unused)) = true; bool test __attribute__((unused)) = true;
VERIFY(regex_match(L"\u1234", wregex(L"\\u1234"))); VERIFY(regex_match_debug(L"\u1234", wregex(L"\\u1234")));
} }
int int
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
...@@ -33,33 +37,33 @@ test01() ...@@ -33,33 +37,33 @@ test01()
{ {
std::regex re("pre/[za-x]", std::regex::extended); std::regex re("pre/[za-x]", std::regex::extended);
VERIFY( std::regex_match("pre/z", re) ); VERIFY( regex_match_debug("pre/z", re) );
VERIFY( std::regex_match("pre/a", re) ); VERIFY( regex_match_debug("pre/a", re) );
VERIFY( !std::regex_match("pre/y", re) ); VERIFY( !regex_match_debug("pre/y", re) );
} }
{ {
std::regex re("pre/[[:uPPer:]]", std::regex::extended); std::regex re("pre/[[:uPPer:]]", std::regex::extended);
VERIFY( std::regex_match("pre/Z", re) ); VERIFY( regex_match_debug("pre/Z", re) );
VERIFY( !std::regex_match("pre/_", re) ); VERIFY( !regex_match_debug("pre/_", re) );
VERIFY( !std::regex_match("pre/a", re) ); VERIFY( !regex_match_debug("pre/a", re) );
VERIFY( !std::regex_match("pre/0", re) ); VERIFY( !regex_match_debug("pre/0", re) );
} }
{ {
std::regex re("pre/[[:lOWer:]]", std::regex::extended | std::regex::icase); std::regex re("pre/[[:lOWer:]]", std::regex::extended | std::regex::icase);
VERIFY( std::regex_match("pre/Z", re) ); VERIFY( regex_match_debug("pre/Z", re) );
VERIFY( std::regex_match("pre/a", re) ); VERIFY( regex_match_debug("pre/a", re) );
} }
{ {
std::regex re("pre/[[:w:][.tilde.]]", std::regex::extended); std::regex re("pre/[[:w:][.tilde.]]", std::regex::extended);
VERIFY( std::regex_match("pre/~", re) ); VERIFY( regex_match_debug("pre/~", re) );
VERIFY( std::regex_match("pre/_", re) ); VERIFY( regex_match_debug("pre/_", re) );
VERIFY( std::regex_match("pre/a", re) ); VERIFY( regex_match_debug("pre/a", re) );
VERIFY( std::regex_match("pre/0", re) ); VERIFY( regex_match_debug("pre/0", re) );
} }
{ {
std::regex re("pre/[[=a=]]", std::regex::extended); std::regex re("pre/[[=a=]]", std::regex::extended);
VERIFY( std::regex_match("pre/a", re) ); VERIFY( regex_match_debug("pre/a", re) );
VERIFY( std::regex_match("pre/A", re) ); VERIFY( regex_match_debug("pre/A", re) );
} }
} }
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
...@@ -35,7 +39,7 @@ test01() ...@@ -35,7 +39,7 @@ test01()
const char target[] = "aa"; const char target[] = "aa";
std::cmatch m; std::cmatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( re.mark_count() == 1 ); VERIFY( re.mark_count() == 1 );
VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.size() == re.mark_count()+1 );
...@@ -53,9 +57,9 @@ test01() ...@@ -53,9 +57,9 @@ test01()
VERIFY( m[1].second == target+sizeof(target)-1 ); VERIFY( m[1].second == target+sizeof(target)-1 );
VERIFY( m[1].matched == true ); VERIFY( m[1].matched == true );
VERIFY(!std::regex_match("", std::regex("a+", std::regex::extended))); VERIFY(!regex_match_debug("", std::regex("a+", std::regex::extended)));
VERIFY(std::regex_match("a", std::regex("a+", std::regex::extended))); VERIFY(regex_match_debug("a", std::regex("a+", std::regex::extended)));
VERIFY(std::regex_match("aa", std::regex("a+", std::regex::extended))); VERIFY(regex_match_debug("aa", std::regex("a+", std::regex::extended)));
} }
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
...@@ -35,7 +39,7 @@ test01() ...@@ -35,7 +39,7 @@ test01()
char target[] = "a"; char target[] = "a";
std::cmatch m; std::cmatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( re.mark_count() == 1 ); VERIFY( re.mark_count() == 1 );
VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.size() == re.mark_count()+1 );
...@@ -53,9 +57,9 @@ test01() ...@@ -53,9 +57,9 @@ test01()
VERIFY( m[1].second == target+sizeof(target)-1 ); VERIFY( m[1].second == target+sizeof(target)-1 );
VERIFY( m[1].matched == true ); VERIFY( m[1].matched == true );
VERIFY(std::regex_match("", std::regex("a?", std::regex::extended))); VERIFY(regex_match_debug("", std::regex("a?", std::regex::extended)));
VERIFY(std::regex_match("a", std::regex("a?", std::regex::extended))); VERIFY(regex_match_debug("a", std::regex("a?", std::regex::extended)));
VERIFY(!std::regex_match("aa", std::regex("a?", std::regex::extended))); VERIFY(!regex_match_debug("aa", std::regex("a?", std::regex::extended)));
} }
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -35,29 +37,29 @@ test01() ...@@ -35,29 +37,29 @@ test01()
regex re; regex re;
re.assign("(ab){3}", std::regex::extended); re.assign("(ab){3}", std::regex::extended);
VERIFY(!regex_match("abab", re)); VERIFY(!regex_match_debug("abab", re));
VERIFY(regex_match("ababab", re)); VERIFY(regex_match_debug("ababab", re));
VERIFY(!regex_match("abababab", re)); VERIFY(!regex_match_debug("abababab", re));
re.assign("(ab){3,}", std::regex::extended); re.assign("(ab){3,}", std::regex::extended);
VERIFY(!regex_match("abab", re)); VERIFY(!regex_match_debug("abab", re));
VERIFY(regex_match("ababab", re)); VERIFY(regex_match_debug("ababab", re));
VERIFY(regex_match("abababab", re)); VERIFY(regex_match_debug("abababab", re));
VERIFY(regex_match("ababababab", re)); VERIFY(regex_match_debug("ababababab", re));
re.assign("(ab){0,3}", std::regex::extended); re.assign("(ab){0,3}", std::regex::extended);
VERIFY(regex_match("", re)); VERIFY(regex_match_debug("", re));
VERIFY(regex_match("ab", re)); VERIFY(regex_match_debug("ab", re));
VERIFY(regex_match("abab", re)); VERIFY(regex_match_debug("abab", re));
VERIFY(regex_match("ababab", re)); VERIFY(regex_match_debug("ababab", re));
VERIFY(!regex_match("abababab", re)); VERIFY(!regex_match_debug("abababab", re));
re.assign("(a|b){0,2}", std::regex::extended); re.assign("(a|b){0,2}", std::regex::extended);
VERIFY(regex_match("", re)); VERIFY(regex_match_debug("", re));
VERIFY(regex_match("a", re)); VERIFY(regex_match_debug("a", re));
VERIFY(regex_match("b", re)); VERIFY(regex_match_debug("b", re));
VERIFY(regex_match("aa", re)); VERIFY(regex_match_debug("aa", re));
VERIFY(regex_match("ab", re)); VERIFY(regex_match_debug("ab", re));
VERIFY(regex_match("ba", re)); VERIFY(regex_match_debug("ba", re));
VERIFY(regex_match("bb", re)); VERIFY(regex_match_debug("bb", re));
VERIFY(!regex_match("aaa", re)); VERIFY(!regex_match_debug("aaa", re));
} }
int int
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
...@@ -35,7 +39,7 @@ test01() ...@@ -35,7 +39,7 @@ test01()
std::string target("aaba"); std::string target("aaba");
std::smatch m; std::smatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.size() == re.mark_count()+1 );
VERIFY( m.empty() == false ); VERIFY( m.empty() == false );
......
...@@ -38,10 +38,12 @@ template<typename _Bi_iter, typename _Alloc, ...@@ -38,10 +38,12 @@ template<typename _Bi_iter, typename _Alloc,
regex_constants::match_flag_type __flags regex_constants::match_flag_type __flags
= regex_constants::match_default) = regex_constants::match_default)
{ {
using namespace __detail;
auto& __res = (vector<sub_match<_Bi_iter>, _Alloc>&)(__m); auto& __res = (vector<sub_match<_Bi_iter>, _Alloc>&)(__m);
VERIFY( (dynamic_cast VERIFY( (dynamic_cast
<__detail::_DFSExecutor<_Bi_iter, _Alloc, _Ch_type, _Rx_traits>*> <_DFSExecutor<_Bi_iter, _Alloc, _Ch_type, _Rx_traits>*>
(&*__detail::__get_executor(__s, __e, __res, __re, __flags)) (&*__get_executor<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
_RegexExecutorPolicy::_S_auto>(__s, __e, __res, __re, __flags))
!= nullptr) ); != nullptr) );
} }
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
void void
test01() test01()
...@@ -35,7 +38,7 @@ test01() ...@@ -35,7 +38,7 @@ test01()
std::string target("aa"); std::string target("aa");
std::smatch m; std::smatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.size() == re.mark_count()+1 );
VERIFY( m.empty() == false ); VERIFY( m.empty() == false );
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
...@@ -35,7 +39,7 @@ test01() ...@@ -35,7 +39,7 @@ test01()
std::string target("aa"); std::string target("aa");
std::smatch m; std::smatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.size() == re.mark_count()+1 );
VERIFY( m.empty() == false ); VERIFY( m.empty() == false );
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
...@@ -35,7 +39,7 @@ test01() ...@@ -35,7 +39,7 @@ test01()
std::string target("aa"); std::string target("aa");
std::smatch m; std::smatch m;
VERIFY( std::regex_match(target, m, re) ); VERIFY( regex_match_debug(target, m, re) );
VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.size() == re.mark_count()+1 );
VERIFY( m.empty() == false ); VERIFY( m.empty() == false );
......
...@@ -26,6 +26,10 @@ ...@@ -26,6 +26,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
...@@ -37,7 +41,7 @@ test01() ...@@ -37,7 +41,7 @@ test01()
re2.imbue(std::locale("de_DE.UTF-8")); re2.imbue(std::locale("de_DE.UTF-8"));
re2.assign(L"[[:upper:]]*", std::regex::extended); re2.assign(L"[[:upper:]]*", std::regex::extended);
std::wsmatch m2; std::wsmatch m2;
VERIFY(std::regex_match(str2, m2, re2)); VERIFY(regex_match_debug(str2, m2, re2));
} }
int int
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
...@@ -35,7 +39,7 @@ test01() ...@@ -35,7 +39,7 @@ test01()
std::string target("xxasdfyy"); std::string target("xxasdfyy");
std::smatch m; std::smatch m;
VERIFY( std::regex_search(target, m, re) ); VERIFY( regex_search_debug(target, m, re) );
VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.size() == re.mark_count()+1 );
VERIFY( m.empty() == false ); VERIFY( m.empty() == false );
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -33,21 +35,21 @@ test01() ...@@ -33,21 +35,21 @@ test01()
{ {
bool test __attribute__((unused)) = true; bool test __attribute__((unused)) = true;
VERIFY(!regex_search("2123456", regex("^1234"))); VERIFY(!regex_search_debug("2123456", regex("^1234")));
VERIFY(regex_search("123456", regex("^1234"))); VERIFY(regex_search_debug("123456", regex("^1234")));
VERIFY(regex_search("123456", regex("(5|^)1234"))); VERIFY(regex_search_debug("123456", regex("(5|^)1234")));
VERIFY(regex_search("5123456", regex("(5|^)1234"))); VERIFY(regex_search_debug("5123456", regex("(5|^)1234")));
VERIFY(!regex_search("1234562", regex("3456$"))); VERIFY(!regex_search_debug("1234562", regex("3456$")));
VERIFY(regex_search("123456", regex("3456$"))); VERIFY(regex_search_debug("123456", regex("3456$")));
VERIFY(!regex_search("123456", regex("(?=1234)56"))); VERIFY(!regex_search_debug("123456", regex("(?=1234)56")));
VERIFY(regex_search("123456", regex("(?=1234)123456"))); VERIFY(regex_search_debug("123456", regex("(?=1234)123456")));
VERIFY(regex_search("123456", regex("(?!1234)56"))); VERIFY(regex_search_debug("123456", regex("(?!1234)56")));
VERIFY(!regex_search("123456", regex("(?!1234)123456"))); VERIFY(!regex_search_debug("123456", regex("(?!1234)123456")));
VERIFY(regex_search("a-", regex("a\\b-"))); VERIFY(regex_search_debug("a-", regex("a\\b-")));
VERIFY(!regex_search("ab", regex("a\\bb"))); VERIFY(!regex_search_debug("ab", regex("a\\bb")));
VERIFY(!regex_search("a-", regex("a\\B-"))); VERIFY(!regex_search_debug("a-", regex("a\\B-")));
VERIFY(regex_search("ab", regex("a\\Bb"))); VERIFY(regex_search_debug("ab", regex("a\\Bb")));
string s("This is a regular expression"); string s("This is a regular expression");
string sol[] = string sol[] =
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -35,32 +37,34 @@ test01() ...@@ -35,32 +37,34 @@ test01()
cmatch m; cmatch m;
regex re("((as)(df))", regex_constants::ECMAScript | regex_constants::nosubs); regex re("((as)(df))", regex_constants::ECMAScript | regex_constants::nosubs);
VERIFY(regex_search("asdf", m, re)); VERIFY(regex_search_debug("asdf", m, re));
VERIFY(m.size() == 1); VERIFY(m.size() == 1);
VERIFY(m[0].matched && string(m[0].first, m[0].second) == "asdf"); VERIFY(m[0].matched && string(m[0].first, m[0].second) == "asdf");
VERIFY( regex_search("a", regex("^a"))); VERIFY( regex_search_debug("a", regex("^a")));
VERIFY(!regex_search("a", regex("^a"), regex_constants::match_not_bol)); VERIFY(!regex_search_debug("a", regex("^a"), regex_constants::match_not_bol));
VERIFY( regex_search("a", regex("a$"))); VERIFY( regex_search_debug("a", regex("a$")));
VERIFY(!regex_search("a", regex("a$"), regex_constants::match_not_eol)); VERIFY(!regex_search_debug("a", regex("a$"), regex_constants::match_not_eol));
VERIFY( regex_search("a", regex("\\ba"))); VERIFY( regex_search_debug("a", regex("\\ba")));
VERIFY(!regex_search("a", regex("\\ba"), regex_constants::match_not_bow)); VERIFY(!regex_search_debug("a", regex("\\ba"),
VERIFY( regex_search("a", regex("a\\b"))); regex_constants::match_not_bow));
VERIFY(!regex_search("a", regex("a\\b"), regex_constants::match_not_eow)); VERIFY( regex_search_debug("a", regex("a\\b")));
VERIFY( regex_search("", regex(""))); VERIFY(!regex_search_debug("a", regex("a\\b"),
VERIFY(!regex_search("", regex(""), regex_constants::match_not_null)); regex_constants::match_not_eow));
VERIFY( regex_search("", regex("^$"))); VERIFY( regex_search_debug("", regex("")));
VERIFY(!regex_search("", regex("^$"), regex_constants::match_not_null)); VERIFY(!regex_search_debug("", regex(""), regex_constants::match_not_null));
VERIFY( regex_search("aaa", m, regex("a*?"), VERIFY( regex_search_debug("", regex("^$")));
regex_constants::match_not_null)); VERIFY(!regex_search_debug("", regex("^$"), regex_constants::match_not_null));
VERIFY( regex_search_debug("aaa", m, regex("a*?"),
regex_constants::match_not_null));
VERIFY(m[0].matched && string(m[0].first, m[0].second) == "a"); VERIFY(m[0].matched && string(m[0].first, m[0].second) == "a");
VERIFY( regex_search("asdf", regex("sdf"))); VERIFY( regex_search_debug("asdf", regex("sdf")));
VERIFY(!regex_search("asdf", regex("sdf"), VERIFY(!regex_search_debug("asdf", regex("sdf"),
regex_constants::match_continuous)); regex_constants::match_continuous));
VERIFY( regex_search(" a"+1, regex("\\ba"), VERIFY( regex_search_debug(" a"+1, regex("\\ba"),
regex_constants::match_prev_avail)); regex_constants::match_prev_avail));
VERIFY( regex_search("ba"+1, regex("\\Ba"), VERIFY( regex_search_debug("ba"+1, regex("\\Ba"),
regex_constants::match_prev_avail)); regex_constants::match_prev_avail));
} }
int int
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std; using namespace std;
void void
...@@ -35,30 +37,30 @@ test01() ...@@ -35,30 +37,30 @@ test01()
cmatch m; cmatch m;
#define TEST(i, s) VERIFY(m[i].matched && string(m[i].first, m[i].second) == s) #define TEST(i, s) VERIFY(m[i].matched && string(m[i].first, m[i].second) == s)
VERIFY(regex_search("aaaa", m, regex("a*"))); VERIFY(regex_search_debug("aaaa", m, regex("a*")));
TEST(0, "aaaa"); TEST(0, "aaaa");
VERIFY(regex_search("aaaa", m, regex("a*?"))); VERIFY(regex_search_debug("aaaa", m, regex("a*?")));
TEST(0, ""); TEST(0, "");
VERIFY(regex_search("aaaa", m, regex("a+"))); VERIFY(regex_search_debug("aaaa", m, regex("a+")));
TEST(0, "aaaa"); TEST(0, "aaaa");
VERIFY(regex_search("aaaa", m, regex("a+?"))); VERIFY(regex_search_debug("aaaa", m, regex("a+?")));
TEST(0, "a"); TEST(0, "a");
VERIFY(regex_search("a", m, regex("a?"))); VERIFY(regex_search_debug("a", m, regex("a?")));
TEST(0, "a"); TEST(0, "a");
VERIFY(regex_search("a", m, regex("a??"))); VERIFY(regex_search_debug("a", m, regex("a??")));
TEST(0, ""); TEST(0, "");
VERIFY(regex_search("", m, regex("a??"))); VERIFY(regex_search_debug("", m, regex("a??")));
TEST(0, ""); TEST(0, "");
VERIFY(regex_search("aaaa", m, regex("(a+)(a+)"))); VERIFY(regex_search_debug("aaaa", m, regex("(a+)(a+)")));
TEST(1, "aaa"); TEST(1, "aaa");
TEST(2, "a"); TEST(2, "a");
VERIFY(regex_search("aaaa", m, regex("(a+?)(a+)"))); VERIFY(regex_search_debug("aaaa", m, regex("(a+?)(a+)")));
TEST(1, "a"); TEST(1, "a");
TEST(2, "aaa"); TEST(2, "aaa");
VERIFY(regex_search("aaaa", m, regex("(a+?)(a+)"))); VERIFY(regex_search_debug("aaaa", m, regex("(a+?)(a+)")));
TEST(1, "a"); TEST(1, "a");
TEST(2, "aaa"); TEST(2, "aaa");
VERIFY(regex_search("aaaa", m, regex("(a+?)(a+?)"))); VERIFY(regex_search_debug("aaaa", m, regex("(a+?)(a+?)")));
TEST(1, "a"); TEST(1, "a");
TEST(2, "a"); TEST(2, "a");
} }
......
...@@ -25,13 +25,17 @@ ...@@ -25,13 +25,17 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace __gnu_test;
using namespace std;
void void
test01() test01()
{ {
bool test __attribute__((unused)) = true; bool test __attribute__((unused)) = true;
VERIFY(std::regex_search("", std::regex(""))); VERIFY(regex_search_debug("", std::regex("")));
} }
int int
......
...@@ -25,8 +25,10 @@ ...@@ -25,8 +25,10 @@
#include <regex> #include <regex>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_regex.h>
using namespace std; using namespace std;
using namespace __gnu_test;
void void
test01() test01()
...@@ -34,8 +36,8 @@ test01() ...@@ -34,8 +36,8 @@ test01()
bool test __attribute__((unused)) = true; bool test __attribute__((unused)) = true;
cmatch m; cmatch m;
VERIFY(regex_search("*** this is a string !!!", m, VERIFY(regex_search_debug("*** this is a string !!!", m,
regex("(\\w+) (\\w+) (\\w+) (\\w+)"))); regex("(\\w+) (\\w+) (\\w+) (\\w+)")));
VERIFY(m.format("$&|$`|$3|$4|$2|$1|$'$$$") VERIFY(m.format("$&|$`|$3|$4|$2|$1|$'$$$")
== "this is a string|*** |a|string|is|this| !!!$$"); == "this is a string|*** |a|string|is|this| !!!$$");
VERIFY(m.format("&|\\3|\\4|\\2|\\1|\\", VERIFY(m.format("&|\\3|\\4|\\2|\\1|\\",
......
...@@ -31,9 +31,12 @@ namespace __gnu_test ...@@ -31,9 +31,12 @@ namespace __gnu_test
// Test on a compilation of simple expressions, throw regex_error on error. // Test on a compilation of simple expressions, throw regex_error on error.
typedef std::regex regex_type; typedef std::regex regex_type;
typedef regex_type::flag_type flag_type; typedef regex_type::flag_type flag_type;
typedef std::regex_constants::match_flag_type match_flag_type;
typedef std::regex_constants::error_type error_type; typedef std::regex_constants::error_type error_type;
typedef std::size_t size_type; typedef std::size_t size_type;
typedef std::string string_type; typedef std::string string_type;
using std::basic_regex;
using std::match_results;
// Utilities // Utilities
struct regex_expected_fail { }; struct regex_expected_fail { };
...@@ -126,5 +129,177 @@ namespace __gnu_test ...@@ -126,5 +129,177 @@ namespace __gnu_test
} }
} }
// regex_match_debug behaves like regex_match, but will run *two* executors
// (if there's no back-reference) and check if their results agree. If not,
// an exception throws. One can use them just in the way of using regex_match.
template<typename _Bi_iter, typename _Alloc,
typename _Ch_type, typename _Rx_traits>
bool
regex_match_debug(_Bi_iter __s,
_Bi_iter __e,
match_results<_Bi_iter, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __re,
match_flag_type __flags
= std::regex_constants::match_default)
{
using namespace std::__detail;
auto __res1 = __regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
_RegexExecutorPolicy::_S_auto, true>
(__s, __e, __m, __re, __flags);
match_results<_Bi_iter, _Alloc> __mm;
auto __res2 = __regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
_RegexExecutorPolicy::_S_force_dfs, true>
(__s, __e, __mm, __re, __flags);
if (__res1 == __res2 && __m == __mm)
return __res1;
throw(std::exception());
}
// No match_results version
template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
inline bool
regex_match_debug(_Bi_iter __first,
_Bi_iter __last,
const basic_regex<_Ch_type, _Rx_traits>& __re,
match_flag_type __flags
= std::regex_constants::match_default)
{
match_results<_Bi_iter> __what;
return regex_match_debug(__first, __last, __what, __re, __flags);
}
// C-string version
template<typename _Ch_type, typename _Alloc, typename _Rx_traits>
inline bool
regex_match_debug(const _Ch_type* __s,
match_results<const _Ch_type*, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __re,
match_flag_type __f
= std::regex_constants::match_default)
{ return regex_match_debug(__s, __s + _Rx_traits::length(__s),
__m, __re, __f); }
// C-string version without match_results
template<typename _Ch_type, class _Rx_traits>
inline bool
regex_match_debug(const _Ch_type* __s,
const basic_regex<_Ch_type, _Rx_traits>& __re,
match_flag_type __f
= std::regex_constants::match_default)
{ return regex_match_debug(__s, __s + _Rx_traits::length(__s),
__re, __f); }
// std::basic_string version
template<typename _Ch_traits, typename _Ch_alloc,
typename _Alloc, typename _Ch_type, typename _Rx_traits>
inline bool
regex_match_debug(const std::basic_string<_Ch_type, _Ch_traits,
_Ch_alloc>& __s,
match_results<typename std::basic_string<_Ch_type,
_Ch_traits, _Ch_alloc>::const_iterator,
_Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __re,
match_flag_type __flags
= std::regex_constants::match_default)
{ return regex_match_debug(__s.begin(), __s.end(),
__m, __re, __flags); }
// std::basic_string version without match_results
template<typename _Ch_traits, typename _Str_allocator,
typename _Ch_type, typename _Rx_traits>
inline bool
regex_match_debug(const std::basic_string<_Ch_type, _Ch_traits,
_Str_allocator>& __s,
const basic_regex<_Ch_type, _Rx_traits>& __re,
match_flag_type __flags
= std::regex_constants::match_default)
{ return regex_match_debug(__s.begin(), __s.end(), __re, __flags); }
// regex_match_debug behaves like regex_match, but will run *two* executors
// (if there's no back-reference) and check if their results agree. If not,
// an exception throws. One can use them just in the way of using regex_match.
template<typename _Bi_iter, typename _Alloc,
typename _Ch_type, typename _Rx_traits>
bool
regex_search_debug(_Bi_iter __s,
_Bi_iter __e,
match_results<_Bi_iter, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __re,
match_flag_type __flags
= std::regex_constants::match_default)
{
using namespace std::__detail;
auto __res1 = __regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
_RegexExecutorPolicy::_S_auto, false>
(__s, __e, __m, __re, __flags);
match_results<_Bi_iter, _Alloc> __mm;
auto __res2 = __regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
_RegexExecutorPolicy::_S_force_dfs, false>
(__s, __e, __mm, __re, __flags);
if (__res1 == __res2 && __m == __mm)
return __res1;
throw(std::exception()); // Let test fail. Give it a name.
}
// No match_results version
template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
inline bool
regex_search_debug(_Bi_iter __first,
_Bi_iter __last,
const basic_regex<_Ch_type, _Rx_traits>& __re,
match_flag_type __flags
= std::regex_constants::match_default)
{
match_results<_Bi_iter> __what;
return regex_search_debug(__first, __last, __what, __re, __flags);
}
// C-string version
template<typename _Ch_type, class _Alloc, class _Rx_traits>
inline bool
regex_search_debug(const _Ch_type* __s,
match_results<const _Ch_type*, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __e,
match_flag_type __f
= std::regex_constants::match_default)
{ return regex_search_debug(__s, __s + _Rx_traits::length(__s),
__m, __e, __f); }
// C-string version without match_results
template<typename _Ch_type, typename _Rx_traits>
inline bool
regex_search_debug(const _Ch_type* __s,
const basic_regex<_Ch_type, _Rx_traits>& __e,
match_flag_type __f
= std::regex_constants::match_default)
{ return regex_search_debug(__s, __s + _Rx_traits::length(__s),
__e, __f); }
// std::basic_string version
template<typename _Ch_traits, typename _Ch_alloc,
typename _Alloc, typename _Ch_type,
typename _Rx_traits>
inline bool
regex_search_debug(const std::basic_string<_Ch_type, _Ch_traits,
_Ch_alloc>& __s,
match_results<typename std::basic_string<_Ch_type,
_Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&
__m,
const basic_regex<_Ch_type, _Rx_traits>& __e,
match_flag_type __f
= std::regex_constants::match_default)
{ return regex_search_debug(__s.begin(), __s.end(), __m, __e, __f); }
// std::basic_string version without match_results
template<typename _Ch_traits, typename _String_allocator,
typename _Ch_type, typename _Rx_traits>
inline bool
regex_search_debug(const std::basic_string<_Ch_type, _Ch_traits,
_String_allocator>& __s,
const basic_regex<_Ch_type, _Rx_traits>& __e,
match_flag_type __f
= std::regex_constants::match_default)
{ return regex_search_debug(__s.begin(), __s.end(), __e, __f); }
} // namespace __gnu_test } // namespace __gnu_test
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment