merged changes in regex5 branch

[SVN r26692]
This commit is contained in:
John Maddock
2005-01-13 17:06:21 +00:00
parent de0ab9092a
commit 71a0e020e2
275 changed files with 37305 additions and 27154 deletions

View File

@ -40,10 +40,10 @@ struct saved_state
{
union{
unsigned int id;
// these ensure that this struct gets the same alignment as derived structs:
void* padding1;
std::size_t padding2;
std::ptrdiff_t padding3;
// this padding ensures correct alignment on 64-bit platforms:
std::size_t padding1;
std::ptrdiff_t padding2;
void* padding3;
};
saved_state(unsigned i) : id(i) {}
};
@ -109,44 +109,47 @@ struct save_state_init
template <class BidiIterator>
struct saved_single_repeat : public saved_state
{
unsigned count;
std::size_t count;
const re_repeat* rep;
BidiIterator last_position;
saved_single_repeat(unsigned c, const re_repeat* r, BidiIterator lp, int arg_id)
saved_single_repeat(std::size_t c, const re_repeat* r, BidiIterator lp, int arg_id)
: saved_state(arg_id), count(c), rep(r), last_position(lp){}
};
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_all_states()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_all_states()
{
static matcher_proc_type const s_match_vtable[26] =
static matcher_proc_type const s_match_vtable[29] =
{
(&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark),
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_endmark,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_literal,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_start_line,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_end_line,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_wild,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_match,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_boundary,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_within_word,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_start,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_start,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_backref,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_jump,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_combining,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_soft_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_restart_continue,
(::boost::is_random_access_iterator<BidiIterator>::value ? &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_fast : &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_slow),
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_repeat,
(&perl_matcher<BidiIterator, Allocator, traits>::match_startmark),
&perl_matcher<BidiIterator, Allocator, traits>::match_endmark,
&perl_matcher<BidiIterator, Allocator, traits>::match_literal,
&perl_matcher<BidiIterator, Allocator, traits>::match_start_line,
&perl_matcher<BidiIterator, Allocator, traits>::match_end_line,
&perl_matcher<BidiIterator, Allocator, traits>::match_wild,
&perl_matcher<BidiIterator, Allocator, traits>::match_match,
&perl_matcher<BidiIterator, Allocator, traits>::match_word_boundary,
&perl_matcher<BidiIterator, Allocator, traits>::match_within_word,
&perl_matcher<BidiIterator, Allocator, traits>::match_word_start,
&perl_matcher<BidiIterator, Allocator, traits>::match_word_end,
&perl_matcher<BidiIterator, Allocator, traits>::match_buffer_start,
&perl_matcher<BidiIterator, Allocator, traits>::match_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits>::match_backref,
&perl_matcher<BidiIterator, Allocator, traits>::match_long_set,
&perl_matcher<BidiIterator, Allocator, traits>::match_set,
&perl_matcher<BidiIterator, Allocator, traits>::match_jump,
&perl_matcher<BidiIterator, Allocator, traits>::match_alt,
&perl_matcher<BidiIterator, Allocator, traits>::match_rep,
&perl_matcher<BidiIterator, Allocator, traits>::match_combining,
&perl_matcher<BidiIterator, Allocator, traits>::match_soft_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits>::match_restart_continue,
(::boost::is_random_access_iterator<BidiIterator>::value ? &perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_fast : &perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_slow),
&perl_matcher<BidiIterator, Allocator, traits>::match_char_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::match_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::match_long_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::match_backstep,
&perl_matcher<BidiIterator, Allocator, traits>::match_assert_backref,
&perl_matcher<BidiIterator, Allocator, traits>::match_toggle_case,
};
push_recursion_stopper();
@ -158,8 +161,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_all_states
if(!(this->*proc)())
{
if(state_count > max_state_count)
raise_error(traits_inst, REG_ESPACE);
if((m_match_flags & match_partial) && (position == last))
raise_error(traits_inst, regex_constants::error_space);
if((m_match_flags & match_partial) && (position == last) && (position != search_base))
m_has_partial_match = true;
if(false == unwind(false))
return m_recursive_result;
@ -169,8 +172,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_all_states
return m_recursive_result;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::extend_stack()
template <class BidiIterator, class Allocator, class traits>
void perl_matcher<BidiIterator, Allocator, traits>::extend_stack()
{
if(used_block_count)
{
@ -186,11 +189,11 @@ void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::extend_stack()
m_backup_state = block;
}
else
raise_error(traits_inst, REG_E_MEMORY);
raise_error(traits_inst, regex_constants::error_size);
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_matched_paren(int index, const sub_match<BidiIterator>& sub)
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_matched_paren(int index, const sub_match<BidiIterator>& sub)
{
assert(index);
saved_matched_paren<BidiIterator>* pmp = static_cast<saved_matched_paren<BidiIterator>*>(m_backup_state);
@ -205,8 +208,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_matc
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_recursion_stopper()
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_recursion_stopper()
{
saved_state* pmp = m_backup_state;
--pmp;
@ -220,8 +223,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_recu
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_assertion(const re_syntax_base* ps, bool positive)
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_assertion(const re_syntax_base* ps, bool positive)
{
saved_assertion<BidiIterator>* pmp = static_cast<saved_assertion<BidiIterator>*>(m_backup_state);
--pmp;
@ -235,8 +238,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_asse
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_alt(const re_syntax_base* ps)
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_alt(const re_syntax_base* ps)
{
saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
--pmp;
@ -250,8 +253,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_alt(
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_non_greedy_repeat(const re_syntax_base* ps)
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_non_greedy_repeat(const re_syntax_base* ps)
{
saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
--pmp;
@ -265,8 +268,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_non_
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_repeater_count(int i, repeater_count<BidiIterator>** s)
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_repeater_count(int i, repeater_count<BidiIterator>** s)
{
saved_repeater<BidiIterator>* pmp = static_cast<saved_repeater<BidiIterator>*>(m_backup_state);
--pmp;
@ -280,8 +283,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_repe
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_single_repeat(unsigned c, const re_repeat* r, BidiIterator last_position, int id)
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_single_repeat(std::size_t c, const re_repeat* r, BidiIterator last_position, int id)
{
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
--pmp;
@ -295,8 +298,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_sing
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_startmark()
{
int index = static_cast<const re_brace*>(pstate)->index;
switch(index)
@ -316,10 +319,13 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark(
case -3:
{
// independent sub-expression, currently this is always recursive:
bool old_independent = m_independent;
m_independent = true;
const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
pstate = pstate->next.p->next.p;
bool r = match_all_states();
pstate = next_pstate;
m_independent = old_independent;
#ifdef BOOST_REGEX_MATCH_EXTRA
if(r && (m_match_flags & match_extra))
{
@ -349,6 +355,37 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark(
#endif
return r;
}
case -4:
{
// conditional expression:
const re_alt* alt = static_cast<const re_alt*>(pstate->next.p);
BOOST_ASSERT(alt->type == syntax_element_alt);
pstate = alt->next.p;
if(pstate->type == syntax_element_assert_backref)
{
if(!match_assert_backref())
pstate = alt->alt.p;
break;
}
else
{
// zero width assertion, have to match this recursively:
BOOST_ASSERT(pstate->type == syntax_element_startmark);
bool negated = static_cast<const re_brace*>(pstate)->index == -2;
BidiIterator saved_position = position;
const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
pstate = pstate->next.p->next.p;
bool r = match_all_states();
position = saved_position;
if(negated)
r = !r;
if(r)
pstate = next_pstate;
else
pstate = alt->alt.p;
break;
}
}
default:
{
assert(index > 0);
@ -364,11 +401,11 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark(
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_alt()
{
bool take_first, take_second;
const re_jump* jmp = static_cast<const re_jump*>(pstate);
const re_alt* jmp = static_cast<const re_alt*>(pstate);
// find out which of these two alternatives we need to take:
if(position == last)
@ -378,8 +415,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
}
else
{
take_first = access::can_start(*position, jmp->_map, (unsigned char)mask_take);
take_second = access::can_start(*position, jmp->_map, (unsigned char)mask_skip);
take_first = can_start(*position, jmp->_map, (unsigned char)mask_take);
take_second = can_start(*position, jmp->_map, (unsigned char)mask_skip);
}
if(take_first)
@ -401,8 +438,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
return false; // neither option is possible
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_rep()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -422,8 +459,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
}
else
{
take_first = access::can_start(*position, rep->_map, (unsigned char)mask_take);
take_second = access::can_start(*position, rep->_map, (unsigned char)mask_skip);
take_first = can_start(*position, rep->_map, (unsigned char)mask_take);
take_second = can_start(*position, rep->_map, (unsigned char)mask_skip);
}
if(take_first || (next_count->get_id() != rep->id))
@ -452,7 +489,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
return false;
}
if(rep->greedy)
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
if(greedy)
{
// try and take the repeat if we can:
if((next_count->get_count() < rep->max) && take_first)
@ -501,8 +539,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_slow()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_slow()
{
unsigned count = 0;
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
@ -515,7 +553,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
return false;
++count;
}
if(rep->greedy)
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
if(greedy)
{
// repeat for as long as we can:
while(count < rep->max)
@ -541,18 +580,21 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
if(count < rep->max)
push_single_repeat(count, rep, position, saved_state_rep_slow_dot);
pstate = rep->alt.p;
return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
}
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_fast()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_fast()
{
if(m_match_flags & (match_not_dot_newline | match_not_dot_null))
if(m_match_flags & match_not_dot_null)
return match_dot_repeat_slow();
if((static_cast<const re_dot*>(pstate->next.p)->mask & match_any_mask) == 0)
return match_dot_repeat_slow();
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
unsigned count = (std::min)(static_cast<unsigned>(re_detail::distance(position, last)), static_cast<unsigned>(rep->greedy ? rep->max : rep->min));
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
unsigned count = static_cast<unsigned>((std::min)(static_cast<unsigned>(::boost::re_detail::distance(position, last)), static_cast<unsigned>(greedy ? rep->max : rep->min)));
if(rep->min > count)
{
position = last;
@ -560,7 +602,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
}
std::advance(position, count);
if(rep->greedy)
if(greedy)
{
if((rep->leading) && (count < rep->max))
restart = position;
@ -577,12 +619,12 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
if(count < rep->max)
push_single_repeat(count, rep, position, saved_state_rep_fast_dot);
pstate = rep->alt.p;
return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
}
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repeat()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_char_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -594,21 +636,22 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
assert(1 == static_cast<const re_literal*>(rep->next.p)->length);
const char_type what = *reinterpret_cast<const char_type*>(static_cast<const re_literal*>(rep->next.p) + 1);
unsigned count = 0;
std::size_t count = 0;
//
// start by working out how much we can skip:
//
unsigned desired = rep->greedy ? rep->max : rep->min;
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t desired = greedy ? rep->max : rep->min;
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
BidiIterator origin(position);
while((position != end) && (traits_inst.translate(*position, icase) == what))
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
count = (unsigned)::boost::re_detail::distance(origin, position);
}
else
{
@ -622,7 +665,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
if(count < rep->min)
return false;
if(rep->greedy)
if(greedy)
{
if((rep->leading) && (count < rep->max))
restart = position;
@ -639,7 +682,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
if(count < rep->max)
push_single_repeat(count, rep, position, saved_state_rep_char);
pstate = rep->alt.p;
return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
}
#ifdef __BORLANDC__
#pragma option pop
@ -649,8 +692,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_set_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -661,25 +704,26 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
#endif
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
const unsigned char* map = static_cast<const re_set*>(rep->next.p)->_map;
unsigned count = 0;
std::size_t count = 0;
//
// start by working out how much we can skip:
//
unsigned desired = rep->greedy ? rep->max : rep->min;
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t desired = greedy ? rep->max : rep->min;
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
BidiIterator origin(position);
while((position != end) && map[(traits_uchar_type)traits_inst.translate(*position, icase)])
while((position != end) && map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
count = (unsigned)::boost::re_detail::distance(origin, position);
}
else
{
while((count < desired) && (position != last) && map[(traits_uchar_type)traits_inst.translate(*position, icase)])
while((count < desired) && (position != last) && map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
++position;
++count;
@ -689,7 +733,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
if(count < rep->min)
return false;
if(rep->greedy)
if(greedy)
{
if((rep->leading) && (count < rep->max))
restart = position;
@ -706,7 +750,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
if(count < rep->max)
push_single_repeat(count, rep, position, saved_state_rep_short_set);
pstate = rep->alt.p;
return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
}
#ifdef __BORLANDC__
#pragma option pop
@ -716,8 +760,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_repeat()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_long_set_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -726,27 +770,29 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
#ifdef __BORLANDC__
#pragma option push -w-8008 -w-8066 -w-8004
#endif
typedef typename traits::char_class_type mask_type;
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
const re_set_long* set = static_cast<const re_set_long*>(pstate->next.p);
unsigned count = 0;
const re_set_long<mask_type>* set = static_cast<const re_set_long<mask_type>*>(pstate->next.p);
std::size_t count = 0;
//
// start by working out how much we can skip:
//
unsigned desired = rep->greedy ? rep->max : rep->min;
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t desired = greedy ? rep->max : rep->min;
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
BidiIterator origin(position);
while((position != end) && (position != re_is_set_member(position, last, set, re)))
while((position != end) && (position != re_is_set_member(position, last, set, re.get_data(), icase)))
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
count = (unsigned)::boost::re_detail::distance(origin, position);
}
else
{
while((count < desired) && (position != last) && (position != re_is_set_member(position, last, set, re)))
while((count < desired) && (position != last) && (position != re_is_set_member(position, last, set, re.get_data(), icase)))
{
++position;
++count;
@ -756,7 +802,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
if(count < rep->min)
return false;
if(rep->greedy)
if(greedy)
{
if((rep->leading) && (count < rep->max))
restart = position;
@ -773,7 +819,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
if(count < rep->max)
push_single_repeat(count, rep, position, saved_state_rep_long_set);
pstate = rep->alt.p;
return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
}
#ifdef __BORLANDC__
#pragma option pop
@ -790,25 +836,25 @@ unwinding does in the recursive implementation.
****************************************************************************/
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind(bool have_match)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind(bool have_match)
{
static unwind_proc_type const s_unwind_table[14] =
{
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_paren,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_recursion_stopper,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_assertion,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_alt,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_repeater_counter,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_extra_block,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_greedy_single_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_non_greedy_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_end,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_paren,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_recursion_stopper,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_assertion,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_alt,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_repeater_counter,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_extra_block,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_greedy_single_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_slow_dot_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_fast_dot_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_char_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_short_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_long_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_non_greedy_repeat,
};
m_recursive_result = have_match;
@ -828,15 +874,15 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind(bool have
return pstate ? true : false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_end(bool)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_end(bool)
{
pstate = 0; // nothing left to search
return false; // end of stack nothing more to search
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_paren(bool have_match)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_paren(bool have_match)
{
saved_matched_paren<BidiIterator>* pmp = static_cast<saved_matched_paren<BidiIterator>*>(m_backup_state);
// restore previous values if no match was found:
@ -858,16 +904,16 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_paren(boo
return true; // keep looking
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_recursion_stopper(bool)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_recursion_stopper(bool)
{
boost::re_detail::inplace_destroy(m_backup_state++);
pstate = 0; // nothing left to search
return false; // end of stack nothing more to search
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_assertion(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_assertion(bool r)
{
saved_assertion<BidiIterator>* pmp = static_cast<saved_assertion<BidiIterator>*>(m_backup_state);
pstate = pmp->pstate;
@ -879,8 +925,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_assertion
return !result; // return false if the assertion was matched to stop search.
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_alt(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_alt(bool r)
{
saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
if(!r)
@ -893,8 +939,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_alt(bool
return r;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_repeater_counter(bool)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_repeater_counter(bool)
{
saved_repeater<BidiIterator>* pmp = static_cast<saved_repeater<BidiIterator>*>(m_backup_state);
boost::re_detail::inplace_destroy(pmp++);
@ -902,8 +948,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_repeater_
return true; // keep looking
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_extra_block(bool)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_extra_block(bool)
{
saved_extra_block* pmp = static_cast<saved_extra_block*>(m_backup_state);
void* condemmed = m_stack_base;
@ -914,16 +960,16 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_extra_blo
return true; // keep looking
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::destroy_single_repeat()
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::destroy_single_repeat()
{
saved_single_repeat<BidiIterator>* p = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
boost::re_detail::inplace_destroy(p++);
m_backup_state = p;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_greedy_single_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_greedy_single_repeat(bool r)
{
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
@ -935,7 +981,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_greedy_si
}
const re_repeat* rep = pmp->rep;
unsigned count = pmp->count;
std::size_t count = pmp->count;
assert(rep->next.p != 0);
assert(rep->alt.p != 0);
@ -953,13 +999,13 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_greedy_si
--position;
--count;
++state_count;
}while(count && !access::can_start(*position, rep->_map, mask_skip));
}while(count && !can_start(*position, rep->_map, mask_skip));
// if we've hit base, destroy this state:
if(count == 0)
{
destroy_single_repeat();
if(!access::can_start(*position, rep->_map, mask_skip))
if(!can_start(*position, rep->_map, mask_skip))
return true;
}
else
@ -971,8 +1017,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_greedy_si
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_slow_dot_repeat(bool r)
{
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
@ -984,7 +1030,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_
}
const re_repeat* rep = pmp->rep;
unsigned count = pmp->count;
std::size_t count = pmp->count;
assert(rep->type == syntax_element_dot_rep);
assert(rep->next.p != 0);
assert(rep->alt.p != 0);
@ -1008,7 +1054,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_
++count;
++state_count;
pstate = rep->next.p;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
}while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
}
if(position == last)
{
@ -1021,7 +1067,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(!access::can_start(*position, rep->_map, mask_skip))
if(!can_start(*position, rep->_map, mask_skip))
return true;
}
else
@ -1033,8 +1079,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_fast_dot_repeat(bool r)
{
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
@ -1046,7 +1092,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_
}
const re_repeat* rep = pmp->rep;
unsigned count = pmp->count;
std::size_t count = pmp->count;
assert(count < rep->max);
position = pmp->last_position;
@ -1059,7 +1105,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_
++position;
++count;
++state_count;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
}while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
}
if(position == last)
@ -1073,7 +1119,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(!access::can_start(*position, rep->_map, mask_skip))
if(!can_start(*position, rep->_map, mask_skip))
return true;
}
else
@ -1085,8 +1131,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_char_repeat(bool r)
{
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
@ -1098,7 +1144,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repe
}
const re_repeat* rep = pmp->rep;
unsigned count = pmp->count;
std::size_t count = pmp->count;
pstate = rep->next.p;
const char_type what = *reinterpret_cast<const char_type*>(static_cast<const re_literal*>(pstate) + 1);
position = pmp->last_position;
@ -1124,7 +1170,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repe
++ position;
++state_count;
pstate = rep->next.p;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
}while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
}
if(position == last)
{
@ -1137,7 +1183,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repe
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(!access::can_start(*position, rep->_map, mask_skip))
if(!can_start(*position, rep->_map, mask_skip))
return true;
}
else
@ -1149,8 +1195,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repe
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_short_set_repeat(bool r)
{
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
@ -1162,7 +1208,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set
}
const re_repeat* rep = pmp->rep;
unsigned count = pmp->count;
std::size_t count = pmp->count;
pstate = rep->next.p;
const unsigned char* map = static_cast<const re_set*>(rep->next.p)->_map;
position = pmp->last_position;
@ -1178,7 +1224,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set
// wind forward until we can skip out of the repeat:
do
{
if(!map[(traits_uchar_type)traits_inst.translate(*position, icase)])
if(!map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
// failed repeat match, discard this state and look for another:
destroy_single_repeat();
@ -1188,7 +1234,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set
++ position;
++state_count;
pstate = rep->next.p;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
}while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
}
if(position == last)
{
@ -1201,7 +1247,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(!access::can_start(*position, rep->_map, mask_skip))
if(!can_start(*position, rep->_map, mask_skip))
return true;
}
else
@ -1213,9 +1259,10 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_long_set_repeat(bool r)
{
typedef typename traits::char_class_type mask_type;
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
// if we have a match, just discard this state:
@ -1226,16 +1273,15 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_
}
const re_repeat* rep = pmp->rep;
unsigned count = pmp->count;
std::size_t count = pmp->count;
pstate = rep->next.p;
const re_set_long* set = static_cast<const re_set_long*>(pstate);
const re_set_long<mask_type>* set = static_cast<const re_set_long<mask_type>*>(pstate);
position = pmp->last_position;
assert(rep->type == syntax_element_long_set_rep);
assert(rep->next.p != 0);
assert(rep->alt.p != 0);
assert(rep->next.p->type == syntax_element_long_set);
assert(position != last);
assert(count < rep->max);
if(position != last)
@ -1243,7 +1289,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_
// wind forward until we can skip out of the repeat:
do
{
if(position == re_is_set_member(position, last, set, re))
if(position == re_is_set_member(position, last, set, re.get_data(), icase))
{
// failed repeat match, discard this state and look for another:
destroy_single_repeat();
@ -1253,7 +1299,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_
++count;
++state_count;
pstate = rep->next.p;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
}while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
}
if(position == last)
{
@ -1266,7 +1312,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(!access::can_start(*position, rep->_map, mask_skip))
if(!can_start(*position, rep->_map, mask_skip))
return true;
}
else
@ -1278,8 +1324,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_non_greedy_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_non_greedy_repeat(bool r)
{
saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
if(!r)