// class template regex -*- C++ -*-
-// Copyright (C) 2013 Free Software Foundation, Inc.
+// Copyright (C) 2013-2014 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
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
- template<typename _FwdIter, typename _CharT, typename _TraitsT>
- _Compiler<_FwdIter, _CharT, _TraitsT>::
+ template<typename _FwdIter, typename _TraitsT>
+ _Compiler<_FwdIter, _TraitsT>::
_Compiler(_FwdIter __b, _FwdIter __e,
const _TraitsT& __traits, _FlagT __flags)
: _M_flags((__flags
? __flags
: __flags | regex_constants::ECMAScript),
_M_traits(__traits),
+ _M_ctype(std::use_facet<_CtypeT>(_M_traits.getloc())),
_M_scanner(__b, __e, _M_flags, _M_traits.getloc()),
- _M_ctype(std::use_facet<std::ctype<_CharT>>(_M_traits.getloc())),
_M_nfa(_M_flags)
{
_StateSeqT __r(_M_nfa, _M_nfa._M_start());
_M_nfa._M_eliminate_dummy();
}
- template<typename _FwdIter, typename _CharT, typename _TraitsT>
+ template<typename _FwdIter, typename _TraitsT>
void
- _Compiler<_FwdIter, _CharT, _TraitsT>::
+ _Compiler<_FwdIter, _TraitsT>::
_M_disjunction()
{
this->_M_alternative();
}
}
- template<typename _FwdIter, typename _CharT, typename _TraitsT>
+ template<typename _FwdIter, typename _TraitsT>
void
- _Compiler<_FwdIter, _CharT, _TraitsT>::
+ _Compiler<_FwdIter, _TraitsT>::
_M_alternative()
{
if (this->_M_term())
_M_stack.push(_StateSeqT(_M_nfa, _M_nfa._M_insert_dummy()));
}
- template<typename _FwdIter, typename _CharT, typename _TraitsT>
+ template<typename _FwdIter, typename _TraitsT>
bool
- _Compiler<_FwdIter, _CharT, _TraitsT>::
+ _Compiler<_FwdIter, _TraitsT>::
_M_term()
{
if (this->_M_assertion())
return false;
}
- template<typename _FwdIter, typename _CharT, typename _TraitsT>
+ template<typename _FwdIter, typename _TraitsT>
bool
- _Compiler<_FwdIter, _CharT, _TraitsT>::
+ _Compiler<_FwdIter, _TraitsT>::
_M_assertion()
{
if (_M_match_token(_ScannerT::_S_token_line_begin))
- _M_stack.push(_StateSeqT(_M_nfa, _M_nfa.
- _M_insert_line_begin()));
+ _M_stack.push(_StateSeqT(_M_nfa, _M_nfa._M_insert_line_begin()));
else if (_M_match_token(_ScannerT::_S_token_line_end))
- _M_stack.push(_StateSeqT(_M_nfa, _M_nfa.
- _M_insert_line_end()));
+ _M_stack.push(_StateSeqT(_M_nfa, _M_nfa._M_insert_line_end()));
else if (_M_match_token(_ScannerT::_S_token_word_bound))
// _M_value[0] == 'n' means it's negtive, say "not word boundary".
_M_stack.push(_StateSeqT(_M_nfa, _M_nfa.
return true;
}
- template<typename _FwdIter, typename _CharT, typename _TraitsT>
+ template<typename _FwdIter, typename _TraitsT>
void
- _Compiler<_FwdIter, _CharT, _TraitsT>::
+ _Compiler<_FwdIter, _TraitsT>::
_M_quantifier()
{
bool __neg = (_M_flags & regex_constants::ECMAScript);
__throw_regex_error(regex_constants::error_badbrace);
_StateSeqT __r(_M_pop());
_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;
- int __n;
+ long __n;
// {3
if (_M_match_token(_ScannerT::_S_token_comma))
__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());
if (__infi)
// "match less" one. Switch _M_alt and _M_next of all created
// nodes. This is a hacking but IMO works well.
std::stack<_StateIdT> __stack;
- for (int __i = 0; __i < __n; ++__i)
+ for (long __i = 0; __i < __n; ++__i)
{
auto __tmp = __r._M_clone();
auto __alt = _M_nfa._M_insert_alt(__tmp._M_start,
}
}
- template<typename _FwdIter, typename _CharT, typename _TraitsT>
+ template<typename _FwdIter, typename _TraitsT>
bool
- _Compiler<_FwdIter, _CharT, _TraitsT>::
+ _Compiler<_FwdIter, _TraitsT>::
_M_atom()
{
if (_M_match_token(_ScannerT::_S_token_anychar))
_M_stack.push(_StateSeqT(_M_nfa,
_M_nfa._M_insert_matcher
- (_AnyMatcher<_CharT, _TraitsT>(_M_traits))));
+ (_AnyMatcher<_TraitsT>(_M_traits))));
else if (_M_try_char())
_M_stack.push(_StateSeqT(_M_nfa,
_M_nfa._M_insert_matcher
- (_CharMatcher<_CharT, _TraitsT>(_M_value[0],
+ (_CharMatcher<_TraitsT>(_M_value[0],
_M_traits,
_M_flags))));
else if (_M_match_token(_ScannerT::_S_token_backref))
_M_traits, _M_flags);
__matcher._M_add_character_class(_M_value);
_M_stack.push(_StateSeqT(_M_nfa,
- _M_nfa._M_insert_matcher(__matcher)));
+ _M_nfa._M_insert_matcher(std::move(__matcher))));
}
else if (_M_match_token(_ScannerT::_S_token_subexpr_no_group_begin))
{
}
else if (_M_match_token(_ScannerT::_S_token_subexpr_begin))
{
- int __mark = _M_nfa._M_sub_count();
_StateSeqT __r(_M_nfa, _M_nfa._M_insert_subexpr_begin());
this->_M_disjunction();
if (!_M_match_token(_ScannerT::_S_token_subexpr_end))
return true;
}
- template<typename _FwdIter, typename _CharT, typename _TraitsT>
+ template<typename _FwdIter, typename _TraitsT>
bool
- _Compiler<_FwdIter, _CharT, _TraitsT>::
+ _Compiler<_FwdIter, _TraitsT>::
_M_bracket_expression()
{
bool __neg =
_BMatcherT __matcher(__neg, _M_traits, _M_flags);
while (!_M_match_token(_ScannerT::_S_token_bracket_end))
_M_expression_term(__matcher);
- _M_stack.push(_StateSeqT(_M_nfa, _M_nfa._M_insert_matcher(__matcher)));
+ _M_stack.push(_StateSeqT(_M_nfa,
+ _M_nfa._M_insert_matcher(std::move(__matcher))));
return true;
}
- template<typename _FwdIter, typename _CharT, typename _TraitsT>
+ template<typename _FwdIter, typename _TraitsT>
void
- _Compiler<_FwdIter, _CharT, _TraitsT>::
+ _Compiler<_FwdIter, _TraitsT>::
_M_expression_term(_BMatcherT& __matcher)
{
if (_M_match_token(_ScannerT::_S_token_collsymbol))
__throw_regex_error(regex_constants::error_brack);
}
- template<typename _FwdIter, typename _CharT, typename _TraitsT>
+ template<typename _FwdIter, typename _TraitsT>
bool
- _Compiler<_FwdIter, _CharT, _TraitsT>::
+ _Compiler<_FwdIter, _TraitsT>::
_M_try_char()
{
bool __is_char = false;
return __is_char;
}
- template<typename _FwdIter, typename _CharT, typename _TraitsT>
+ template<typename _FwdIter, typename _TraitsT>
bool
- _Compiler<_FwdIter, _CharT, _TraitsT>::
+ _Compiler<_FwdIter, _TraitsT>::
_M_match_token(_TokenT token)
{
if (token == _M_scanner._M_get_token())
return false;
}
- template<typename _FwdIter, typename _CharT, typename _TraitsT>
+ template<typename _FwdIter, typename _TraitsT>
int
- _Compiler<_FwdIter, _CharT, _TraitsT>::
+ _Compiler<_FwdIter, _TraitsT>::
_M_cur_int_value(int __radix)
{
- int __v = 0;
+ long __v = 0;
for (typename _StringT::size_type __i = 0;
__i < _M_value.length(); ++__i)
__v =__v * __radix + _M_traits.value(_M_value[__i], __radix);
return __v;
}
- template<typename _CharT, typename _TraitsT>
- bool _BracketMatcher<_CharT, _TraitsT>::
- operator()(_CharT __ch) const
+ template<typename _TraitsT>
+ bool
+ _BracketMatcher<_TraitsT>::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
{