summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/include/bits/regex.h
diff options
context:
space:
mode:
authortimshen <timshen@138bc75d-0d04-0410-961f-82ee72b054a4>2013-09-18 15:56:20 +0000
committertimshen <timshen@138bc75d-0d04-0410-961f-82ee72b054a4>2013-09-18 15:56:20 +0000
commita504122233268b6ce669a07c2f83cd5e9a6cd084 (patch)
treedb5788d9dc9a22dd1aeac31c52fb72395dd7756d /libstdc++-v3/include/bits/regex.h
parent803ed83f4ecf58326158d384d0c00fe8f50e00e5 (diff)
downloadppe42-gcc-a504122233268b6ce669a07c2f83cd5e9a6cd084.tar.gz
ppe42-gcc-a504122233268b6ce669a07c2f83cd5e9a6cd084.zip
2013-09-18 Tim Shen <timshen91@gmail.com>
* include/bits/regex.h: Add friend classes. (match_results<>::position, regex_iterator<>::operator++): Implement position specification in regex_iterator. (regex_match<>, regex_search<>): Move match_results initializations to these function. Remove `todo`. * include/bits/regex_compiler.tcc: (_Compiler<>::_M_quantifier): Fix greedy/ungreedy of interval matching. * include/bits/regex_constants.h: Fix indentation. Change match_flag_type to enum type. * include/bits/regex_executor.h: Merge identical code to the base class _Executor. Support flags in regex_constants. * include/bits/regex_executor.tcc: Likewise. * include/bits/regex_scanner.h: Add comments. * include/bits/regex_scanner.tcc: Same. * testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc: Add a testcase. * testsuite/28_regex/algorithms/regex_search/ecma/flags.cc: New. * testsuite/28_regex/iterators/regex_iterator/char/ string_position_01.cc: Remove `xfail`. * testsuite/28_regex/iterators/regex_iterator/wchar_t/string_02.cc: Remove `xfail` and make the case really work. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@202706 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/bits/regex.h')
-rw-r--r--libstdc++-v3/include/bits/regex.h63
1 files changed, 51 insertions, 12 deletions
diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h
index 659bee13120..9d1438aab23 100644
--- a/libstdc++-v3/include/bits/regex.h
+++ b/libstdc++-v3/include/bits/regex.h
@@ -1004,6 +1004,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const basic_regex<_Cp, _Rp>&,
regex_constants::match_flag_type);
+ template<typename, typename, typename, typename>
+ friend class __detail::_Executor;
+
+ template<typename, typename, typename, typename>
+ friend class __detail::_DFSExecutor;
+
+ template<typename, typename, typename, typename>
+ friend class __detail::_BFSExecutor;
+
flag_type _M_flags;
_Rx_traits _M_traits;
_AutomatonPtr _M_automaton;
@@ -1783,21 +1792,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*/
explicit
match_results(const _Alloc& __a = _Alloc())
- : _Base_type(__a)
+ : _Base_type(__a), _M_in_iterator(false)
{ }
/**
* @brief Copy constructs a %match_results.
*/
match_results(const match_results& __rhs)
- : _Base_type(__rhs)
+ : _Base_type(__rhs), _M_in_iterator(false)
{ }
/**
* @brief Move constructs a %match_results.
*/
match_results(match_results&& __rhs) noexcept
- : _Base_type(std::move(__rhs))
+ : _Base_type(std::move(__rhs)), _M_in_iterator(false)
{ }
/**
@@ -1905,8 +1914,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
difference_type
position(size_type __sub = 0) const
{
- return __sub < size() ? std::distance(this->prefix().first,
- (*this)[__sub].first) : -1;
+ // [28.12.1.4.5]
+ if (_M_in_iterator)
+ return __sub < size() ? std::distance(_M_begin,
+ (*this)[__sub].first) : -1;
+ else
+ return __sub < size() ? std::distance(this->prefix().first,
+ (*this)[__sub].first) : -1;
}
/**
@@ -2106,6 +2120,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename, typename, typename, typename>
friend class __detail::_BFSExecutor;
+ template<typename, typename, typename>
+ friend class regex_iterator;
+
template<typename _Bp, typename _Ap,
typename _Ch_type, typename _Rx_traits>
friend bool
@@ -2121,6 +2138,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const basic_regex<_Ch_type,
_Rx_traits>&,
regex_constants::match_flag_type);
+
+ _Bi_iter _M_begin;
+ bool _M_in_iterator;
};
typedef match_results<const char*> cmatch;
@@ -2200,8 +2220,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @retval false Otherwise.
*
* @throws an exception of type regex_error.
- *
- * @todo Implement this function.
*/
template<typename _Bi_iter, typename _Alloc,
typename _Ch_type, typename _Rx_traits>
@@ -2215,6 +2233,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
if (__re._M_automaton == nullptr)
return false;
+
+ auto __size = __re._M_automaton->_M_sub_count();
+ __size += 2;
+ __m.resize(__size);
+ for (decltype(__size) __i = 0; __i < __size; ++__i)
+ __m.at(__i).matched = false;
+
if (__detail::__get_executor(__s, __e, __m, __re, __flags)->_M_match())
{
for (auto __it : __m)
@@ -2360,8 +2385,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* undefined.
*
* @throws an exception of type regex_error.
- *
- * @todo Implement this function.
*/
template<typename _Bi_iter, typename _Alloc,
typename _Ch_type, typename _Rx_traits>
@@ -2374,6 +2397,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
if (__re._M_automaton == nullptr)
return false;
+
+ auto __size = __re._M_automaton->_M_sub_count();
+ __size += 2;
+ __m.resize(__size);
+ for (decltype(__size) __i = 0; __i < __size; ++__i)
+ __m.at(__i).matched = false;
+
if (__detail::__get_executor(__first, __last, __m, __re, __flags)
->_M_search())
{
@@ -2677,7 +2707,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
regex_iterator<_Bi_iter, _Ch_type, _Rx_traits>::
operator++()
{
- // FIXME: In all cases in which the call to regex_search returns true,
+ // In all cases in which the call to regex_search returns true,
// match.prefix().first shall be equal to the previous value of
// match[0].second, and for each index i in the half-open range
// [0, match.size()) for which match[i].matched is true,
@@ -2697,12 +2727,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (regex_search(__start, _M_end, _M_match, *_M_pregex, _M_flags
| regex_constants::match_not_null
| regex_constants::match_continuous))
- return *this;
+ {
+ _M_match._M_in_iterator = true;
+ _M_match._M_begin = _M_begin;
+ return *this;
+ }
else
++__start;
}
_M_flags |= regex_constants::match_prev_avail;
- if (!regex_search(__start, _M_end, _M_match, *_M_pregex, _M_flags))
+ if (regex_search(__start, _M_end, _M_match, *_M_pregex, _M_flags))
+ {
+ _M_match._M_in_iterator = true;
+ _M_match._M_begin = _M_begin;
+ }
+ else
_M_match = value_type();
}
return *this;
OpenPOWER on IntegriCloud